From e33b3e86d047362d359f88f9df698f4f103a80ad Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Mon, 10 Feb 2020 22:33:29 -0500 Subject: [PATCH] Drop support for String constructor (#1873) BREAKING CHANGE: Drop support for String constructor (#1873) When checking types of strings, Nock will no longer recognize the String constructor, only string primitives. --- lib/back.js | 4 +--- lib/common.js | 9 +++------ lib/intercept.js | 4 +--- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/back.js b/lib/back.js index 1d47385ae..308422ca6 100644 --- a/lib/back.js +++ b/lib/back.js @@ -1,7 +1,6 @@ 'use strict' const assert = require('assert') -const _ = require('lodash') const recorder = require('./recorder') const { activate, @@ -61,8 +60,7 @@ function Back(fixtureName, options, nockedFn) { ) } - // TODO-12.x: Replace with `typeof fixtureName === 'string'`. - if (!_.isString(fixtureName)) { + if (typeof fixtureName !== 'string') { throw new Error('Parameter fixtureName must be a string') } diff --git a/lib/common.js b/lib/common.js index cbfb6fc38..f4fbfb549 100644 --- a/lib/common.js +++ b/lib/common.js @@ -174,8 +174,7 @@ function stringifyRequest(options, body) { function isContentEncoded(headers) { const contentEncoding = headers['content-encoding'] - // TODO-12.x: Replace with `typeof contentEncoding === 'string'`. - return _.isString(contentEncoding) && contentEncoding !== '' + return typeof contentEncoding === 'string' && contentEncoding !== '' } function contentEncoding(headers, encoder) { @@ -364,8 +363,7 @@ function deleteHeadersField(headers, fieldNameToDelete) { throw Error('headers must be an object') } - // TODO-12.x: Replace with `typeof fieldNameToDelete !== 'string'`. - if (!_.isString(fieldNameToDelete)) { + if (typeof fieldNameToDelete !== 'string') { throw Error('field name must be a string') } @@ -446,8 +444,7 @@ function formatQueryValue(key, value, stringFormattingFn) { case value === undefined: value = '' break - // TODO-12.x: Replace with `typeof value === 'string'`. - case _.isString(value): + case typeof value === 'string': if (stringFormattingFn) { value = stringFormattingFn(value) } diff --git a/lib/intercept.js b/lib/intercept.js index b3c6afdb8..ce1c0164e 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -8,7 +8,6 @@ const { InterceptedRequestRouter } = require('./intercepted_request_router') const common = require('./common') const { inherits } = require('util') const http = require('http') -const _ = require('lodash') const debug = require('debug')('nock.intercept') const globalEmitter = require('./global_emitter') @@ -52,8 +51,7 @@ let allowNetConnect * nock.enableNetConnect(/(google|amazon)/); */ function enableNetConnect(matcher) { - // TODO-12.x: Replace with `typeof matcher === 'string'`. - if (_.isString(matcher)) { + if (typeof matcher === 'string') { allowNetConnect = new RegExp(matcher) } else if (matcher instanceof RegExp) { allowNetConnect = matcher