lambdajson-js 1.0.1 → 1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambdajson-js",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "LambdaJSON to JavaScript function compiler",
5
5
  "type": "module",
6
6
  "main": "./src/js-compiler.js",
@@ -1,4 +1,4 @@
1
- import { isObject, isString, map, get, find, mapValues, isArray, every } from 'lodash-es'
1
+ import { isObject, isString, map, get, find, mapValues, isArray, every, has } from 'lodash-es'
2
2
  import { primitives } from './primitives.js';
3
3
 
4
4
  export {
@@ -30,8 +30,12 @@ function compileTree(primitives, tree) {
30
30
  }
31
31
 
32
32
  const varsDeclarationKey = '$let';
33
+ const valueDeclarationKey = '$literal';
33
34
 
34
35
  function compilePrimitive(primitives, tree) {
36
+ if (has(tree, valueDeclarationKey)) {
37
+ return _ => tree[valueDeclarationKey];
38
+ }
35
39
  const keys = Object.keys(tree);
36
40
  const getLocalVars = compileVars(primitives, tree[varsDeclarationKey]);
37
41
  const primitiveKey = find(keys, k => k !== varsDeclarationKey);
@@ -102,10 +106,20 @@ function compileVars(primitives, obj) {
102
106
 
103
107
  function compileObject(primitives, obj) {
104
108
  const funks = mapValues(obj, n => compileTree(primitives, n));
105
- return x => mapValues(funks, funk => funk(x));
109
+ return x => {
110
+ const result = {};
111
+ for (const key in funks) {
112
+ const pKey = key.startsWith('\\') ? key.slice(1) : key;
113
+ result[pKey] = funks[key](x);
114
+ }
115
+ return result;
116
+ };
106
117
  }
107
118
 
108
119
  function compileString(str) {
120
+ if (str.startsWith('\\')) {
121
+ return () => str.slice(1);
122
+ }
109
123
  if (str === '#') {
110
124
  return ({ input }) => input;
111
125
  }
package/src/primitives.js CHANGED
@@ -6,6 +6,7 @@ const input = ({ input }) => input
6
6
 
7
7
  export const primitives = {
8
8
  $let: true,
9
+ $literal: true,
9
10
  $: f => x => v => f({ ...x, input: v}),
10
11
  $in: f => x => f(x),
11
12
  $return: f => x => f(x),