Comparing version 2.2.1 to 2.3.0
{ | ||
"name": "json-e", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"description": "json parameterization module inspired from json-parameterization", | ||
@@ -8,3 +8,2 @@ "main": "./src/index.js", | ||
"test": "mocha test/*_test.js", | ||
"prepublish": "npm test", | ||
"build-demo": "cd demo && yarn && yarn build", | ||
@@ -11,0 +10,0 @@ "start-demo": "cd demo && yarn && yarn start" |
@@ -284,2 +284,28 @@ # [JSON-e](https://taskcluster.github.io/json-e) | ||
### `$mergeDeep` | ||
The `$mergeDeep` operator is like `$merge`, but it recurses into objects to | ||
combine their contents property by property. Arrays are concatenated. | ||
```yaml | ||
context: {} | ||
template: | ||
$mergeDeep: | ||
- task: | ||
payload: | ||
command: [a, b] | ||
- task: | ||
extra: | ||
foo: bar | ||
- task: | ||
payload: | ||
command: [c] | ||
result: | ||
task: | ||
extra: | ||
foo: bar | ||
payload: | ||
command: [a, b, c] | ||
``` | ||
### `$sort` | ||
@@ -511,2 +537,3 @@ | ||
* `str(x)` -- convert string, number, boolean, or array to string | ||
* `lstrip(s)`, `rstrip(s)`, `strip(s)` -- strip whitespace from left, right, or both ends of a string | ||
* `len(x)` -- length of a string or array | ||
@@ -548,3 +575,3 @@ | ||
* Update the version, commit, and tag -- `npm patch` (or minor or major, depending) | ||
* Update the version, commit, and tag -- `npm version patch` (or minor or major, depending) | ||
* Push to release the JS version -- `git push && git push --tags` | ||
@@ -551,0 +578,0 @@ * Release to PyPi: |
@@ -100,2 +100,17 @@ var {BuiltinError} = require('./error'); | ||
define('strip', builtins, { | ||
argumentTests: ['string'], | ||
invoke: str => str.trim(), | ||
}); | ||
define('rstrip', builtins, { | ||
argumentTests: ['string'], | ||
invoke: str => str.replace(/\s+$/, ''), | ||
}); | ||
define('lstrip', builtins, { | ||
argumentTests: ['string'], | ||
invoke: str => str.replace(/^\s+/, ''), | ||
}); | ||
// Miscellaneous | ||
@@ -102,0 +117,0 @@ define('fromNow', builtins, { |
@@ -164,2 +164,40 @@ var interpreter = require('./interpreter'); | ||
operators.$mergeDeep = (template, context) => { | ||
let value = render(template['$mergeDeep'], context); | ||
if (!isArray(value) || value.some(o => !isObject(o))) { | ||
throw new TemplateError('$mergeDeep value must evaluate to an array of objects'); | ||
} | ||
if (value.length === 0) { | ||
return {}; | ||
} | ||
// merge two values, preferring the right but concatenating lists and | ||
// recursively merging objects | ||
let merge = (l, r) => { | ||
console.log(`merge(${JSON.stringify(l)}, ${JSON.stringify(r)})`); | ||
if (isArray(l) && isArray(r)) { | ||
return l.concat(r); | ||
} | ||
if (isObject(l) && isObject(r)) { | ||
let res = Object.assign({}, l); | ||
for (let p in r) { // eslint-disable-line taskcluster/no-for-in | ||
if (p in l) { | ||
res[p] = merge(l[p], r[p]); | ||
console.log(`-> ${JSON.stringify(res[p])}`); | ||
} else { | ||
res[p] = r[p]; | ||
} | ||
} | ||
return res; | ||
} | ||
return r; | ||
}; | ||
console.log(`merging ${JSON.stringify(value)}`); | ||
// start with the first element of the list | ||
return value.reduce(merge, value.shift()); | ||
return Object.assign({}, ...value); | ||
}; | ||
operators.$reverse = (template, context) => { | ||
@@ -166,0 +204,0 @@ let value = render(template['$reverse'], context); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
66675
1064
578
0