@jplorg/jpl 1.0.0 → 1.1.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.
@@ -130,6 +130,44 @@ func map(f): ([.[] | f()])
130
130
  | func all(cond): (allBy(func (): (.[]), cond))
131
131
  | func anyBy(f, cond): (not isEmpty(func (): (f() | cond() or void())))
132
132
  | func any(cond): (anyBy(func (): (.[]), cond))
133
+
134
+ | func getPath(path): (
135
+ fields = (path | if type() == 'string' then . / '.' end)
136
+ | reduce->(fields, func (sum): sum[if type->(sum) == 'array' then toNumber() else toString() end], .)
137
+ )
138
+ | func updatePath(path, update): (
139
+ fields = (path | if type() == 'string' then (. / '.')[] |= (v = . | try toNumber() catch v) end)
140
+ | reduce->(
141
+ reverse->(fields),
142
+ func (sum): (
143
+ field = .
144
+ | func (): (
145
+ if type() == 'array'
146
+ then (
147
+ input = .
148
+ | try toNumber->(field) catch toString->(field)
149
+ | if type() == 'number'
150
+ then input[.] |= sum()
151
+ else {}[.] |= sum()
152
+ end
153
+ ) elif type() == 'object'
154
+ then (
155
+ .[toString->(field)] |= sum()
156
+ ) elif type->(field) == 'number'
157
+ then (
158
+ [][field] |= sum()
159
+ ) else (
160
+ {}[toString->(field)] |= sum()
161
+ )
162
+ end
163
+ )
164
+ ),
165
+ update
166
+ )->(.)
167
+ )
168
+ | func setPath(path, value): (
169
+ updatePath(path, func (): value)
170
+ )
133
171
  `;
134
172
  const getBuiltins = (0, _createSingleton.default)(async () => {
135
173
  await undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jplorg/jpl",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "JPL interpreter",
5
5
  "main": "./lib/index.js",
6
6
  "exports": {
@@ -122,6 +122,44 @@ func map(f): ([.[] | f()])
122
122
  | func all(cond): (allBy(func (): (.[]), cond))
123
123
  | func anyBy(f, cond): (not isEmpty(func (): (f() | cond() or void())))
124
124
  | func any(cond): (anyBy(func (): (.[]), cond))
125
+
126
+ | func getPath(path): (
127
+ fields = (path | if type() == 'string' then . / '.' end)
128
+ | reduce->(fields, func (sum): sum[if type->(sum) == 'array' then toNumber() else toString() end], .)
129
+ )
130
+ | func updatePath(path, update): (
131
+ fields = (path | if type() == 'string' then (. / '.')[] |= (v = . | try toNumber() catch v) end)
132
+ | reduce->(
133
+ reverse->(fields),
134
+ func (sum): (
135
+ field = .
136
+ | func (): (
137
+ if type() == 'array'
138
+ then (
139
+ input = .
140
+ | try toNumber->(field) catch toString->(field)
141
+ | if type() == 'number'
142
+ then input[.] |= sum()
143
+ else {}[.] |= sum()
144
+ end
145
+ ) elif type() == 'object'
146
+ then (
147
+ .[toString->(field)] |= sum()
148
+ ) elif type->(field) == 'number'
149
+ then (
150
+ [][field] |= sum()
151
+ ) else (
152
+ {}[toString->(field)] |= sum()
153
+ )
154
+ end
155
+ )
156
+ ),
157
+ update
158
+ )->(.)
159
+ )
160
+ | func setPath(path, value): (
161
+ updatePath(path, func (): value)
162
+ )
125
163
  `;
126
164
 
127
165
  const getBuiltins = createSingleton(async () => {