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

itools.js

v1.0.6

Published

前端开发中常用的工具方法

Downloads

13

Readme

itools

前端开发中常用的工具方法

size < 3K

Install

npm i -S itools.js

Usage

// esm 
import iTools from 'itools.js'
// vue
Vue.prototype.$tools = iTools

// cjs
const iTools = require('itools.js')

// iife
<script src='dist/itools.js'></script>

API

  • clone

    对象深拷贝

    let obj_a = { a: 1 }
    let obj_b = iTools.clone(obj_a) // cloneDeep
  • cookie

    cookie 操作

    iTools.cookie.set('name','value','exSeconds','path')
    let name = iTools.cookie.get('name')
    iTools.cookie.del('name')
  • copy

    复制一个字符串到剪贴板

      let str = 'copy str'
    if(iTools.copy(str)){
        alert('copy success')
    }
  • download

    保存一个路径到本地并重命名

    let filename = '当前页面'
    let filePath = window.location.href
    iTools.download(filename, filePath)
  • getParam

    获取浏览器地址栏中的参数

    let name = iTools.getParam('name')
    let age = iTools.getParam('age', 'https://suohb.com?age=18')
  • randomStr

    获取固定长度的随机字符串

    let str = iTools.randomStr(10) // 
    let str2 = iTools.randomStr(9,'letter') // only letter
    let str3 = iTools.randomStr(8,'number') // only number
    console.log(str, str2, str3) // lq3hc8ogxl carijlvjz 83568934
  • type

    判断变量类型

    console.log(iTools.type('str')) // string
    console.log(iTools.type(124)) // number
    console.log(iTools.type(true)) // boolean
    console.log(iTools.type(null)) // null
    console.log(iTools.type([1, 2, 3])) // array
    console.log(iTools.type(() => { })) // function
    console.log(iTools.type({ a: 1 })) // object
    console.log(iTools.type(new Date())) // date
    console.log(iTools.type(undefined)) // undefined
  • uniqueId

    获取唯一ID

    console.log(iTools.uniqueId()) // kdqsnvmi_zri604sxb89
  • debounce & throttle

    防抖和节流函数

      function logPos(e) {
      	console.log(e.pageX, e.pageY)
      }
      // debounce
      // document.addEventListener('mousemove', iTools.debounce(logPos, 500))
      // throttle
      document.addEventListener('mousemove', iTools.throttle(logPos, 500))
  • trim

    针对 string、array、object格式,深度trim

    let str4 = ' aa '
    let arr = [' aa ', ' bb ']
    let obj = { a: ' aa ', b: [' bb  '] }
    console.log(iTools.trim(str4)) // aa
    console.log(iTools.trim(arr)) // ['aa','bb']
    console.log(iTools.trim(obj)) // {a:'aa',b:['bb']}
  • once

    方法仅执行一次

    	let objOnce = {
    		name: 'once',
    		getName(value) {
    			console.log(this.name, value)
    		}
    	}
    	let objOnce2 = {
    		name: 'once2'
    	}
    	let onceFn = iTools.once(objOnce.getName, objOnce2)
    	onceFn(1) // once2 1
    	onceFn(2)