@tslite/operators 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,165 @@
1
+ 'use strict';var parser=require('@tslite/parser');var l=n=>{let e=parser.parse(n),t={};for(let r of e.body)r.type==="TSTypeAliasDeclaration"&&r.id?.name&&r.typeAnnotation&&(t[r.id.name]=r.typeAnnotation);return t};var T=`
2
+ type identity<T> = (x: T) => T;
3
+ type always<T> = (value: T) => () => T;
4
+ type tap<T> = {
5
+ (fn: (x: T) => unknown): (x: T) => T;
6
+ (fn: (x: T) => unknown, x: T): T;
7
+ };
8
+ `;var u=`
9
+ type prop<T, K extends keyof T> = {
10
+ (key: K): (obj: T) => T[K];
11
+ (key: K, obj: T): T[K];
12
+ };
13
+ type path = {
14
+ (keys: string[]): (obj: unknown) => unknown;
15
+ (keys: string[], obj: unknown): unknown;
16
+ };
17
+ type propOr<D> = {
18
+ (def: D, key: string): (obj: unknown) => unknown;
19
+ (def: D, key: string, obj: unknown): unknown;
20
+ };
21
+ type pathOr<D> = {
22
+ (def: D, keys: string[]): (obj: unknown) => unknown;
23
+ (def: D, keys: string[], obj: unknown): unknown;
24
+ };
25
+ /* pick: afrouxado \u2014 a vers\xE3o precisa \`keys: K[]\` sofre com o alargamento de
26
+ literal em elemento de array-arg (\`["a"]\` \u2192 string[], viola K extends keyof T).
27
+ Follow-up de checker (preserva\xE7\xE3o de literal em array). Aqui: keys string[],
28
+ retorno Partial<T> (subconjunto das chaves de T \u2014 honesto e util). */
29
+ type pick<T> = {
30
+ (keys: string[]): (obj: T) => { [P in keyof T]?: T[P] };
31
+ (keys: string[], obj: T): { [P in keyof T]?: T[P] };
32
+ };
33
+ type omit<T> = {
34
+ (keys: string[]): (obj: T) => T;
35
+ (keys: string[], obj: T): T;
36
+ };
37
+ type assoc<T, V> = {
38
+ (key: string, value: V): (obj: T) => T;
39
+ (key: string, value: V, obj: T): T;
40
+ };
41
+ type merge<A, B> = {
42
+ (a: A): (b: B) => A & B;
43
+ (a: A, b: B): A & B;
44
+ };
45
+ type keys<T> = (obj: T) => (keyof T)[];
46
+ type values<T> = (obj: T) => T[keyof T][];
47
+ type entries<T> = (obj: T) => [keyof T, T[keyof T]][];
48
+ type fromEntries<V> = (pairs: [string, V][]) => { [k: string]: V };
49
+ type has<T> = {
50
+ (key: string): (obj: T) => boolean;
51
+ (key: string, obj: T): boolean;
52
+ };
53
+ type applySpec<S> = {
54
+ (spec: S): (input: unknown) => { [K in keyof S]: ReturnType<S[K]> };
55
+ (spec: S, input: unknown): { [K in keyof S]: ReturnType<S[K]> };
56
+ };
57
+ type evolve<T> = {
58
+ (transforms: { [K in keyof T]?: (value: T[K]) => T[K] }): (obj: T) => T;
59
+ (transforms: { [K in keyof T]?: (value: T[K]) => T[K] }, obj: T): T;
60
+ };
61
+ `;var c=`
62
+ type map<T, U> = {
63
+ (fn: (item: T) => U): (list: T[]) => U[];
64
+ (fn: (item: T) => U, list: T[]): U[];
65
+ };
66
+ type filter<T> = {
67
+ (pred: (item: T) => boolean): (list: T[]) => T[];
68
+ (pred: (item: T) => boolean, list: T[]): T[];
69
+ };
70
+ type find<T> = {
71
+ (pred: (item: T) => boolean): (list: T[]) => T | undefined;
72
+ (pred: (item: T) => boolean, list: T[]): T | undefined;
73
+ };
74
+ type reduce<T, A> = {
75
+ (fn: (acc: A, item: T) => A, init: A): (list: T[]) => A;
76
+ (fn: (acc: A, item: T) => A, init: A, list: T[]): A;
77
+ };
78
+ type pluck<T, K extends keyof T> = {
79
+ (key: K): (list: T[]) => T[K][];
80
+ (key: K, list: T[]): T[K][];
81
+ };
82
+ type indexBy<T> = {
83
+ (fn: (item: T) => string): (list: T[]) => { [k: string]: T };
84
+ (fn: (item: T) => string, list: T[]): { [k: string]: T };
85
+ };
86
+ type groupBy<T> = {
87
+ (fn: (item: T) => string): (list: T[]) => { [k: string]: T[] };
88
+ (fn: (item: T) => string, list: T[]): { [k: string]: T[] };
89
+ };
90
+ type uniqBy<T, U> = {
91
+ (fn: (item: T) => U): (list: T[]) => T[];
92
+ (fn: (item: T) => U, list: T[]): T[];
93
+ };
94
+ type sortBy<T, U> = {
95
+ (fn: (item: T) => U): (list: T[]) => T[];
96
+ (fn: (item: T) => U, list: T[]): T[];
97
+ };
98
+ type flatten<T> = (list: T[][]) => T[];
99
+ type includes<T> = {
100
+ (value: T): (list: T[]) => boolean;
101
+ (value: T, list: T[]): boolean;
102
+ };
103
+ type some<T> = {
104
+ (pred: (item: T) => boolean): (list: T[]) => boolean;
105
+ (pred: (item: T) => boolean, list: T[]): boolean;
106
+ };
107
+ type length<T> = (list: T[]) => number;
108
+ type sum = (list: number[]) => number;
109
+ `;var f=`
110
+ type equals<T> = {
111
+ (a: T): (b: T) => boolean;
112
+ (a: T, b: T): boolean;
113
+ };
114
+ type propEq = {
115
+ (key: string, value: unknown): (obj: unknown) => boolean;
116
+ (key: string, value: unknown, obj: unknown): boolean;
117
+ };
118
+ type whereEq = {
119
+ (spec: { [k: string]: unknown }): (obj: unknown) => boolean;
120
+ (spec: { [k: string]: unknown }, obj: unknown): boolean;
121
+ };
122
+ type ifElse<T, R> = {
123
+ (pred: (x: T) => boolean, onTrue: (x: T) => R, onFalse: (x: T) => R): (value: T) => R;
124
+ (pred: (x: T) => boolean, onTrue: (x: T) => R, onFalse: (x: T) => R, value: T): R;
125
+ };
126
+ type when<T> = {
127
+ (pred: (x: T) => boolean, fn: (x: T) => T): (value: T) => T;
128
+ (pred: (x: T) => boolean, fn: (x: T) => T, value: T): T;
129
+ };
130
+ /* cond: loose \u2014 a infer\xEAncia de T/R atrav\xE9s do tuple-array de fns aninhado n\xE3o
131
+ aterra (nem no tsc \xE9 trivial). Vanilla: value/result unknown (o switch costuma
132
+ alimentar string/label; anote o resultado se precisar). */
133
+ type cond = (
134
+ pairs: [(x: unknown) => boolean, (x: unknown) => unknown][],
135
+ ) => (value: unknown) => unknown;
136
+ type defaultTo<T> = {
137
+ (def: T): (value: T) => T;
138
+ (def: T, value: T): T;
139
+ };
140
+ type isNil = (value: unknown) => boolean;
141
+ type isEmpty = (value: unknown) => boolean;
142
+ `;var d=`
143
+ type toUpper = (str: string) => string;
144
+ type toLower = (str: string) => string;
145
+ type trim = (str: string) => string;
146
+ type split = {
147
+ (sep: string): (str: string) => string[];
148
+ (sep: string, str: string): string[];
149
+ };
150
+ type join = {
151
+ (sep: string): (list: string[]) => string;
152
+ (sep: string, list: string[]): string;
153
+ };
154
+ type template = {
155
+ (tpl: string): (data: unknown) => string;
156
+ (tpl: string, data: unknown): string;
157
+ };
158
+ `;var g=`
159
+ type toNumber = (value: unknown) => number;
160
+ type asString = (value: unknown) => string;
161
+ type toBoolean = (value: unknown) => boolean;
162
+ type parse = (text: string) => unknown;
163
+ type stringify = (value: unknown) => string;
164
+ `;var m=[T,u,c,f,d,g].join(`
165
+ `),h=l(m);var o=(n,e)=>{let t=r=>r.length>=n?e(...r.slice(0,n)):(...a)=>t([...r,...a]);return (...r)=>t(r)},p=(n,e)=>{if(n===e)return true;if(n===null||e===null||typeof n!="object"||typeof e!="object")return n===e;if(Array.isArray(n)!==Array.isArray(e))return false;let r=Object.keys(n),a=Object.keys(e);return r.length!==a.length?false:r.every(y=>p(n[y],e[y]))},s=n=>n==null,x={identity:n=>n,always:n=>()=>n,tap:o(2,(n,e)=>(n(e),e)),prop:o(2,(n,e)=>s(e)?void 0:e[n]),path:o(2,(n,e)=>n.reduce((t,r)=>s(t)?void 0:t[r],e)),propOr:o(3,(n,e,t)=>{let r=s(t)?void 0:t[e];return s(r)?n:r}),pathOr:o(3,(n,e,t)=>{let r=e.reduce((a,y)=>s(a)?void 0:a[y],t);return s(r)?n:r}),pick:o(2,(n,e)=>{let t={};if(!s(e))for(let r of n)r in e&&(t[r]=e[r]);return t}),omit:o(2,(n,e)=>{let t=new Set(n),r={};for(let a in e)t.has(a)||(r[a]=e[a]);return r}),assoc:o(3,(n,e,t)=>({...t,[n]:e})),merge:o(2,(n,e)=>({...n,...e})),keys:n=>Object.keys(n??{}),values:n=>Object.values(n??{}),entries:n=>Object.entries(n??{}),fromEntries:n=>Object.fromEntries(n),has:o(2,(n,e)=>!s(e)&&Object.prototype.hasOwnProperty.call(e,n)),applySpec:o(2,(n,e)=>{let t={};for(let r in n)t[r]=n[r](e);return t}),evolve:o(2,(n,e)=>{let t={...e};for(let r in n)r in t&&(t[r]=n[r](t[r]));return t}),map:o(2,(n,e)=>e.map(t=>n(t))),filter:o(2,(n,e)=>e.filter(t=>n(t))),find:o(2,(n,e)=>e.find(t=>n(t))),reduce:o(3,(n,e,t)=>t.reduce((r,a)=>n(r,a),e)),pluck:o(2,(n,e)=>e.map(t=>s(t)?void 0:t[n])),indexBy:o(2,(n,e)=>{let t={};for(let r of e)t[n(r)]=r;return t}),groupBy:o(2,(n,e)=>{var r;let t={};for(let a of e)(t[r=n(a)]??(t[r]=[])).push(a);return t}),uniqBy:o(2,(n,e)=>{let t=new Set,r=[];for(let a of e){let y=n(a);t.has(y)||(t.add(y),r.push(a));}return r}),sortBy:o(2,(n,e)=>[...e].sort((t,r)=>{let a=n(t),y=n(r);return a<y?-1:a>y?1:0})),flatten:n=>n.reduce((e,t)=>e.concat(t),[]),includes:o(2,(n,e)=>e.some(t=>p(t,n))),some:o(2,(n,e)=>e.some(t=>n(t))),length:n=>n.length,sum:n=>n.reduce((e,t)=>e+t,0),equals:o(2,(n,e)=>p(n,e)),propEq:o(3,(n,e,t)=>!s(t)&&p(t[n],e)),whereEq:o(2,(n,e)=>{for(let t in n)if(s(e)||!p(e[t],n[t]))return false;return true}),ifElse:o(4,(n,e,t,r)=>n(r)?e(r):t(r)),when:o(3,(n,e,t)=>n(t)?e(t):t),cond:n=>e=>{for(let[t,r]of n)if(t(e))return r(e)},defaultTo:o(2,(n,e)=>s(e)||typeof e=="number"&&Number.isNaN(e)?n:e),isNil:n=>s(n),isEmpty:n=>s(n)?true:typeof n=="string"||Array.isArray(n)?n.length===0:typeof n=="object"?Object.keys(n).length===0:false,toUpper:n=>n.toUpperCase(),toLower:n=>n.toLowerCase(),trim:n=>n.trim(),split:o(2,(n,e)=>e.split(n)),join:o(2,(n,e)=>e.join(n)),template:o(2,(n,e)=>n.replace(/\{(\w+)\}/g,(t,r)=>{let a=s(e)?void 0:e[r];return s(a)?"":String(a)})),toNumber:n=>Number(n),asString:n=>String(n),toBoolean:n=>!!n,parse:n=>JSON.parse(n),stringify:n=>JSON.stringify(n)};var i=(n,e,t)=>({operator:n,on:e,call:t}),k={length:i("length","value",n=>`length(${n})`),map:i("map","array",(n,e)=>`map(${e[0]??"fn"}, ${n})`),filter:i("filter","array",(n,e)=>`filter(${e[0]??"fn"}, ${n})`),find:i("find","array",(n,e)=>`find(${e[0]??"fn"}, ${n})`),reduce:i("reduce","array",(n,e)=>`reduce(${e[0]??"fn"}, ${e[1]??"init"}, ${n})`),some:i("some","array",(n,e)=>`some(${e[0]??"fn"}, ${n})`),includes:i("includes","value",(n,e)=>`includes(${e[0]??"x"}, ${n})`),flat:i("flatten","array",n=>`flatten(${n})`),join:i("join","array",(n,e)=>`join(${e[0]??'", "'}, ${n})`),trim:i("trim","string",n=>`trim(${n})`),toUpperCase:i("toUpper","string",n=>`toUpper(${n})`),toLowerCase:i("toLower","string",n=>`toLower(${n})`),split:i("split","string",(n,e)=>`split(${e[0]??'","'}, ${n})`),toString:i("asString","value",n=>`asString(${n})`)},b=new Set(["push","pop","shift","unshift","splice","sort","reverse","slice","concat","indexOf","lastIndexOf","forEach","every","flatMap","fill","charAt","charCodeAt","substring","substr","replace","replaceAll","padStart","padEnd","startsWith","endsWith","repeat","at","keys","values","entries","hasOwnProperty","valueOf"]),j=n=>n in k||b.has(n);exports.isKnownProtoMember=j;exports.jsMethodReplacements=k;exports.knownProtoMembersWithoutOperator=b;exports.loadOperators=l;exports.vanilla=h;exports.vanillaRuntime=x;exports.vanillaSource=m;
@@ -0,0 +1,41 @@
1
+ import { Schema } from '@tslite/type-core';
2
+
3
+ /**
4
+ * Parseia um bloco de aliases TSL e devolve `Record<name, Schema>` — o `vars`
5
+ * pronto pro `createEnv`. Cada operador vira um valor com o tipo do corpo do alias.
6
+ */
7
+ declare const loadOperators: (source: string) => Record<string, Schema>;
8
+
9
+ /** O fonte TSL completo do tier vanilla (todas as categorias concatenadas). */
10
+ declare const vanillaSource: string;
11
+ /** O `Record<name, Schema>` do vanilla — pronto pra `createEnv(vanilla)`. */
12
+ declare const vanilla: Record<string, Schema>;
13
+
14
+ type Fn = (...args: any[]) => any;
15
+ declare const vanillaRuntime: Record<string, Fn>;
16
+
17
+ /** Substituição de um método JS por um operador do vanilla. */
18
+ interface OperatorReplacement {
19
+ /** o operador do `@tslite/operators` que faz o mesmo. */
20
+ readonly operator: string;
21
+ /** o receptor típico do método — só pra compor a mensagem. */
22
+ readonly on: "array" | "string" | "value";
23
+ /**
24
+ * Monta a chamada equivalente em código TSL, dado o RECEPTOR (`arr` em
25
+ * `arr.map(f)`) e os ARGS do método (`[f]`). Reordena pro estilo FP (dado por
26
+ * último): `arr.map(f)` → `map(f, arr)`. Placeholders quando o arg falta.
27
+ */
28
+ readonly call: (receiver: string, args: readonly string[]) => string;
29
+ }
30
+ /** Método JS (por NOME) → o operador que o substitui. Cresce junto com o vanilla. */
31
+ declare const jsMethodReplacements: Readonly<Record<string, OperatorReplacement>>;
32
+ /**
33
+ * Métodos de protótipo JS COMUNS que NÃO têm operador 1:1 (mutação / sem
34
+ * equivalente FP direto). São reconhecidos como "JS-ism" (pra a mensagem
35
+ * explicativa), mas sem sugestão de operador nem auto-fix.
36
+ */
37
+ declare const knownProtoMembersWithoutOperator: ReadonlySet<string>;
38
+ /** Todo nome que denuncia "pensei em JS/OO" num acesso de membro que não existe. */
39
+ declare const isKnownProtoMember: (name: string) => boolean;
40
+
41
+ export { type OperatorReplacement, isKnownProtoMember, jsMethodReplacements, knownProtoMembersWithoutOperator, loadOperators, vanilla, vanillaRuntime, vanillaSource };
@@ -0,0 +1,41 @@
1
+ import { Schema } from '@tslite/type-core';
2
+
3
+ /**
4
+ * Parseia um bloco de aliases TSL e devolve `Record<name, Schema>` — o `vars`
5
+ * pronto pro `createEnv`. Cada operador vira um valor com o tipo do corpo do alias.
6
+ */
7
+ declare const loadOperators: (source: string) => Record<string, Schema>;
8
+
9
+ /** O fonte TSL completo do tier vanilla (todas as categorias concatenadas). */
10
+ declare const vanillaSource: string;
11
+ /** O `Record<name, Schema>` do vanilla — pronto pra `createEnv(vanilla)`. */
12
+ declare const vanilla: Record<string, Schema>;
13
+
14
+ type Fn = (...args: any[]) => any;
15
+ declare const vanillaRuntime: Record<string, Fn>;
16
+
17
+ /** Substituição de um método JS por um operador do vanilla. */
18
+ interface OperatorReplacement {
19
+ /** o operador do `@tslite/operators` que faz o mesmo. */
20
+ readonly operator: string;
21
+ /** o receptor típico do método — só pra compor a mensagem. */
22
+ readonly on: "array" | "string" | "value";
23
+ /**
24
+ * Monta a chamada equivalente em código TSL, dado o RECEPTOR (`arr` em
25
+ * `arr.map(f)`) e os ARGS do método (`[f]`). Reordena pro estilo FP (dado por
26
+ * último): `arr.map(f)` → `map(f, arr)`. Placeholders quando o arg falta.
27
+ */
28
+ readonly call: (receiver: string, args: readonly string[]) => string;
29
+ }
30
+ /** Método JS (por NOME) → o operador que o substitui. Cresce junto com o vanilla. */
31
+ declare const jsMethodReplacements: Readonly<Record<string, OperatorReplacement>>;
32
+ /**
33
+ * Métodos de protótipo JS COMUNS que NÃO têm operador 1:1 (mutação / sem
34
+ * equivalente FP direto). São reconhecidos como "JS-ism" (pra a mensagem
35
+ * explicativa), mas sem sugestão de operador nem auto-fix.
36
+ */
37
+ declare const knownProtoMembersWithoutOperator: ReadonlySet<string>;
38
+ /** Todo nome que denuncia "pensei em JS/OO" num acesso de membro que não existe. */
39
+ declare const isKnownProtoMember: (name: string) => boolean;
40
+
41
+ export { type OperatorReplacement, isKnownProtoMember, jsMethodReplacements, knownProtoMembersWithoutOperator, loadOperators, vanilla, vanillaRuntime, vanillaSource };
package/dist/index.js ADDED
@@ -0,0 +1,165 @@
1
+ import {parse}from'@tslite/parser';var l=n=>{let e=parse(n),t={};for(let r of e.body)r.type==="TSTypeAliasDeclaration"&&r.id?.name&&r.typeAnnotation&&(t[r.id.name]=r.typeAnnotation);return t};var T=`
2
+ type identity<T> = (x: T) => T;
3
+ type always<T> = (value: T) => () => T;
4
+ type tap<T> = {
5
+ (fn: (x: T) => unknown): (x: T) => T;
6
+ (fn: (x: T) => unknown, x: T): T;
7
+ };
8
+ `;var u=`
9
+ type prop<T, K extends keyof T> = {
10
+ (key: K): (obj: T) => T[K];
11
+ (key: K, obj: T): T[K];
12
+ };
13
+ type path = {
14
+ (keys: string[]): (obj: unknown) => unknown;
15
+ (keys: string[], obj: unknown): unknown;
16
+ };
17
+ type propOr<D> = {
18
+ (def: D, key: string): (obj: unknown) => unknown;
19
+ (def: D, key: string, obj: unknown): unknown;
20
+ };
21
+ type pathOr<D> = {
22
+ (def: D, keys: string[]): (obj: unknown) => unknown;
23
+ (def: D, keys: string[], obj: unknown): unknown;
24
+ };
25
+ /* pick: afrouxado \u2014 a vers\xE3o precisa \`keys: K[]\` sofre com o alargamento de
26
+ literal em elemento de array-arg (\`["a"]\` \u2192 string[], viola K extends keyof T).
27
+ Follow-up de checker (preserva\xE7\xE3o de literal em array). Aqui: keys string[],
28
+ retorno Partial<T> (subconjunto das chaves de T \u2014 honesto e util). */
29
+ type pick<T> = {
30
+ (keys: string[]): (obj: T) => { [P in keyof T]?: T[P] };
31
+ (keys: string[], obj: T): { [P in keyof T]?: T[P] };
32
+ };
33
+ type omit<T> = {
34
+ (keys: string[]): (obj: T) => T;
35
+ (keys: string[], obj: T): T;
36
+ };
37
+ type assoc<T, V> = {
38
+ (key: string, value: V): (obj: T) => T;
39
+ (key: string, value: V, obj: T): T;
40
+ };
41
+ type merge<A, B> = {
42
+ (a: A): (b: B) => A & B;
43
+ (a: A, b: B): A & B;
44
+ };
45
+ type keys<T> = (obj: T) => (keyof T)[];
46
+ type values<T> = (obj: T) => T[keyof T][];
47
+ type entries<T> = (obj: T) => [keyof T, T[keyof T]][];
48
+ type fromEntries<V> = (pairs: [string, V][]) => { [k: string]: V };
49
+ type has<T> = {
50
+ (key: string): (obj: T) => boolean;
51
+ (key: string, obj: T): boolean;
52
+ };
53
+ type applySpec<S> = {
54
+ (spec: S): (input: unknown) => { [K in keyof S]: ReturnType<S[K]> };
55
+ (spec: S, input: unknown): { [K in keyof S]: ReturnType<S[K]> };
56
+ };
57
+ type evolve<T> = {
58
+ (transforms: { [K in keyof T]?: (value: T[K]) => T[K] }): (obj: T) => T;
59
+ (transforms: { [K in keyof T]?: (value: T[K]) => T[K] }, obj: T): T;
60
+ };
61
+ `;var c=`
62
+ type map<T, U> = {
63
+ (fn: (item: T) => U): (list: T[]) => U[];
64
+ (fn: (item: T) => U, list: T[]): U[];
65
+ };
66
+ type filter<T> = {
67
+ (pred: (item: T) => boolean): (list: T[]) => T[];
68
+ (pred: (item: T) => boolean, list: T[]): T[];
69
+ };
70
+ type find<T> = {
71
+ (pred: (item: T) => boolean): (list: T[]) => T | undefined;
72
+ (pred: (item: T) => boolean, list: T[]): T | undefined;
73
+ };
74
+ type reduce<T, A> = {
75
+ (fn: (acc: A, item: T) => A, init: A): (list: T[]) => A;
76
+ (fn: (acc: A, item: T) => A, init: A, list: T[]): A;
77
+ };
78
+ type pluck<T, K extends keyof T> = {
79
+ (key: K): (list: T[]) => T[K][];
80
+ (key: K, list: T[]): T[K][];
81
+ };
82
+ type indexBy<T> = {
83
+ (fn: (item: T) => string): (list: T[]) => { [k: string]: T };
84
+ (fn: (item: T) => string, list: T[]): { [k: string]: T };
85
+ };
86
+ type groupBy<T> = {
87
+ (fn: (item: T) => string): (list: T[]) => { [k: string]: T[] };
88
+ (fn: (item: T) => string, list: T[]): { [k: string]: T[] };
89
+ };
90
+ type uniqBy<T, U> = {
91
+ (fn: (item: T) => U): (list: T[]) => T[];
92
+ (fn: (item: T) => U, list: T[]): T[];
93
+ };
94
+ type sortBy<T, U> = {
95
+ (fn: (item: T) => U): (list: T[]) => T[];
96
+ (fn: (item: T) => U, list: T[]): T[];
97
+ };
98
+ type flatten<T> = (list: T[][]) => T[];
99
+ type includes<T> = {
100
+ (value: T): (list: T[]) => boolean;
101
+ (value: T, list: T[]): boolean;
102
+ };
103
+ type some<T> = {
104
+ (pred: (item: T) => boolean): (list: T[]) => boolean;
105
+ (pred: (item: T) => boolean, list: T[]): boolean;
106
+ };
107
+ type length<T> = (list: T[]) => number;
108
+ type sum = (list: number[]) => number;
109
+ `;var f=`
110
+ type equals<T> = {
111
+ (a: T): (b: T) => boolean;
112
+ (a: T, b: T): boolean;
113
+ };
114
+ type propEq = {
115
+ (key: string, value: unknown): (obj: unknown) => boolean;
116
+ (key: string, value: unknown, obj: unknown): boolean;
117
+ };
118
+ type whereEq = {
119
+ (spec: { [k: string]: unknown }): (obj: unknown) => boolean;
120
+ (spec: { [k: string]: unknown }, obj: unknown): boolean;
121
+ };
122
+ type ifElse<T, R> = {
123
+ (pred: (x: T) => boolean, onTrue: (x: T) => R, onFalse: (x: T) => R): (value: T) => R;
124
+ (pred: (x: T) => boolean, onTrue: (x: T) => R, onFalse: (x: T) => R, value: T): R;
125
+ };
126
+ type when<T> = {
127
+ (pred: (x: T) => boolean, fn: (x: T) => T): (value: T) => T;
128
+ (pred: (x: T) => boolean, fn: (x: T) => T, value: T): T;
129
+ };
130
+ /* cond: loose \u2014 a infer\xEAncia de T/R atrav\xE9s do tuple-array de fns aninhado n\xE3o
131
+ aterra (nem no tsc \xE9 trivial). Vanilla: value/result unknown (o switch costuma
132
+ alimentar string/label; anote o resultado se precisar). */
133
+ type cond = (
134
+ pairs: [(x: unknown) => boolean, (x: unknown) => unknown][],
135
+ ) => (value: unknown) => unknown;
136
+ type defaultTo<T> = {
137
+ (def: T): (value: T) => T;
138
+ (def: T, value: T): T;
139
+ };
140
+ type isNil = (value: unknown) => boolean;
141
+ type isEmpty = (value: unknown) => boolean;
142
+ `;var d=`
143
+ type toUpper = (str: string) => string;
144
+ type toLower = (str: string) => string;
145
+ type trim = (str: string) => string;
146
+ type split = {
147
+ (sep: string): (str: string) => string[];
148
+ (sep: string, str: string): string[];
149
+ };
150
+ type join = {
151
+ (sep: string): (list: string[]) => string;
152
+ (sep: string, list: string[]): string;
153
+ };
154
+ type template = {
155
+ (tpl: string): (data: unknown) => string;
156
+ (tpl: string, data: unknown): string;
157
+ };
158
+ `;var g=`
159
+ type toNumber = (value: unknown) => number;
160
+ type asString = (value: unknown) => string;
161
+ type toBoolean = (value: unknown) => boolean;
162
+ type parse = (text: string) => unknown;
163
+ type stringify = (value: unknown) => string;
164
+ `;var m=[T,u,c,f,d,g].join(`
165
+ `),h=l(m);var o=(n,e)=>{let t=r=>r.length>=n?e(...r.slice(0,n)):(...a)=>t([...r,...a]);return (...r)=>t(r)},p=(n,e)=>{if(n===e)return true;if(n===null||e===null||typeof n!="object"||typeof e!="object")return n===e;if(Array.isArray(n)!==Array.isArray(e))return false;let r=Object.keys(n),a=Object.keys(e);return r.length!==a.length?false:r.every(y=>p(n[y],e[y]))},s=n=>n==null,x={identity:n=>n,always:n=>()=>n,tap:o(2,(n,e)=>(n(e),e)),prop:o(2,(n,e)=>s(e)?void 0:e[n]),path:o(2,(n,e)=>n.reduce((t,r)=>s(t)?void 0:t[r],e)),propOr:o(3,(n,e,t)=>{let r=s(t)?void 0:t[e];return s(r)?n:r}),pathOr:o(3,(n,e,t)=>{let r=e.reduce((a,y)=>s(a)?void 0:a[y],t);return s(r)?n:r}),pick:o(2,(n,e)=>{let t={};if(!s(e))for(let r of n)r in e&&(t[r]=e[r]);return t}),omit:o(2,(n,e)=>{let t=new Set(n),r={};for(let a in e)t.has(a)||(r[a]=e[a]);return r}),assoc:o(3,(n,e,t)=>({...t,[n]:e})),merge:o(2,(n,e)=>({...n,...e})),keys:n=>Object.keys(n??{}),values:n=>Object.values(n??{}),entries:n=>Object.entries(n??{}),fromEntries:n=>Object.fromEntries(n),has:o(2,(n,e)=>!s(e)&&Object.prototype.hasOwnProperty.call(e,n)),applySpec:o(2,(n,e)=>{let t={};for(let r in n)t[r]=n[r](e);return t}),evolve:o(2,(n,e)=>{let t={...e};for(let r in n)r in t&&(t[r]=n[r](t[r]));return t}),map:o(2,(n,e)=>e.map(t=>n(t))),filter:o(2,(n,e)=>e.filter(t=>n(t))),find:o(2,(n,e)=>e.find(t=>n(t))),reduce:o(3,(n,e,t)=>t.reduce((r,a)=>n(r,a),e)),pluck:o(2,(n,e)=>e.map(t=>s(t)?void 0:t[n])),indexBy:o(2,(n,e)=>{let t={};for(let r of e)t[n(r)]=r;return t}),groupBy:o(2,(n,e)=>{var r;let t={};for(let a of e)(t[r=n(a)]??(t[r]=[])).push(a);return t}),uniqBy:o(2,(n,e)=>{let t=new Set,r=[];for(let a of e){let y=n(a);t.has(y)||(t.add(y),r.push(a));}return r}),sortBy:o(2,(n,e)=>[...e].sort((t,r)=>{let a=n(t),y=n(r);return a<y?-1:a>y?1:0})),flatten:n=>n.reduce((e,t)=>e.concat(t),[]),includes:o(2,(n,e)=>e.some(t=>p(t,n))),some:o(2,(n,e)=>e.some(t=>n(t))),length:n=>n.length,sum:n=>n.reduce((e,t)=>e+t,0),equals:o(2,(n,e)=>p(n,e)),propEq:o(3,(n,e,t)=>!s(t)&&p(t[n],e)),whereEq:o(2,(n,e)=>{for(let t in n)if(s(e)||!p(e[t],n[t]))return false;return true}),ifElse:o(4,(n,e,t,r)=>n(r)?e(r):t(r)),when:o(3,(n,e,t)=>n(t)?e(t):t),cond:n=>e=>{for(let[t,r]of n)if(t(e))return r(e)},defaultTo:o(2,(n,e)=>s(e)||typeof e=="number"&&Number.isNaN(e)?n:e),isNil:n=>s(n),isEmpty:n=>s(n)?true:typeof n=="string"||Array.isArray(n)?n.length===0:typeof n=="object"?Object.keys(n).length===0:false,toUpper:n=>n.toUpperCase(),toLower:n=>n.toLowerCase(),trim:n=>n.trim(),split:o(2,(n,e)=>e.split(n)),join:o(2,(n,e)=>e.join(n)),template:o(2,(n,e)=>n.replace(/\{(\w+)\}/g,(t,r)=>{let a=s(e)?void 0:e[r];return s(a)?"":String(a)})),toNumber:n=>Number(n),asString:n=>String(n),toBoolean:n=>!!n,parse:n=>JSON.parse(n),stringify:n=>JSON.stringify(n)};var i=(n,e,t)=>({operator:n,on:e,call:t}),k={length:i("length","value",n=>`length(${n})`),map:i("map","array",(n,e)=>`map(${e[0]??"fn"}, ${n})`),filter:i("filter","array",(n,e)=>`filter(${e[0]??"fn"}, ${n})`),find:i("find","array",(n,e)=>`find(${e[0]??"fn"}, ${n})`),reduce:i("reduce","array",(n,e)=>`reduce(${e[0]??"fn"}, ${e[1]??"init"}, ${n})`),some:i("some","array",(n,e)=>`some(${e[0]??"fn"}, ${n})`),includes:i("includes","value",(n,e)=>`includes(${e[0]??"x"}, ${n})`),flat:i("flatten","array",n=>`flatten(${n})`),join:i("join","array",(n,e)=>`join(${e[0]??'", "'}, ${n})`),trim:i("trim","string",n=>`trim(${n})`),toUpperCase:i("toUpper","string",n=>`toUpper(${n})`),toLowerCase:i("toLower","string",n=>`toLower(${n})`),split:i("split","string",(n,e)=>`split(${e[0]??'","'}, ${n})`),toString:i("asString","value",n=>`asString(${n})`)},b=new Set(["push","pop","shift","unshift","splice","sort","reverse","slice","concat","indexOf","lastIndexOf","forEach","every","flatMap","fill","charAt","charCodeAt","substring","substr","replace","replaceAll","padStart","padEnd","startsWith","endsWith","repeat","at","keys","values","entries","hasOwnProperty","valueOf"]),j=n=>n in k||b.has(n);export{j as isKnownProtoMember,k as jsMethodReplacements,b as knownProtoMembersWithoutOperator,l as loadOperators,h as vanilla,x as vanillaRuntime,m as vanillaSource};
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@tslite/operators",
3
+ "version": "0.2.0",
4
+ "description": "TSLite operators — functional operator signatures as native TSL types, injectable into the checker Env (FP, no OO). The typed stdlib for JSON mappers.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "sideEffects": false,
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/andersondrosa/tslite.git",
26
+ "directory": "packages/operators"
27
+ },
28
+ "keywords": [
29
+ "operators",
30
+ "functional",
31
+ "ramda",
32
+ "mapper",
33
+ "etl",
34
+ "json",
35
+ "typescript"
36
+ ],
37
+ "author": "Anderson D. Rosa <andersondrosa@outlook.com>",
38
+ "license": "MIT",
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "dependencies": {
43
+ "@tslite/type-core": "0.2.0",
44
+ "@tslite/parser": "0.1.0"
45
+ },
46
+ "devDependencies": {
47
+ "@tslite/interpret": "0.1.0",
48
+ "@tslite/checker": "0.2.0"
49
+ },
50
+ "scripts": {
51
+ "build": "tsup",
52
+ "dev": "tsup --watch",
53
+ "test": "vitest run",
54
+ "test:watch": "vitest",
55
+ "test:coverage": "vitest run --coverage",
56
+ "typecheck": "tsc --noEmit",
57
+ "lint": "eslint src tests",
58
+ "lint:fix": "eslint src tests --fix",
59
+ "clean": "rm -rf dist",
60
+ "format": "prettier --write \"src/**/*.ts\"",
61
+ "format:check": "prettier --check \"src/**/*.ts\""
62
+ }
63
+ }