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

zb-fjs

v1.1.13

Published

工具项目

Downloads

8

Readme

zb-fjs

工具函数项目

npm install zb-fjs --save

deep-clone

深拷贝函数 使用方法:

import { deepClone } from 'zb-fjs'

deepClone(obj)

输出的值是深拷贝之后的值,详情请看博客实现一个深拷贝函数

precision

解决计算机精度问题 使用方法:

import { precision } from 'zb-fjs'

/**
 * 小数点后面保留第 n 位
 *
 * @param x 做近似处理的数
 * @param n 小数点后第 n 位
 * @returns 近似处理后的数
 */
precision(num, n)

详情:JS 精度问题总结

debounce

防抖和节流,使用方法:

import { debounceAt, debounce, throttleAt, throttle } from 'zb-fjs'

class a {
  //参数number类型 延迟时间,默认300,第二参数boolean类型,第一次点击是否立即执行   throttleAt同
  @debounceAt(500, true)
  click() {
    //click
  }
  @throttleAt(500)
  click2() {
    //click2
  }
}

objClearUndefined

清除 object 中 不存在的属性

使用方法:

import { objClearUndefined } from 'zb-fjs'

const obj = {
  a: 123,
  b: '',
  c: undefined
}

objClearUndefined(obj) // => { a: 123 }

timeFormat

时间格式化 分->时+分

import { timeFormat } from 'zb-fjs'

timeFormat(70) // => 1小时10分钟
timeFormat(70, 'obj') // => { h:1,min:10 }

dateFormat

时间格式化 年-Y 月-M 日-D 小时-H 分-m 秒-s 毫秒-S

import { dateFormat } from 'zb-fjs'

dateFormat('1993-11-11T12:00:00', 'YYYY.MM.DD HH:mm:ss') // => 1993.11.11 12:00:00
dateFormat('1993-11-11T12:00:00', 'YYYY-MM-DD HH:mm:ss') // => 1993-11-11 12:00:00

moneyFormat

金钱格式化(分)

import { moneyFormat } from 'zb-fjs'

moneyFormat(230) // => { yuan:2, fen:30 }

lineClamp

canvas 中文字的换行和限定行数

接受 context 参数, text:渲染文字,x,y 坐标,line 行数,maxWidth:最大宽度,lineHeight: (文字高度+行间距)

import { lineClamp } from 'zb-fjs'

lineClamp(ctx, text, x, y, line, maxWidth, lineHeight)

sumArr

数组求和
将数组中的所有数字或者数字字符串相加,返回 number 类型

import { sumArr, sumObjArr } from 'zb-fjs'

sumArr([1, 3, 4, 5, 6]) // 19
sumObjArr([{ a: 1 }, { a: 2 }, { a: 3 }], 'a') // 6

objEquar

对象是否相等

import { objEquar } from 'zb-fjs'

objEquar({a: '123',b: {c:'aaa',d: [1,2]},{a:'123',b: {c:'aaa',d: [1,2]}}})

arrEquar

数组是否相等

import { arrEquar } from 'zb-fjs'

arrEquar([1, 2], [1, 2])
arrEquar([1, 1], [1, 2])
arrEquar([1, 2, { a: '12' }], [1, 2, { a: '12' }])

objArrRepeat

对象数组根据 key 去重

import { objArrRepeat } from 'zb-fjs'

objArrRepeat([{ name: '1' }, { name: '2' }, { name: '1' }], 'name')

getQuery

获取 url 上的 query 参数

import { getQuery } from 'zb-fjs'

getQuery('name')

flat

数组扁平化, 接受参数 1 数组, 2:拍平层级,默认展开所有

import { flat } from 'zb-fjs'

flat(arr, 1)

getCountDown 倒计时

1.1.5

import { getCountDown } from 'zb-fjs'

getCountDown('2020-6-12 11:00:00', 'format')

base64Encode base64Decode base64加密、解密

1.1.8

import { base64Encode, base64Decode } from 'zb-fjs'

base64Encode('123')
base64Decode('MTIz')