export function headers(headers, config, req) { const normalizedHeaders = new HTTPHeaders(headers); if (isFunction(config)) { return config(normalizedHeaders, req); } if (isObjectLike(config) && isArray(config.exclude)) { config.exclude.forEach(header => delete normalizedHeaders[header]); } return normalizedHeaders; }
shallowClone(value) { let clone; if (isArray(value)) { clone = [...value]; } else if (value instanceof Date) { clone = new Date(value); } else { clone = {...value}; } this._cache.add(clone); return clone; }
preferredThisArg(target, thisArg, thisProxyTarget) { const {name} = target; if (this.isHandledMethod(thisProxyTarget, name)) { if (isArray(thisProxyTarget)) { this._onIsChanged = SHALLOW_MUTABLE_ARRAY_METHODS[name]; } return thisProxyTarget; } return thisArg; }
isHandledMethod(target, name) { if (isArray(target) && (IMMUTABLE_OBJECT_METHODS.has(name) || IMMUTABLE_ARRAY_METHODS.has(name) || name in SHALLOW_MUTABLE_ARRAY_METHODS)) { return true; } return isObject(target) && IMMUTABLE_OBJECT_METHODS.has(name); }
export default function toNVPairs(o) { return keys(o || {}).reduce((pairs, name) => { const value = o[name]; if (isArray(value)) { // _fromType is used to convert the stored header back into the // type it originally was. Take the following example: // { 'content-type': ['text/htm'] } // => { name: 'content-type', value: 'text/html', _fromType: 'array } // => { 'content-type': ['text/htm'] } pairs.push(...value.map(v => ({ name, value: v, _fromType: 'array' }))); } else { pairs.push({ name, value }); } return pairs; }, []); }
// Interpret and default an options object export function getOptions(opts) { let options = {} for (let opt in defaultOptions) options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt] if (options.ecmaVersion >= 2015) options.ecmaVersion -= 2009 if (options.allowReserved == null) options.allowReserved = options.ecmaVersion < 5 if (isArray(options.onToken)) { let tokens = options.onToken options.onToken = (token) => tokens.push(token) } if (isArray(options.onComment)) options.onComment = pushComment(options, options.onComment) return options }
function updateClassName(oldVnode, vnode) { const oldName = oldVnode.data.className const newName = vnode.data.className if (!oldName && !newName) return if (oldName === newName) return const elm = vnode.elm if (typeof newName === 'string' && newName) { elm.className = newName.toString() } else if (isArray(newName)) { elm.className = '' newName.forEach(v => { elm.classList.add(v) }) } else { // 所有不合法的值或者空值,都把 className 设为 '' elm.className = '' } }
/** * Get the value of the given header name. If the value is an array, * get the first value. * * @export * @param {PollyRequest | PollyResponse} r * @param {string} name * @returns {string | undefined} */ export default function getFirstHeader(r, name) { const value = r.getHeader(name); if (isArray(value)) { return value.length > 0 ? value[0] : ''; } return value; }
if (isArray(children)) {
if (_state && (typeof _state !== 'object' || isArray(_state))) { error('%s.state: must be set to an object or null', name);
function normalizeHeaders(headers) { return (headers || []).reduce((accum, { name, value, _fromType }) => { const existingValue = accum[name]; if (existingValue) { if (!isArray(existingValue)) { accum[name] = [existingValue]; } accum[name].push(value); } else { accum[name] = _fromType === 'array' ? [value] : value; } return accum; }, {}); }
export function headers(headers, config, req) { const normalizedHeaders = new HTTPHeaders(headers); if (isFunction(config)) { return config(normalizedHeaders, req); } if (isObjectLike(config) && isArray(config.exclude)) { config.exclude.forEach(header => delete normalizedHeaders[header]); } return normalizedHeaders; }
function normalizeHeaders(headers) { return (headers || []).reduce((accum, { name, value, _fromType }) => { const existingValue = accum[name]; if (existingValue) { if (!isArray(existingValue)) { accum[name] = [existingValue]; } accum[name].push(value); } else { accum[name] = _fromType === 'array' ? [value] : value; } return accum; }, {}); }
/** * Get the value of the given header name. If the value is an array, * get the first value. * * @export * @param {PollyRequest | PollyResponse} r * @param {string} name * @returns {string | undefined} */ export default function getFirstHeader(r, name) { const value = r.getHeader(name); if (isArray(value)) { return value.length > 0 ? value[0] : ''; } return value; }
export default function toNVPairs(o) { return keys(o || {}).reduce((pairs, name) => { const value = o[name]; if (isArray(value)) { // _fromType is used to convert the stored header back into the // type it originally was. Take the following example: // { 'content-type': ['text/htm'] } // => { name: 'content-type', value: 'text/html', _fromType: 'array } // => { 'content-type': ['text/htm'] } pairs.push(...value.map(v => ({ name, value: v, _fromType: 'array' }))); } else { pairs.push({ name, value }); } return pairs; }, []); }