postman-collection
Advanced tools
Comparing version 0.2.2 to 0.3.0
@@ -99,2 +99,10 @@ var _ = require('../util').lodash, | ||
/** | ||
* Specifies whether the index lookup of this property, when in a list is case insensitive or not | ||
* @private | ||
* @readOnly | ||
* @type {boolean} | ||
*/ | ||
_postman_propertyIndexCaseInsensitive: true, | ||
/** | ||
* Parses a multi line header string into an array of {@link Header~definition}. | ||
@@ -101,0 +109,0 @@ * |
@@ -6,2 +6,3 @@ var _ = require('../util').lodash, | ||
DEFAULT_INDEX_ATTR = 'id', | ||
DEFAULT_INDEXCASE_ATTR = false, | ||
@@ -17,3 +18,10 @@ PropertyList; | ||
*/ | ||
PropertyList = function PostmanPropertyList (type, parent, populate, options) { | ||
PropertyList = function PostmanPropertyList (type, parent, populate) { | ||
// @todo add this test sometime later | ||
// if (!type) { | ||
// throw new Error('postman-collection: cannot initialise a list without a type parameter'); | ||
// } | ||
PropertyList.super_.call(this); // call super with appropriate options | ||
_.assignLocked(this, __PARENT, parent); // save reference to parent | ||
@@ -33,12 +41,20 @@ _.extend(this, /** @lends PropertyList.prototype */ { | ||
* @private | ||
* @type {function} | ||
* @type {Function} | ||
*/ | ||
Type: type, | ||
/** | ||
* Holds holds the attribute to index this PropertyList by. Default: 'id' | ||
* Holds the attribute to index this PropertyList by. Default: 'id' | ||
* | ||
* @private | ||
* @type {function} | ||
* @type {String} | ||
*/ | ||
indexBy: (options && options.indexBy) || (type && type._postman_propertyIndexKey) || DEFAULT_INDEX_ATTR | ||
_postman_propertyIndexKey: _.getOwn(type, '_postman_propertyIndexKey', DEFAULT_INDEX_ATTR), | ||
/** | ||
* Holds the attribute whether indexing of this list is case sensitive or not | ||
* | ||
* @private | ||
* @type {String | ||
*/ | ||
_postman_propertyIndexCaseInsensitive: _.getOwn(type, '_postman_propertyIndexCaseInsensitive', | ||
DEFAULT_INDEXCASE_ATTR) | ||
}); | ||
@@ -68,3 +84,4 @@ | ||
var duplicate = this.indexOf(item); | ||
var duplicate = this.indexOf(item), | ||
index; | ||
@@ -83,3 +100,10 @@ // remove from previous list | ||
(before > -1) ? this.members.splice(before, 0, item) : this.members.push(item); | ||
item[this.indexBy] && (this.reference[item[this.indexBy]] = item); // store reference by id | ||
// store reference by id, so create the index string. we first ensure that the index value is truthy and then | ||
// recheck that the string conversion of the same is truthy as well. | ||
if ((index = item[this._postman_propertyIndexKey]) && (index = String(index))) { | ||
// desensitise case, if the property needs it to be | ||
this._postman_propertyIndexCaseInsensitive && (index = index.toLowerCase()); | ||
this.reference[index] = item; | ||
} | ||
}, | ||
@@ -141,7 +165,6 @@ | ||
// if predicate is id, then create a function to remove that from array | ||
if (_.isString(predicate) && this.reference[predicate]) { | ||
match = predicate; | ||
predicate = function (item) { | ||
return item && (item[this.indexBy] === match); | ||
}; | ||
if (_.isString(predicate)) { | ||
(match = this.one(predicate)) && (predicate = function (item) { | ||
return (item === match); | ||
}); | ||
} | ||
@@ -157,5 +180,8 @@ // in case an object reference is sent, prepare it for removal | ||
_.isFunction(predicate) && _.remove(this.members, function (item) { | ||
var index; | ||
if (predicate.apply(context, arguments)) { | ||
(this.reference[item[this.indexBy]] === item) && | ||
(delete this.reference[item[this.indexBy]]); // delete id reference | ||
if ((index = item[this._postman_propertyIndexKey]) && (index = String(index))) { | ||
this._postman_propertyIndexCaseInsensitive && (index = index.toLowerCase()); | ||
delete this.reference[index]; | ||
} | ||
delete item[__PARENT]; // unlink from its parent | ||
@@ -204,3 +230,3 @@ return true; | ||
one: function (id) { | ||
return this.reference[id]; | ||
return this.reference[this._postman_propertyIndexCaseInsensitive ? String(id).toLowerCase() : id]; | ||
}, | ||
@@ -207,0 +233,0 @@ |
@@ -19,4 +19,4 @@ var /** | ||
lookup: function mimeFormatLookup (mime) { | ||
return db[mime] || { | ||
type: mime && (mime = mime.split(SEP)) && mime[0], | ||
return mime && (mime = String(mime)) && (mime = mime.replace(/^\s*?([^;\s]+).*$/g, '$1')) && db[mime] || { | ||
type: (mime = mime.split(SEP)) && mime[0], | ||
format: 'raw' | ||
@@ -23,0 +23,0 @@ }; |
@@ -107,3 +107,3 @@ /* global btoa */ | ||
* @param Prop | ||
* @returns {undefined} | ||
* @returns {Prop|undefined} | ||
*/ | ||
@@ -115,2 +115,15 @@ createDefined: function (obj, name, Prop) { | ||
/** | ||
* Returns the value of a property if defined in object, else the default | ||
* | ||
* @param {Object} obj | ||
* @param {String} prop | ||
* @param {*} def | ||
* | ||
* @returns {*} | ||
*/ | ||
getOwn: function (obj, prop, def) { | ||
return _.has(obj, prop) ? obj[prop] : def; | ||
}, | ||
/** | ||
* Creates a clone of an object, but uses the toJSON method if available. | ||
@@ -117,0 +130,0 @@ * |
@@ -5,3 +5,3 @@ { | ||
"author": "Postman Labs <help@getpostman.com>", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"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
317964
7978