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

@xizher/js-utils

v1.1.6

Published

JavaScript 常用工具继承库

Downloads

7

Readme

@xizher/js-utils

安装

npm install @xizher/js-utils

接口文档

baseUtils

| 成员 | 说明 | | ---------------------- | ------------------------------------ | | deepCopyJSON () | 深度复制(采用JSON解析方式) | | deepCopy () | 深度复制(采用递归式) | | createGuid () | 创建GUID | | createIntRandom () | 创建指定范围的随机整数 | | isFromMobileBrowser () | 判断网页是否通过移动端设备打开 | | copyText () | 复制文本 | | $extend () | 对象扩展(JQuery $.extend 实现代码) | | debounce () | 防抖 | | throttle () | 节流 | | loadCss () | 加载css | | loadJs () | 加载js | | getArrayItemRandom () | 随机获取数组中的一个子集 |

cookieUtils

| 成员 | 说明 | | ------------- | ------------------------------------ | | set () | 设置Cookie | | del () | 删除Cookie | | get () | 获取Cookie | | getUseJSON () | 取Cookie(结果为经过JSON解析的对象) |

storageUtils

| 成员 | 说明 | | --------------------- | ------------------------------ | | local.set () | 设置LocalStorage | | local.get () | 获取LocalStorage | | local.getUseJSON () | 获取经过JSON解析的LocalStorage | | local.remove() | 移除指定LocalStorage | | local.clear () | 清空LocalStorage | | session.set () | 设置SessionStorage | | session.get () | 获取SessionStorage | | session.getUseJSON () | 获取经过JSON解析的LocalStorage | | session.remove () | 移除指定SessionStorage | | session.clear () | 清空SessionStorage |

descriptoUtils

| 成员 | 说明 | | ----------- | ------------------------ | | AutoBind () | 自动绑定this上下文装饰器 | | Debounce () | 防抖 | | Throttle () | 节流 |

cryptoUtils

| 成员 | 说明 | | --------------- | ----------- | | setGlobelKey () | 设置全局Key | | setGlobelIV () | 设置全局IV | | encrypto () | 加密字符串 | | decrypto () | 解密字符串 |

使用样例

import { baseUtils } from '@xizher/js-utils'

test('deepCopyJSON: can run true', () => {

  const obj = {
    a: 1, b: '2', c: '', d: false, e: {}, f: () => 1, g: null, h: class {}
  }
  const newObj = baseUtils.deepCopyJSON(obj)

  expect(newObj !== obj).toBe(true)
  expect(newObj.a).toBe(1)
  expect(newObj.b).toBe('2')
  expect(newObj.c === '').toBe(true)
  expect(newObj.d).toBe(false)
  expect(typeof newObj.e).toBe('object')
  expect(typeof newObj.f === 'undefined').toBe(true)
  expect(newObj.g === null).toBe(true)
  expect(typeof newObj.h === 'undefined').toBe(true)
})

test('deepCopy: can run true', () => {

  const obj = {
    a: 1, b: '2', c: '', d: false, e: {}, f: () => 1, g: null, h: class {}
  }
  const newObj = baseUtils.deepCopy(obj)

  expect(newObj !== obj).toBe(true)
  expect(newObj.a).toBe(1)
  expect(newObj.b).toBe('2')
  expect(newObj.c === '').toBe(true)
  expect(newObj.d).toBe(false)
  expect(typeof newObj.e).toBe('object')
  expect(newObj.f()).toBe(1)
  expect(newObj.g === null).toBe(true)
  expect(typeof newObj.h).toBe('function')
})

test('createGuid: can run true', () => {
  const guid = baseUtils.createGuid()
  expect(guid.length).toBe(36)
})

test('createIntRandom: can run true', () => {
  const num = baseUtils.createIntRandom(0, 1)
  expect(num === 1 || num === 0).toBe(true)
})


test('$extend: can run true', () => {
  const obj = { a: 1, b: { b1: 2 } }
  baseUtils.$extend(true, obj, {
    c: 2, b: { b2: 3 }
  })
  expect(obj.a).toBe(1)
  expect(obj.c).toBe(2)
  expect(obj.b.b1).toBe(2)
  expect(obj.b.b2).toBe(3)
})
import { cryptoUtils } from '@xizher/js-utils'

test('encrypto and decrypto: can run true', () => {
  const str = 'hello world'
  const enStr = cryptoUtils.encrypto(str)
  const deStr = cryptoUtils.decrypto(enStr)
  expect(deStr).toBe(str)
})