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.1.6 to 0.2.0

lib/array/each.js

2

index.js
/*!
* utils <https://github.com/jonschlinkert/utils>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Copyright (c) 2014 Jon Schlinkert.
* Licensed under the MIT license.

@@ -6,0 +6,0 @@ */

'use strict';
/**
* Loop over each item in an array and call the given function
* on every element.
* Loop over each item in an array and call the given function on every element.
*

@@ -20,2 +19,3 @@ * ```js

* @name .forEach
* @alias .each
* @param {Array} `array`

@@ -28,12 +28,2 @@ * @param {Function} `fn`

module.exports = function forEach(arr, cb, thisArg) {
if (arr == null) return;
var len = arr.length;
var i = -1;
while (++i < len) {
if (cb.call(thisArg, arr[i], i, arr) === false) {
break;
}
}
};
module.exports = require('./each');

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

module.exports = function isObject(val) {
return typeOf(val) === 'object' && typeOf(val) !== 'regexp';
return typeOf(val) === 'object';
};
{
"name": "utils",
"description": "Fast, generic JavaScript/node.js utility functions.",
"version": "0.1.6",
"version": "0.2.0",
"homepage": "https://github.com/jonschlinkert/utils",

@@ -38,2 +38,4 @@ "author": {

"arr-union": "^2.0.1",
"array-each": "^0.1.0",
"array-slice": "^0.2.3",
"array-unique": "^0.2.1",

@@ -45,3 +47,3 @@ "center-align": "^0.1.1",

"for-own": "^0.1.3",
"has-values": "^0.1.2",
"has-values": "^0.1.3",
"is-number": "^1.1.2",

@@ -51,4 +53,5 @@ "is-plain-object": "^1.0.0",

"make-iterator": "^0.1.1",
"object.defaults": "^0.3.0",
"object.filter": "^0.3.0",
"object.omit": "^0.2.1",
"object.omit": "^1.1.0",
"object.pick": "^1.1.1",

@@ -61,13 +64,12 @@ "object.reduce": "^0.1.6",

"chalk": "^1.0.0",
"gulp-istanbul": "^0.7.0",
"gulp-jshint": "^1.9.4",
"gulp-mocha": "^2.0.0",
"gulp-istanbul": "^0.8.1",
"gulp-jshint": "^1.10.0",
"gulp-mocha": "^2.0.1",
"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",
"lodash": "^3.7.0",
"mocha": "^2.2.4",
"relative": "^3.0.0",
"should": "^6.0.1",
"through2": "^0.6.5",
"verb": "^0.5.0",

@@ -74,0 +76,0 @@ "vinyl": "^0.4.6"

@@ -5,15 +5,3 @@ # utils [![NPM version](https://badge.fury.io/js/utils.svg)](http://badge.fury.io/js/utils) [![Build Status](https://travis-ci.org/jonschlinkert/utils.svg)](https://travis-ci.org/jonschlinkert/utils)

**Why another utils lib?**
- I'm a node.js developer. I want fast, light, dependable utility functions for node.js projects.
- Do you really need bloated, everything-but-the-kitchen-sink functions that are guaranteed to work with IE 4, **for your Yeoman generator or gulp plugin**!? Nonsense.
- The benchmarks that accompany many of the functions in the library show that in some cases, the penalty for using such "kitchen-sink" code is a 2,000-5,000% reduction in speed. Sometimes greater.
**Goals**
- Fastest implementation of each method, without too much compromise. Covering uncommon cases is fine, but don't go overboard.
- Clean well-documented, commented code.
- [When it makes sense](#adding-utils), external libraries are used and exposed instead of writing new code.
- Focus on node.js usage and projects that are likely to use a number of these utils in one project. If you only need one or two of these in a small project, don't use this. Use small modules that do only one thing.
## Install with [npm](npmjs.org)

@@ -37,3 +25,9 @@

* [Running verb](#running-verb)
- [About](#about)
- [Related projects](#related-projects)
- [Author](#author)
- [License](#license)
_(Table of contents generated by [verb])_
<!-- tocstop -->

@@ -52,3 +46,3 @@

See [example.md](./example.md) for visual representation of the object.
See [example.md](./example.md) for an example of the `utils` object.

@@ -74,12 +68,5 @@

<!-- ## Code links
These links take you to the code for each function. There are currently {%= codelinks('lib/', 'utils in 7 sub-categories:') %} -->
## API
### [.after](lib/array/after.js#L19)
_(The below API documentation is generated by [Verb]. )_
### [.after](./lib/array/after.js#L19)
Returns all of the items in an array after the specified index.

@@ -96,3 +83,3 @@

### [.arrayify](./lib/array/arrayify.js#L20)
### [.arrayify](lib/array/arrayify.js#L20)

@@ -112,3 +99,3 @@ Cast the give `value` to an array.

### [.before](./lib/array/before.js#L20)
### [.before](lib/array/before.js#L20)

@@ -126,3 +113,3 @@ Returns all of the items in an array up to the specified number Opposite of `<%= after() %`.

### [.compact](./lib/array/compact.js#L17)
### [.compact](lib/array/compact.js#L17)

@@ -139,3 +126,3 @@ Remove all falsey values from an array.

### [.difference](./lib/array/difference.js#L24)
### [.difference](lib/array/difference.js#L24)

@@ -156,4 +143,25 @@ Return the difference between the first array and additional arrays.

### [.first](./lib/array/first.js#L20)
### [.each](lib/array/each.js#L27)
Loop over each item in an array and call the given function on every element.
* `array` **{Array}**
* `fn` **{Function}**
* `thisArg` **{Object}**: Optionally pass a `thisArg` to be used as the context in which to call the function.
* `returns`: {Array}
```js
each(['a', 'b', 'c'], function (ele) {
return ele + ele;
});
//=> ['aa', 'bb', 'cc']
each(['a', 'b', 'c'], function (ele, i) {
return i + ele;
});
//=> ['0a', '1b', '2c']
```
### [.first](lib/array/first.js#L20)
Returns the first item, or first `n` items of an array.

@@ -170,3 +178,3 @@

### [.flatten](./lib/array/flatten.js#L18)
### [.flatten](lib/array/flatten.js#L18)

@@ -183,3 +191,3 @@ Recursively flatten an array or arrays. Uses the fastest implementation of array flatten for node.js

### [.forEach](./lib/array/forEach.js#L27)
### [.forEach](lib/array/forEach.js#L27)

@@ -205,8 +213,4 @@ Loop over each item in an array and call the given function on every element.

### [.isArray](lib/array/isArray.js#L19)
### [.isArray](./lib/array/isArray.js#L19)
Returns true if the given `value` is an array.

@@ -224,3 +228,3 @@

### [.last](./lib/array/last.js#L20)
### [.last](lib/array/last.js#L20)

@@ -238,3 +242,3 @@ Returns the last item, or last `n` items of an array.

### [.map](./lib/array/map.js#L27)
### [.map](lib/array/map.js#L27)

@@ -259,6 +263,19 @@ Returns a new array with the results of calling the given function on every element in the array. This is a faster, node.js focused alternative to JavaScript's native array map.

### [.slice](lib/array/slice.js#L21)
Alternative to JavaScript's native array-slice method. Slices `array` from the `start` index up to but not including the `end` index.
### [.union](./lib/array/union.js#L19)
* `array` **{Array}**: the array to slice.
* `start` **{Number}**: Optionally define the starting index.
* `end` **{Number}**: Optionally define the ending index.
```js
var arr = ['a', 'b', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
slice(arr, 3, 6);
//=> ['e', 'f', 'g']
```
### [.union](lib/array/union.js#L19)
Return an array free of duplicate values. Fastest ES5 implementation.

@@ -274,3 +291,3 @@

### [.unique](./lib/array/unique.js#L19)
### [.unique](lib/array/unique.js#L19)

@@ -287,3 +304,3 @@ Return an array free of duplicate values. Fastest ES5 implementation.

### [.any](./lib/collection/any.js#L14)
### [.any](lib/collection/any.js#L14)

@@ -297,3 +314,3 @@ * `value` **{*}**

### [.contains](./lib/collection/contains.js#L17)
### [.contains](lib/collection/contains.js#L17)

@@ -306,8 +323,4 @@ * `collection` **{Array|Object}**

### [.tryReaddir](lib/fs/tryReaddir.js#L16)
### [.tryReaddir](./lib/fs/tryReaddir.js#L16)
* `dir` **{String}**: Starting directory

@@ -320,3 +333,3 @@ * `returns` **{Array}**: Array of files.

### [.tryRequire](./lib/fs/tryRequire.js#L15)
### [.tryRequire](lib/fs/tryRequire.js#L15)

@@ -329,6 +342,4 @@ * `fp` **{String}**: File path of the file to require

### [.hasValues](lib/lang/hasValues.js#L34)
### [.hasValues](./lib/lang/hasValues.js#L34)
Returns true if any value exists, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays.

@@ -360,6 +371,4 @@

### [.isEmpty](lib/lang/isEmpty.js#L37)
### [.isEmpty](./lib/lang/isEmpty.js#L37)
Returns true if the given value is empty, false if any value exists. Works for booleans, functions, numbers, strings, nulls, objects and arrays.

@@ -391,3 +400,3 @@

### [.isObject](./lib/lang/isObject.js#L22)
### [.isObject](lib/lang/isObject.js#L22)

@@ -407,3 +416,3 @@ Return true if the given `value` is an object with keys.

### [.isPlainObject](./lib/lang/isPlainObject.js#L23)
### [.isPlainObject](lib/lang/isPlainObject.js#L23)

@@ -426,6 +435,4 @@ Return true if the given `value` is an object with keys.

### [.sum](lib/math/sum.js#L20)
### [.sum](./lib/math/sum.js#L20)
Returns the sum of all numbers in the given array.

@@ -441,18 +448,20 @@

### [.extend](./lib/object/extend.js#L16)
### [.defaults](lib/object/defaults.js#L13)
* `o` **{Object}**: The target object. Pass an empty object to shallow clone.
* `object` **{Object}**: The target object. Pass an empty object to shallow clone.
* `objects` **{Object}**
* `returns`: {Object}
Extend `o` with properties of other `objects`.
Extend `object` with properties of other `objects`
### [.extend](lib/object/extend.js#L16)
* `o` **{Object}**: The target object. Pass an empty object to shallow clone.
* `objects` **{Object}**
* `returns`: {Object}
Extend `o` with properties of other `objects`.
### [.functions](lib/object/functions.js#L20)
### [.functions](./lib/object/functions.js#L20)
Returns a copy of the given `obj` filtered to have only enumerable properties that have function values.

@@ -468,3 +477,3 @@

### [.hasOwn](./lib/object/hasOwn.js#L18)
### [.hasOwn](lib/object/hasOwn.js#L18)

@@ -481,6 +490,4 @@ Return true if `key` is an own, enumerable property of the given `obj`.

### [.keys](lib/object/keys.js#L15)
### [.keys](./lib/object/keys.js#L15)
* `obj` **{Object}**

@@ -492,3 +499,3 @@ * `returns` **{Array}**: Array of keys.

### [merge](./lib/object/merge.js#L23)
### [.merge](lib/object/merge.js#L23)

@@ -502,3 +509,3 @@ * `o` **{Object}**: The target object. Pass an empty object to shallow clone.

### [.methods](./lib/object/methods.js#L15)
### [.methods](lib/object/methods.js#L15)

@@ -511,12 +518,4 @@ * `obj` **{Object}**

### [.camelcase](lib/string/camelcase.js#L20)
### [.camelcase](./lib/string/camelcase.js#L20)
camelCase the characters in `string`.

@@ -532,3 +531,3 @@

### [.centerAlign](./lib/string/centerAlign.js#L21)
### [.centerAlign](lib/string/centerAlign.js#L21)

@@ -544,3 +543,3 @@ Center align the characters in a string using non-breaking spaces.

### [.chop](./lib/string/chop.js#L26)
### [.chop](lib/string/chop.js#L26)

@@ -563,3 +562,3 @@ Like trim, but removes both extraneous whitespace and non-word characters from the beginning and end of a string.

### [.count](./lib/string/count.js#L21)
### [.count](lib/string/count.js#L21)

@@ -577,3 +576,3 @@ Count the number of occurrances of a substring within a string.

### [.dashcase](./lib/string/dashcase.js#L22)
### [.dashcase](lib/string/dashcase.js#L22)

@@ -590,3 +589,3 @@ dash-case the characters in `string`. This is similar to [slugify], but [slugify] makes the string compatible to be used as a URL slug.

### [.dotcase](./lib/string/dotcase.js#L20)
### [.dotcase](lib/string/dotcase.js#L20)

@@ -603,3 +602,3 @@ dot.case the characters in `string`.

### [.ellipsis](./lib/string/ellipsis.js#L23)
### [.ellipsis](lib/string/ellipsis.js#L23)

@@ -618,3 +617,3 @@ Truncate a string to the specified `length`, and append it with an elipsis, `…`.

### [.hyphenate](./lib/string/hyphenate.js#L20)
### [.hyphenate](lib/string/hyphenate.js#L20)

@@ -631,6 +630,4 @@ Replace spaces in a string with hyphens. This

### [.isString](lib/string/isString.js#L20)
### [.isString](./lib/string/isString.js#L20)
Returns true if the value is a string.

@@ -649,3 +646,3 @@

### [.pascalcase](./lib/string/pascalcase.js#L20)
### [.pascalcase](lib/string/pascalcase.js#L20)

@@ -662,3 +659,3 @@ PascalCase the characters in `string`.

### [.pathcase](./lib/string/pathcase.js#L20)
### [.pathcase](lib/string/pathcase.js#L20)

@@ -675,3 +672,3 @@ path/case the characters in `string`.

### [.replace](./lib/string/replace.js#L21)
### [.replace](lib/string/replace.js#L21)

@@ -690,3 +687,3 @@ Replace occurrences of `a` with `b`.

### [.reverse](./lib/string/reverse.js#L19)
### [.reverse](lib/string/reverse.js#L19)

@@ -703,3 +700,3 @@ Reverse the characters in a string.

### [.rightAlign](./lib/string/rightAlign.js#L21)
### [.rightAlign](lib/string/rightAlign.js#L21)

@@ -715,3 +712,3 @@ Right align the characters in a string using non-breaking spaces.

### [.sentencecase](./lib/string/sentencecase.js#L19)
### [.sentencecase](lib/string/sentencecase.js#L19)

@@ -728,6 +725,4 @@ Sentence-case the characters in `string`.

### [.snakecase](lib/string/snakecase.js#L20)
### [.snakecase](./lib/string/snakecase.js#L20)
snake_case the characters in `string`.

@@ -743,6 +738,4 @@

### [.truncate](lib/string/truncate.js#L21)
### [.truncate](./lib/string/truncate.js#L21)
Truncate a string by removing all HTML tags and limiting the result to the specified `length`.

@@ -759,3 +752,3 @@

### [.wordwrap](./lib/string/wordwrap.js#L21)
### [.wordwrap](lib/string/wordwrap.js#L21)

@@ -773,2 +766,4 @@ Wrap words to a specified width using [word-wrap].

_(API documentation generated by [Verb])_
## Code coverage

@@ -782,3 +777,3 @@

-----------------------|-----------|-----------|-----------|-----------|
array/ | 76.24 | 67.19 | 85.71 | 77.32 |
array/ | 82.29 | 71.67 | 92.31 | 82.8 |
after.js | 100 | 75 | 100 | 100 |

@@ -789,5 +784,6 @@ arrayify.js | 100 | 100 | 100 | 100 |

difference.js | 100 | 100 | 100 | 100 |
each.js | 100 | 100 | 100 | 100 |
first.js | 88.89 | 83.33 | 100 | 88.24 |
flatten.js | 100 | 100 | 100 | 100 |
forEach.js | 12.5 | 0 | 0 | 14.29 |
forEach.js | 100 | 100 | 100 | 100 |
indexOf.js | 7.69 | 0 | 0 | 8.33 |

@@ -797,2 +793,3 @@ isArray.js | 100 | 100 | 100 | 100 |

map.js | 100 | 100 | 100 | 100 |
slice.js | 100 | 100 | 100 | 100 |
sort.js | 90.91 | 87.5 | 100 | 90.91 |

@@ -814,3 +811,4 @@ union.js | 100 | 100 | 100 | 100 |

sum.js | 100 | 100 | 100 | 100 |
object/ | 69.57 | 54.55 | 27.27 | 68.66 |
object/ | 70 | 54.55 | 27.27 | 69.12 |
defaults.js | 100 | 100 | 100 | 100 |
extend.js | 100 | 83.33 | 100 | 100 |

@@ -852,3 +850,3 @@ filter.js | 100 | 100 | 100 | 100 |

-----------------------|-----------|-----------|-----------|-----------|
All files | 84.55 | 77.27 | 75.44 | 83.55 |
All files | 86.43 | 79.05 | 76.79 | 85.34 |
-----------------------|-----------|-----------|-----------|-----------|

@@ -859,3 +857,3 @@

## Running tests
Install dev dependencies.
Install dev dependencies:

@@ -866,2 +864,3 @@ ```bash

## Contributing

@@ -890,5 +889,3 @@ > Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/utils/issues)

### Running verb
Run [verb] to generate documentation:

@@ -900,6 +897,52 @@

## About
**Why another utils lib?**
- I'm a node.js developer. I want fast, light, dependable utility functions for node.js projects.
- Do you really need bloated, everything-but-the-kitchen-sink functions that are guaranteed to work with IE 4, **for your Yeoman generator or gulp plugin**!? Nonsense.
- The benchmarks that accompany many of the functions in the library show that in some cases, the penalty for using such "kitchen-sink" code is a 2,000-5,000% reduction in speed. Sometimes greater.
**Project goals**
- Fastest implementation of each method, without too much compromise. Covering uncommon cases is fine, but don't go overboard.
- Clean well-documented, commented code.
- [When it makes sense](#adding-utils), external libraries are used and exposed instead of writing new code.
- Focus on node.js usage and projects that are likely to use a number of these utils in one project. If you only need one or two of these in a small project, don't use this. Use small modules that do only one thing.
## Related projects
> This project depends on these great libraries:
* [any](https://github.com/jonschlinkert/any): Returns `true` if a value exists in the given string, array or object.
* [arr-diff](https://github.com/jonschlinkert/arr-diff): Returns an array with only the unique values from the first array, by excluding all values from additional arrays using strict equality for comparisons.
* [arr-flatten](https://github.com/jonschlinkert/arr-flatten): Recursively flatten an array or arrays. This is the fastest implementation of array flatten.
* [arr-map](https://github.com/jonschlinkert/arr-map): Faster, node.js focused alternative to JavaScript's native array map.
* [arr-union](https://github.com/jonschlinkert/arr-union): Combines a list of arrays, returning a single array with unique values, using strict equality for comparisons.
* [array-each](https://github.com/jonschlinkert/array-each): Loop over each item in an array and call the given function on every element.
* [array-slice](https://github.com/jonschlinkert/array-slice): Array-slice method. Slices `array` from the `start` index up to, but not including, the `end` index.
* [array-unique](https://github.com/jonschlinkert/array-unique): Return an array free of duplicate values. Fastest ES5 implementation.
* [center-align](https://github.com/jonschlinkert/center-align): Center-align the text in a string.
* [export-dirs](https://github.com/jonschlinkert/export-dirs): Export directories and their files as node.js modules.
* [export-files](https://github.com/jonschlinkert/export-files): node.js utility for exporting a directory of files as modules.
* [for-in](https://github.com/jonschlinkert/for-in): Iterate over the own and inherited enumerable properties of an objecte, and return an object with properties that evaluate to true from the callback. Exit early by returning `false`. JavaScript/Node.js
* [for-own](https://github.com/jonschlinkert/for-own): Iterate over the own enumerable properties of an object, and return an object with properties that evaluate to true from the callback. Exit early by returning `false`. JavaScript/Node.js.
* [has-values](https://github.com/jonschlinkert/has-values): Returns true if any values exist, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays.
* [is-number](https://github.com/jonschlinkert/is-number): Returns true if the value is a number. comprehensive tests.
* [is-plain-object](https://github.com/jonschlinkert/is-plain-object): Returns true if an object was created by the `Object` constructor.
* [kind-of](https://github.com/jonschlinkert/kind-of): Get the native type of a value.
* [make-iterator](https://github.com/jonschlinkert/make-iterator): Convert an argument into a valid iterator. Based on the `.makeIterator()` implementation in mout https://github.com/mout/mout.
* [object.defaults](https://github.com/jonschlinkert/object.defaults): Like `extend` but only copies missing properties/values to the target object.
* [object.filter](https://github.com/jonschlinkert/object.filter): Create a new object filtered to have only properties for which the callback returns true.
* [object.omit](https://github.com/jonschlinkert/object.omit): Return a copy of an object without the given key, or array of keys.
* [object.pick](https://github.com/jonschlinkert/object.pick): Returns a filtered copy of an object with only the specified keys, like `pick` from lo-dash / underscore.
* [object.reduce](https://github.com/jonschlinkert/object.reduce): Reduces an object to a value that is the accumulated result of running each property in the object through a callback.
* [right-align](https://github.com/jonschlinkert/right-align): Right-align the text in a string.
* [word-wrap](https://github.com/jonschlinkert/word-wrap): Wrap words to a specified length.
## Author
**Jon Schlinkert**
+ [github/jonschlinkert](https://github.com/jonschlinkert)

@@ -909,6 +952,10 @@ + [twitter/jonschlinkert](http://twitter.com/jonschlinkert)

## License
Copyright (c) 2015 Jon Schlinkert
Copyright (c) 2014-2015 Jon Schlinkert
Released under the MIT license
<!-- generated reference links -->
[verb]: https://github.com/assemble/verb
[assemble]: http://assemble.io
<!-- deps:mocha jshint-stylish -->
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