2.0.0 • Published 5 years ago

short-methods v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

short-methods NPM version Build Status Dependency Status

Useful shorthand methods mostly for arrays but see the list below.

About

All methods defined tries to work w/ the given array, avoiding creating a new one. Except if thats the direct intent of the function (.clone).

By requiring it, the returned object will be a function. It has the full API on its properties, however you also extend a simple object or the original prototypes (this is DANGEROUS, only use it if you know what you're doing).

Install

# Navigate to your projects directory and use npm to install it as a dependency: npm install -S short-methods

Usage

In your code: var shortMethods = require('short-methods');

After this you can use it multiple ways:

var
  array;

# Use the properties of the returned object:

array = [1, 2, 3];

shortMethods.array.remove(array, 2);    // ===> array [1, 3];
shortMethods.array.removeAt(array, 2);  // ===> array [1, 2];

# Use the properties of the returned object in short format:

array = [1, 2, 3];

shortMethods.a.remove(array, 2);    // ===> array [1, 3];
shortMethods.a.removeAt(array, 2);  // ===> array [1, 2];

# Extend a specific object:

array = shortMethods([1, 2, 3]);

array.remove(2);   // ===> array [1, 3];
array.removeAt(2); // ===> array [1, 2];

# Extend prototypes (this is DANGEROUS, only use it if you know what you're doing):
shortMethods(true);

array = [1, 2, 3];

array.remove(2);    // ===> array [1, 3];
array.removeAt(2);  // ===> array [1, 2];

API

Short list w/ the default behavior, for more info about parameter usage check out the specs.

\<Number>.random(number)

Returns a number between 0 and number.

\<Array>.clear()

Clears the array.

\<Array>.clone()

Clones the array.

\<Array>.count(item)

Counts the occurences of an item in the array.

\<Array>.get(val, key)

Find an item in the array, useful if you have an array of objects.

\<Array>.has(item)

Check if the array has a specific item.

\<Array>.remap(callback)

Remap all elements of an array by the returned value of the callback.

\<Array>.remove(item)

Remove the first occurence of an element in the array.

\<Array>.removeAt(index)

Remove an element on a specific position in the array.

\<Array>.union(array)

Unions two array.

\<Array>.uniq()

Make the elements of an array uniq.

License

MIT © p1100i

2.0.0

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.10.0

7 years ago

0.9.0

7 years ago

0.8.0

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago