postman-collection
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -5,14 +5,4 @@ var _ = require('../util').lodash, | ||
Description = require('./description').Description, | ||
Substitutor = require('../superstring').Substitutor, | ||
/** | ||
* Maintain a list of types that are native | ||
* @private | ||
* @enum {String} | ||
*/ | ||
nativeTypes = { | ||
'string': true, | ||
'number': true, | ||
'boolean': true | ||
}, | ||
Property; // constructor | ||
@@ -158,18 +148,2 @@ | ||
/** | ||
* Regular expression to be used in {String}.replace for extracting variable substitutions | ||
* @private | ||
* @readOnly | ||
* @type {RegExp} | ||
*/ | ||
REGEX_EXTRACT_VARS: /\{\{([^}]*?)}}/g, | ||
/** | ||
* Upper iteration limit for recursive variable resolution. The resolver runs till a count of one less than this. | ||
* @private | ||
* @readOnly | ||
* @type {Integer} | ||
*/ | ||
MAX_RESOLUTION_LIMIT: 21, | ||
/** | ||
* This function accepts a string followed by a number of variable sources as arguments. One or more variable | ||
@@ -185,28 +159,8 @@ * sources can be provided and it will use the one that has the value in left-to-right order. | ||
// if there is nothing to replace, we move on | ||
if (!(str && _.isString(str))) { | ||
return str; | ||
} | ||
if (!(str && _.isString(str))) { return str; } | ||
// extract all arguments to get the list of variables | ||
!_.isArray(variables) && (variables = _.tail(arguments)); | ||
var resolvedStr, | ||
replaced = true, | ||
resolutionLimit = this.MAX_RESOLUTION_LIMIT, | ||
onReplace = function (match, token) { | ||
replaced = true; | ||
var r = _.findValue(variables, token); | ||
r && _.isFunction(r) && (r = r()); | ||
r && _.isFunction(r.toString) && (r = r.toString()); | ||
return nativeTypes[(typeof r)] ? r : match; | ||
}; | ||
// recursively find and resolve variables within a range this.MAX_RESOLUTION_LIMIT | ||
while (replaced && --resolutionLimit) { | ||
replaced = false; | ||
resolvedStr = str; | ||
str = str.replace(this.REGEX_EXTRACT_VARS, onReplace); | ||
} | ||
return resolvedStr; | ||
// if variables object is not an instance of substitutor then ensure that it is an array so that it becomes | ||
// compatibule with the constructor arguments for a substitutor | ||
!Substitutor.isInstance(variables) && !_.isArray(variables) && (variables = _.tail(arguments)); | ||
return Substitutor.box(variables, Substitutor.DEFAULT_VARS).parse(str).toString(); | ||
}, | ||
@@ -229,2 +183,5 @@ | ||
// convert the variables to a substitutor object (will not reconvert if already substitutor) | ||
variables = Substitutor.box(variables, Substitutor.DEFAULT_VARS); | ||
return _.merge(mutate ? obj : {}, obj, function (objectValue, sourceValue) { | ||
@@ -231,0 +188,0 @@ return _.isString(sourceValue) ? this.replaceSubstitutions(sourceValue, variables) : undefined; |
@@ -310,3 +310,3 @@ var _ = require('../util').lodash, | ||
// extract the query string | ||
p.query = _.get(url.match(/^\?([^#$]+)/), '[1]'); | ||
p.query = _.get(url.match(/^\?([^#]+)/), '[1]'); | ||
_.isString(p.query) && ((url = url.substr(p.query.length + 1)), (p.query = QueryParam.parse(p.query))); | ||
@@ -313,0 +313,0 @@ |
var _ = require('../util').lodash, | ||
uuid = require('node-uuid'), | ||
PropertyList = require('./property-list').PropertyList, | ||
@@ -18,19 +17,2 @@ PropertyBase = require('./property-base').PropertyBase, | ||
/** | ||
* Holds the default variables that Postman supports. | ||
* | ||
* @type {Object} | ||
*/ | ||
DEFAULT_VARS = { | ||
$guid: function () { | ||
return uuid.v4(); | ||
}, | ||
$timestamp: function () { | ||
return Math.round(Date.now() / 1000); | ||
}, | ||
$randomInt: function () { | ||
return ~~(Math.random() * (1000 + 1)); | ||
} | ||
}, | ||
VariableList; | ||
@@ -60,3 +42,3 @@ | ||
return (proxies.push(VariableList.proxy(parent, VariableList.objectify(child))), _.last(proxies)); | ||
}, DEFAULT_VARS); // @todo: allow injecting default variables into this externally. | ||
}, {}); // @todo: allow injecting default variables into this externally. | ||
@@ -162,8 +144,2 @@ // pre-create the reference object (will be used by super) to store the actual variables | ||
/** | ||
* @private | ||
* | ||
* @type {RegExp} | ||
*/ | ||
REGEX_EXTRACT_VARS: /\{\{([^}]*?)}}/g, | ||
/** | ||
* Converts an object into an inheritable constructor, creates a new instance and returns the same with the `values` | ||
@@ -170,0 +146,0 @@ * parameter copied |
@@ -132,31 +132,2 @@ 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 obj, | ||
i, | ||
ii; | ||
for (i = 0, ii = arr.length; i < ii; i++) { | ||
obj = arr[i]; | ||
// ensure that the item is an object | ||
if (!(obj && _.isObject(obj))) { | ||
continue; | ||
} | ||
if (obj.constructor._postman_propertyName === 'VariableList') { | ||
if (obj.has(key)) { return obj.one(key); } | ||
} | ||
else if (_.has(obj, key)) { | ||
return obj[key]; | ||
} | ||
} | ||
} | ||
@@ -163,0 +134,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"author": "Postman Labs <help@getpostman.com>", | ||
"version": "0.1.0", | ||
"version": "0.1.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
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
246804
61
5685