scriptable 0.0.6 → 0.1.1

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.
Files changed (44) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +11 -0
  3. package/.github/workflows/release.yml +62 -0
  4. package/CHANGELOG.md +14 -0
  5. package/README.md +185 -0
  6. package/dist/binary-ops.d.ts +2 -0
  7. package/dist/binary-ops.js +16 -0
  8. package/dist/builtin-functions.d.ts +3 -0
  9. package/dist/builtin-functions.js +151 -0
  10. package/dist/environment.d.ts +16 -0
  11. package/dist/environment.js +111 -0
  12. package/dist/evaluate.d.ts +5 -0
  13. package/dist/evaluate.js +232 -0
  14. package/dist/index.d.ts +13 -0
  15. package/dist/index.js +26 -0
  16. package/dist/logic-ops.d.ts +2 -0
  17. package/dist/logic-ops.js +5 -0
  18. package/package.json +22 -52
  19. package/scripts/release.js +127 -0
  20. package/src/__tests__/{break-out.js → break-out.test.ts} +3 -14
  21. package/src/__tests__/{builtin-functions-date.js → builtin-functions-date.test.ts} +30 -11
  22. package/src/__tests__/{builtin-functions.js → builtin-functions.test.ts} +2 -3
  23. package/src/__tests__/{expressions.js → expressions.test.ts} +2 -3
  24. package/src/__tests__/{functions.js → functions.test.ts} +7 -8
  25. package/src/__tests__/{logic.js → logic.test.ts} +2 -3
  26. package/src/__tests__/new-features.test.ts +158 -0
  27. package/src/__tests__/security.test.ts +399 -0
  28. package/src/__tests__/{variables.js → variables.test.ts} +3 -6
  29. package/src/binary-ops.ts +18 -0
  30. package/src/builtin-functions.ts +177 -0
  31. package/src/environment.ts +132 -0
  32. package/src/evaluate.ts +275 -0
  33. package/src/index.ts +42 -0
  34. package/src/logic-ops.ts +6 -0
  35. package/tsconfig.json +16 -0
  36. package/.npmignore +0 -1
  37. package/src/__tests__/index.js +0 -85
  38. package/src/binary-ops.js +0 -13
  39. package/src/builtin-functions.js +0 -58
  40. package/src/environment.js +0 -73
  41. package/src/evaluate.js +0 -174
  42. package/src/index.js +0 -26
  43. package/src/logic-ops.js +0 -6
  44. package/yarn.lock +0 -2632
