+42
-0
@@ -0,1 +1,43 @@ | ||
| Jsone 3.0.0 (2018-11-01) | ||
| ======================== | ||
| Features | ||
| -------- | ||
| - Support of `index` or `key` context variable in `$map` operation. | ||
| ```yaml | ||
| template: | ||
| $map: [2, 4, 6] | ||
| each(x,i): {$eval: 'x + a + i'} | ||
| context: {a: 1} | ||
| result: [3, 6, 9] | ||
| --- | ||
| template: | ||
| $map: {a: 1, b: 2, c: 3} | ||
| each(v,k): {'${k}x': {$eval: 'v + 1'}} | ||
| context: {} | ||
| result: {ax: 2, bx: 3, cx: 4} | ||
| ``` (#235) | ||
| - Add support for element indexes in $map (#242) | ||
| Bugfixes | ||
| -------- | ||
| - [BREAKING] make typeof(null) be "null", not null | ||
| This is a breaking change, as it changes an existing, documented behavior. | ||
| However, it is unlikely to affect most uses of JSON-e. (#246) | ||
| Jsone (2018-09-22) | ||
| =================== | ||
| Bugfixes | ||
| -------- | ||
| - Ensure that `$match` results are deterministic (#258) | ||
| Jsone 2.7.0 (2018-08-23) | ||
@@ -2,0 +44,0 @@ ======================== |
+8
-1
| { | ||
| "name": "json-e", | ||
| "version": "2.7.0", | ||
| "version": "3.0.0", | ||
| "description": "json parameterization module inspired from json-parameterization", | ||
@@ -34,3 +34,10 @@ "main": "./src/index.js", | ||
| "node": ">=6.4.0" | ||
| }, | ||
| "renovate": { | ||
| "extends": [ | ||
| "config:base", | ||
| ":preserveSemverRanges", | ||
| ":rebaseStalePrs" | ||
| ] | ||
| } | ||
| } |
+18
-5
@@ -330,10 +330,17 @@ * [Full documentation](https://taskcluster.github.io/json-e) | ||
| result: [3, 5, 7] | ||
| --- | ||
| template: | ||
| $map: [2, 4, 6] | ||
| each(x,i): {$eval: 'x + a + i'} | ||
| context: {a: 1} | ||
| result: [3, 6, 9] | ||
| ``` | ||
| The array or object is the value of the `$map` property, and the expression to evaluate | ||
| is given by `each(var)` where `var` is the name of the variable containing each | ||
| element. In the case of iterating over an object, `var` will be an object with two keys: | ||
| `key` and `val`. These keys correspond to a key in the object and its corresponding value. | ||
| is given by `each(var[,key|index])` where `var` is the name of the variable containing each | ||
| element and `key|index` is either the object key or array index of the value. In the case of | ||
| iterating over an object and no `key|index` var name is given, `var` will be an object with | ||
| two keys: `key` and `val`. These keys correspond to a key in the object and its corresponding value. | ||
| When $map is given an object, the expression defined by `each(var)` must evaluate to an | ||
| object for each key/value pair (`key` and `val`).The objects constructed by each 'each(var)' | ||
| object for each key/value pair (`key` and `val`). The objects constructed by each 'each(var)' | ||
| can then be merged internally to give the resulting object with later keys overwriting | ||
@@ -348,2 +355,8 @@ the previous ones.Otherwise the expression becomes invalid for the $map operator | ||
| result: {ax: 2, bx: 3, cx: 4} | ||
| --- | ||
| template: | ||
| $map: {a: 1, b: 2, c: 3} | ||
| each(v,k): {'${k}x': {$eval: 'v + 1'}} | ||
| context: {} | ||
| result: {ax: 2, bx: 3, cx: 4} | ||
| ``` | ||
@@ -719,3 +732,3 @@ | ||
| - function | ||
| - null # note: the value null, not the string "null" | ||
| - null | ||
| - '' # .. which interpolates to an empty string | ||
@@ -722,0 +735,0 @@ ``` |
+1
-1
@@ -135,3 +135,3 @@ var {BuiltinError} = require('./error'); | ||
| if (types['null'](x)) { | ||
| return null; | ||
| return 'null'; | ||
| } | ||
@@ -138,0 +138,0 @@ throw builtinError('builtin: typeof', `argument ${x} to be a valid json-e type. found ${typeof arg}`); |
+15
-10
@@ -156,3 +156,3 @@ var interpreter = require('./interpreter'); | ||
| operators.$map = (template, context) => { | ||
| EACH_RE = 'each\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)'; | ||
| EACH_RE = 'each\\(([a-zA-Z_][a-zA-Z0-9_]*)(,\\s*([a-zA-Z_][a-zA-Z0-9_]*))?\\)'; | ||
| checkUndefinedProperties(template, ['\\$map', EACH_RE]); | ||
@@ -169,3 +169,3 @@ let value = render(template['$map'], context); | ||
| let eachKey = Object.keys(template).filter(k => k !== '$map')[0]; | ||
| let match = /^each\(([a-zA-Z_][a-zA-Z0-9_]*)\)$/.exec(eachKey); | ||
| let match = /^each\(([a-zA-Z_][a-zA-Z0-9_]*)(,\s*([a-zA-Z_][a-zA-Z0-9_]*))?\)$/.exec(eachKey); | ||
| if (!match) { | ||
@@ -176,2 +176,3 @@ throw new TemplateError('$map requires each(identifier) syntax'); | ||
| let x = match[1]; | ||
| let i = match[3]; | ||
| let each = template[eachKey]; | ||
@@ -185,3 +186,4 @@ | ||
| value = value.map(v => { | ||
| eachValue = render(each, Object.assign({}, context, {[x]: v})); | ||
| let args = typeof i !== 'undefined' ? {[x]: v.val, [i]: v.key} : {[x]: v}; | ||
| eachValue = render(each, Object.assign({}, context, args)); | ||
| if (!isObject(eachValue)) { | ||
@@ -195,4 +197,6 @@ throw new TemplateError(`$map on objects expects each(${x}) to evaluate to an object`); | ||
| } else { | ||
| return value.map(v => render(each, Object.assign({}, context, {[x]: v}))) | ||
| .filter(v => v !== deleteMarker); | ||
| return value.map((v, idx) => { | ||
| let args = typeof i !== 'undefined' ? {[x]: v, [i]: idx} : {[x]: v}; | ||
| return render(each, Object.assign({}, context, args)); | ||
| }).filter(v => v !== deleteMarker); | ||
| } | ||
@@ -209,6 +213,7 @@ }; | ||
| const result = []; | ||
| const conditions = template['$match']; | ||
| for (var condition in template['$match']) { | ||
| if ({}.hasOwnProperty.call(template['$match'], condition)) { | ||
| isTruthy(interpreter.parse(condition, context)) && result.push(render(template['$match'][condition], context)); | ||
| for (let condition of Object.keys(conditions).sort()) { | ||
| if (isTruthy(interpreter.parse(condition, context))) { | ||
| result.push(render(conditions[condition], context)); | ||
| } | ||
@@ -377,3 +382,3 @@ } | ||
| } else if (/^\$[a-zA-Z][a-zA-Z0-9]*$/.test(key)) { | ||
| throw new TemplateError('$<identifier> is reserved; ues $$<identifier>'); | ||
| throw new TemplateError('$<identifier> is reserved; use $$<identifier>'); | ||
| } else { | ||
@@ -400,2 +405,2 @@ key = interpolate(key, context); | ||
| return result; | ||
| }; | ||
| }; |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
74331
2%1125
0.54%744
1.78%