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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mytools202010abc

v1.0.1

Published

一个模仿lodash的工具包

Downloads

1

Readme

使用方法 import {ITools} from 'mytools'

function 绑定this指向,立即执行 apply(fn,obj,args) fn:需要指定this的方法 obj:this指向的对象 args:往函数里传递的参数,要求是数组

绑定this指向,立即执行 call(fn,obj,...args) fn:需要指定this的方法 obj:this指向的对象 args:往函数里传递的参数,要求是数据列表

绑定this指向,不立即执行 bind(fn,obj,...args) fn:需要指定this的方法 obj:this指向的对象 args:往函数里传递的参数,要求是数据列表

函数防抖,在一个周期内多次触发事件,只执行最后一次 debounce(callback,time) callback:需要执行的函数 time:周期,单位毫秒

函数节流,事件触发一次后,在一个周期内不再执行 throttle(callback,time,immediately) callback:需要执行的函数 time:周期,单位毫秒 immediately:第一次触发是否立即执行,默认为true

string 限制字符串显示长度 truncate(str,size) str:需要显示的字符串 size:可以显示的长度

翻转字符串 reverseString(str)

判断字符串是否回文 palindrome(str)

array 重写数组方法 map(array,callback) reduce(array,callback,prev) filter(array,callback) find(array,callback) findIndex(array,callback) every(array,callback) some(array,callback)

将一个数组截成多个数组 chunk(array,size) array:需要操作的数组 size:截取数组的长度,默认为1

将数组中的假值去除 compact(array)

合并数组 concat(array,...args) array:数组 args:参数,可以是数组或其他数据

找出数组中不与其他数组重复的项 difference(array, ...arr) array:基准数组 arr:对照组

去除数组左边size项 drop(array,size) 去除数组右边size项 dropRight(array,size)

扁平化数组 flatten(array)

合并数组,若原数组有该值时忽略该值 mergeArray(array,...arrs) array:原数组 arrs:需要合并的数组

删除数组中与values相同的数据 pull(array,...values) 删除数组中的数据,values为数组 pullAll(array,values)

截取数组中的一段 slice(array,begin,end) begin:开始截取的位置,默认从下标0开始 end:截取到的位置,默认为数组长度

数组去重 unique(array)

object 浅克隆 clone(target) 深度克隆 deepClone4(target,map) map默认值为new Map()

判断对象的原型 instanceOf(obj,Type)

合并对象,遇到同名属性时合并为一个数组 mergeObject(...objs)

创建Fn构造函数的实例对象 newinstance(Fn,...args)

事件总线 EventBus let e = new EventBus() const func1 = function(a){ console.log('hi') console.log(a) } 添加监听事件,传入事件名和函数 e.addListener('sayHi',func1) 触发事件,传入事件名和参数 e.emit('sayHi',222) 移除监听事件,传入事件名和函数 e.removeListener('sayHi',func1)

继承 inherit(father,son) father:父元素 son:子元素

消息订阅 let messae = new ITools.PubSub(); 进行消息注册 messae.register("cc"); 进行消息订阅,传入消息标识和要触发的函数 messae.subscribe("cc", subsfun); 触发消息 messae.fire("cc", "hi"); 需要被触发的函数 function subsfun(event) { console.log(event.type, event.args); }

ajax和axios ITools.ajax(options) 传入一个对象,属性如下 { method:'get',//方法 url:'http://developer.duyiedu.com/edu/testAjaxCrossOrigin',//地址 data:{ name:'cc', age:18 },//参数 success:function(res){ console.log('cg',res) },//成功后的回调函数 error:function(error){ console.log('出错了',error) }//失败后的回调函数 } ITools.ajaxPromise(options)//promise版的的ajax

axios 封装了4个静态方法,都是返回一个promise get(url,options) post(url,data,options) put(url,data,options) delete(url,options)