2.0.5 • Published 8 years ago

utils-igor v2.0.5

Weekly downloads
75
License
-
Repository
github
Last release
8 years ago

utils-igor


Installation


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']);

Modules

arr

Function for array

arr.mvVal

Kind: static class of arr

new exports.mvVal(arr, value)

Delete all elements whith specified value

ParamTypeDescription
arrArrayмассив для очистки
value*значение

arr.check(arr)

Check parameter be array. if not return empty array

Kind: static method of arr

ParamType
arr*

arr.sortNumber(a, b) ⇒ number

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

ParamType
aNumber
bNumber

arr.share(arr1, arr2) ⇒ Array

Return share part of the array

Kind: static method of arr

Param
arr1
arr2

arr.diff(arr1, arr2) ⇒ Array

Return different part of the array

Kind: static method of arr

ParamType
arr1Array
arr2Array

arr.unique(arr)

Clear repeat values

Kind: static method of arr

ParamType
arrArray

arr.sum() ⇒ Number

Sum of array elements

Kind: static method of arr

arr.avg(a) ⇒ number

Return average elements array

Kind: static method of arr

ParamType
aArray

arr.urls(arr) ⇒ Array

Return array. When element is url collect from specified array

Kind: static method of arr

ParamType
arrArray

date

Function for date

date.ts : Object

Time constant in milliseconds

Kind: static property of date

date.time(ts)

Get time string

Kind: static method of date

ParamType
tsNumber | null | undefined

Example

'11:40:46'

date.date(shiftDays, ts, format) ⇒ string

Get date string

Kind: static method of date

ParamType
shiftDaysNumber | null
tsNumber | null | undefined
formatstring | null | undefined

Example

date() => '2014-11-30'

Example

date(null, null, 'd-m-y') => '30-11-2014'

date.dateTime(shiftDays, ts, format)

  • Get date time string

Kind: static method of date

ParamType
shiftDaysNumber | null | undefined
tsNumber | null | undefined
formatString | null | undefined

Example

'2014-11-30 11:40:46'

Example

dateTime() this work

date.tsToSec(ts, up)

unix-time to seconds

Kind: static method of date

ParamType
tsNumber | null | undefined
upboolean | null

Example

1417323330

date.tsToMin(ts, up)

unix-time to minutes

Kind: static method of date

ParamType
tsNumber | null | undefined
upboolean | null

Example

23622056

date.secToTs(sec)

seconds to unix-time

Kind: static method of date

ParamType
secNumber

Example

1417323330

date.minToTs(min)

minutes to unix-time

Kind: static method of date

ParamType
minNumber

Example

23622056

date~unix(ts)

Return date (now or by unixTime).

Kind: inner method of date

ParamType
tsNumber | null | undefined

date~round(number, up)

Be round up or down

Kind: inner method of date

ParamType
numberNumber
upboolean | null

obj

Function for object

obj.arrToObjByKey(arr, prop, fnIterProp) ⇒ Object

Return object. When keys is specified property, value is object from array objects

Kind: static method of obj

ParamType
arrArray
propString
fnIterPropfunction

obj.keysChange(obj, keys) ⇒ Object

Get properties from obj by keys

Kind: static method of obj

ParamTypeDescription
objobject
keys*{keyOld : keyNew,...}

obj.sort(obj, down) ⇒ Object

Return new object when keys be sort

Kind: static method of obj

ParamType
objObject
downBoolean

obj.propInc(obj, prop, byVal)

Increment object property to the specified value

Kind: static method of obj

ParamType
objObject
propString
byValNumber

obj.beInObj(ob, prop, def)

Check is set object. If not, it creates it with the specified value

Kind: static method of obj

ParamType
obObject
propString
defObject

obj.pathCreate(obj, path, def)

Create path in object

Kind: static method of obj

ParamType
objObject | Array | String
pathArray | String | null | undefined
def*

obj.isPathExist(obj, path) ⇒ Boolean

Check exist path in object

Kind: static method of obj

ParamType
objObject
path*

obj.pathVal(obj, path) ⇒ *

Get element by path in object

Kind: static method of obj

ParamType
objObject
pathString

