npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

function-com-utils

v0.0.5

Published

Some utils of function

Downloads

12

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

	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

	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

	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

	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

	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

	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

	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

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

md5

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

How To Use

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

LINCESE

MIT