vuke
Version:
Better version of a map with more utility methods.
248 lines (150 loc) • 5.01 kB
Markdown
# Vuke
Basically a simplified map with extra utility methods.
## Install
Node 8.0.0 or higher is required.
```bash
$ npm install vuke --save
```
## Example Usage
```js
const Vuke = require('vuke');
const myList = new Vuke();
myList.set('john.doe@example.com', 'really-good-password-123');
console.log(`Password: ${myList.get('john.doe@example.com')}`)
```
## API
### .set(key, val)
Creates a key with a value in a specific collection.
### .delete(key)
Removes a key and value from a specific collection.
### .array()
Creates an ordered array of the values of a specific collection, and caches it internally.
__Returns: `Array`__
### .keyArray()
Creates an ordered array of the keys of a specific collection, and caches it internally.
__Returns: `Array`__
### .first(count)
Obtains the first value(s) in this collection.
| Parameter | Type | Optional | Default |
|-----------|--------|----------|---------|
| count | Number | True | none |
__Returns: `Array`__
### .firstKey(count)
Obtains the first key(s) in this collection.
| Parameter | Type | Optional | Default |
|-----------|--------|----------|---------|
| count | Number | True | none |
__Returns: `Array`__
### .last(count)
Obtains the last value(s) in this collection.
| Parameter | Type | Optional | Default |
|-----------|--------|----------|---------|
| count | Number | True | none |
__Returns: `Array`__
### .lastKey(count)
Obtains the last key(s) in this collection.
| Parameter | Type | Optional | Default |
|-----------|--------|----------|---------|
| count | Number | True | none |
__Returns: `Array`__
### .random(count)
Obtains random value(s) from this collection.
| Parameter | Type | Optional | Default |
|-----------|--------|----------|---------|
| count | Number | True | none |
__Returns: `Array`__
### .randomKey(count)
Obtains random key(s) from this collection.
| Parameter | Type | Optional | Default |
|-----------|--------|----------|---------|
| count | Number | True | none |
__Returns: `Array`__
### .filter(fn, thisArg)
Identical to Array.filter(), but returns a Collection instead of an Array.
| Parameter | Type | Optional | Default |
|-----------|----------|----------|---------|
| fn | Function | | |
| thisArg | Object | True | none |
__Returns: `Vuke`__
### .map(fn, thisArg)
Identical to [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).
| Parameter | Type | Optional | Default |
|-----------|----------|----------|---------|
| fn | Function | | |
| thisArg | * | True | none |
__Returns: `Array`__
### .some(fn, thisArg)
Identical to [Array.some()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some).
| Parameter | Type | Optional | Default |
|-----------|----------|----------|---------|
| fn | Function | | |
| thisArg | Object | True | none |
__Returns: `Boolean`__
### .every(fn, thisArg)
Identical to [Array.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every).
| Parameter | Type | Optional | Default |
|-----------|----------|----------|---------|
| fn | Function | | |
| thisArg | Object | True | none |
__Returns: `Boolean`__
### .reduce(fn, initialValue)
Identical to [Array.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).
| Parameter | Type | Optional | Default |
|--------------|----------|----------|---------|
| fn | Function | | |
| initialValue | * | True | none |
__Returns: `*`__
### .clone()
Creates an identical shallow copy of this collection.
**Examples:**
```js
const myNewList = myList.clone();
```
__Returns: `Vuke`__
### .concat(...collections)
Creates an identical shallow copy of this collection.
| Parameter | Type |
|-------------|---------------|
| collections | ...Collection |
**Examples:**
```js
const myNewList = someColl.concat(myList1, myList2, myList3);
```
__Returns: `Vuke`__
### .deleteAll()
Calls the `delete()` method on all items that have it.
__Returns: `Array`__
### .equals(collection)
Checks if this collection shares identical key-value pairings with another.
| Parameter | Type |
|-------------|------------|
| collections | Collection |
__Returns: `Boolean`__
### .sort(compareFunction)
Sorts the elements of a collection in place and returns the collection.
| Parameter | Type | Optional | Default |
|-----------------|----------|----------|---------|
| compareFunction | Function | True | none |
__Returns: `Vuke`__
## License
MIT © Aiden Bai