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 🙏

© 2026 – Pkg Stats / Ryan Hefner

charlie-tools

v1.5.1

Published

## 简介

Readme

charlie-tools

简介

charlie-tools 是一个实用工具库。文档

遵循 MIT 开源协议发布,并且支持最新的运行环境。 查看各个构件版本的区别并选择一个适合你的版本。

安装

npm i charlie-tools

使用

import { getQueryObject } from 'charlie-tools'
getQueryObject('https://www.baidu.com?a=1&b=2')
// { a: 1, b: 2 }

方法

getQueryObject

获取链接中的query object

| 参数 | 类型 | 默认值 | | ---- | ---- | ---- | | url ? | string | location.href |

import { getQueryObject } from 'charlie-tools'
getQueryObject('https://www.baidu.com?a=1&b=2')
// { a: 1, b: 2 }

copyTexts

复制文案

| 参数 | 类型 | | ---- | ---- | | texts | string |

import { copyTexts } from 'charlie-tools'
(() => {
  copyTexts('copy content')
    .then(() => {
      // 复制成功
    }).catch(() => {
      // 复制失败
    })
})()

formatTime

格式化时间

| 参数 | 类型 | | ---- | ---- | | date | Date、string、number | | fmt | string|

import { formatTime } from 'charlie-tools'
formatTime(new Date('2022/12/12 10:00:00').getTime(), 'yyyy-MM-dd hh:mm:ss')
// 2022-12-12 10:00:00

getTypeOf

获取类型

| 参数 | 类型 | | ---- | ---- | | val | unknown |

import { getTypeOf } from 'charlie-tools'
getTypeOf('hello')
// String
getTypeOf(10)
// Number
getTypeOf(() => {})
// Function

debounce

防抖

| 参数 | 类型 | 默认值 | | ---- | ---- | ---- | | fn | (...params: unknown[]) => unknown | 无 | | timeout? | number | 1000 |

<template>
  <button @click="handleClick">click</button>
</template>

<script>
import { debounce } from 'charlie-tools'
export default {
  methods: {
    handleClick: debounce(() => {
      console.log('handleClick')
    })
  }
}
</script>

throttle

节流

| 参数 | 类型 | 默认值 | | ---- | ---- | ---- | | fn | (...params: unknown[]) => unknown | 无 | | timeout? | number | 1000 |

<template>
  <button @click="handleClick">click</button>
</template>

<script>
import { throttle } from 'charlie-tools'
export default {
  methods: {
    handleClick: throttle(() => {
      console.log('handleClick')
    })
  }
}
</script>

hexToRgb

将十六进制颜色转换为具有RGB

| 参数 | 类型 | | ---- | ---- | | hex | string |

import { hexToRgb } from 'charlie-tools'
hexToRgb('#27ae60')
// 'rgb(39, 174, 96)'

onVisibilityChange

当页面可见性发生改变(兼容写法)

| 参数 | 类型 | | ---- | ---- | | cb | (isHidden: boolean) => unknown |

import { onVisibilityChange } from 'charlie-tools'
const cancel = onVisibilityChange(isHidden => {
  if (isHidden) {
    console.log('页面隐藏')
  } else {
    console.log('页面显示')
  }
})
// 取消监听
cancel()

cMath

提供了加、减、乘、除方法, (解决了精度丢失问题)。add, subtract, multiply, divide。

| 参数 | 类型 | | ---- | ---- | | num1 | number | | num2 | number |

import { cMath } from 'charlie-tools'
cMath.add(0.1, 0.2)
// 0.3
cMath.subtract(0.32, 0.2)
// 0.12
cMath.multiply(0.1, 0.12)
// 0.012
cMath.divide(0.3, 0.2)
// 1.5

linkMath

提供了可链式调用的加、减、乘、除方法, (解决了精度丢失问题)。

| 参数 | 类型 | | ---- | ---- | | num1 | number |

import { linkMath } from 'charlie-tools'
linkMath.input(1).add(7).subtract(2).multiply(3).divide(9).getResult()
// 2