File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,28 @@ export interface LoomConfig<
88 TInputSchema extends z . ZodType ,
99 TOptionsSchema extends z . ZodType ,
1010> {
11+ /**
12+ * The schema of the input data.
13+ */
1114 inputSchema : TInputSchema ;
15+
16+ /**
17+ * The schema of the options.
18+ */
1219 optionsSchema : TOptionsSchema ;
20+
21+ /**
22+ * The template function.
23+ */
1324 template : (
1425 ctx : LoomContext < TOptionsSchema > ,
1526 item : TInputSchema [ "_input" ]
1627 ) => string ;
28+
29+ /**
30+ * The predicate function.
31+ */
32+ predicate ?: ( ctx : LoomContext < TOptionsSchema > , item : TInputSchema [ "_input" ] ) => boolean ;
1733}
1834
1935export interface LoomInstance <
@@ -43,6 +59,11 @@ export function createLoom<
4359 const lines : string [ ] = [ ] ;
4460
4561 for ( const item of validatedInput ) {
62+ // if predicate is defined, and returns false, skip this item
63+ if ( config . predicate && ! config . predicate ( ctx , item ) ) {
64+ continue ;
65+ }
66+
4667 lines . push ( config . template ( ctx , item ) ) ;
4768 }
4869
You can’t perform that action at this time.
0 commit comments