Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lodash dependency to decrease global package size #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions configure/request-next.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

var core = require('../'),
isArray = require('lodash/isArray'),
isFunction = require('lodash/isFunction'),
isObjectLike = require('lodash/isObjectLike');
helpers = require('../lib/helpers'),
isArray = Array.isArray,
isFunction = helpers.isFunction,
isObjectLike = helpers.isObjectLike;


module.exports = function (options) {
Expand Down
7 changes: 4 additions & 3 deletions configure/request2.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

var core = require('../'),
isArray = require('lodash/isArray'),
isFunction = require('lodash/isFunction'),
isObjectLike = require('lodash/isObjectLike');
helpers = require('../lib/helpers'),
isArray = Array.isArray,
isFunction = helpers.isFunction,
isObjectLike = helpers.isObjectLike;


module.exports = function (options) {
Expand Down
8 changes: 4 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var chalk = require('chalk');
var rimraf = require('rimraf');
var coveralls = require('gulp-coveralls');
var eslint = require('gulp-eslint');
var _ = require('lodash');
var flatten = require('lodash.flatten');

var chai = require('chai');
global.expect = chai.expect;
Expand All @@ -27,7 +27,7 @@ gulp.task('dev', ['watch', 'validate']);

gulp.task('watch', function () {

gulp.watch(_.flatten([
gulp.watch(flatten([
paths.libJsFiles,
paths.specFiles,
paths.fixtureFiles,
Expand All @@ -36,7 +36,7 @@ gulp.task('watch', function () {
'validate'
]);

gulp.watch(_.flatten([
gulp.watch(flatten([
paths.eslintrc
]), [
'lint'
Expand All @@ -50,7 +50,7 @@ gulp.task('validate', function (done) {

gulp.task('lint', function () {

return gulp.src(_.flatten([
return gulp.src(flatten([
paths.libJsFiles,
paths.gulpfile,
paths.specFiles,
Expand Down
89 changes: 89 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
'use strict';

/*
The following code is extracted and adapted from the lodash library.
It is protected by the the MIT License.

Copyright JS Foundation and other contributors <https://js.foundation/>

Based on Underscore.js, copyright Jeremy Ashkenas,
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>

This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/lodash/lodash

The following license applies to all parts of this software except as
documented below:

====

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

var
asyncTag = '[object AsyncFunction]',
funcTag = '[object Function]',
genTag = '[object GeneratorFunction]',
proxyTag = '[object Proxy]',
nullTag = '[object Null]',
stringTag = '[object String]',
undefinedTag = '[object Undefined]';

function baseGetTag(value) {
if (value === undefined) {
return undefinedTag;
}

if (value === null) {
return nullTag;
}

return Object.prototype.toString.call(value);
}

function isObject(value) {
var type = typeof value;
return value !== undefined && value !== null && (type === 'object' || type === 'function');
}

function isFunction(value) {
if (!isObject(value)) {
return false;
}

var tag = baseGetTag(value);
return tag === funcTag || tag === genTag || tag === asyncTag || tag === proxyTag;
}

function isObjectLike(value) {
return value !== undefined && value !== null && typeof value === 'object';
}

function isString(value) {
return typeof value === 'string' ||
!Array.isArray(value) && isObjectLike(value) && baseGetTag(value) === stringTag;
}

module.exports = {
isFunction: isFunction,
isString: isString,
isObjectLike: isObjectLike
};
10 changes: 5 additions & 5 deletions lib/plumbing.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

var errors = require('./errors.js'),
isFunction = require('lodash/isFunction'),
isObjectLike = require('lodash/isObjectLike'),
isString = require('lodash/isString'),
isUndefined = require('lodash/isUndefined');
helpers = require('./helpers'),
isFunction = helpers.isFunction,
isObjectLike = helpers.isObjectLike,
isString = helpers.isString;


module.exports = function (options) {
Expand All @@ -19,7 +19,7 @@ module.exports = function (options) {
throw new TypeError(errorText + '.PromiseImpl');
}

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

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
"engines": {
"node": ">=0.10.0"
},
"dependencies": {
"lodash": "^4.17.15"
},
"peerDependencies": {
"request": "^2.34"
},
Expand All @@ -50,6 +47,8 @@
"gulp-eslint": "~2.1.0",
"gulp-istanbul": "~1.0.0",
"gulp-mocha": "~2.2.0",
"lodash.flatten": "^4.4.0",
"lodash.isfunction": "^3.0.9",
"node-version": "~1.0.0",
"publish-please": "~2.4.1",
"request": "^2.34.0",
Expand Down
12 changes: 6 additions & 6 deletions test/spec/plumbing.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var _ = require('lodash'),
var isFunction = require('lodash.isfunction'),
Bluebird = require('bluebird'),
errors = require('../../errors'),
plumbing = require('../../');
Expand Down Expand Up @@ -62,8 +62,8 @@ describe('Promise-Core\'s Plumbing', function () {

pl.init.call(context, {});

expect(_.isFunction(context._rp_promise.then)).to.eql(true);
expect(_.isFunction(context._rp_resolve)).to.eql(true);
expect(isFunction(context._rp_promise.then)).to.eql(true);
expect(isFunction(context._rp_resolve)).to.eql(true);

context._rp_resolve();

Expand All @@ -82,8 +82,8 @@ describe('Promise-Core\'s Plumbing', function () {
var context = {};
pl.init.call(context, {});

expect(_.isFunction(context._rp_promise.then)).to.eql(true);
expect(_.isFunction(context._rp_reject)).to.eql(true);
expect(isFunction(context._rp_promise.then)).to.eql(true);
expect(isFunction(context._rp_reject)).to.eql(true);

context._rp_reject(new Error('Rejected by test case'));

Expand Down Expand Up @@ -134,7 +134,7 @@ describe('Promise-Core\'s Plumbing', function () {
var context = {};
pl.init.call(context, {});

expect(_.isFunction(context._rp_options.callback)).to.eql(true);
expect(isFunction(context._rp_options.callback)).to.eql(true);
delete context._rp_options.callback;

expect(context._rp_options).to.eql({
Expand Down