npm install utils-igor
### Example
package.json
```json
{
"name": "test_util",
"version": "0.0.1",
"description": "",
"main": "index.js",
"license": "UNLICENSED",
"dependencies" : {
"express" : "*",
"async": "1.4.2",
"utils-igor" : "*"
}
}
index.js
/**
* Created by igor on 30.05.16.
*/
/* globals process, require */
var express = require('express');
var app = express();
var port = process.env.PORT || 3000;
app.get('/', function (req, res) {
// include all blocks
var utils = require('utils-igor')();
var arr = [2,3,4,4,4,4,5];
var obj = {};
res.send( 200,{
objEmpty : utils.obj.isEmpty(obj),
isFunction : utils.type.isFn(obj),
arr : utils.arr.unique(arr)
});
});
app.listen(port, function () {
console.log('Example app listening on port '+ port + '!');
});
Result:
{"objEmpty":true,"isFunction":false,"arr":[2,3,4,5]}
To include one block change
- var utils = require('utils-igor')();
+ var utils = require('utils-igor')('obj');
To include more than one block change
- var utils = require('utils-igor')();
+ var utils = require('utils-igor')(['obj', 'arr']);
- arr
Function for array
- date
Function for date
- obj
Function for object
- str
Function for string
- type
Working with types
Function for array
- arr
- .mvVal
- .check(arr)
- .sortNumber(a, b) ⇒
number
- .share(arr1, arr2) ⇒
Array
- .diff(arr1, arr2) ⇒
Array
- .unique(arr)
- .sum() ⇒
Number
- .avg(a) ⇒
number
- .urls(arr) ⇒
Array
Kind: static class of arr
Delete all elements whith specified value
Param | Type | Description |
---|---|---|
arr | Array |
массив для очистки |
value | * |
значение |
Check parameter be array. if not return empty array
Kind: static method of arr
Param | Type |
---|---|
arr | * |
By default the sort method sorts elements alphabetically. To sort numerically just add a new method which handles numeric sorts e.g. [11, 1, 2].sort(utils.sortNumber);
Kind: static method of arr
Param | Type |
---|---|
a | Number |
b | Number |
Return share part of the array
Kind: static method of arr
Param |
---|
arr1 |
arr2 |
Return different part of the array
Kind: static method of arr
Param | Type |
---|---|
arr1 | Array |
arr2 | Array |
Clear repeat values
Kind: static method of arr
Param | Type |
---|---|
arr | Array |
Sum of array elements
Kind: static method of arr
Return average elements array
Kind: static method of arr
Param | Type |
---|---|
a | Array |
Return array. When element is url collect from specified array
Kind: static method of arr
Param | Type |
---|---|
arr | Array |
Function for date
- date
- static
- inner
Time constant in milliseconds
Kind: static property of date
Get time string
Kind: static method of date
Param | Type |
---|---|
ts | Number | null | undefined |
Example
'11:40:46'
Get date string
Kind: static method of date
Param | Type |
---|---|
shiftDays | Number | null |
ts | Number | null | undefined |
format | string | null | undefined |
Example
date() => '2014-11-30'
Example
date(null, null, 'd-m-y') => '30-11-2014'
- Get date time string
Kind: static method of date
Param | Type |
---|---|
shiftDays | Number | null | undefined |
ts | Number | null | undefined |
format | String | null | undefined |
Example
'2014-11-30 11:40:46'
Example
dateTime() this work
unix-time to seconds
Kind: static method of date
Param | Type |
---|---|
ts | Number | null | undefined |
up | boolean | null |
Example
1417323330
unix-time to minutes
Kind: static method of date
Param | Type |
---|---|
ts | Number | null | undefined |
up | boolean | null |
Example
23622056
seconds to unix-time
Kind: static method of date
Param | Type |
---|---|
sec | Number |
Example
1417323330
minutes to unix-time
Kind: static method of date
Param | Type |
---|---|
min | Number |
Example
23622056
Return date (now or by unixTime).
Kind: inner method of date
Param | Type |
---|---|
ts | Number | null | undefined |
Be round up or down
Kind: inner method of date
Param | Type |
---|---|
number | Number |
up | boolean | null |
Function for object
- obj
- static
- .arrToObjByKey(arr, prop, fnIterProp) ⇒
Object
- .keysChange(obj, keys) ⇒
Object
- .sort(obj, down) ⇒
Object
- .propInc(obj, prop, byVal)
- .beInObj(ob, prop, def)
- .pathCreate(obj, path, def)
- .isPathExist(obj, path) ⇒
Boolean
- .pathVal(obj, path) ⇒
*
- .pathMv(obj, path) ⇒
*
- .urlParams(obj) ⇒
string
- .ext(obj, add) ⇒
*
- .getPropToArr(arObj, prop) ⇒
Array
- .propToArr(obj) ⇒
Array
- .each(obj, fn, fnSort)
- .isEmpty(obj) ⇒
boolean
- .beRound(ob, prop, round)
- .arrToObjByKey(arr, prop, fnIterProp) ⇒
- inner
- ~isObj(obj) ⇒
boolean
- ~isSet(v)
- ~isObj(obj) ⇒
- static
Return object. When keys is specified property, value is object from array objects
Kind: static method of obj
Param | Type |
---|---|
arr | Array |
prop | String |
fnIterProp | function |
Get properties from obj by keys
Kind: static method of obj
Param | Type | Description |
---|---|---|
obj | object |
|
keys | * |
[{keyOld : keyNew,...}] |
Return new object when keys be sort
Kind: static method of obj
Param | Type |
---|---|
obj | Object |
down | Boolean |
Increment object property to the specified value
Kind: static method of obj
Param | Type |
---|---|
obj | Object |
prop | String |
byVal | Number |
Check is set object. If not, it creates it with the specified value
Kind: static method of obj
Param | Type |
---|---|
ob | Object |
prop | String |
def | Object |
Create path in object
Kind: static method of obj
Param | Type |
---|---|
obj | Object | Array | String |
path | Array | String | null | undefined |
def | * |
Check exist path in object
Kind: static method of obj
Param | Type |
---|---|
obj | Object |
path | * |
Get element by path in object
Kind: static method of obj
Param | Type |
---|---|
obj | Object |
path | String |
Delete element by path in object
Kind: static method of obj
Param | Type |
---|---|
obj | Object |
path | String |
Serialize object to url params
Kind: static method of obj
Param | Type |
---|---|
obj | Object |
Properties in add object adding to obj or if properties not exits create him
Kind: static method of obj
Param | Type |
---|---|
obj | Object |
add | Object |
Get property from array objects
Kind: static method of obj
Param | Type |
---|---|
arObj | Array |
prop | String |
Collect object property to array
Kind: static method of obj
Param | Type |
---|---|
obj | Object |
ForEach for Object fn(key, val) and sort keys by fnSort
Kind: static method of obj
Param | Type |
---|---|
obj | Object |
fn | function |
fnSort | function |
if o is object return true else false
Kind: static method of obj
Param | Type |
---|---|
obj | Object |
If the object property exists, its rounded
Kind: static method of obj
Param | Type |
---|---|
ob | Object |
prop | String |
round | Number |
Check is object
Kind: inner method of obj
Param | Type |
---|---|
obj | Object |
Check v be no undefined or null
Kind: inner method of obj
Param | Type |
---|---|
v | * |
Function for string
- str
- .base64(str, decode) ⇒
string
- .salt(len) ⇒
String
- .hash(str, salt, secret, method) ⇒
*
- .up1stChar(s) ⇒
string
- .regexpEscape(text)
- .fullReplace(str, find, replace)
- .htmlEscape(str, maxLength) ⇒
*
- .oneSpace(str) ⇒
String
- .removeSpecSymbols(str) ⇒
String
- .makeKey(accept, n) ⇒
string
- .decodeURIUniversal(str) ⇒
String
- .boolString(vl) ⇒
Boolean
- .base64(str, decode) ⇒
Return string encode/decode in base64
Kind: static method of str
Param | Type |
---|---|
str | |
decode | boolean |
Return salt
Kind: static method of str
Returns: String
- salt
Param | Type |
---|---|
len | Number | null | undefined |
Return string hash
Kind: static method of str
Param | Type |
---|---|
str | String |
salt | String | null | undefined |
secret | String | null | undefined |
method | 'md5' | 'sha512' | 'sha256' | null | undefined |
Return string, fist char in upper case.
Kind: static method of str
Param | Type |
---|---|
s | string |
Escapes special characters for RegExp
Kind: static method of str
Param | Type |
---|---|
text | String |
Replace all find word to replace word
Kind: static method of str
Param | Type |
---|---|
str | String |
find | String |
replace | String |
Escapes special characters for html and trim unnecessary
Kind: static method of str
Param | Type |
---|---|
str | String |
maxLength | Number | null | undefined |
Replace spaces to only one space
Kind: static method of str
Returns: String
- Output string
Param | Type | Description |
---|---|---|
str | String |
string |
Replace all spacial symbols to space
Kind: static method of str
Returns: String
- Output string
Param | Type | Description |
---|---|---|
str | String |
string |
It generates key specified length. Used accept symbols
Kind: static method of str
Param | Type |
---|---|
accept | String | null | undefined |
n | Number | null | undefined |
Decoding URI by all methods
Kind: static method of str
Param | Type |
---|---|
str | String |
Return value after convert string boolean to boolean. if vl === 'true' then vl = true. Other vl = false
Kind: static method of str
Param | Type |
---|---|
vl | String |
Working with types
- type
- .isString(s) ⇒
boolean
- .isSet(v) ⇒
boolean
- .noop()
- .isFn(f) ⇒
boolean
- .isObj(o)
- .beFn(fn) ⇒
*
- .cloneVar(v) ⇒
string
- .isNm(n)
- .isString(s) ⇒
Check s is string
Kind: static method of type
Param | Type |
---|---|
s | Mixed |
Check v is not null or undefined
Kind: static method of type
Param | Type |
---|---|
v | Mixed |
Empty function
Kind: static method of type
if f is function return true else false
Kind: static method of type
Param | Type |
---|---|
f | function |
Check parameter is object
Kind: static method of type
Param | Type |
---|---|
o | Mixed |
if fn is not function change to empty function
Kind: static method of type
Param | Type |
---|---|
fn | function |
Return new instance variable v
Kind: static method of type
Param | Type |
---|---|
v | Mixed |
Check this value is number
Kind: static method of type
Param | Type |
---|---|
n | Number |
2.0.0 What is new ? - Used "use strict" mode. - Used minification js files. - Attach unit test - Maximum use ESMA6 within Node 4.x.x - Change : Remove function obj.clone him be in type.cloneVar Remove function date.showTime add parameter format in date.date Add new function arr.check And etc... 2.0.2 Adding time constant in date module 2.0.3 Correct function arr.mvVal
Author and developer is Igor Stcherbina
MIT
Free Software