@@ -0,0 +1,177 @@
1
+ export type FunctionMap = Record<string, (...args: any[]) => any>;
2
+
3
+ // ---------------------------------------------------------------------------
4
+ // Date helpers (Intl-based, no moment dependency)
5
+ // ---------------------------------------------------------------------------
6
+
7
+ function getDateParts(date: Date, tz: string) {
8
+ const fmt = (opts: Intl.DateTimeFormatOptions) =>
9
+ new Intl.DateTimeFormat("en-US", { timeZone: tz, ...opts });
10
+
11
+ const year = parseInt(fmt({ year: "numeric" }).format(date));
12
+ const month = parseInt(fmt({ month: "numeric" }).format(date));
13
+ const day = parseInt(fmt({ day: "numeric" }).format(date));
14
+
15
+ const h24Parts = fmt({
16
+ hour: "numeric",
17
+ minute: "numeric",
18
+ second: "numeric",
19
+ hourCycle: "h23",
20
+ }).formatToParts(date);
21
+
22
+ const part = (type: string) =>
23
+ h24Parts.find((p) => p.type === type)?.value || "0";
24
+ const hour24 = parseInt(part("hour"));
25
+ const minute = parseInt(part("minute"));
26
+ const second = parseInt(part("second"));
27
+
28
+ const hour12 = hour24 === 0 ? 12 : hour24 > 12 ? hour24 - 12 : hour24;
29
+ const ampm = hour24 >= 12 ? "pm" : "am";
30
+
31
+ const monthShort = fmt({ month: "short" }).format(date);
32
+ const monthLong = fmt({ month: "long" }).format(date);
33
+
34
+ const tzAbbr =
35
+ fmt({ timeZoneName: "short" })
36
+ .formatToParts(date)
37
+ .find((p) => p.type === "timeZoneName")?.value || "";
38
+
39
+ return {
40
+ year, month, day,
41
+ hour12, hour24, minute, second,
42
+ ampm, monthShort, monthLong, tzAbbr,
43
+ };
44
+ }
45
+
46
+ const FORMAT_TOKENS =
47
+ /YYYY|YY|MMMM|MMM|MM|M|DD|D|HH|H|hh|h|mm|m|ss|s|a|A|z/g;
48
+
49
+ function applyFormat(parts: ReturnType<typeof getDateParts>, format: string) {
50
+ return format.replace(FORMAT_TOKENS, (token) => {
51
+ switch (token) {
52
+ case "YYYY": return String(parts.year);
53
+ case "YY": return String(parts.year).slice(-2);
54
+ case "MMMM": return parts.monthLong;
55
+ case "MMM": return parts.monthShort;
56
+ case "MM": return String(parts.month).padStart(2, "0");
57
+ case "M": return String(parts.month);
58
+ case "DD": return String(parts.day).padStart(2, "0");
59
+ case "D": return String(parts.day);
60
+ case "HH": return String(parts.hour24).padStart(2, "0");
61
+ case "H": return String(parts.hour24);
62
+ case "hh": return String(parts.hour12).padStart(2, "0");
63
+ case "h": return String(parts.hour12);
64
+ case "mm": return String(parts.minute).padStart(2, "0");
65
+ case "m": return String(parts.minute);
66
+ case "ss": return String(parts.second).padStart(2, "0");
67
+ case "s": return String(parts.second);
68
+ case "a": return parts.ampm;
69
+ case "A": return parts.ampm.toUpperCase();
70
+ case "z": return parts.tzAbbr;
71
+ default: return token;
72
+ }
73
+ });
74
+ }
75
+
76
+ // ---------------------------------------------------------------------------
77
+ // Number helpers
78
+ // ---------------------------------------------------------------------------
79
+
80
+ function numberFormatter(...args: any[]) {
81
+ return new Intl.NumberFormat(...args).format;
82
+ }
83
+
84
+ const functions: FunctionMap = {
85
+ push(...args: any[]) {
86
+ const [target, item] = args;
87
+ target.push(item);
88
+ },
89
+
90
+ shift(...args: any[]) {
91
+ const [target] = args;
92
+ return target.shift();
93
+ },
94
+
95
+ currentDate(tz?: string) {
96
+ return new Date();
97
+ },
98
+
99
+ formatDate(dateString: string, format: string, timezone?: string) {
100
+ const date = /^\d+$/.test(dateString)
101
+ ? new Date(+dateString)
102
+ : new Date(dateString);
103
+ const tz = timezone || "UTC";
104
+ return applyFormat(getDateParts(date, tz), format);
105
+ },
106
+
107
+ numberFormatter,
108
+
109
+ formatDollars: numberFormatter("en-us", {
110
+ minimumFractionDigits: 2,
111
+ maximumFractionDigits: 2,
112
+ }),
113
+
114
+ // Array/collection operations (replaces lodash)
115
+ map(arr: any[], fn: (...args: any[]) => any) {
116
+ return arr.map(fn);
117
+ },
118
+ filter(arr: any[], fn: (...args: any[]) => any) {
119
+ return arr.filter(fn);
120
+ },
121
+ find(arr: any[], fn: (...args: any[]) => any) {
122
+ return arr.find(fn);
123
+ },
124
+ forEach(arr: any[], fn: (...args: any[]) => any) {
125
+ arr.forEach(fn);
126
+ },
127
+ reduce(arr: any[], fn: (...args: any[]) => any, initial?: any) {
128
+ return initial !== undefined ? arr.reduce(fn, initial) : arr.reduce(fn);
129
+ },
130
+ concat(arr: any[], ...items: any[]) {
131
+ return arr.concat(...items);
132
+ },
133
+ keys(obj: any) {
134
+ return Object.keys(obj);
135
+ },
136
+ values(obj: any) {
137
+ return Object.values(obj);
138
+ },
139
+ entries(obj: any) {
140
+ return Object.entries(obj);
141
+ },
142
+ assign(...args: any[]) {
143
+ return Object.assign({}, ...args);
144
+ },
145
+ join(arr: any[], sep: string) {
146
+ return arr.join(sep);
147
+ },
148
+ includes(arr: any[], item: any) {
149
+ return arr.includes(item);
150
+ },
151
+ slice(arr: any[], start?: number, end?: number) {
152
+ return arr.slice(start, end);
153
+ },
154
+ sort(arr: any[], fn?: (...args: any[]) => any) {
155
+ return [...arr].sort(fn);
156
+ },
157
+ reverse(arr: any[]) {
158
+ return [...arr].reverse();
159
+ },
160
+ flat(arr: any[], depth?: number) {
161
+ return arr.flat(depth);
162
+ },
163
+ flatMap(arr: any[], fn: (...args: any[]) => any) {
164
+ return arr.flatMap(fn);
165
+ },
166
+ some(arr: any[], fn: (...args: any[]) => any) {
167
+ return arr.some(fn);
168
+ },
169
+ every(arr: any[], fn: (...args: any[]) => any) {
170
+ return arr.every(fn);
171
+ },
172
+ indexOf(arr: any[], item: any) {
173
+ return arr.indexOf(item);
174
+ },
175
+ };
176
+
177
+ export default functions;
@@ -0,0 +1,132 @@
1
+ // Properties that could be used for prototype-chain traversal or pollution.
2
+ // Defense-in-depth: also checked in evaluate.ts MemberExpression.
3
+ const BLOCKED_PROPS = new Set([
4
+ "constructor",
5
+ "__proto__",
6
+ "prototype",
7
+ "__defineGetter__",
8
+ "__defineSetter__",
9
+ "__lookupGetter__",
10
+ "__lookupSetter__",
11
+ ]);
12
+
13
+ function assertSafeParts(parts: string[]): void {
14
+ for (const part of parts) {
15
+ if (BLOCKED_PROPS.has(part)) {
16
+ throw new Error(`Access to property '${part}' is not allowed`);
17
+ }
18
+ }
19
+ }
20
+
21
+ function deepHas(obj: any, path: string): boolean {
22
+ const parts = path.split(".");
23
+ assertSafeParts(parts);
24
+ let current = obj;
25
+ for (const part of parts) {
26
+ if (current == null || typeof current !== "object") return false;
27
+ if (!Object.prototype.hasOwnProperty.call(current, part)) return false;
28
+ current = current[part];
29
+ }
30
+ return true;
31
+ }
32
+
33
+ function deepGet(obj: any, path: string): any {
34
+ const parts = path.split(".");
35
+ assertSafeParts(parts);
36
+ let current = obj;
37
+ for (const part of parts) {
38
+ if (current == null) return undefined;
39
+ current = current[part];
40
+ }
41
+ return current;
42
+ }
43
+
44
+ function deepSet(obj: any, path: string, value: any): void {
45
+ const parts = path.split(".");
46
+ assertSafeParts(parts);
47
+ let current = obj;
48
+ for (let i = 0; i < parts.length - 1; i++) {
49
+ if (current[parts[i]] == null || typeof current[parts[i]] !== "object") {
50
+ current[parts[i]] = {};
51
+ }
52
+ current = current[parts[i]];
53
+ }
54
+ current[parts[parts.length - 1]] = value;
55
+ }
56
+
57
+ export interface Loc {
58
+ line: number;
59
+ column: number;
60
+ }
61
+
62
+ export default class Environment {
63
+ vars: Record<string, any>;
64
+ parent: Environment | null;
65
+
66
+ constructor(parent?: Environment) {
67
+ this.vars = Object.create(parent ? parent.vars : null);
68
+ this.parent = parent || null;
69
+ }
70
+
71
+ extend(): Environment {
72
+ return new Environment(this);
73
+ }
74
+
75
+ getGlobalScope(): Environment {
76
+ let scope: Environment = this;
77
+ while (scope.parent) {
78
+ scope = scope.parent;
79
+ }
80
+ return scope;
81
+ }
82
+
83
+ lookup(name: string): Environment {
84
+ let scope: Environment = this;
85
+ while (scope.parent) {
86
+ if (Object.prototype.hasOwnProperty.call(scope.vars, name)) {
87
+ return scope;
88
+ }
89
+ scope = scope.parent;
90
+ }
91
+ return scope;
92
+ }
93
+
94
+ defined(name: string): boolean {
95
+ if (name in this.vars) {
96
+ return true;
97
+ }
98
+ if (deepHas(this.vars, name)) {
99
+ return true;
100
+ }
101
+ return false;
102
+ }
103
+
104
+ get(name: string, loc: Loc): any {
105
+ if (name in this.vars) {
106
+ return this.vars[name];
107
+ }
108
+ if (deepHas(this.vars, name)) {
109
+ return deepGet(this.vars, name);
110
+ }
111
+ throw new ReferenceError(
112
+ `"${name}" is not defined (${loc.line}:${loc.column})`
113
+ );
114
+ }
115
+
116
+ set(name: string, value: any, loc: Loc): any {
117
+ const baseName = name.replace(/\..*/, "");
118
+ const scope = this.lookup(baseName);
119
+ if (!scope && this.parent) {
120
+ throw new ReferenceError(
121
+ `"${name}" is not defined (${loc.line}:${loc.column})`
122
+ );
123
+ }
124
+ deepSet((scope || this).vars, name, value);
125
+ return value;
126
+ }
127
+
128
+ def(name: string, value: any): any {
129
+ deepSet(this.vars, name, value);
130
+ return value;
131
+ }
132
+ }
@@ -0,0 +1,275 @@
1
+ import type { Node } from "acorn";
2
+ import binaryOps from "./binary-ops.js";
3
+ import logicOps from "./logic-ops.js";
4
+ import type Environment from "./environment.js";
5
+ import type { FunctionMap } from "./builtin-functions.js";
6
+
7
+ type AnyNode = Node & Record<string, any>;
8
+
9
+ // Properties that enable sandbox escape (prototype chain → Function constructor)
10
+ // or prototype pollution. Blocked in both MemberExpression and deep path access.
11
+ const BLOCKED_PROPS = new Set([
12
+ "constructor",
13
+ "__proto__",
14
+ "prototype",
15
+ "__defineGetter__",
16
+ "__defineSetter__",
17
+ "__lookupGetter__",
18
+ "__lookupSetter__",
19
+ ]);
20
+
21
+ function assertSafeProperty(prop: string): void {
22
+ if (BLOCKED_PROPS.has(prop)) {
23
+ throw new Error(`Access to property '${prop}' is not allowed`);
24
+ }
25
+ }
26
+
27
+ // Execution step counter — reset via resetStepCounter() before each run.
28
+ let _steps = 0;
29
+ let _maxSteps = 0;
30
+
31
+ export function resetStepCounter(maxSteps: number): void {
32
+ _steps = 0;
33
+ _maxSteps = maxSteps;
34
+ }
35
+
36
+ function loc(exp: AnyNode) {
37
+ return exp.loc!.start;
38
+ }
39
+
40
+ function makeFunc(
41
+ params: string[],
42
+ body: AnyNode,
43
+ env: Environment,
44
+ functions: FunctionMap
45
+ ) {
46
+ const scope = env.extend();
47
+ return (...args: any[]) => {
48
+ params.forEach((param, idx) => {
49
+ scope.def(param, idx < args.length ? args[idx] : false);
50
+ });
51
+ return evaluate(body, scope, functions);
52
+ };
53
+ }
54
+
55
+ const evals: Record<
56
+ string,
57
+ (exp: AnyNode, env: Environment, functions: FunctionMap) => any
58
+ > = {
59
+ ArrowFunctionExpression(exp, env, functions) {
60
+ const params = exp.params.map((param: AnyNode) => evaluate(param));
61
+ return makeFunc(params, exp.body, env, functions);
62
+ },
63
+
64
+ ArrayExpression(exp, env, functions) {
65
+ const result: any[] = [];
66
+ for (const el of exp.elements) {
67
+ if (el && el.type === "SpreadElement") {
68
+ const spread = evaluate(el.argument, env, functions);
69
+ result.push(...spread);
70
+ } else if (el) {
71
+ result.push(evaluate(el, env, functions));
72
+ }
73
+ }
74
+ return result;
75
+ },
76
+
77
+ AssignmentExpression(exp, env, functions) {
78
+ const target = evaluate(exp.left);
79
+ return env.set(target, evaluate(exp.right, env, functions), loc(exp));
80
+ },
81
+
82
+ BinaryExpression(exp, env, functions) {
83
+ const left = evaluate(exp.left, env, functions);
84
+ const right = evaluate(exp.right, env, functions);
85
+ return binaryOps[exp.operator](left, right);
86
+ },
87
+
88
+ BlockStatement(exp, env, functions) {
89
+ const scope = env.extend();
90
+ let result;
91
+ for (const part of exp.body) {
92
+ result = evaluate(part, scope, functions);
93
+ if (part.type === "ReturnStatement") {
94
+ break;
95
+ }
96
+ }
97
+ return result;
98
+ },
99
+
100
+ CallExpression(exp, env, functions) {
101
+ const func = evaluate(exp.callee);
102
+
103
+ // Collect args, handling spread
104
+ const args: any[] = [];
105
+ for (const arg of exp.arguments) {
106
+ if (arg.type === "SpreadElement") {
107
+ const spread = evaluate(arg.argument, env, functions);
108
+ args.push(...spread);
109
+ } else {
110
+ args.push(evaluate(arg, env, functions));
111
+ }
112
+ }
113
+
114
+ if (functions[func]) {
115
+ return functions[func](...args);
116
+ }
117
+
118
+ if (env.defined(func)) {
119
+ const customFunc = env.get(func, loc(exp));
120
+ if (typeof customFunc === "function") {
121
+ return customFunc(...args);
122
+ }
123
+ }
124
+ const l = loc(exp);
125
+ throw new Error(`${func} is not a function (${l.line}:${l.column})`);
126
+ },
127
+
128
+ ConditionalExpression(exp, env, functions) {
129
+ const test = evaluate(exp.test, env, functions);
130
+ return test
131
+ ? evaluate(exp.consequent, env, functions)
132
+ : evaluate(exp.alternate, env, functions);
133
+ },
134
+
135
+ ExpressionStatement(exp, env, functions) {
136
+ return evaluate(exp.expression, env, functions);
137
+ },
138
+
139
+ FunctionDeclaration(exp, env, functions) {
140
+ const name = evaluate(exp.id);
141
+ const params = exp.params.map((param: AnyNode) => evaluate(param));
142
+ env.set(name, makeFunc(params, exp.body, env, functions), loc(exp));
143
+ },
144
+
145
+ Identifier(exp, env) {
146
+ if (env) {
147
+ return env.get(exp.name, loc(exp));
148
+ }
149
+ return exp.name;
150
+ },
151
+
152
+ IfStatement(exp, env, functions) {
153
+ const test = evaluate(exp.test, env, functions);
154
+ if (test) {
155
+ return evaluate(exp.consequent, env, functions);
156
+ }
157
+ if (exp.alternate) {
158
+ return evaluate(exp.alternate, env, functions);
159
+ }
160
+ },
161
+
162
+ Literal(exp) {
163
+ return exp.value;
164
+ },
165
+
166
+ LogicalExpression(exp, env, functions) {
167
+ const left = evaluate(exp.left, env, functions);
168
+ const right = evaluate(exp.right, env, functions);
169
+ return logicOps[exp.operator](left, right);
170
+ },
171
+
172
+ MemberExpression(exp, env, functions) {
173
+ if (!env) {
174
+ const obj = evaluate(exp.object);
175
+ const prop = evaluate(exp.property);
176
+ assertSafeProperty(prop);
177
+ return `${obj}.${prop}`;
178
+ }
179
+ const obj = evaluate(exp.object, env, functions);
180
+ if (exp.computed) {
181
+ const prop = evaluate(exp.property, env, functions);
182
+ assertSafeProperty(String(prop));
183
+ return obj[prop];
184
+ }
185
+ const prop = evaluate(exp.property);
186
+ assertSafeProperty(prop);
187
+ return obj[prop];
188
+ },
189
+
190
+ ObjectExpression(exp, env, functions) {
191
+ const result: Record<string, any> = {};
192
+ for (const prop of exp.properties) {
193
+ if (prop.type === "SpreadElement") {
194
+ const spread = evaluate(prop.argument, env, functions);
195
+ Object.assign(result, spread);
196
+ } else {
197
+ // Property — key can be Identifier or Literal
198
+ const key =
199
+ prop.key.type === "Identifier" ? prop.key.name : prop.key.value;
200
+ result[key] = evaluate(prop.value, env, functions);
201
+ }
202
+ }
203
+ return result;
204
+ },
205
+
206
+ Program(exp, env, functions) {
207
+ let result;
208
+ for (const node of exp.body) {
209
+ result = evaluate(node, env, functions);
210
+ }
211
+ return result;
212
+ },
213
+
214
+ ReturnStatement(exp, env, functions) {
215
+ return evaluate(exp.argument, env, functions);
216
+ },
217
+
218
+ TemplateLiteral(exp, env, functions) {
219
+ let result = "";
220
+ for (let i = 0; i < exp.quasis.length; i++) {
221
+ result += exp.quasis[i].value.cooked;
222
+ if (i < exp.expressions.length) {
223
+ result += String(evaluate(exp.expressions[i], env, functions));
224
+ }
225
+ }
226
+ return result;
227
+ },
228
+
229
+ UnaryExpression(exp, env, functions) {
230
+ const arg = evaluate(exp.argument, env, functions);
231
+ switch (exp.operator) {
232
+ case "!":
233
+ return !arg;
234
+ case "-":
235
+ return -arg;
236
+ case "+":
237
+ return +arg;
238
+ case "typeof":
239
+ return typeof arg;
240
+ default:
241
+ throw new Error(`Unsupported unary operator: ${exp.operator}`);
242
+ }
243
+ },
244
+
245
+ VariableDeclaration(exp, env, functions) {
246
+ if (exp.kind === "var") {
247
+ const globalScope = env.getGlobalScope();
248
+ for (const dec of exp.declarations) {
249
+ evaluate(dec, globalScope, functions);
250
+ }
251
+ return;
252
+ }
253
+ for (const dec of exp.declarations) {
254
+ evaluate(dec, env, functions);
255
+ }
256
+ },
257
+
258
+ VariableDeclarator(exp, env, functions) {
259
+ const name = evaluate(exp.id);
260
+ const value = exp.init ? evaluate(exp.init, env, functions) : undefined;
261
+ return env.def(name, value);
262
+ },
263
+ };
264
+
265
+ function evaluate(exp: AnyNode, env?: any, functions?: any): any {
266
+ if (_maxSteps > 0 && ++_steps > _maxSteps) {
267
+ throw new Error("Execution limit exceeded");
268
+ }
269
+ if (evals[exp.type]) {
270
+ return evals[exp.type](exp, env, functions);
271
+ }
272
+ throw new Error("Cannot evaluate " + exp.type);
273
+ }
274
+
275
+ export default evaluate;
package/src/index.ts ADDED
@@ -0,0 +1,42 @@
1
+ import * as acorn from "acorn";
2
+ import evaluate, { resetStepCounter } from "./evaluate.js";
3
+ import builtinFuncs from "./builtin-functions.js";
4
+ import type { FunctionMap } from "./builtin-functions.js";
5
+ import Environment from "./environment.js";
6
+
7
+ function parse(code: string) {
8
+ return acorn.parse(code, {
9
+ ecmaVersion: "latest",
10
+ sourceType: "script",
11
+ locations: true,
12
+ });
13
+ }
14
+
15
+ export interface RunnerOptions {
16
+ functions?: FunctionMap;
17
+ maxSteps?: number;
18
+ }
19
+
20
+ export interface RunResult {
21
+ result: any;
22
+ env: Record<string, any>;
23
+ }
24
+
25
+ const DEFAULT_MAX_STEPS = 100_000;
26
+
27
+ export default function runner({ functions = builtinFuncs, maxSteps = DEFAULT_MAX_STEPS }: RunnerOptions = {}) {
28
+ return (code: string, env: Record<string, any> = {}, debug?: boolean): RunResult => {
29
+ const ast = parse(code);
30
+ debug && console.log(JSON.stringify(ast.body, null, 2));
31
+ resetStepCounter(maxSteps);
32
+ const globalEnv = new Environment();
33
+ Object.keys(env).forEach((key) => {
34
+ globalEnv.def(key, env[key]);
35
+ });
36
+ const result = evaluate(ast, globalEnv, functions);
37
+ return { result, env: globalEnv.vars };
38
+ };
39
+ }
40
+
41
+ export { Environment };
42
+ export type { FunctionMap };
@@ -0,0 +1,6 @@
1
+ const logicOps: Record<string, (l: unknown, r: unknown) => unknown> = {
2
+ "||": (l: any, r: any) => l || r,
3
+ "&&": (l: any, r: any) => l && r,
4
+ };
5
+
6
+ export default logicOps;
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ES2020",
5
+ "moduleResolution": "bundler",
6
+ "declaration": true,
7
+ "outDir": "dist",
8
+ "rootDir": "src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true
13
+ },
14
+ "include": ["src"],
15
+ "exclude": ["src/__tests__"]
16
+ }
package/.npmignore DELETED
@@ -1 +0,0 @@
1
- node_modules/