obj.pathMv(obj, path) ⇒ *

Delete element by path in object

Kind: static method of obj

ParamType
objObject
pathString

obj.urlParams(obj) ⇒ string

Serialize object to url params

Kind: static method of obj

ParamType
objObject

obj.ext(obj, add) ⇒ *

Properties in add object adding to obj or if properties not exits create him

Kind: static method of obj

ParamType
objObject
addObject

obj.getPropToArr(arObj, prop) ⇒ Array

Get property from array objects

Kind: static method of obj

ParamType
arObjArray
propString

obj.propToArr(obj) ⇒ Array

Collect object property to array

Kind: static method of obj

ParamType
objObject

obj.each(obj, fn, fnSort)

ForEach for Object fn(key, val) and sort keys by fnSort

Kind: static method of obj

ParamType
objObject
fnfunction
fnSortfunction

obj.isEmpty(obj) ⇒ boolean

if o is object return true else false

Kind: static method of obj

ParamType
objObject

obj.beRound(ob, prop, round)

If the object property exists, its rounded

Kind: static method of obj

ParamType
obObject
propString
roundNumber

obj~isObj(obj) ⇒ boolean

Check is object

Kind: inner method of obj

ParamType
objObject

obj~isSet(v)

Check v be no undefined or null

Kind: inner method of obj

ParamType
v*

str

Function for string

str.base64(str, decode) ⇒ string

Return string encode/decode in base64

Kind: static method of str

ParamType
str
decodeboolean

str.salt(len) ⇒ String

Return salt

Kind: static method of str
Returns: String - salt

ParamType
lenNumber | null | undefined

str.hash(str, salt, secret, method) ⇒ *

Return string hash

Kind: static method of str

ParamType
strString
saltString | null | undefined
secretString | null | undefined
method'md5' | 'sha512' | 'sha256' | null | undefined

str.up1stChar(s) ⇒ string

Return string, fist char in upper case.

Kind: static method of str

ParamType
sstring

str.regexpEscape(text)

Escapes special characters for RegExp

Kind: static method of str

ParamType
textString

str.fullReplace(str, find, replace)

Replace all find word to replace word

Kind: static method of str

ParamType
strString
findString
replaceString

str.htmlEscape(str, maxLength) ⇒ *

Escapes special characters for html and trim unnecessary

Kind: static method of str

ParamType
strString
maxLengthNumber | null | undefined

str.oneSpace(str) ⇒ String

Replace spaces to only one space

Kind: static method of str
Returns: String - Output string

ParamTypeDescription
strStringstring

str.removeSpecSymbols(str) ⇒ String

Replace all spacial symbols to space

Kind: static method of str
Returns: String - Output string

ParamTypeDescription
strStringstring

str.makeKey(accept, n) ⇒ string

It generates key specified length. Used accept symbols

Kind: static method of str

ParamType
acceptString | null | undefined
nNumber | null | undefined

str.decodeURIUniversal(str) ⇒ String

Decoding URI by all methods

Kind: static method of str

ParamType
strString

str.boolString(vl) ⇒ Boolean

Return value after convert string boolean to boolean. if vl === 'true' then vl = true. Other vl = false

Kind: static method of str

ParamType
vlString

type

Working with types

type.isString(s) ⇒ boolean

Check s is string

Kind: static method of type

ParamType
sMixed

type.isSet(v) ⇒ boolean

Check v is not null or undefined

Kind: static method of type

ParamType
vMixed

type.noop()

Empty function

Kind: static method of type

type.isFn(f) ⇒ boolean

if f is function return true else false

Kind: static method of type

ParamType
ffunction

type.isObj(o)

Check parameter is object

Kind: static method of type

ParamType
oMixed

type.beFn(fn) ⇒ *

if fn is not function change to empty function

Kind: static method of type

ParamType
fnfunction

type.cloneVar(v) ⇒ string

Return new instance variable v

Kind: static method of type

ParamType
vMixed

type.isNm(n)

Check this value is number

Kind: static method of type

ParamType
nNumber

Version


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

People


Author and developer is Igor Stcherbina

License


MIT

Free Software

2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago