Comparing version 13.3.4 to 13.3.5
'use strict' | ||
const debug = require('debug')('nock.common') | ||
const isPlainObject = require('lodash/isPlainObject') | ||
const set = require('lodash/set') | ||
const timers = require('timers') | ||
@@ -572,13 +570,2 @@ const url = require('url') | ||
/** | ||
* Converts flat objects whose keys use JSON path notation to nested objects. | ||
* | ||
* The input object is not mutated. | ||
* | ||
* @example | ||
* { 'foo[bar][0]': 'baz' } -> { foo: { bar: [ 'baz' ] } } | ||
*/ | ||
const expand = input => | ||
Object.entries(input).reduce((acc, [k, v]) => set(acc, k, v), {}) | ||
/** | ||
* Performs a recursive strict comparison between two values. | ||
@@ -669,2 +656,88 @@ * | ||
/** | ||
* Returns true if the given value is a plain object and not an Array. | ||
* @param {*} value | ||
* @returns {boolean} | ||
*/ | ||
function isPlainObject(value) { | ||
if (typeof value !== 'object' || value === null) return false | ||
if (Object.prototype.toString.call(value) !== '[object Object]') return false | ||
const proto = Object.getPrototypeOf(value) | ||
if (proto === null) return true | ||
const Ctor = | ||
Object.prototype.hasOwnProperty.call(proto, 'constructor') && | ||
proto.constructor | ||
return ( | ||
typeof Ctor === 'function' && | ||
Ctor instanceof Ctor && | ||
Function.prototype.call(Ctor) === Function.prototype.call(value) | ||
) | ||
} | ||
const prototypePollutionBlockList = ['__proto__', 'prototype', 'constructor'] | ||
const blocklistFilter = function (part) { | ||
return prototypePollutionBlockList.indexOf(part) === -1 | ||
} | ||
/** | ||
* Converts flat objects whose keys use JSON path notation to nested objects. | ||
* | ||
* The input object is not mutated. | ||
* | ||
* @example | ||
* { 'foo[bar][0]': 'baz' } -> { foo: { bar: [ 'baz' ] } } | ||
*/ | ||
const expand = input => { | ||
if (input === undefined || input === null) { | ||
return input | ||
} | ||
const keys = Object.keys(input) | ||
const result = {} | ||
let resultPtr = result | ||
for (let path of keys) { | ||
const originalPath = path | ||
if (path.indexOf('[') >= 0) { | ||
path = path.replace(/\[/g, '.').replace(/]/g, '') | ||
} | ||
const parts = path.split('.') | ||
const check = parts.filter(blocklistFilter) | ||
if (check.length !== parts.length) { | ||
return undefined | ||
} | ||
resultPtr = result | ||
const lastIndex = parts.length - 1 | ||
for (let i = 0; i < parts.length; ++i) { | ||
const part = parts[i] | ||
if (i === lastIndex) { | ||
if (Array.isArray(resultPtr)) { | ||
resultPtr[+part] = input[originalPath] | ||
} else { | ||
resultPtr[part] = input[originalPath] | ||
} | ||
} else { | ||
if (resultPtr[part] === undefined || resultPtr[part] === null) { | ||
const nextPart = parts[i + 1] | ||
if (/^\d+$/.test(nextPart)) { | ||
resultPtr[part] = [] | ||
} else { | ||
resultPtr[part] = {} | ||
} | ||
} | ||
resultPtr = resultPtr[part] | ||
} | ||
} | ||
} | ||
return result | ||
} | ||
module.exports = { | ||
@@ -674,2 +747,3 @@ contentEncoding, | ||
deleteHeadersField, | ||
expand, | ||
forEachHeader, | ||
@@ -676,0 +750,0 @@ formatQueryValue, |
'use strict' | ||
const mapValues = require('lodash/mapValues') | ||
const querystring = require('querystring') | ||
@@ -65,2 +64,10 @@ | ||
function mapValues(object, cb) { | ||
const keys = Object.keys(object) | ||
for (const key of keys) { | ||
object[key] = cb(object[key], key, object) | ||
} | ||
return object | ||
} | ||
/** | ||
@@ -67,0 +74,0 @@ * Based on lodash issue discussion |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "13.3.4", | ||
"version": "13.3.5", | ||
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>", | ||
@@ -28,3 +28,2 @@ "repository": { | ||
"json-stringify-safe": "^5.0.1", | ||
"lodash": "^4.17.21", | ||
"propagate": "^2.0.0" | ||
@@ -53,3 +52,3 @@ }, | ||
"rimraf": "^3.0.0", | ||
"semantic-release": "^21.0.2", | ||
"semantic-release": "^22.0.5", | ||
"sinon": "^15.0.1", | ||
@@ -56,0 +55,0 @@ "sinon-chai": "^3.7.0", |
@@ -1231,3 +1231,3 @@ # Nock | ||
- `response` - the body of the reply which can be a JSON, string, hex string representing binary buffers or an array of such hex strings (when handling `content-encoded` in reply header) | ||
- `headers` - the headers of the reply | ||
- `rawHeaders` - the headers of the reply which are formatted as a flat array containing header name and header value pairs (e.g. `['accept', 'application/json', 'set-cookie', 'my-cookie=value']`) | ||
- `reqheader` - the headers of the request | ||
@@ -1234,0 +1234,0 @@ |
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
182128
3
3583
- Removedlodash@^4.17.21
- Removedlodash@4.17.21(transitive)