@@ -15,6 +15,7 @@ import { selectKeysObj } from "@thi.ng/object-utils/select-keys";
15
15
import type { ASTNode , Expression , Implementations , Sym } from "@thi.ng/sexpr" ;
16
16
import { parse } from "@thi.ng/sexpr/parse" ;
17
17
import { runtime } from "@thi.ng/sexpr/runtime" ;
18
+ import { capitalize , lower , upper } from "@thi.ng/strings/case" ;
18
19
import { KERNEL } from "./kernel.js" ;
19
20
20
21
export type Env = Record < string , any > ;
@@ -221,6 +222,23 @@ export const ENV: Env = {
221
222
// there're no further items
222
223
next : ( arg : any ) => ( arg . length > 1 ? arg . slice ( 1 ) : undefined ) ,
223
224
225
+ // strings
226
+ lower,
227
+ upper,
228
+ capitalize,
229
+ "pad-left" : ( x : string , width : number , fill : string ) =>
230
+ x . padStart ( width , fill ) ,
231
+ "pad-right" : ( x : string , width : number , fill : string ) =>
232
+ x . padEnd ( width , fill ) ,
233
+ substr : ( x : string , from : number , to ?: number ) => x . substring ( from , to ) ,
234
+ trim : ( x : string ) => x . trimEnd ( ) ,
235
+ regexp : ( src : string , flags ?: string ) => new RegExp ( src , flags ) ,
236
+ "re-test" : ( regexp : RegExp , x : string ) => regexp . test ( x ) ,
237
+ "re-match" : ( regexp : RegExp , x : string ) => regexp . exec ( x ) ,
238
+ replace : ( x : string , regexp : RegExp , replacement : string ) =>
239
+ x . replace ( regexp , replacement ) ,
240
+
241
+ // misc
224
242
print : console . log ,
225
243
226
244
env : ( ) =>
@@ -232,13 +250,13 @@ export const ENV: Env = {
232
250
} ;
233
251
234
252
/**
235
- * Evaluates given S-expression(s) and returns result of last. If no environment
236
- * is provided, uses {@link ENV}.
253
+ * Parses & evaluates given S-expression(s) and returns result of last one . If
254
+ * no environment is provided, uses {@link ENV}.
237
255
*
238
256
* @param src
239
257
* @param env
240
258
*/
241
- export const evalExpressions = ( src : string , env : Env = ENV ) =>
259
+ export const evalSource = ( src : string , env : Env = ENV ) =>
242
260
parse ( src ) . children . reduce ( ( _ , x ) => interpret ( x , env ) , < any > undefined ) ;
243
261
244
262
export const evalArgs = ( nodes : ASTNode [ ] , env : Env = ENV ) =>
@@ -252,4 +270,4 @@ export const interpret = runtime<Implementations<Env, any>, Env, any>({
252
270
} ) ;
253
271
254
272
// evaluate built-ins and inject into root env
255
- evalExpressions ( KERNEL ) ;
273
+ evalSource ( KERNEL ) ;
0 commit comments