An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# toxic-utils

[![Build Status](https://img.shields.io/travis/toxic-johann/toxic-utils/master.svg?style=flat-square)](https://travis-ci.org/toxic-johann/toxic-utils.svg?branch=master)
[![Coverage Status](https://img.shields.io/coveralls/toxic-johann/toxic-utils/master.svg?style=flat-square)](https://coveralls.io/github/toxic-johann/toxic-utils?branch=master)
[![npm](https://img.shields.io/npm/v/toxic-utils.svg?colorB=brightgreen&style=flat-square)](https://www.npmjs.com/package/toxic-utils)
[![dependency Status](https://david-dm.org/toxic-johann/toxic-utils.svg)](https://david-dm.org/toxic-johann/toxic-utils)
[![devDependency Status](https://david-dm.org/toxic-johann/toxic-utils/dev-status.svg)](https://david-dm.org/toxic-johann/toxic-utils?type=dev) [![Greenkeeper badge](https://badges.greenkeeper.io/toxic-johann/toxic-utils.svg)](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`