Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

utils

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

utils - npm Package Compare versions

Comparing version 0.0.2 to 0.1.5

lib/array/after.js

2

index.js

@@ -10,2 +10,2 @@ /*!

module.exports = require('./lib');
module.exports = require('./lib');
'use strict';
/**
* Coerce value to an array.
* Cast the give `value` to an array.
*
* @param {Object} `value`
* ```js
* arrayify('abc')
* //=> ['abc']
*
* arrayify(['abc'])
* //=> ['abc']
* ```
*
* @name .arrayify
* @param {*} `val`
* @return {Array}

@@ -12,3 +21,3 @@ * @api public

module.exports = function arrayify(val) {
return Array.isArray(val) ? val : [val];
return !Array.isArray(val) ? [val] : val;
};
'use strict';
/**
* Removes all falsey values from an array.
* Remove all falsey values from an array.
*

@@ -11,8 +11,13 @@ * ```js

*
* @name .compact
* @param {Array} `arr`
* @return {Array}
* @api public
*/
module.exports = function compact(arr) {
if (!Array.isArray(arr)) {
throw new TypeError('utils#array.compact() expects an array.');
}
return arr.filter(Boolean);
};
'use strict';
module.exports = require('arr-flatten');
/**
* Recursively flatten an array or arrays. Uses the fastest
* implementation of array flatten for node.js
*
* ```js
* flatten(['a', ['b', ['c']], 'd', ['e']]);
* //=> ['a', 'b', 'c', 'd', 'e']
* ```
*
* @name .flatten
* @param {Array} `array`
* @return {Array} Flattened array
* @api public
*/
module.exports = require('arr-flatten');
'use strict';
/**
* Loop over each item in an array and call the given function
* on every element.
*
* ```js
* forEach(['a', 'b', 'c'], function (ele) {
* return ele + ele;
* });
* //=> ['aa', 'bb', 'cc']
*
* forEach(['a', 'b', 'c'], function (ele, i) {
* return i + ele;
* });
* //=> ['0a', '1b', '2c']
* ```
*
* @name .forEach
* @param {Array} `array`
* @param {Function} `fn`
* @param {Object} `thisArg` Optionally pass a `thisArg` to be used as the context in which to call the function.
* @return {Array}
* @api public
*/
module.exports = function forEach(arr, cb, thisArg) {
if (!arr) {
return;
}
if (arr == null) return;
var len = arr.length;

@@ -9,0 +30,0 @@ var i = -1;

'use strict';
/**
* Array.indexOf
* Fast array `.index()`.
*
* ```js
* indexOf(['a', 'b'], 'b');
* //=> 1
*
* indexOf(['a', 'b', 'a', 'b'], 'b', 2);
* //=> 3
* ```
*
* @name .indexOf
* @param {Array} `arr` Array to iterate over
* @param {String} `ele` The element to find.
* @param {Array} `start` Starting index.
* @return {Number} Returns the index of `ele` or `-1`
*/
module.exports = function indexOf(arr, item, fromIndex) {
fromIndex = fromIndex || 0;
if (arr == null) {
return -1;
module.exports = function indexOf(arr, ele, start) {
if (!Array.isArray(arr)) {
throw new TypeError('utils#array.indexOf() expects an array.');
}
if (typeof ele === 'undefined') return -1;
start = start || 0;
var len = arr.length;
var i = fromIndex < 0 ? len + fromIndex : fromIndex;
var i = start < 0
? len + start
: start;
while (i < len) {
// we iterate over sparse items since there is no way to make it
// work properly on IE 7-8. see #64
if (arr[i] === item) {
if (arr[i] === ele) {
return i;
}
i++;

@@ -24,0 +39,0 @@ }

'use strict';
var isNumber = require('is-number');
/**
* Return the last element in an array.
* Returns the last item, or last `n` items of an array.
*
* ```js
* last(['a', 'b', 'c', 'd', 'e'], 2)
* //=> ['d', 'e']
* ```
*
* @name .last
* @param {Array} `array`
* @param {Number} `n` Number of items to return, starting with the last item.
* @return {Array}
* @api public
*/
module.exports = function last(arr) {
if (!arr || arr.length === 0) {
return undefined;
module.exports = function last_(arr, fn) {
if (!Array.isArray(arr)) {
throw new TypeError('utils#array.last() expects an array.');
}
return arr[arr.length - 1];
};
var len = arr.length;
if (len === 0) {
return [];
}
if (!fn) return arr[arr.length - 1];
if (isNumber(fn)) {
return arr.slice(-fn);
}
if (typeof fn === 'function') {
var val, i = 0;
while (len--) {
val = arr[i++];
if (fn(val, i, arr)) {
return val;
}
}
}
return [];
};
'use strict';
var path = require('path');
var list = require('dirs');
var isDir = require('is-directory');
var filename = require('./path/name');
function requireFile(fp) {
fp = path.resolve(__dirname, fp);
if (!/index/.test(fp) && /\.js/.test(fp) && !isDir(fp)) {
exports[filename(fp)] = require(fp);
}
return exports;
}
// list(__dirname).filter(requireFile);
// list(__dirname + '/core').filter(requireFile);
list(__dirname + '/array').filter(requireFile);
list(__dirname + '/fs').filter(requireFile);
list(__dirname + '/lang').filter(requireFile);
list(__dirname + '/object').filter(requireFile);
list(__dirname + '/path').filter(requireFile);
list(__dirname + '/string').filter(requireFile);
console.log(exports);
module.exports = require('export-dirs')(__dirname);
var typeOf = require('kind-of');
/**
* sourced from github.com/mout/mout
* Return true if the given `value` is an arguments object.
*
* ```js
* isArguments(arguments)
* //=> 'true'
* ```
*
* @name .isArguments
* @attribution sourced from github.com/mout/mout
* @param {*} `value` The value to check.
* @return {Boolean}
* @api public
*/

@@ -6,0 +17,0 @@

'use strict';
var hasValue = require('has-value');
var hasValues = require('has-values');
/**
* Returns true if the given value is empty, false if any value exists. Works for booleans,
* functions, numbers, strings, nulls, objects and arrays.
*
* ```js
* utils.lang.isEmpty('a');
* //=> true
*
* utils.lang.isEmpty('');
* //=> false
*
* utils.lang.isEmpty(1);
* //=> true
*
* utils.lang.isEmpty({a: 'a'}});
* //=> true
*
* utils.lang.isEmpty({}});
* //=> false
*
* utils.lang.isEmpty(['a']);
* //=> true
* ```
*
* @name .isEmpty
* @crosslink hasValues
* @param {Object} `object` The object to check for `value`
* @param {*} `value` the value to look for
* @return {Boolean} False if any values exists.
* @api public
*/
module.exports = function isEmpty(val) {
return !hasValue(val);
return !hasValues(val);
};
'use strict';
module.exports = function extend(a, objects) {
var args = [].slice.call(arguments);
if (a == null) {
return {};
}
if (objects == null) {
return a;
}
var hasOwn = require('./hasOwn');
var isPlainObject = require('../lang/isPlainObject');
var len = args.length;
var o = {};
/**
* Extend `o` with properties of other `objects`.
*
* @name .extend
* @param {Object} `o` The target object. Pass an empty object to shallow clone.
* @param {Object} `objects`
* @return {Object}
* @api public
*/
module.exports = function extend(o) {
if (!isPlainObject(o)) { return {}; }
var args = arguments;
var len = args.length - 1;
for (var i = 0; i < len; i++) {
var obj = args[i];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
o[key] = obj[key];
var obj = args[i + 1];
if (isPlainObject(obj)) {
for (var key in obj) {
if (hasOwn(obj, key)) {
o[key] = obj[key];
}
}
}
}
return o;
};
'use strict';
module.exports = require('object.filter');
/**
*
*
* @type {[type]}
*/
module.exports = require('object.filter');
'use strict';
module.exports = require('for-in');
module.exports = require('for-in');

@@ -6,7 +6,13 @@ 'use strict';

/**
* Returns a list of all enumerable properties of `obj` that have function
* values
* Returns a copy of the given `obj` filtered to have only enumerable
* properties that have function values.
*
* ```js
* functions({a: 'b', c: function() {}});
* //=> {c: function() {}}
* ```
*
* @name .functions
* @param {Object} `obj`
* @return {Array}
* @return {Object}
* @api public

@@ -16,9 +22,11 @@ */

module.exports = function functions(obj) {
var keys = [];
var res = {};
forIn(obj, function (val, key) {
if (typeof val === 'function') {
keys.push(key);
res[key] = val;
}
});
return keys;
return res;
};

@@ -5,3 +5,3 @@ 'use strict';

* Return true if `key` is an own, enumerable property
* of `this.cache` or the given `obj`.
* of the given `obj`.
*

@@ -12,2 +12,3 @@ * ```js

*
* @name .hasOwn
* @param {String} `key`

@@ -14,0 +15,0 @@ * @param {Object} `obj` Optionally pass an object to check.

@@ -6,9 +6,8 @@ 'use strict';

/**
* Return an array of keys for the given `obj`.
* Return an array of keys for the given `obj`. Uses `Object.keys`
* when available, otherwise falls back on `forOwn`.
*
* Uses `Object.keys` when available, otherwise falls
* back on `forOwn`.]
*
* @name .keys
* @param {Object} `obj`
* @return {Array}
* @return {Array} Array of keys.
* @api public

@@ -15,0 +14,0 @@ */

'use strict';
var forOwn = require('for-own');
var makeIterator = require('make-iterator');
var iterator = require('make-iterator');
module.exports = function some(obj, cb, thisArg) {
cb = makeIterator(cb, thisArg);
cb = iterator(cb, thisArg);
var result = false;

@@ -16,4 +16,3 @@

});
return result;
};

@@ -5,3 +5,4 @@ 'use strict';

* If `val` is null or undefined returns an empty string,
* otherwise `val` is typecast to a String
* otherwise `val` is cast it to a String.
*
*/

@@ -8,0 +9,0 @@

{
"name": "utils",
"description": "Generic utility functions for JavaScript/node.js",
"version": "0.0.2",
"description": "Fast, generic JavaScript/node.js utility functions.",
"version": "0.1.5",
"homepage": "https://github.com/jonschlinkert/utils",

@@ -17,7 +17,9 @@ "author": {

},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/jonschlinkert/utils/blob/master/LICENSE-MIT"
}
"license": {
"type": "MIT",
"url": "https://github.com/jonschlinkert/utils/blob/master/LICENSE"
},
"files": [
"index.js",
"lib/"
],

@@ -29,22 +31,55 @@ "main": "index.js",

"scripts": {
"test": "mocha -R spec"
"test": "mocha"
},
"devDependencies": {
"mocha": "*"
},
"dependencies": {
"arr-flatten": "^0.2.1",
"array-slice": "^0.2.2",
"dirs": "^0.1.2",
"for-in": "^0.1.3",
"for-own": "^0.1.2",
"has-value": "^0.1.0",
"is-directory": "^0.2.2",
"kind-of": "^0.1.2",
"any": "^1.0.0",
"arr-diff": "^1.0.1",
"arr-flatten": "^1.0.1",
"arr-map": "^2.0.0",
"arr-union": "^2.0.1",
"array-unique": "^0.2.1",
"center-align": "^0.1.1",
"export-dirs": "^0.2.4",
"export-files": "^2.0.1",
"for-in": "^0.1.4",
"for-own": "^0.1.3",
"has-values": "^0.1.2",
"is-number": "^1.1.2",
"is-plain-object": "^1.0.0",
"kind-of": "^1.1.0",
"make-iterator": "^0.1.1",
"object.filter": "^0.2.0",
"object.filter": "^0.3.0",
"object.omit": "^0.2.1",
"object.pick": "^0.1.1",
"object.reduce": "^0.1.3"
"object.pick": "^1.1.1",
"object.reduce": "^0.1.6",
"right-align": "^0.1.1",
"word-wrap": "^1.0.2"
},
"devDependencies": {
"chalk": "^1.0.0",
"gulp-istanbul": "^0.7.0",
"gulp-jshint": "^1.9.4",
"gulp-mocha": "^2.0.0",
"gulp-util": "^3.0.4",
"jshint-stylish": "^1.0.1",
"lodash": "^3.5.0",
"mocha": "*",
"relative": "^2.0.0",
"should": "*",
"strip-ansi": "^2.0.1",
"through2": "^0.6.3",
"verb": "^0.5.0",
"vinyl": "^0.4.6"
},
"keywords": [
"util",
"utils"
],
"verb": {
"deps": {
"ignore": [
"staging"
]
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc