Sand
Sand is a JavaScript utility library delivering modularity, consistency and more, following UMD pattern.
Installation
Manual download
See my releases page for download.
NPM
npm install --save sand-util
Load
Directly by HTML using global variable sand.
CommonJS
var sand = ;
AMD
;
Usage
Please do your project use the default name for our library like sand.
Specifications and examples
In the sand there are specific methods for certain types.
Function
Throttle - Throttle calls to callback routine and ensure that it is not invoked any more often than delay milliseconds.
{ ...} var delay = 100; sand;
Debounce - Returns a function, that, as long as it continues to be invoked, will not be triggered. The function will be called after it stops being called for n milliseconds.
{ ...} var delay = 100; sand;
Array
Find - Find a object in an array according to informed rule.
var array = a: 2 b: 'b' a: 1 b: 'a'; sand; // {a: 1, b: 'a'}sand; // undefined
Filter - Creates a new array with all elements that pass the test implemented by callback.
var array = a: 2 b: 'b' a: 1 b: 'a'; var { return elemb === 'b';}; sand; // [{a: 2, b: 'b'}]
Map - Creates a new array with the results of calling the callback on every element in this array.
var array = a: 2 b: 'b' a: 1 b: 'a'; var { return elem;}; sand; // [{a: 2, b: 'b'}, {a: 1, b: 'a'}]
Sort - Sort an array according to informed key. Order default is asc.
var array = a: 2 b: 'b' a: 1 b: 'a'; sand; // [{a: 1, b: 'a'}, {a: 2, b: 'b'}]sand; // [{a: 1, b: 'a'}, {a: 2, b: 'b'}]sand; // [{a: 2, b: 'b'}, {a: 1, b: 'a'}]sand; // [{a: 2, b: 'b'}, {a: 1, b: 'a'}]
Inject - Inject methods for manipulation. It does not inject methods in the prototype, it injects methods in the given array.
Method | Description |
---|---|
get | returns the object at the current position or in the given position |
set | change the current position of the array and call get |
previous | returns the object in the previous position found or false if there is no |
next | returns the object in the next position found or false if there is no |
example:
var array = a: 2 b: 'b' a: 1 b: 'a'; sand; array; // {a: 2, b: 'b'}array; // {a: 1, b: 'a'} array; // {a: 1, b: 'a'} array; // {a: 1, b: 'a'}array; // {a: 2, b: 'b'} arrayprevious; // {a: 2, b: 'b'}arrayprevious; // false arraynext; // {a: 2, b: 'b'}arraynext; // {a: 1, b: 'a'}arraynext; // false
Object
Has key - Check if exists the key directly in object.
var object = a: 1 b: 2 c: 3 d: 4 e: 5; sand; // truesand; // false
Has value - Check if exists the value directly in object.
var object = a: 1 b: 2 c: 3 d: 4 e: 5; sand; // truesand; // false
Inject - Inject methods for manipulation of keys. It does not inject methods in the prototype, it injects methods in the given object.
Method | Description |
---|---|
keys | returns all keys of object |
getKey | returns the key at the current position |
setKey | change the current position of the key and call getKey |
previousKey | returns the key in the previous position found or false if there is no |
nextKey | returns the key in the next position found or false if there is no |
example:
var object = a: 'a' b: 'b' c: 'c' d: 'd' e: 'e'; sand; object; // ['a', 'b', 'c', 'd', 'e'] object; // 'a'object; // 'c' object; // 'd'object; // 'e' object; // 'd'object; // 'c'
Date
Now - Gets the current timestamp as integer.
sand; // example: 1432395347945
Number
Is number - Check if a value is number.
sand; // falsesand; // falsesand; // truesand; // truesand; // true
Issues
For questions, bug reports, improve documentation, and feature request please search through existing issue and if you don't find and answer open a new one here. If you need support send me an email. You can also contact me for any non public concerns.
Contribution
When issuing a pull request, please exclude changes in the dist folder to avoid merge conflicts.
License
Sand is released under the MIT license. See LICENSE for details.
More
Sand is a work in progress, feel free to improve it.