postman-collection
Advanced tools
Comparing version 0.0.11 to 0.0.12-beta.1
@@ -52,3 +52,3 @@ var _ = require('../util').lodash, | ||
// Basically, removes the trailing "s" from key if the value is a property list. | ||
if (value && value._postman_isGroup && _.endsWith(key, 's')) { | ||
if (value && value._postman_propertyIsList && _.endsWith(key, 's')) { | ||
key = key.slice(0, -1); | ||
@@ -55,0 +55,0 @@ } |
@@ -53,3 +53,3 @@ var _ = require('../util').lodash, | ||
*/ | ||
_postman_isGroup: true, | ||
_postman_propertyIsList: true, | ||
@@ -300,3 +300,3 @@ /** | ||
// Basically, removes the trailing "s" from key if the value is a property list. | ||
if (value && value._postman_isGroup && _.endsWith(key, 's')) { | ||
if (value && value._postman_propertyIsList && _.endsWith(key, 's')) { | ||
key = key.slice(0, -1); | ||
@@ -303,0 +303,0 @@ } |
@@ -106,4 +106,5 @@ var _ = require('../util').lodash, | ||
* | ||
* @param {VariableList=} [variables] - One can specifically provide a VariableList for doing the substitution. In | ||
* @param {?VariableList=} [variables] - One can specifically provide a VariableList for doing the substitution. In | ||
* the event one is not provided, the variables are taken from this object or one from the parent tree. | ||
* @param {Array<Object>} overrides - additional objects to lookup for variable values | ||
* @returns {Object|undefined} | ||
@@ -113,3 +114,3 @@ * | ||
*/ | ||
toObjectResolved: function (variables) { | ||
toObjectResolved: function (variables, overrides) { | ||
var variableSourceObj = this; | ||
@@ -129,3 +130,3 @@ | ||
return variables ? variables.substitute(this.toJSON()) : undefined; | ||
return variables ? variables.substitute(this.toJSON(), overrides) : undefined; | ||
} | ||
@@ -132,0 +133,0 @@ }); |
@@ -63,11 +63,13 @@ var _ = require('../util').lodash, | ||
/** | ||
* Replaces the variable tokens inside a string with its actual values | ||
* Replaces the variable tokens inside a string with its actual values. | ||
* | ||
* @param {String} str | ||
* @param {Array<Object>=} [overrides] - additional objects to lookup for variable values | ||
* @returns {String} | ||
*/ | ||
replace: function (str) { | ||
replace: function (str, overrides) { | ||
var self = this; | ||
return str.replace ? str.replace(VariableList.REGEX_EXTRACT_VARS, function (a, b) { | ||
var r = self.one(b) && self.one(b).toString(); | ||
var r = self.has(b) ? self.one(b) : _.findValue(overrides, b); | ||
r && _.isFunction(r.toString) && (r = r.toString()); | ||
return nativeTypes[(typeof r)] ? r : a; | ||
@@ -79,11 +81,12 @@ }) : str; | ||
* Recursively replace strings in an object with instances of variables. Note that it clones the original object. If | ||
* the `mutate` param is set to true, then it replaces the same object instead of creatinbg a new one. | ||
* the `mutate` param is set to true, then it replaces the same object instead of creating a new one. | ||
* | ||
* @param {Array|Object} obj | ||
* @param {?Array<Object>=} [overrides] - additional objects to lookup for variable values | ||
* @param {Boolean=} [mutate=false] | ||
* @returns {Array|Object} | ||
*/ | ||
substitute: function (obj, mutate) { | ||
substitute: function (obj, overrides, mutate) { | ||
return _.isObject(obj) ? _.merge(mutate ? obj : {}, obj, function (objectValue, sourceValue) { | ||
return _.isString(sourceValue) ? this.replace(sourceValue) : undefined; | ||
return _.isString(sourceValue) ? this.replace(sourceValue, overrides) : undefined; | ||
}, this) : obj; | ||
@@ -108,3 +111,3 @@ }, | ||
* myCollection.variables.env(1); // gets the second environment as Object | ||
* myCollection.variables.env(0, null, true); // cleares the first environment (does not delete the layer though) | ||
* myCollection.variables.env(0, null, true); // clears the first environment (does not delete the layer though) | ||
* myCollection.variables.env(0, { | ||
@@ -111,0 +114,0 @@ * var1: "variable-value" |
@@ -132,2 +132,21 @@ var _ = require('lodash'); | ||
return obj ? ((obj[key] === value) || _.inSuperChain(obj.super_, key, value)) : false; | ||
}, | ||
/** | ||
* Similar to _.find, except that it returns the value if it is present | ||
* @param {Array} arr | ||
* @param {String} key | ||
* @returns {*} | ||
*/ | ||
findValue: function (arr, key) { | ||
if (!_.isArray(arr) || !arr.length) { return; } | ||
var i, | ||
ii; | ||
for (i = 0, ii = arr.length; i < ii; i++) { | ||
if (_.isObject(arr[i]) && _.has(arr[i], key)) { | ||
return arr[i][key]; | ||
} | ||
} | ||
} | ||
@@ -134,0 +153,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"author": "Postman Labs <help@getpostman.com>", | ||
"version": "0.0.11", | ||
"version": "0.0.12-beta.1", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "postman" |
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
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
221336
5100
1