Beedrill
A micro library containing high level utility functions.
Installation
Install beedrill
by running:
$ npm install --save beedrill
Documentation
-
beedrill
-
.isUndefined(value) ⇒
Boolean
-
.isString(value) ⇒
Boolean
-
.isArray(value) ⇒
Boolean
-
.isObject(value) ⇒
Boolean
-
.has(object, key) ⇒
Boolean
-
.keys(object) ⇒
Array
-
.pick(object, keys) ⇒
Object
-
.clone(value) ⇒
Object
-
.random(min, max) ⇒
Number
-
.unique(array) ⇒
Array
-
.isUndefined(value) ⇒
Boolean
beedrill.isUndefined(value) ⇒ Returns a boolean indicating if the value is undefined.
Kind: static method of beedrill
Returns: Boolean
- - true if the value is undefined, false otherwise.
Access: public
Param | Type | Description |
---|---|---|
value | Mixed |
Value to check. |
Example
const B = require('beedrill');
var foo;
B.isUndefined(foo); // --> true
Boolean
beedrill.isString(value) ⇒ Returns a boolean indicating if the value is a string.
Kind: static method of beedrill
Returns: Boolean
- - true if the value is a string, false otherwise.
Access: public
Param | Type | Description |
---|---|---|
value | Mixed |
Value to check. |
Example
const B = require('beedrill');
const foo = 'string';
const bar = 123;
B.isString(foo); // --> true
B.isString(bar); // --> false
Boolean
beedrill.isArray(value) ⇒ Returns a boolean indicating if the value is an array.
Kind: static method of beedrill
Returns: Boolean
- - true if the value is an array, false otherwise.
Access: public
Param | Type | Description |
---|---|---|
value | Mixed |
Value to check. |
Example
const B = require('beedrill');
const foo = 'string';
const bar = [1, 2, 3];
B.isArray(foo); // --> false
B.isArray(bar); // --> true
Boolean
beedrill.isObject(value) ⇒ Returns a boolean indicating if the value is an object literal.
Kind: static method of beedrill
Returns: Boolean
- - true if the value is an object, false otherwise.
Access: public
Param | Type | Description |
---|---|---|
value | Mixed |
Value to check. |
Example
const B = require('beedrill');
const foo = 'string';
const bar = { hello: 'world' };
B.isObject(foo); // --> false
B.isObject(bar); // --> true
Boolean
beedrill.has(object, key) ⇒ Checks if key is a direct property of object.
Kind: static method of beedrill
Returns: Boolean
- - Returns true if the key exists, else false.
Access: public
Param | Type | Description |
---|---|---|
object | Object |
The object to check. |
key | String |
The key to check. |
Example
const B = require('beedrill');
const foo = { hello: 'world' };
B.has(foo, 'bar'); // --> false
B.has(foo, 'hello'); // --> true
Array
beedrill.keys(object) ⇒ Creates an array of the own enumerable property names of object.
Kind: static method of beedrill
Returns: Array
- - An array of property names.
Access: public
Param | Type | Description |
---|---|---|
object | Object |
The object to retrieve property names from. |
Example
const B = require('beedrill');
const object = {
hello: 'world',
foo: 'bar'
};
B.keys(object); // --> ['hello', 'foo']
Object
beedrill.pick(object, keys) ⇒ Creates an object composed of the picked object properties.
Kind: static method of beedrill
Returns: Object
- - The new object.
Access: public
Param | Type | Description |
---|---|---|
object | Object |
The source object. |
keys |
String | Array
|
The property keys to pick. |
Example
const B = require('beedrill');
const object = {
foo: 1,
bar: 2,
hello: 3
};
B.pick(object, 'foo'); // --> { foo: 1 }
B.pick(object, ['bar', 'hello']); // --> { bar: 2, hello: 3 }
Object
beedrill.clone(value) ⇒ Creates a clone of a simple object
Kind: static method of beedrill
Returns: Object
- - The cloned object.
Access: public
Todo
- [ ] expand types that can be cloned using https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
Param | Type | Description |
---|---|---|
value | Object |
The object to clone. |
Example
const B = require('beedrill');
const object = { foo: 'bar' };
B.clone(object); // --> { foo: 'bar' }
Number
beedrill.random(min, max) ⇒ Returns a random integer between min and max, inclusive.
Kind: static method of beedrill
Returns: Number
- - A random number between min and max
Access: public
Param | Type | Description |
---|---|---|
min | Number |
The lowest possible random number. |
max | Number |
The highest possible random number. |
Example
const B = require('beedrill');
const num = B.random(0, 100); // --> 36
Array
beedrill.unique(array) ⇒ Produces a duplicate-free version of the array, using === to test object equality.
Kind: static method of beedrill
Returns: Array
- - Returns the new duplicate free array.
Access: public
Param | Type | Description |
---|---|---|
array | Array |
The array to inspect |
Example
const B = require('beedrill');
const source = [1, 2, 3, 1, 5, 5, 3, 2, 1];
const uniqueSource = B.unique(source); // --> [1, 2, 3, 5,]