Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-e

Package Overview
Dependencies
Maintainers
9
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-e - npm Package Compare versions

Comparing version 2.7.0 to 3.0.0

9

package.json
{
"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"
]
}
}

23

README.md

@@ -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 @@ ```

@@ -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}`);

@@ -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;
};
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc