_id
stringlengths 2
6
| title
stringlengths 0
58
| partition
stringclasses 3
values | text
stringlengths 52
373k
| language
stringclasses 1
value | meta_information
dict |
|---|---|---|---|---|---|
q44600
|
train
|
function (mutation) {
// bail out for empty or unsupported mutations
if (!(mutation && isPrimitiveMutation(mutation))) {
return;
}
// if autoCompact is set, we need to compact while adding
if (this.autoCompact) {
this.addAndCompact(mutation);
return;
}
// otherwise just push to the stream of mutations
this.stream.push(mutation);
}
|
javascript
|
{
"resource": ""
}
|
|
q44601
|
train
|
function (mutation) {
// for `set` and `unset` mutations the key to compact with is the `keyPath`
var key = mutation[0];
// convert `keyPath` to a string
key = Array.isArray(key) ? key.join('.') : key;
this.compacted[key] = mutation;
}
|
javascript
|
{
"resource": ""
}
|
|
q44602
|
train
|
function (instruction) {
// @todo: use argument spread here once we drop support for node v4
var payload = Array.prototype.slice.call(arguments, 1);
// invalid call
if (!(instruction && payload)) {
return;
}
// unknown instruction
if (!(instruction === PRIMITIVE_MUTATIONS.SET || instruction === PRIMITIVE_MUTATIONS.UNSET)) {
return;
}
// for primitive mutations the arguments form the mutation object
// if there is more complex mutation, we have to use a processor to create a mutation for the instruction
this.addMutation(payload);
}
|
javascript
|
{
"resource": ""
}
|
|
q44603
|
train
|
function (target) {
if (!(target && target.applyMutation)) {
return;
}
var applyIndividualMutation = function applyIndividualMutation (mutation) {
applyMutation(target, mutation);
};
// mutations move from `stream` to `compacted`, so we apply the compacted mutations first
// to ensure FIFO of mutations
// apply the compacted mutations first
_.forEach(this.compacted, applyIndividualMutation);
// apply the mutations in the stream
_.forEach(this.stream, applyIndividualMutation);
}
|
javascript
|
{
"resource": ""
}
|
|
q44604
|
train
|
function (options) {
_.has(options, 'pattern') && (_.isString(options.pattern) && !_.isEmpty(options.pattern)) &&
(this.pattern = options.pattern);
// create a match pattern and store it on cache
this._matchPatternObject = this.createMatchPattern();
}
|
javascript
|
{
"resource": ""
}
|
|
q44605
|
train
|
function () {
var matchPattern = this.pattern,
// Check the match pattern of sanity and split it into protocol, host and path
match = matchPattern.match(regexes.patternSplit);
if (!match) {
// This ensures it is a invalid match pattern
return;
}
return {
protocols: _.uniq(match[1].split(PROTOCOL_DELIMITER)),
host: match[5],
port: match[6] && match[6].substr(1), // remove leading `:`
path: this.globPatternToRegexp(match[7])
};
}
|
javascript
|
{
"resource": ""
}
|
|
q44606
|
train
|
function (pattern) {
// Escape everything except ? and *.
pattern = pattern.replace(regexes.escapeMatcher, regexes.escapeMatchReplacement);
pattern = pattern.replace(regexes.questionmarkMatcher, regexes.questionmarkReplacment);
pattern = pattern.replace(regexes.starMatcher, regexes.starReplacement);
return new RegExp(PREFIX_DELIMITER + pattern + POSTFIX_DELIMITER);
}
|
javascript
|
{
"resource": ""
}
|
|
q44607
|
train
|
function (protocol) {
var matchRegexObject = this._matchPatternObject;
return _.includes(ALLOWED_PROTOCOLS, protocol) &&
(_.includes(matchRegexObject.protocols, MATCH_ALL) || _.includes(matchRegexObject.protocols, protocol));
}
|
javascript
|
{
"resource": ""
}
|
|
q44608
|
train
|
function (host) {
/*
* For Host match, we are considering the port with the host, hence we are using getRemote() instead of getHost()
* We need to address three cases for the host urlStr
* 1. * It matches all the host + protocol, hence we are not having any parsing logic for it.
* 2. *.foo.bar.com Here the prefix could be anything but it should end with foo.bar.com
* 3. foo.bar.com This is the absolute matching needs to done.
*/
var matchRegexObject = this._matchPatternObject;
return (
this.matchAnyHost(matchRegexObject) ||
this.matchAbsoluteHostPattern(matchRegexObject, host) ||
this.matchSuffixHostPattern(matchRegexObject, host)
);
}
|
javascript
|
{
"resource": ""
}
|
|
q44609
|
train
|
function (port, protocol) {
var portRegex = this._matchPatternObject.port,
// default port for given protocol
defaultPort = protocol && DEFAULT_PROTOCOL_PORT[protocol];
// return true if both given port and match pattern are absent
if (typeof port === UNDEFINED && typeof portRegex === UNDEFINED) {
return true;
}
// convert integer port to string
(port && typeof port !== STRING) && (port = String(port));
// assign default port or portRegex
!port && (port = defaultPort);
!portRegex && (portRegex = defaultPort);
// matches * or specific port
return (
portRegex === MATCH_ALL ||
portRegex === port
);
}
|
javascript
|
{
"resource": ""
}
|
|
q44610
|
train
|
function (key) {
// bail out if property protocolProfileBehavior is not set or key is non-string
if (!(typeof this.protocolProfileBehavior === OBJECT && typeof key === STRING)) {
return this;
}
if (this.protocolProfileBehavior.hasOwnProperty(key)) {
delete this.protocolProfileBehavior[key];
}
return this;
}
|
javascript
|
{
"resource": ""
}
|
|
q44611
|
forEachItem
|
train
|
function forEachItem (callback) {
this.items.each(function (item) {
return ItemGroup.isItemGroup(item) ? item.forEachItem(callback) : callback(item, this);
}, this);
}
|
javascript
|
{
"resource": ""
}
|
q44612
|
forEachItemGroup
|
train
|
function forEachItemGroup (callback) {
this.items.each(function (item) {
if (ItemGroup.isItemGroup(item)) {
item.forEachItemGroup(callback);
callback(item, this); // eslint-disable-line callback-return
}
}, this);
}
|
javascript
|
{
"resource": ""
}
|
q44613
|
train
|
function (idOrName) {
if (!_.isString(idOrName)) { return; }
var item;
this.items.each(function (eachItem) {
if (eachItem.id === idOrName || eachItem.name === idOrName) {
item = eachItem;
return false; // we found something, so bail out of the for loop.
}
if (ItemGroup.isItemGroup(eachItem)) {
item = eachItem.oneDeep(idOrName);
return !item; // bail out of the for loop if we found anything
}
});
return item;
}
|
javascript
|
{
"resource": ""
}
|
|
q44614
|
train
|
function (item) {
if (Item.isItem(item) || ItemGroup.isItemGroup(item)) { return item; }
return item && item.item ? new ItemGroup(item) : new Item(item);
}
|
javascript
|
{
"resource": ""
}
|
|
q44615
|
train
|
function (options) {
// return early if options is empty or invalid
if (!_.isObject(options)) {
return;
}
_.mergeDefined(this, /** @lends Certificate.prototype */ {
/**
* Unique identifier
* @type {String}
*/
id: options.id,
/**
* Name for user reference
* @type {String}
*/
name: options.name,
/**
* List of match pattern
* @type {UrlMatchPatternList}
*/
matches: options.matches && new UrlMatchPatternList({}, options.matches),
/**
* Private Key
* @type {{ src: (string) }}
*/
key: _.isObject(options.key) ? options.key : { src: options.key },
/**
* Certificate
* @type {{ src: (string) }}
*/
cert: _.isObject(options.cert) ? options.cert : { src: options.cert },
/**
* PFX or PKCS12 Certificate
* @type {{ src: (string) }}
*/
pfx: _.isObject(options.pfx) ? options.pfx : { src: options.pfx },
/**
* passphrase
* @type {Object}
*/
passphrase: options.passphrase
});
}
|
javascript
|
{
"resource": ""
}
|
|
q44616
|
train
|
function (url) {
if (_.isEmpty(url)) {
return false;
}
// convert url strings to Url
(typeof url === STRING) && (url = new Url(url));
// this ensures we don't proceed any further for any protocol
// that is not https
if (url.protocol !== HTTPS) {
return false;
}
// test the input url against allowed matches
return this.matches.test(url);
}
|
javascript
|
{
"resource": ""
}
|
|
q44617
|
train
|
function (obj) {
return Boolean(obj) && ((obj instanceof Certificate) ||
_.inSuperChain(obj.constructor, '_postman_propertyName', Certificate._postman_propertyName));
}
|
javascript
|
{
"resource": ""
}
|
|
q44618
|
train
|
function (content, type) {
(Description.isDescription(this.description) ? this.description : (this.description = new Description()))
.update(content, type);
}
|
javascript
|
{
"resource": ""
}
|
|
q44619
|
train
|
function (scope, overrides, options) {
var ignoreOwnVariables = options && options.ignoreOwnVariables,
variableSourceObj,
variables,
reference;
// ensure you do not substitute variables itself!
reference = this.toJSON();
_.isArray(reference.variable) && (delete reference.variable);
// if `ignoreScopeVariables` is turned on, ignore `.variables` and resolve with only `overrides`
// otherwise find `.variables` on current object or `scope`
if (ignoreOwnVariables) {
return Property.replaceSubstitutionsIn(reference, overrides);
}
// 1. if variables is passed as params, use it or fall back to oneself
// 2. for a source from point (1), and look for `.variables`
// 3. if `.variables` is not found, then rise up the parent to find first .variables
variableSourceObj = scope || this;
do {
variables = variableSourceObj.variables;
variableSourceObj = variableSourceObj.__parent;
} while (!variables && variableSourceObj);
if (!variables) { // worst case = no variable param and none detected in tree or object
throw Error('Unable to resolve variables. Require a List type property for variable auto resolution.');
}
return variables.substitute(reference, overrides);
}
|
javascript
|
{
"resource": ""
}
|
|
q44620
|
train
|
function (str, variables) {
// if there is nothing to replace, we move on
if (!(str && _.isString(str))) { return str; }
// if variables object is not an instance of substitutor then ensure that it is an array so that it becomes
// compatible 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();
}
|
javascript
|
{
"resource": ""
}
|
|
q44621
|
train
|
function (obj, variables, mutate) {
// if there is nothing to replace, we move on
if (!(obj && _.isObject(obj))) {
return obj;
}
// convert the variables to a substitutor object (will not reconvert if already substitutor)
variables = Substitutor.box(variables, Substitutor.DEFAULT_VARS);
var customizer = function (objectValue, sourceValue) {
objectValue = objectValue || {};
if (!_.isString(sourceValue)) {
_.forOwn(sourceValue, function (value, key) {
sourceValue[key] = customizer(objectValue[key], value);
});
return sourceValue;
}
return this.replaceSubstitutions(sourceValue, variables);
}.bind(this);
return _.mergeWith(mutate ? obj : {}, obj, customizer);
}
|
javascript
|
{
"resource": ""
}
|
|
q44622
|
train
|
function (options) {
if (!_.isObject(options)) {
return;
}
var parsedUrl,
port = _.get(options, 'port') >> 0;
if (_.isString(options.host)) {
parsedUrl = nodeUrl.parse(options.host);
// we want to strip the protocol, but if protocol is not present then parsedUrl.hostname will be null
this.host = parsedUrl.protocol ? parsedUrl.hostname : options.host;
}
_.isString(options.match) && (this.match = new UrlMatchPattern(options.match));
_.isString(_.get(options, 'match.pattern')) && (this.match = new UrlMatchPattern(options.match.pattern));
port && (this.port = port);
_.isBoolean(options.tunnel) && (this.tunnel = options.tunnel);
// todo: Add update method in parent class Property and call that here
_.isBoolean(options.disabled) && (this.disabled = options.disabled);
_.isBoolean(options.authenticate) && (this.authenticate = options.authenticate);
_.isString(options.username) && (this.username = options.username);
_.isString(options.password) && (this.password = options.password);
}
|
javascript
|
{
"resource": ""
}
|
|
q44623
|
train
|
function (protocols) {
if (!protocols) {
return;
}
var updatedProtocols,
hostAndPath = _.split(this.match.pattern, PROTOCOL_HOST_SEPARATOR)[1];
if (!hostAndPath) {
return;
}
updatedProtocols = _.intersection(ALLOWED_PROTOCOLS, _.castArray(protocols));
_.isEmpty(updatedProtocols) && (updatedProtocols = ALLOWED_PROTOCOLS);
this.match.update({
pattern: updatedProtocols.join(PROTOCOL_DELIMITER) + PROTOCOL_HOST_SEPARATOR + hostAndPath
});
}
|
javascript
|
{
"resource": ""
}
|
|
q44624
|
train
|
function () {
var auth = E;
// Add authentication method to URL if the same is requested. We do it this way because
// this is how `postman-request` library accepts auth credentials in its proxy configuration.
if (this.authenticate) {
auth = (this.username || E);
if (this.password) {
auth += (COLON + (this.password || E));
}
if (auth) {
auth += AUTH_CREDENTIALS_SEPARATOR;
}
}
return DEFAULT_PROTOCOL + PROTOCOL_HOST_SEPARATOR + auth + this.host + COLON + this.port;
}
|
javascript
|
{
"resource": ""
}
|
|
q44625
|
train
|
function () {
if (!this.count()) { return 0; }
var raw = this.reduce(function (acc, header) {
// unparse header only if it has a valid key and is not disabled
if (header && !header.disabled) {
// *( header-field CRLF )
acc += Header.unparseSingle(header) + CRLF;
}
return acc;
}, E);
return raw.length;
}
|
javascript
|
{
"resource": ""
}
|
|
q44626
|
train
|
function (obj) {
return Boolean(obj) && ((obj instanceof HeaderList) ||
_.inSuperChain(obj.constructor, PROP_NAME, HeaderList._postman_propertyName));
}
|
javascript
|
{
"resource": ""
}
|
|
q44627
|
train
|
function (definition) {
if (!definition) {
return;
}
var result,
script = definition.script;
if (Script.isScript(script)) {
result = script;
}
else if (_.isArray(script) || _.isString(script)) {
result = new Script({ exec: script });
}
else if (_.isObject(script)) {
result = new Script(script);
}
_.mergeDefined(this, /** @lends Event.prototype */ {
/**
* Name of the event that this instance is intended to listen to.
* @type {String}
*/
listen: _.isString(definition.listen) ? definition.listen.toLowerCase() : undefined,
/**
* The script that is to be executed when this event is triggered.
* @type {Script}
*/
script: result
});
}
|
javascript
|
{
"resource": ""
}
|
|
q44628
|
train
|
function (content, type) {
_.isObject(content) && ((type = content.type), (content = content.content));
_.assign(this, /** @lends Description.prototype */ {
/**
* The raw content of the description
*
* @type {String}
*/
content: content,
/**
* The mime-type of the description.
*
* @type {String}
*/
type: type || DEFAULT_MIMETYPE
});
}
|
javascript
|
{
"resource": ""
}
|
|
q44629
|
train
|
function (obj) {
return Boolean(obj) && ((obj instanceof Description) ||
_.inSuperChain(obj.constructor, '_postman_propertyName', Description._postman_propertyName));
}
|
javascript
|
{
"resource": ""
}
|
|
q44630
|
train
|
function (name) {
var all;
// we first procure all matching events from this list
all = this.listenersOwn(name);
this.eachParent(function (parent) {
var parentEvents;
// we check that the parent is not immediate mother. then we check whether the non immediate mother has a
// valid `events` store and only if this store has events with specified listener, we push them to the
// array we are compiling for return
(parent !== this.__parent) && EventList.isEventList(parent.events) &&
(parentEvents = parent.events.listenersOwn(name)) && parentEvents.length &&
all.unshift.apply(all, parentEvents); // eslint-disable-line prefer-spread
}, this);
return all;
}
|
javascript
|
{
"resource": ""
}
|
|
q44631
|
train
|
function (obj) {
return Boolean(obj) && ((obj instanceof EventList) ||
_.inSuperChain(obj.constructor, '_postman_propertyName', EventList._postman_propertyName));
}
|
javascript
|
{
"resource": ""
}
|
|
q44632
|
train
|
function (options) {
/**
* The header Key
* @type {String}
* @todo avoid headers with falsy key.
*/
this.key = _.get(options, 'key') || E;
/**
* The header value
* @type {String}
*/
this.value = _.get(options, 'value') || E;
/**
* Indicates whether the header was added by internal SDK operations, such as authorizing a request.
* @type {*|boolean}
*/
_.has(options, 'system') && (this.system = options.system);
/**
* Indicates whether the header should be .
* @type {*|boolean}
* @todo figure out whether this should be in property.js
*/
_.has(options, 'disabled') && (this.disabled = options.disabled);
}
|
javascript
|
{
"resource": ""
}
|
|
q44633
|
train
|
function (header) {
if (!_.isString(header)) { return { key: E, value: E }; }
var index = header.indexOf(HEADER_KV_SEPARATOR),
key,
value;
(index < 0) && (index = header.length);
key = header.substr(0, index);
value = header.substr(index + 1);
return {
key: _.trim(key),
value: _.trim(value)
};
}
|
javascript
|
{
"resource": ""
}
|
|
q44634
|
train
|
function (header) {
if (!_.isObject(header)) { return E; }
return header.key + HEADER_KV_SEPARATOR + SPC + header.value;
}
|
javascript
|
{
"resource": ""
}
|
|
q44635
|
train
|
function (obj) {
return Boolean(obj) && ((obj instanceof Header) ||
_.inSuperChain(obj.constructor, '_postman_propertyName', Header._postman_propertyName));
}
|
javascript
|
{
"resource": ""
}
|
|
q44636
|
train
|
function () {
var value = this.valueOf();
// returns empty string if the value is
// null or undefined or does not implement a toString
return (!_.isNil(value) && _.isFunction(value.toString)) ? value.toString() : E;
}
|
javascript
|
{
"resource": ""
}
|
|
q44637
|
train
|
function (typeName, _noCast) {
!_.isNil(typeName) && (typeName = typeName.toString().toLowerCase()); // sanitize
if (!Variable.types[typeName]) {
return this.type || ANY; // @todo: throw new Error('Invalid variable type.');
}
// set type if it is valid
this.type = typeName;
// 1. get the current value
// 2. set the new type if it is valid and cast the stored value
// 3. then set the interstitial value
var interstitialCastValue;
// do not touch value functions
if (!(_noCast || _.isFunction(this.value))) {
interstitialCastValue = this.get();
this.set(interstitialCastValue);
interstitialCastValue = null; // just a precaution
}
return this.type;
}
|
javascript
|
{
"resource": ""
}
|
|
q44638
|
train
|
function (options) {
if (!_.isObject(options)) {
return;
}
// set type and value.
// @note that we cannot update the key, once created during construction
options.hasOwnProperty('type') && this.valueType(options.type, options.hasOwnProperty('value'));
options.hasOwnProperty('value') && this.set(options.value);
options.hasOwnProperty('system') && (this.system = options.system);
options.hasOwnProperty('disabled') && (this.disabled = options.disabled);
}
|
javascript
|
{
"resource": ""
}
|
|
q44639
|
train
|
function (val) {
var value;
try {
value = JSON.parse(val);
}
catch (e) {
value = undefined;
}
return Array.isArray(value) ? value : undefined;
}
|
javascript
|
{
"resource": ""
}
|
|
q44640
|
train
|
function (obj) {
return Boolean(obj) && ((obj instanceof CookieList) ||
_.inSuperChain(obj.constructor, '_postman_propertyName', CookieList._postman_propertyName));
}
|
javascript
|
{
"resource": ""
}
|
|
q44641
|
train
|
function (value) {
// extract the version logic and in case it failes and value passed is an object, we use that assuming parsed
// value has been sent.
var ver = semver.parse(value) || value || {};
_.assign(this, /** @lends Version.prototype */ {
/**
* The raw URL string. If {@link Version#set} is called with a string parameter, the string is saved here
* before parsing various Version components.
*
* @type {String}
*/
raw: ver.raw,
/**
* @type {String}
*/
major: ver.major,
/**
* @type {String}
*/
minor: ver.minor,
/**
* @type {String}
*/
patch: ver.patch,
/**
* @type {String}
*/
prerelease: ver.prerelease && ver.prerelease.join && ver.prerelease.join() || ver.prerelease,
/**
* @type {String}
*/
build: ver.build && ver.build.join && ver.build.join() || ver.build,
/**
* @type {String}
*/
string: ver.version
});
}
|
javascript
|
{
"resource": ""
}
|
|
q44642
|
train
|
function (options, iterator) {
_.isFunction(options) && (iterator = options, options = {});
if (!_.isFunction(iterator) || !_.isObject(options)) { return; }
var parent = this.parent(),
grandparent = parent && _.isFunction(parent.parent) && parent.parent();
while (parent && (grandparent || options.withRoot)) {
iterator(parent);
parent = grandparent;
grandparent = grandparent && _.isFunction(grandparent.parent) && grandparent.parent();
}
}
|
javascript
|
{
"resource": ""
}
|
|
q44643
|
train
|
function (property, customizer) {
var owner = this.findParentContaining(property, customizer);
return owner ? owner[property] : undefined;
}
|
javascript
|
{
"resource": ""
}
|
|
q44644
|
train
|
function (property, customizer) {
var parent = this;
// if customizer is present test with it
if (customizer) {
customizer = customizer.bind(this);
do {
// else check for existence
if (customizer(parent)) {
return parent;
}
parent = parent.__parent;
} while (parent);
}
// else check for existence
else {
do {
if (parent[property]) {
return parent;
}
parent = parent.__parent;
} while (parent);
}
}
|
javascript
|
{
"resource": ""
}
|
|
q44645
|
train
|
function () {
return arguments.length ? _.pick(this._, Array.prototype.slice.apply(arguments)) : _.cloneDeep(this._);
}
|
javascript
|
{
"resource": ""
}
|
|
q44646
|
train
|
function (options) {
// no splitting is being done here, as string scripts are split right before assignment below anyway
(_.isString(options) || _.isArray(options)) && (options = { exec: options });
if (!options) { return; } // in case definition object is missing, there is no point moving forward
// create the request property
/**
* @augments {Script.prototype}
* @type {string}
*/
this.type = options.type || 'text/javascript';
options.hasOwnProperty('src') && (
/**
* @augments {Script.prototype}
* @type {Url}
*/
this.src = new Url(options.src)
);
if (!this.src && options.hasOwnProperty('exec')) { // eslint-disable-line no-prototype-builtins
/**
* @augments {Script.prototype}
* @type {Array<string>}
*/
this.exec = _.isString(options.exec) ? options.exec.split(SCRIPT_NEWLINE_PATTERN) :
_.isArray(options.exec) ? options.exec : undefined;
}
}
|
javascript
|
{
"resource": ""
}
|
|
q44647
|
train
|
function (url) {
// url must be either string or an instance of url.
if (!_.isString(url) && !Url.isUrl(url)) {
return;
}
// @todo - use a fixed-length cacheing of regexes in future
return this.find(function (proxyConfig) {
return !proxyConfig.disabled && proxyConfig.test(url);
});
}
|
javascript
|
{
"resource": ""
}
|
|
q44648
|
train
|
function (obj) {
return Boolean(obj) && ((obj instanceof ProxyConfigList) ||
_.inSuperChain(obj.constructor, '_postman_propertyName', ProxyConfigList._postman_propertyName));
}
|
javascript
|
{
"resource": ""
}
|
|
q44649
|
train
|
function (item, before) {
if (!_.isObject(item)) { return; } // do not proceed on empty param
var duplicate = this.indexOf(item),
index;
// remove from previous list
PropertyList.isPropertyList(item[__PARENT]) && (item[__PARENT] !== this) && item[__PARENT].remove(item);
// inject the parent reference
_.assignHidden(item, __PARENT, this);
// ensure that we do not double insert things into member array
(duplicate > -1) && this.members.splice(duplicate, 1);
// find the position of the reference element
before && (before = this.indexOf(before));
// inject to the members array ata position or at the end in case no item is there for reference
(before > -1) ? this.members.splice(before, 0, item) : this.members.push(item);
// 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_listIndexKey]) && (index = String(index))) {
// desensitise case, if the property needs it to be
this._postman_listIndexCaseInsensitive && (index = index.toLowerCase());
// if multiple values are allowed, the reference may contain an array of items, mapped to an index.
if (this._postman_listAllowsMultipleValues && this.reference.hasOwnProperty(index)) {
// if the value is not an array, convert it to an array.
!_.isArray(this.reference[index]) && (this.reference[index] = [this.reference[index]]);
// add the item to the array of items corresponding to this index
this.reference[index].push(item);
}
else {
this.reference[index] = item;
}
}
}
|
javascript
|
{
"resource": ""
}
|
|
q44650
|
train
|
function (item) {
// do not proceed on empty param, but empty strings are in fact valid.
// eslint-disable-next-line lodash/prefer-is-nil
if (_.isNull(item) || _.isUndefined(item) || _.isNaN(item)) { return; }
// create new instance of the item based on the type specified if it is not already
this.insert((item.constructor === this.Type) ? item :
// if the property has a create static function, use it.
// eslint-disable-next-line prefer-spread
(_.has(this.Type, 'create') ? this.Type.create.apply(this.Type, arguments) : new this.Type(item)));
}
|
javascript
|
{
"resource": ""
}
|
|
q44651
|
train
|
function (item) {
// do not proceed on empty param, but empty strings are in fact valid.
if (_.isNil(item) || _.isNaN(item)) { return null; }
var indexer = this._postman_listIndexKey,
existing = this.one(item[indexer]);
if (existing) {
if (!_.isFunction(existing.update)) {
throw new Error('collection: unable to upsert into a list of Type that does not support .update()');
}
existing.update(item);
return false;
}
// since there is no existing item, just add a new one
this.add(item);
return true; // indicate added
}
|
javascript
|
{
"resource": ""
}
|
|
q44652
|
train
|
function (predicate, context) {
var match; // to be used if predicate is an ID
!context && (context = this);
if (_.isString(predicate)) {
// if predicate is id, then create a function to remove that
// need to take care of case sensitivity as well :/
match = this._postman_listIndexCaseInsensitive ? predicate.toLowerCase() : predicate;
predicate = function (item) {
var id = item[this._postman_listIndexKey];
this._postman_listIndexCaseInsensitive && (id = id.toLowerCase());
return id === match;
}.bind(this);
}
else if (predicate instanceof this.Type) {
// in case an object reference is sent, prepare it for removal using direct reference comparison
match = predicate;
predicate = function (item) {
return (item === match);
};
}
_.isFunction(predicate) && _.remove(this.members, function (item) {
var index;
if (predicate.apply(context, arguments)) {
if ((index = item[this._postman_listIndexKey]) && (index = String(index))) {
this._postman_listIndexCaseInsensitive && (index = index.toLowerCase());
if (this._postman_listAllowsMultipleValues && _.isArray(this.reference[index])) {
// since we have an array of multiple values, remove only the value for which the
// predicate returned truthy. If the array becomes empty, just delete it.
_.remove(this.reference[index], function (each) {
return each === item;
});
// If the array becomes empty, remove it
(this.reference[index].length === 0) && (delete this.reference[index]);
// If the array contains only one element, remove the array, and assign the element
// as the reference value
(this.reference[index].length === 1) && (this.reference[index] = this.reference[index][0]);
}
else {
delete this.reference[index];
}
}
delete item[__PARENT]; // unlink from its parent
return true;
}
}.bind(this));
}
|
javascript
|
{
"resource": ""
}
|
|
q44653
|
train
|
function () {
// we unlink every member from it's parent (assuming this is their parent)
this.all().forEach(PropertyList._unlinkItemFromParent);
this.members.length = 0; // remove all items from list
// now we remove all items from index reference
Object.keys(this.reference).forEach(function (key) {
delete this.reference[key];
}.bind(this));
}
|
javascript
|
{
"resource": ""
}
|
|
q44654
|
train
|
function (items) {
// if Type supports parsing of string headers then do it before adding it.
_.isString(items) && _.isFunction(this.Type.parse) && (items = this.Type.parse(items));
// add a single item or an array of items.
_.forEach(_.isArray(items) ? items :
// if population is not an array, we send this as single item in an array or send each property separately
// if the core Type supports Type.create
((_.isPlainObject(items) && _.has(this.Type, 'create')) ? items : [items]), this.add.bind(this));
}
|
javascript
|
{
"resource": ""
}
|
|
q44655
|
train
|
function (source, prune) {
var members = PropertyList.isPropertyList(source) ? source.members : source,
list = this,
indexer = list._postman_listIndexKey,
sourceKeys = {}; // keeps track of added / updated keys for later exclusion
if (!_.isArray(members)) {
return;
}
members.forEach(function (item) {
if (!(item && item.hasOwnProperty(indexer))) { return; }
list.upsert(item);
sourceKeys[item[indexer]] = true;
});
// now remove any variable that is not in source object
// @note - using direct `this.reference` list of keys here so that we can mutate the list while iterating
// on it
if (prune) {
_.forEach(list.reference, function (value, key) {
if (sourceKeys.hasOwnProperty(key)) { return; } // de not delete if source obj has this variable
list.remove(key); // use PropertyList functions to remove so that the .members array is cleared too
});
}
}
|
javascript
|
{
"resource": ""
}
|
|
q44656
|
train
|
function (id) {
var val = this.reference[this._postman_listIndexCaseInsensitive ? String(id).toLowerCase() : id];
if (this._postman_listAllowsMultipleValues && Array.isArray(val)) {
return val.length ? val[val.length - 1] : undefined;
}
return val;
}
|
javascript
|
{
"resource": ""
}
|
|
q44657
|
train
|
function (iterator, context) {
_.forEach(this.members, _.isFunction(iterator) ? iterator.bind(context || this.__parent) : iterator);
}
|
javascript
|
{
"resource": ""
}
|
|
q44658
|
train
|
function (rule, context) {
return _.find(this.members, _.isFunction(rule) && _.isObject(context) ? rule.bind(context) : rule);
}
|
javascript
|
{
"resource": ""
}
|
|
q44659
|
train
|
function (iterator, context) {
return _.map(this.members, _.isFunction(iterator) ? iterator.bind(context || this) : iterator);
}
|
javascript
|
{
"resource": ""
}
|
|
q44660
|
train
|
function (iterator, accumulator, context) {
return _.reduce(this.members, _.isFunction(iterator) ? iterator.bind(context || this) : iterator, accumulator);
}
|
javascript
|
{
"resource": ""
}
|
|
q44661
|
train
|
function (item) {
return this.members.indexOf(_.isString(item) ? (item = this.one(item)) : item);
}
|
javascript
|
{
"resource": ""
}
|
|
q44662
|
train
|
function (item, value) {
var match,
val,
i;
match = _.isString(item) ?
this.reference[this._postman_listIndexCaseInsensitive ? item.toLowerCase() : item] :
this.filter(function (member) {
return member === item;
});
// If we don't have a match, there's nothing to do
if (!match) { return false; }
// if no value is provided, just check if item exists
if (arguments.length === 1) {
return Boolean(_.isArray(match) ? match.length : match);
}
// If this property allows multiple values and we get an array, we need to iterate through it and see
// if any element matches.
if (this._postman_listAllowsMultipleValues && _.isArray(match)) {
for (i = 0; i < match.length; i++) {
// use the value of the current element
val = _.isFunction(match[i].valueOf) ? match[i].valueOf() : match[i];
if (val === value) { return true; }
}
// no matches were found, so return false here.
return false;
}
// We didn't have an array, so just check if the matched value equals the provided value.
_.isFunction(match.valueOf) && (match = match.valueOf());
return match === value;
}
|
javascript
|
{
"resource": ""
}
|
|
q44663
|
train
|
function (iterator, context) {
// validate parameters
if (!_.isFunction(iterator)) { return; }
!context && (context = this);
var parent = this.__parent,
prev;
// iterate till there is no parent
while (parent) {
// call iterator with the parent and previous parent
iterator.call(context, parent, prev);
// update references
prev = parent;
parent = parent.__parent;
}
}
|
javascript
|
{
"resource": ""
}
|
|
q44664
|
train
|
function (excludeDisabled, caseSensitive, multiValue, sanitizeKeys) {
var obj = {}, // create transformation data accumulator
// gather all the switches of the list
key = this._postman_listIndexKey,
sanitiseKeys = this._postman_sanitizeKeys || sanitizeKeys,
sensitive = !this._postman_listIndexCaseInsensitive || caseSensitive,
multivalue = this._postman_listAllowsMultipleValues || multiValue;
// iterate on each member to create the transformation object
this.each(function (member) {
// Bail out for the current member if ANY of the conditions below is true:
// 1. The member is falsy.
// 2. The member does not have the specified property list index key.
// 3. The member is disabled and disabled properties have to be ignored.
// 4. The member has a falsy key, and sanitize is true.
if (!member || !member.hasOwnProperty(key) || (excludeDisabled && member.disabled) ||
(sanitiseKeys && !member[key])) {
return;
}
// based on case sensitivity settings, we get the property name of the item
var prop = sensitive ? member[key] : String(member[key]).toLowerCase();
// now, if transformation object already has a member with same property name, we either overwrite it or
// append to an array of values based on multi-value support
if (multivalue && obj.hasOwnProperty(prop)) {
(!Array.isArray(obj[prop])) && (obj[prop] = [obj[prop]]);
obj[prop].push(member.valueOf());
}
else {
obj[prop] = member.valueOf();
}
});
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q44665
|
train
|
function () {
if (this.Type.unparse) {
return this.Type.unparse(this.members);
}
return this.constructor ? this.constructor.prototype.toString.call(this) : '';
}
|
javascript
|
{
"resource": ""
}
|
|
q44666
|
train
|
function (obj) {
return Boolean(obj) && ((obj instanceof PropertyList) ||
_.inSuperChain(obj.constructor, '_postman_propertyName', PropertyList._postman_propertyName));
}
|
javascript
|
{
"resource": ""
}
|
|
q44667
|
train
|
function (options, type) {
// update must have options
if (!_.isObject(options)) { return; }
// validate type parameter and/or choose default from existing type.
if (!RequestAuth.isValidType(type)) { type = this.type; }
var parameters = this[type];
// in case the type holder is not created, we create one and send the population variables
if (!VariableList.isVariableList(parameters)) {
// @todo optimise the handling of legacy object type auth parameters
parameters = this[type] = new VariableList(this);
parameters._postman_requestAuthType = type;
}
// we simply assimilate the new options either it is an array or an object
if (_.isArray(options) || VariableList.isVariableList(options)) {
parameters.assimilate(options);
}
else {
parameters.syncFromObject(options, false, false); // params: no need to track and no need to prune
}
}
|
javascript
|
{
"resource": ""
}
|
|
q44668
|
train
|
function (type) {
if (!(RequestAuth.isValidType(type) && VariableList.isVariableList(this[type]))) {
return;
}
// clear the variable list
this[type].clear();
// if it is not a currently selected auth type, do not delete the variable list, but simply delete it
if (type !== this.type) {
delete this[type];
}
}
|
javascript
|
{
"resource": ""
}
|
|
q44669
|
train
|
function (url) {
!url && (url = E);
var parsedUrl = _.isString(url) ? Url.parse(url) : url,
auth = parsedUrl.auth,
protocol = parsedUrl.protocol,
port = parsedUrl.port,
path = parsedUrl.path,
hash = parsedUrl.hash,
host = parsedUrl.host,
query = parsedUrl.query,
variable = parsedUrl.variable;
// convert object based query string to array
// @todo: create a key value parser
if (query) {
if (_.isString(query)) {
query = QueryParam.parse(query);
}
if (!_.isArray(query) && _.keys(query).length) {
query = _.map(_.keys(query), function (key) {
return {
key: key,
value: query[key]
};
});
}
}
// backward compatibility with path variables being storing thins with `id`
if (_.isArray(variable)) {
variable = _.map(variable, function (v) {
_.isObject(v) && (v.key = v.key || v.id); // @todo Remove once path variables are deprecated
return v;
});
}
// expand string path name
if (_.isString(path)) {
path && (path = path.replace(regexes.trimPath, MATCH_1)); // remove leading slash for valid path
// if path is blank string, we set it to undefined, if '/' then single blank string array
path = path ? (path === PATH_SEPARATOR ? [E] : path.split(PATH_SEPARATOR)) : undefined;
}
// expand host string
_.isString(host) && (host = host.split(regexes.splitDomain));
_.assign(this, /** @lends Url.prototype */ {
/**
* @type {String}
*/
auth: auth,
/**
* @type {String}
*/
protocol: protocol,
/**
* @type {String}
*/
port: port || undefined,
/**
* @type {Array<String>}
*/
path: path,
/**
* @type {String}
*/
hash: hash || undefined,
/**
* @type {Array<String>}
*/
host: host,
/**
* @type {PropertyList<QueryParam>}
*/
query: new PropertyList(QueryParam, this, query || []),
/**
* @type {VariableList}
*/
variables: new VariableList(this, variable || [])
});
}
|
javascript
|
{
"resource": ""
}
|
|
q44670
|
train
|
function (params) {
params = _.isString(params) ? QueryParam.parse(params) : params;
this.query.populate(params);
}
|
javascript
|
{
"resource": ""
}
|
|
q44671
|
train
|
function (params) {
params = _.isArray(params) ? _.map(params, function (param) {
return param.key ? param.key : param;
}) : [params];
this.query.remove(function (param) {
return _.includes(params, param.key);
});
}
|
javascript
|
{
"resource": ""
}
|
|
q44672
|
train
|
function (encode) {
if (!this.query.count()) {
return E;
}
if (typeof encode === OBJECT) { // @todo discontinue in v4
return QueryParam.unparse(this.query.all(), encode);
}
return QueryParam.unparse(this.query.all(), { encode: encode });
}
|
javascript
|
{
"resource": ""
}
|
|
q44673
|
train
|
function (encodeQuery) {
var path = this.getPath();
// check count first so that, we can ensure that ba `?` is always appended, even if a blank query string exists
if (this.query.count()) {
path += (QUERY_SEPARATOR + this.getQueryString(encodeQuery));
}
return path;
}
|
javascript
|
{
"resource": ""
}
|
|
q44674
|
train
|
function () {
if (!this.host) {
return E;
}
return _.isArray(this.host) ? this.host.join(DOMAIN_SEPARATOR) : this.host.toString();
}
|
javascript
|
{
"resource": ""
}
|
|
q44675
|
train
|
function (obj) {
return Boolean(obj) && ((obj instanceof Url) ||
_.inSuperChain(obj.constructor, '_postman_propertyName', Url._postman_propertyName));
}
|
javascript
|
{
"resource": ""
}
|
|
q44676
|
train
|
function (param) {
_.assign(this, /** @lends QueryParam.prototype */ _.isString(param) ? QueryParam.parseSingle(param) : {
key: _.get(param, 'key'), // we do not replace falsey with blank string since null has a meaning
value: _.get(param, 'value')
});
_.has(param, 'system') && (this.system = param.system);
}
|
javascript
|
{
"resource": ""
}
|
|
q44677
|
train
|
function (query) {
return _.isString(query) ? query.split(AMPERSAND).map(QueryParam.parseSingle) : [];
}
|
javascript
|
{
"resource": ""
}
|
|
q44678
|
train
|
function (param, idx, all) {
// helps handle weird edge cases such as "/get?a=b&&"
if (param === EMPTY && // if param is empty
_.isNumber(idx) && // this and the next condition ensures that this is part of a map call
_.isArray(all) &&
idx !== (all && (all.length - 1))) { // not last parameter in the array
return { key: null, value: null };
}
var index = (typeof param === STRING) ? param.indexOf(EQUALS) : -1,
paramObj = {};
// this means that there was no value for this key (not even blank, so we store this info) and the value is set
// to null
if (index < 0) {
paramObj.key = param.substr(0, param.length);
paramObj.value = null;
}
else {
paramObj.key = param.substr(0, index);
paramObj.value = param.substr(index + 1);
}
return paramObj;
}
|
javascript
|
{
"resource": ""
}
|
|
q44679
|
train
|
function (obj, encode) {
if (!obj) { return EMPTY; }
var key = obj.key,
value = obj.value;
if (value === undefined) {
return EMPTY;
}
if (key === null) {
key = EMPTY;
}
if (value === null) {
return encode ? urlEncoder.encode(key) : key;
}
if (encode) {
key = urlEncoder.encode(key);
value = urlEncoder.encode(value);
}
return key + EQUALS + value;
}
|
javascript
|
{
"resource": ""
}
|
|
q44680
|
train
|
function (response) {
var contentType = response.headers.get(HEADERS.CONTENT_TYPE),
contentDisposition = response.headers.get(HEADERS.CONTENT_DISPOSITION),
mimeInfo = getMimeInfo(contentType, response.stream || response.body),
fileName = getFileNameFromDispositionHeader(contentDisposition),
fileExtension = mimeInfo.extension,
/**
* @typedef Response~ResponseContentInfo
*
* @property {String} mimeType sanitized mime type
* @property {String} mimeFormat format for the identified mime type
* @property {String} charset the normalized character set
* @property {String} fileExtension extension identified from the mime type
* @property {String} fileName file name extracted from disposition header
*/
contentInfo = {};
// if file name is not present in the content disposition headers, use a default file name
if (!fileName) {
fileName = DEFAULT_RESPONSE_FILENAME;
// add extension to default if present
fileExtension && (fileName += (DOT + fileExtension));
}
// create a compacted list of content info from mime info and file name
mimeInfo.mimeType && (contentInfo.mimeType = mimeInfo.mimeType);
mimeInfo.mimeFormat && (contentInfo.mimeFormat = mimeInfo.mimeFormat);
mimeInfo.charset && (contentInfo.charset = mimeInfo.charset);
fileExtension && (contentInfo.fileExtension = fileExtension);
fileName && (contentInfo.fileName = fileName);
return contentInfo;
}
|
javascript
|
{
"resource": ""
}
|
|
q44681
|
train
|
function () {
var json = ItemGroup.prototype.toJSON.apply(this);
// move ids and stuff from root level to `info` object
json.info = {
_postman_id: this.id,
name: this.name,
version: this.version,
schema: SCHEMA_URL
};
delete json.id;
delete json.name;
delete json.version;
if (json.hasOwnProperty('description')) {
json.info.description = this.description;
delete json.description;
}
return json;
}
|
javascript
|
{
"resource": ""
}
|
|
q44682
|
train
|
function (child, base) {
Object.defineProperty(child, 'super_', {
value: _.isFunction(base) ? base : _.noop,
configurable: false,
enumerable: false,
writable: false
});
child.prototype = Object.create((_.isFunction(base) ? base.prototype : base), {
constructor: {
value: child,
enumerable: false,
writable: true,
configurable: true
}
});
return child;
}
|
javascript
|
{
"resource": ""
}
|
|
q44683
|
train
|
function (obj, name, Prop, fallback) {
return _.has(obj, name) ? (new Prop(obj[name])) : fallback;
}
|
javascript
|
{
"resource": ""
}
|
|
q44684
|
train
|
function (target, source) {
var key;
for (key in source) {
if (source.hasOwnProperty(key) && !_.isUndefined(source[key])) {
target[key] = source[key];
}
}
return target;
}
|
javascript
|
{
"resource": ""
}
|
|
q44685
|
train
|
function (obj, prop, def) {
return _.has(obj, prop) ? obj[prop] : def;
}
|
javascript
|
{
"resource": ""
}
|
|
q44686
|
train
|
function (obj) {
return _.cloneDeepWith(obj, function (value) {
// falls back to default deepclone if object does not have explicit toJSON().
if (value && _.isFunction(value.toJSON)) {
return value.toJSON();
}
});
}
|
javascript
|
{
"resource": ""
}
|
|
q44687
|
train
|
function (obj, key, value) {
return obj ? ((obj[key] === value) || _.inSuperChain(obj.super_, key, value)) : false;
}
|
javascript
|
{
"resource": ""
}
|
|
q44688
|
train
|
function (obj) {
return Boolean(obj) && ((obj instanceof Cookie) ||
_.inSuperChain(obj.constructor, '_postman_propertyName', Cookie._postman_propertyName));
}
|
javascript
|
{
"resource": ""
}
|
|
q44689
|
train
|
function (str) {
if (!_.isString(str)) {
return str;
}
var obj = {},
pairs = str.split(PAIR_SPLIT_REGEX),
nameval;
nameval = Cookie.splitParam(pairs.shift()); // The first kvp is the name and value
obj.key = nameval.key;
obj.value = nameval.value;
pairs.forEach(function (pair) {
var keyval = Cookie.splitParam(pair),
value = keyval.value,
keyLower = keyval.key.toLowerCase();
if (cookieAttributes[keyLower]) {
obj[cookieAttributes[keyLower]] = value;
}
else {
obj.extensions = obj.extensions || [];
obj.extensions.push(keyval);
}
});
// Handle the hostOnly flag
if (!obj.domain) {
obj.hostOnly = true;
}
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q44690
|
train
|
function (param) {
var split = param.split('='),
key, value;
key = split[0].trim();
value = (split[1]) ? split[1].trim() : true;
if (_.isString(value) && value[0] === '"') {
value = value.slice(1, -1);
}
return { key: key, value: value };
}
|
javascript
|
{
"resource": ""
}
|
|
q44691
|
train
|
function (options) {
_.isString(options) && (options = { mode: 'raw', raw: options });
if (!options.mode) { return; } // need a valid mode @todo raise error?
var mode = RequestBody.MODES[options.mode.toString().toLowerCase()] || RequestBody.MODES.raw,
urlencoded = options.urlencoded,
formdata = options.formdata,
graphql = options.graphql,
file = options.file,
raw = options.raw;
// Handle URL Encoded data
if (options.urlencoded) {
_.isString(options.urlencoded) && (urlencoded = QueryParam.parse(options.urlencoded));
// @todo: The fallback in the ternary expression will never be hit, as urlencoded points to
// @todo: options.urlencoded
urlencoded = urlencoded ? new PropertyList(QueryParam, this, urlencoded) :
new PropertyList(QueryParam, this, []);
}
// Handle Form data
if (options.formdata) {
// @todo: The fallback in the ternary expression will never be hit, as formdata points to
// @todo: options.formdata
formdata = formdata ? new PropertyList(FormParam, this, options.formdata) :
new PropertyList(FormParam, this, []);
}
// Handle GraphQL data
if (options.graphql) {
graphql = {
query: graphql.query,
operationName: graphql.operationName,
variables: graphql.variables
};
}
_.isString(options.file) && (file = { src: file });
// If mode is raw but options does not give raw content, set it to empty string
(mode === RequestBody.MODES.raw && !raw) && (raw = '');
// If mode is urlencoded but options does not provide any content, set it to an empty property list
(mode === RequestBody.MODES.urlencoded && !urlencoded) && (urlencoded = new PropertyList(QueryParam, this, []));
// If mode is formdata but options does not provide any content, set it to an empty property list
(mode === RequestBody.MODES.formdata && !formdata) && (formdata = new PropertyList(FormParam, this, []));
// If mode is graphql but options does not provide any content, set empty query
(mode === RequestBody.MODES.graphql && !graphql) && (graphql = {});
_.assign(this, /** @lends RequestBody.prototype */ {
/**
* Indicates the type of request data to use.
*
* @type {String}
*/
mode: mode,
/**
* If the request has raw body data associated with it, the data is held in this field.
*
* @type {String}
*/
raw: raw,
/**
* Any URL encoded body params go here.
*
* @type {PropertyList<QueryParam>}
*/
urlencoded: urlencoded,
/**
* Form data parameters for this request are held in this field.
*
* @type {PropertyList<FormParam>}
*/
formdata: formdata,
/**
* Holds a reference to a file which should be read as the RequestBody. It can be a file path (when used
* with Node) or a unique ID (when used with the browser).
*
* @note The reference stored here should be resolved by a resolver function (which should be provided to
* the Postman Runtime).
*/
file: file,
/**
* If the request has raw graphql data associated with it, the data is held in this field.
*
* @type {Object}
*/
graphql: graphql,
/**
* Indicates whether to include body in request or not.
*
* @type {Boolean}
*/
disabled: options.disabled
});
}
|
javascript
|
{
"resource": ""
}
|
|
q44692
|
train
|
function () {
// Formdata. Goodluck.
if (this.mode === RequestBody.MODES.formdata || this.mode === RequestBody.MODES.file) {
// @todo: implement this, check if we need to return undefined or something.
return EMPTY;
}
if (this.mode === RequestBody.MODES.urlencoded) {
return PropertyList.isPropertyList(this.urlencoded) ? QueryParam.unparse(this.urlencoded.all()) :
((this.urlencoded && _.isFunction(this.urlencoded.toString)) ? this.urlencoded.toString() : EMPTY);
}
if (this.mode === RequestBody.MODES.raw) {
return (this.raw && _.isFunction(this.raw.toString)) ? this.raw.toString() : EMPTY;
}
return EMPTY;
}
|
javascript
|
{
"resource": ""
}
|
|
q44693
|
train
|
function () {
var mode = this.mode,
data = mode && this[mode];
// bail out if there's no data for the selected mode
if (!data) {
return true;
}
// Handle file mode
// @note this is a legacy exception. ideally every individual data mode
// in future would declare its "empty state".
if (mode === RequestBody.MODES.file) {
return !(data.src || data.content);
}
if (_.isString(data)) {
return (data.length === 0);
}
if (_.isFunction(data.count)) { // handle for property lists
return (data.count() === 0);
}
return _.isEmpty(data); // catch all for remaining data modes
}
|
javascript
|
{
"resource": ""
}
|
|
q44694
|
train
|
function (regex, fn) {
var replacements = 0; // maintain a count of tokens replaced
// to ensure we do not perform needless operations in the replacement, we use multiple replacement functions
// after validating the parameters
this.value = (this.value.replace(regex, _.isFunction(fn) ? function () {
replacements += 1;
return fn.apply(this, arguments);
} : function () { // this case is returned when replacer is not a function (ensures we do not need to check it)
replacements += 1;
return fn;
}));
this.replacements = replacements; // store the last replacements
replacements && (this.substitutions += 1); // if any replacement is done, count that some substitution was made
return this;
}
|
javascript
|
{
"resource": ""
}
|
|
q44695
|
train
|
function (key) {
var arr = this.variables,
obj,
value,
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;
}
// in case the object is a postman variable list, we give special attention
if (obj.constructor._postman_propertyName === 'VariableList') {
value = obj.oneNormalizedVariable(key);
if (value && !value.disabled) {
return value;
}
}
// else we return the value from the plain object
else if (obj.hasOwnProperty(key)) {
return obj[key];
}
}
}
|
javascript
|
{
"resource": ""
}
|
|
q44696
|
train
|
function (options) {
// Nothing to do
if (!options) { return; }
// The existing url is updated.
_.has(options, 'url') && this.url.update(options.url);
// The existing list of headers must be cleared before adding the given headers to it.
options.header && this.headers.repopulate(options.header);
// Only update the method if one is provided.
_.has(options, 'method') && (this.method = _.isNil(options.method) ?
DEFAULT_REQ_METHOD : String(options.method).toUpperCase());
// The rest of the properties are not assumed to exist so we merge in the defined ones.
_.mergeDefined(this, /** @lends Request.prototype */ {
/**
* @type {RequestBody|undefined}
*/
body: _.createDefined(options, 'body', RequestBody),
// auth is a special case, empty RequestAuth should not be created for falsy values
// to allow inheritance from parent
/**
* @type {RequestAuth}
*/
auth: options.auth ? new RequestAuth(options.auth) : undefined,
/**
* @type {ProxyConfig}
*/
proxy: options.proxy && new ProxyConfig(options.proxy),
/**
* @type {Certificate|undefined}
*/
certificate: options.certificate && new Certificate(options.certificate)
});
}
|
javascript
|
{
"resource": ""
}
|
|
q44697
|
train
|
function (type, options) {
if (_.isObject(type) && _.isNil(options)) {
type = options.type;
options = _.omit(options, 'type');
}
// null = delete request
if (type === null) {
_.has(this, 'auth') && (delete this.auth);
return;
}
if (!RequestAuth.isValidType(type)) {
return;
}
// create a new authentication data
if (!this.auth) {
this.auth = new RequestAuth(null, this);
}
else {
this.auth.clear(type);
}
this.auth.use(type, options);
}
|
javascript
|
{
"resource": ""
}
|
|
q44698
|
getHeaders
|
train
|
function getHeaders (options) {
!options && (options = {});
// @note: options.multiValue will not be respected since, Header._postman_propertyAllowsMultipleValues
// gets higher precedence in PropertyLists~toObject.
// @todo: sanitizeKeys for headers by default.
return this.headers.toObject(options.enabled, !options.ignoreCase, options.multiValue, options.sanitizeKeys);
}
|
javascript
|
{
"resource": ""
}
|
q44699
|
train
|
function (toRemove, options) {
toRemove = _.isString(toRemove) ? toRemove : toRemove.key;
options = options || {};
if (!toRemove) { // Nothing to remove :(
return;
}
options.ignoreCase && (toRemove = toRemove.toLowerCase());
this.headers.remove(function (header) {
var key = options.ignoreCase ? header.key.toLowerCase() : header.key;
return key === toRemove;
});
}
|
javascript
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.