function getBoolean(value) { //Is it a boolean anyway? if(_.isBoolean(value)) { return value; } if(_.isString(value)) { return (value.toLowerCase() === "true"); } return false; }
test("isString", function() { var obj = new String("I am a string object"); ok(!_.isString(document.body), 'the document body is not a string'); ok(_.isString([1, 2, 3].join(', ')), 'but strings are'); ok(_.isString(iString), 'even from another frame'); ok(_.isString("I am a string literal"), 'string literals are'); ok(_.isString(obj), 'so are String objects'); });
write (x) { if (!this.headWritten) { this.writeHead () } if (!this.ended) { this.response.write (_.isString (x) ? x : JSON.stringify (x)) }; return this }
//Gets a property from the config object getProp(propName){ if(_.isUndefined(propName)) throw new Error('invalid-prop', 'Property name cannot be undefined'); if(!_.isString(propName)) throw new Error('invalid-prop', 'Property name must be a string'); if(_.isEmpty(propName)) throw new Error('invalid-prop', 'Property name cannot be empty'); return this.config[propName]; }
function merge(dst, src) { _.each(src, function(v, k) { if(_.isArray(v)) { dst[k] = [ ]; merge(dst[k], v); } else if(_.isObject(v)) { if(!dst[k] || _.isString(dst[k]) || !_.isObject(dst[k])) dst[k] = { }; merge(dst[k], v); } else { if(_.isArray(src)) dst.push(v); else dst[k] = v; } }) }
function toMomentObject(date) { if (moment.isMoment(date)) return date; if (date instanceof Date) return moment(date); var regex = new RegExp(/([0-9]{4})-([0-9]{2})-([0-9]{2})/); if(_.isString(date) && !!(date.match(regex))) return moment(date, "YYYY-MM-DD"); throw new Error('Unknown date format. Please use Date() object or String() with format YYYY-MM-DD.'); }
f.dispatch( function(s) { return !f.existy(s) ? 'undefined' : undefined }, function(s) { return _.isString(s) ? (s.length > 1024 ? s.substring(0, 1024) + '...' : s) : undefined}, function(s) { return _.isArray(s) ? stringifyArray(s) : undefined }, function(s) { return _.isObject(s) ? JSON.stringify(s) : undefined }, function(s) { return s.toString() })
guess (x) { return _.isString (x) ? this.text : this.json }
$static (function (cfg) { return new this ({ request: _.extend ({ method: 'POST', pause: _.identity }, cfg.request, _.pick (cfg, 'url', 'method', 'code', 'nonce', 'headers', 'cookies')), response: cfg.response, cookies: cfg.cookies, stub: true, writeHead: function () { return this }, write: function () { return this }, end: function () { return this }, receiveData: () => Promise.resolve ((cfg.data && (_.isString (cfg.data) ? cfg.data : JSON.stringify (cfg.data))) || '') }) })
reload(propName){ if(_.isUndefined(propName)) for (let key in this.propsCache) { if (this.propsCache.hasOwnProperty(key)) { this.setProp(key, this.propsCache[key]); } } if(_.isArray(propName)) for (let item of propName) { if(this.propsCache[item]) this.setProp(item, this.propsCache[item]); } if(_.isString(propName) && !_.isEmpty(propName)) this.setProp(propName, this.propsCache[propName]); return this; }
Object.keys(headers).forEach(function (key) { var value = headers[key]; value = u.isString(value) ? strings.trim(value) : value; if (value == null || value === '') { return; } key = key.toLowerCase(); if (/^x\-bce\-/.test(key) || headersMap[key] === true) { canonicalHeaders.push(util.format('%s:%s', // encodeURIComponent(key), encodeURIComponent(value))); strings.normalize(key), strings.normalize(value))); } });
function stringOrNull(x) { return !f.existy(x) || _.isString(x); }
isFunctionOrChain (obj) { return (obj instanceof Function) || (_.isArray (obj) && !(obj.isEmpty || _.isString (obj[0]) || _.isArray (obj[0]))) }
function emitError(self, name, message) { var error = null; if (_.isString(name)) { error = new Error(); if (message) { error.message = message; } error.name = name; } else if (name instanceof Error) { error = name; } if (_.isObject(error)) { if (native_emitter.listenerCount(self, 'error')) { return self.emit('error', error); } throw error; } }
Object.keys(headers).forEach(function (key) { var value = headers[key]; value = u.isString(value) ? strings.trim(value) : value; if (value == null || value === '') { return; } key = key.toLowerCase(); if (/^x\-bce\-/.test(key) || headersMap[key] === true) { canonicalHeaders.push(util.format('%s:%s', // encodeURIComponent(key), encodeURIComponent(value))); strings.normalize(key), strings.normalize(value))); } });