1
- import { RpsContext , RpsModule , rpsAction } from 'rpscript-interface' ;
1
+ import { RpsContext , RpsModule , rpsAction , R } from 'rpscript-interface' ;
2
2
import { EventEmitter } from 'events' ;
3
- import * as math from '../libs/mathjs/math.min' ;
4
3
5
4
/** Basic utility for rpscript. Contain basic operation such as condition, event listening, variable assignment, terminal print etc.
6
5
* @namespace Basic
@@ -159,39 +158,6 @@ export default class RPSBasic {
159
158
} ) ;
160
159
}
161
160
162
- /**
163
- * @function eval
164
- * @memberof Basic
165
- * @example
166
- * ;wait for 5 second
167
- * eval '1 + 2'
168
- *
169
- * @param {string } alegbra The alegbra to apply.
170
- * @returns {* } result of the calculation.
171
- * @summary Evaluate a mathematical equation.
172
- *
173
- */
174
- @rpsAction ( { verbName :'eval' } )
175
- async evaluate ( ctx :RpsContext , opts :Object , expression :string , ...args :any [ ] ) : Promise < any > {
176
- let retFn = opts [ 'function' ] ;
177
- let expr = math . compile ( expression ) ;
178
-
179
- let objArg = this . argMapToObj ( args ) ;
180
- var that = this ;
181
-
182
- let lateFn = function ( ...fnargs :any [ ] ) {
183
- let allArgs = args . concat ( fnargs ) ;
184
- let objArg = that . argMapToObj ( allArgs ) ;
185
-
186
- return expr . eval ( objArg ) ;
187
- }
188
- <
9E88
/div>
189
- if ( retFn === true ) return lateFn ;
190
- else if ( retFn === false ) return expr . eval ( objArg ) ;
191
- else if ( objArg ) return expr . eval ( objArg ) ;
192
- else return lateFn ;
193
- }
194
-
195
161
/**
196
162
* @function abs
197
163
* @memberof Basic
@@ -204,8 +170,8 @@ export default class RPSBasic {
204
170
*
205
171
*/
206
172
@rpsAction ( { verbName :'abs' } )
207
- async abs ( ctx :RpsContext , opts :{ } , num :number ) : Promise < number > {
208
- return Math . abs ( num ) ;
173
+ async abs ( ctx :RpsContext , opts :{ } , ... args :number [ ] ) : Promise < number | Function > {
174
+ return R . apply ( R . curry ( Math . abs ) , args ) ;
209
175
}
210
176
/**
211
177
* @function ceil
@@ -219,8 +185,8 @@ async abs (ctx:RpsContext,opts:{}, num:number) : Promise<number>{
219
185
*
220
186
*/
221
187
@rpsAction ( { verbName :'ceil' } )
222
- async ceil ( ctx :RpsContext , opts :{ } , num :number ) : Promise < number > {
223
- return Math . ceil ( num ) ;
188
+ async ceil ( ctx :RpsContext , opts :{ } , ... args :number [ ] ) : Promise < number | Function > {
189
+ return R . apply ( R . curry ( Math . ceil ) , args ) ;
224
190
}
225
191
/**
226
192
* @function max
@@ -233,9 +199,9 @@ async ceil (ctx:RpsContext,opts:{}, num:number) : Promise<number>{
233
199
* @returns {number } number.
234
200
*
235
201
*/
236
- @rpsAction ( { verbName :'max' } )
202
+ @rpsAction ( { verbName :'math- max' } )
237
203
async max ( ctx :RpsContext , opts :{ } , ...num :number [ ] ) : Promise < number > {
238
- return Math . max . apply ( this , num ) ;
204
+ return R . apply ( R . curryN ( 2 , Math . max ) , num ) ;
239
205
}
240
206
/**
241
207
* @function min
@@ -248,9 +214,9 @@ async max (ctx:RpsContext,opts:{}, ...num:number[]) : Promise<number>{
248
214
* @returns {number } number.
249
215
*
250
216
*/
251
- @rpsAction ( { verbName :'min' } )
217
+ @rpsAction ( { verbName :'math- min' } )
252
218
async min ( ctx :RpsContext , opts :{ } , ...num :number [ ] ) : Promise < number > {
253
- return Math . min . apply ( this , num ) ;
219
+ return R . apply ( R . curryN ( 2 , Math . min ) , num ) ;
254
220
}
255
221
/**
256
222
* @function floor
@@ -264,8 +230,8 @@ async min (ctx:RpsContext,opts:{}, ...num:number[]) : Promise<number>{
264
230
*
265
231
*/
266
232
@rpsAction ( { verbName :'floor' } )
267
- async floor ( ctx :RpsContext , opts :{ } , num :number ) : Promise < number > {
268
- return Math . floor ( num ) ;
233
+ async floor ( ctx :RpsContext , opts :{ } , ... num :number [ ] ) : Promise < number > {
234
+ return R . apply ( R . curry ( Math . floor ) , num ) ;
269
235
}
270
236
/**
271
237
* @function power
@@ -280,8 +246,8 @@ async floor (ctx:RpsContext,opts:{}, num:number) : Promise<number>{
280
246
*
281
247
*/
282
248
@rpsAction ( { verbName :'pow' } )
283
- async power ( ctx :RpsContext , opts :{ } , x :number , y : number ) : Promise < number > {
284
- return Math . pow ( x , y ) ;
249
+ async power ( ctx :RpsContext , opts :{ } , ... args :number [ ] ) : Promise < number | Function > {
250
+ return R . apply ( R . curry ( Math . pow ) , args ) ;
285
251
}
286
252
/**
287
253
* @function random
@@ -309,7 +275,7 @@ async random (ctx:RpsContext,opts:{}) : Promise<number>{
309
275
*/
310
276
@rpsAction ( { verbName :'round' } )
311
277
async round ( ctx :RpsContext , opts :{ } , num :number ) : Promise < number > {
312
- return Math . round ( num ) ;
278
+ return R . apply ( R . curry ( Math . round ) , num ) ;
313
279
}
314
280
/**
315
281
* @function trunc
@@ -323,7 +289,7 @@ async round (ctx:RpsContext,opts:{},num:number) : Promise<number>{
323
289
*/
324
290
@rpsAction ( { verbName :'trunc' } )
325
291
async trunc ( ctx :RpsContext , opts :{ } , num :number ) : Promise < number > {
326
- return Math . trunc ( num ) ;
292
+ return R . apply ( R . curry ( Math . trunc ) , num ) ;
327
293
}
328
294
329
295
private argMapToObj ( args :any [ ] ) : Object {
0 commit comments