https://github.com/toxic-johann/toxic-utils
some utils function
https://github.com/toxic-johann/toxic-utils
deepassign deepclone utils
Last synced: 4 months ago
JSON representation
some utils function
- Host: GitHub
- URL: https://github.com/toxic-johann/toxic-utils
- Owner: toxic-johann
- License: mit
- Created: 2017-07-02T03:19:38.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-06-02T18:16:30.000Z (almost 6 years ago)
- Last Synced: 2024-05-02T01:12:04.816Z (almost 2 years ago)
- Topics: deepassign, deepclone, utils
- Language: JavaScript
- Size: 332 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# toxic-utils
[](https://travis-ci.org/toxic-johann/toxic-utils.svg?branch=master)
[](https://coveralls.io/github/toxic-johann/toxic-utils?branch=master)
[](https://www.npmjs.com/package/toxic-utils)
[](https://david-dm.org/toxic-johann/toxic-utils)
[](https://david-dm.org/toxic-johann/toxic-utils?type=dev) [](https://greenkeeper.io/)
utils collection
## get started
```shell
npm install toxic-utils --save
```
if you are using `flow`, you should import our flow defination, by adding this to your `.flowconfig`.
```ya
[ignore]
[include]
[libs]
./node_modules/toxic-utils/lib/index.flow.js
[options]
[lints]
```
## doc
### genTraversalHandler
[src/index.js:8-20](https://github.com/toxic-johann/toxic-utils/blob/2b6844986d149e8d81d0c29eb28c4d5a2b92e5f6/src/index.js#L8-L20 "Source code on GitHub")
the handler to generate an deep traversal handler
**Parameters**
- `fn` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** the function you wanna run when you reach in the deep property
Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** the handler
### deepClone
[src/index.js:27-32](https://github.com/toxic-johann/toxic-utils/blob/2b6844986d149e8d81d0c29eb28c4d5a2b92e5f6/src/index.js#L27-L32 "Source code on GitHub")
deeply clone an object
**Parameters**
- `source` **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** if you pass in other type, it will throw an error
Returns **clone-target** the new Object
### deepAssign
[src/index.js:38-50](https://github.com/toxic-johann/toxic-utils/blob/2b6844986d149e8d81d0c29eb28c4d5a2b92e5f6/src/index.js#L38-L50 "Source code on GitHub")
merge multiple objects
**Parameters**
- `args` **...[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** [description]
Returns **merge-object** [description]
### camelize
[src/index.js:57-63](https://github.com/toxic-johann/toxic-utils/blob/2b6844986d149e8d81d0c29eb28c4d5a2b92e5f6/src/index.js#L57-L63 "Source code on GitHub")
camelize any string, e.g hello world -> helloWorld
**Parameters**
- `str` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** only accept string!
- `isBig` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** camelize string
### hypenate
[src/index.js:69-71](https://github.com/toxic-johann/toxic-utils/blob/2b6844986d149e8d81d0c29eb28c4d5a2b92e5f6/src/index.js#L69-L71 "Source code on GitHub")
hypenate any string e.g hello world -> hello-world
**Parameters**
- `str` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** only accept string
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
### bind
[src/index.js:78-90](https://github.com/toxic-johann/toxic-utils/blob/2b6844986d149e8d81d0c29eb28c4d5a2b92e5f6/src/index.js#L78-L90 "Source code on GitHub")
bind the function with some context. we have some fallback strategy here
**Parameters**
- `fn` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** the function which we need to bind the context on
- `context` **any** the context object
Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)**
### uuid
[src/index.js:95-97](https://github.com/toxic-johann/toxic-utils/blob/2b6844986d149e8d81d0c29eb28c4d5a2b92e5f6/src/index.js#L95-L97 "Source code on GitHub")
generate an uuid
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
### S4
[src/index.js:101-103](https://github.com/toxic-johann/toxic-utils/blob/2b6844986d149e8d81d0c29eb28c4d5a2b92e5f6/src/index.js#L101-L103 "Source code on GitHub")
generate an random number which length is 4
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
### rand
[src/index.js:108-114](https://github.com/toxic-johann/toxic-utils/blob/2b6844986d149e8d81d0c29eb28c4d5a2b92e5f6/src/index.js#L108-L114 "Source code on GitHub")
generate an random number with specific length
**Parameters**
- `length` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
### getDeepProperty
[src/index.js:119-147](https://github.com/toxic-johann/toxic-utils/blob/2b6844986d149e8d81d0c29eb28c4d5a2b92e5f6/src/index.js#L119-L147 "Source code on GitHub")
get an deep property
**Parameters**
- `obj` **any**
- `keys` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>)**
- `$2` **any** (optional, default `{}`)
- `$2.throwError` (optional, default `false`)
- `$2.backup`