# function-com-utils

> Some utils of function

Latest version **0.0.5** (published 2019-07-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install function-com-utils
pnpm add function-com-utils
yarn add function-com-utils
bun add function-com-utils
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2019-07-17 |
| First published | 2019-06-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 46.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | chenchao17@58.com |
| Maintainers | chenchao17 |
| Keywords | operation, utils |

## Links

- npm: https://www.npmjs.com/package/function-com-utils
- Repository: https://github.com/liuding-Jason/function-utils
- Homepage: https://github.com/liuding-Jason/function-utils#readme
- Issues: https://github.com/liuding-Jason/function-utils/issues
- npm.io page: https://npm.io/package/function-com-utils

## Dependencies (5)

- [cross-env](https://npm.io/package/cross-env.md) ^5.2.0
- [babel-core](https://npm.io/package/babel-core.md) 6.26.0
- [babel-loader](https://npm.io/package/babel-loader.md) 7.1.2
- [webpack-merge](https://npm.io/package/webpack-merge.md) ^4.2.1
- [react-pure-check](https://npm.io/package/react-pure-check.md) ^0.1.3

## Recent versions

- 0.0.5 (latest) — 2019-07-17
- 0.0.4 — 2019-07-09
- 0.0.3 — 2019-07-02
- 0.0.2 — 2019-06-19
- 0.0.1 — 2019-06-18

## README

# function-com-utils

Some utils of function , like Log、event module 、async module and so on .

---------------------------

## SingleEvent

SingleEvent is a pub/sub module based on self defination event . 
It use document.createEvent function to create a event object .
So it could run in IE 、Chrome and other browser .

Why this module has a single attribute , because you can only used 
one instance , created by SingleEvent() , to listen one EVENT topic name .

But remeber this , SingleEvent can only handle NAMED function .

### How to use

```js
	import { SingleEvent } from "function-com-utils" ;
	let ev = SingleEvent("myEvent") ;
	let a = function(){console.log('a');} ;
	let b = function(){console.log('b');} ;
	// on
	ev.on(a) ;
	ev.on(b) ;
	// emit
	ev.emit() ; // a b
	// remove
	ev.remove(a) ;
	ev.emit() ; // b
```
---------------------------

## MultEvent

MultEvent is a pub/sub module based on self defination event . 
It use document.createEvent function to create a event object .
So it could run in IE 、Chrome and other browser .

### How to use

```js
	import {MultEvent} from "function-com-utils" ;

	let a = function(){console.log('a');} ;
	let b = function(){console.log('b');} ;

	MultEvent.on("topic1" , a) ;
	MultEvent.on("topic1" , b) ;
	MultEvent.remove("topic1" , a) ;
	MultEvent.emit("topic1") ;

	MultEvent.on("topic2" , a) ;
	MultEvent.on("topic2" , b) ;
	MultEvent.emit("topic2") ;
```

---------------------------


## MultAsync

MultAsync could handle given number async process .
With this moulde , you could have a final result 
through binding a final function .


### How to use

```js
	import {MultAsync} from "function-com-utils" ;
	let getFinalData = (res) => { console.log(res);}
	let m = MultAsync(3 , getFinalData) ;
	let t1 = setTimeout(() => { 
		let obj = {a : 1} ; m.registerProcess("key1" , obj) ;
		clearTimeout(t1) ; 
	} , 1000) ;
	let t2 = setTimeout(() => { 
		let obj = {a : 2} ; m.registerProcess("key2" , obj) ;
		clearTimeout(t2) ; 
	} , 2000) ;
	let t3 = setTimeout(() => { 
		let obj = {a : 3} ; m.registerProcess("key3" , obj) ;
		clearTimeout(t3) ; 
	} , 3000) ;
```


---------------------------

## Curry

Curry module has offered a currying process .

### How to use

```js
	import { Curry } from "function-com-utils" ;
	var cost = (function () {
	  var money = 0;
	  return function () {
		    for (var i = 0, l = arguments.length; i < l; i++) {
		      money += arguments[i];
		    }
		    return money;
		  }
	})();
	let caf = Curry(cost) ;
	caf(100) ;
	caf(1000) ;
	console.log(caf()) // 1100 ;
```

---------------------------

## CurryProcess

CurryProcess could help you to curry some process .
Especially , when you want to depart your complex process .

But remeber , this function would no suport async process ,
if you want to do it , you should use async/await or Promise .

### How to use

```js
	import { CurryProcess } from "function-com-utils" 
	let initPrams = { a : 1 } ;
	let process1 = (data) => { return Object.assign({b : 1} , data) } ;
	let process2 = (data) => { return Object.assign({c : 1} , data) } ;
	let res = CurryProcess(initPrams)(process1)(process2)() ;
	console.log(res) ; // { a : 1 , b : 1 , c : 1 } 
```

## MultSync

### Use Pattern

MultSync would help you to handle some sync process .
And the same params would be given in every process .

But remeber , you should use ***next*** function to run next process .


### How to use

```js
	import { MultSync } from "function-com-utils" ;
	let ms = new MultSync() ;
	ms.use(function(a , b){ console.log("====" , a) ; ms.next() ; }) ;
	ms.use(function(a , b){ console.log("====" , b) ; ms.next() ; }) ;
	ms.use(function(a , b){ console.log("====" , a + b) ;ms.next() ; }) ;
	ms.emit(1 , 2) ;
```
---------------------------

## filterXSS

### Use Pattern

```js
	filterXSS(dangerStr , <replacePatten>)	
```

	filterXSS module offer you a XSS filter function ，
	which would filter dangerous script 、console and alert tag and content .
	
### How To Use

```js
	import { filterXSS } from "function-com-utils" ;
	let dangerStr = "<script>alert(111);</script>wqe" ;
	console.log(filterXSS(dangerStr)) ; // wqe
```

## md5

```js
	md5(string)
```
	
	md5 module offer a basic md5 counting function .

### How To Use

```js
	import { md5 } from "function-com-utils" ;
	let str = "this is a md5 test" ;
	console.log(md5(str)) ; 
```
---------------------------

## LINCESE
	
	MIT

---
_Source: https://npm.io/package/function-com-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
