Skip to content

Commit

Permalink
Replace a few more uses of lodash
Browse files Browse the repository at this point in the history
Ref #1285
  • Loading branch information
paulmelnikow committed Feb 18, 2020
1 parent 61fb7e0 commit c8a1bc2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/common.js
Expand Up @@ -436,8 +436,8 @@ function matchStringOrRegexp(target, pattern) {
function formatQueryValue(key, value, stringFormattingFn) {
// TODO: Probably refactor code to replace `switch(true)` with `if`/`else`.
switch (true) {
case _.isNumber(value): // fall-through
case _.isBoolean(value):
case typeof value === 'number': // fall-through
case typeof value === 'boolean':
value = value.toString()
break
case value === null:
Expand Down
12 changes: 9 additions & 3 deletions lib/interceptor.js
Expand Up @@ -102,7 +102,10 @@ module.exports = class Interceptor {
replyWithError(errorMessage) {
this.errorMessage = errorMessage

_.defaults(this.options, this.scope.scopeOptions)
this.options = {
...this.scope.scopeOptions,
...this.options,
}

this.scope.add(this._key, this)
return this.scope
Expand Down Expand Up @@ -132,7 +135,10 @@ module.exports = class Interceptor {
}
}

_.defaults(this.options, this.scope.scopeOptions)
this.options = {
...this.scope.scopeOptions,
...this.options,
}

this.rawHeaders = common.headersInputToRawArray(rawHeaders)

Expand Down Expand Up @@ -557,7 +563,7 @@ module.exports = class Interceptor {
delay(opts) {
let headDelay
let bodyDelay
if (_.isNumber(opts)) {
if (typeof opts === 'number') {
headDelay = opts
bodyDelay = 0
} else if (typeof opts === 'object') {
Expand Down
5 changes: 2 additions & 3 deletions lib/scope.js
Expand Up @@ -7,7 +7,6 @@ const { addInterceptor, isOn } = require('./intercept')
const common = require('./common')
const assert = require('assert')
const url = require('url')
const _ = require('lodash')
const debug = require('debug')('nock.scope')
const { EventEmitter } = require('events')
const util = require('util')
Expand Down Expand Up @@ -184,7 +183,7 @@ class Scope extends EventEmitter {
}
return candidate.replace(filteringArguments[0], filteringArguments[1])
}
} else if (_.isFunction(arguments[0])) {
} else if (typeof arguments[0] === 'function') {
return arguments[0]
}
}
Expand Down Expand Up @@ -356,7 +355,7 @@ function define(nockDefs) {
} else if (nockDef.responseIsBinary) {
response = Buffer.from(nockDef.response, 'hex')
} else {
response = _.isString(nockDef.response)
response = typeof nockDef.response === 'string'
? tryJsonParse(nockDef.response)
: nockDef.response
}
Expand Down

0 comments on commit c8a1bc2

Please sign in to comment.