Skip to content

Commit 38d3507

Browse files
committed
Add helpers and remove lodash dependency
1 parent 3c1de62 commit 38d3507

File tree

5 files changed

+101
-15
lines changed

5 files changed

+101
-15
lines changed

configure/request-next.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict';
22

33
var core = require('../'),
4+
helpers = require('../lib/helpers'),
45
isArray = Array.isArray,
5-
isFunction = require('lodash.isfunction'),
6-
isObjectLike = require('lodash.isobjectlike');
6+
isFunction = helpers.isFunction,
7+
isObjectLike = helpers.isObjectLike;
78

89

910
module.exports = function (options) {

configure/request2.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict';
22

33
var core = require('../'),
4+
helpers = require('../lib/helpers'),
45
isArray = Array.isArray,
5-
isFunction = require('lodash.isfunction'),
6-
isObjectLike = require('lodash.isobjectlike');
6+
isFunction = helpers.isFunction,
7+
isObjectLike = helpers.isObjectLike;
78

89

910
module.exports = function (options) {

lib/helpers.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
'use strict';
2+
3+
/*
4+
The following code is extracted and adapted from the lodash library.
5+
It is protected by the the MIT License.
6+
7+
Copyright JS Foundation and other contributors <https://js.foundation/>
8+
9+
Based on Underscore.js, copyright Jeremy Ashkenas,
10+
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
11+
12+
This software consists of voluntary contributions made by many
13+
individuals. For exact contribution history, see the revision history
14+
available at https://github.com/lodash/lodash
15+
16+
The following license applies to all parts of this software except as
17+
documented below:
18+
19+
====
20+
21+
Permission is hereby granted, free of charge, to any person obtaining
22+
a copy of this software and associated documentation files (the
23+
"Software"), to deal in the Software without restriction, including
24+
without limitation the rights to use, copy, modify, merge, publish,
25+
distribute, sublicense, and/or sell copies of the Software, and to
26+
permit persons to whom the Software is furnished to do so, subject to
27+
the following conditions:
28+
29+
The above copyright notice and this permission notice shall be
30+
included in all copies or substantial portions of the Software.
31+
32+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39+
*/
40+
41+
var
42+
asyncTag = '[object AsyncFunction]',
43+
funcTag = '[object Function]',
44+
genTag = '[object GeneratorFunction]',
45+
proxyTag = '[object Proxy]',
46+
nullTag = '[object Null]',
47+
stringTag = '[object String]',
48+
undefinedTag = '[object Undefined]';
49+
50+
function baseGetTag(value) {
51+
if (value === undefined) {
52+
return undefinedTag;
53+
}
54+
55+
if (value === null) {
56+
return nullTag;
57+
}
58+
59+
return Object.prototype.toString.call(value);
60+
}
61+
62+
function isObject(value) {
63+
var type = typeof value;
64+
return value !== undefined && value !== null && (type === 'object' || type === 'function');
65+
}
66+
67+
function isFunction(value) {
68+
if (!isObject(value)) {
69+
return false;
70+
}
71+
72+
var tag = baseGetTag(value);
73+
return tag === funcTag || tag === genTag || tag === asyncTag || tag === proxyTag;
74+
}
75+
76+
function isObjectLike(value) {
77+
return value !== undefined && value !== null && typeof value === 'object';
78+
}
79+
80+
function isString(value) {
81+
return typeof value === 'string' ||
82+
!Array.isArray(value) && isObjectLike(value) && baseGetTag(value) === stringTag;
83+
}
84+
85+
module.exports = {
86+
isFunction: isFunction,
87+
isString: isString,
88+
isObjectLike: isObjectLike
89+
};

lib/plumbing.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

33
var errors = require('./errors.js'),
4-
isFunction = require('lodash.isfunction'),
5-
isObjectLike = require('lodash.isobjectlike'),
6-
isString = require('lodash.isstring'),
7-
isUndefined = require('lodash.isundefined');
4+
helpers = require('./helpers'),
5+
isFunction = helpers.isFunction,
6+
isObjectLike = helpers.isObjectLike,
7+
isString = helpers.isString;
88

99

1010
module.exports = function (options) {
@@ -19,7 +19,7 @@ module.exports = function (options) {
1919
throw new TypeError(errorText + '.PromiseImpl');
2020
}
2121

22-
if (!isUndefined(options.constructorMixin) && !isFunction(options.constructorMixin)) {
22+
if (options.constructorMixin !== undefined && !isFunction(options.constructorMixin)) {
2323
throw new TypeError(errorText + '.PromiseImpl');
2424
}
2525

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232
"engines": {
3333
"node": ">=0.10.0"
3434
},
35-
"dependencies": {
36-
"lodash.isfunction": "^3.0.9",
37-
"lodash.isobjectlike": "^4.0.0",
38-
"lodash.isstring": "^4.0.1",
39-
"lodash.isundefined": "^3.0.1"
40-
},
4135
"peerDependencies": {
4236
"request": "^2.34"
4337
},
@@ -54,6 +48,7 @@
5448
"gulp-istanbul": "~1.0.0",
5549
"gulp-mocha": "~2.2.0",
5650
"lodash.flatten": "^4.4.0",
51+
"lodash.isfunction": "^3.0.9",
5752
"node-version": "~1.0.0",
5853
"publish-please": "~2.4.1",
5954
"request": "^2.34.0",

0 commit comments

Comments
 (0)