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

candy-bag

v0.0.4

Published

candy-bag,一个`javascript`工具库。用了都说香。

Readme

CandyBag

candy-bag,一个javascript工具库。用了都说香。

安装:

使用npmyarn包管理工具安装:

npm install candy-bag

node项目中使用CommonJS导入方式:

const { firstUpperCase } = require('candy-bag')

webpackvite构建项目中使用ESM导入方式:

import { firstUpperCase } from 'candy-bag'

html静态页面中使用cdn方式导入,同过该方式导入,将暴露一个全局对象CandyBag所有的方法均可以从该对象中取出:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <!-- 通过cdn方式引入全局对象:CandyBag -->
  <script src="https://cdn.jsdelivr.net/npm/candy-bag"></script>
  <script>
    const { firstUpperCase } = CandyBag
    console.log(firstUpperCase('hello')) // Hello
  </script>
</body>
</html>

快速使用:

"Array" Methods:

  1. 获取一个number数组的求和: numArraySum

    Arguments:

    array :Number[]:需要处理的数组,要求必须为number类型组成,长度不限。

    Returns:

    Number :数组的总和

    Example:

import { numArraySum }  from 'candy-bag'
console.log(numArraySum([99, -1, 20])) // 118

"String" Methods:

  1. 将字符串的首字母转化为大写: firstUpperCase

    Arguments:

    message: String:需要处理的字符串,由字母组成。

    Returns:

    String :首个字母被转化为大写的字符串

    Example:

import { firstUpperCase }  from 'candy-bag'
console.log(firstUpperCase('hello')) // Hello

"Higher" Methods:

  1. 防抖函数:debounce

    Arguments:

    fn: Function:需要被执行的函数体, 必传

    delay: Number:每次触发函数延时多久,单位ms(毫秒),必传

    immed: Boolean:是否在首次立即执行,可选

    resultCallback: Function:执行后的回调函数,(result) => void 可从回调函数中拿到执行函数的返回值

    Returns:

    Promise <any> :返回Promise,从then()中可取出函数执行结果

    Example:

import { debounce }  from 'candy-bag'
const foo = () => {
  console.log('foo 函数被执行');
};

const fooDebounce = debounce(foo, 500, true);
fooDebounce().then((res) => {
  console.log(res); // "foo 函数被执行"
});
  1. 节流函数:throttle

    Arguments:

    fn: Function:需要被执行的函数体, 必传

    interval: Number:每次触发间隔市场,单位ms(毫秒),必传

    options: { leading: Boolean; trailing: Boolean; resultCallback?: (result: any) => void)}:选项,可选。

    • leading:是否立即执行

    • trailing:最后是否执行一次

    • resultCallback:执行后的回调函数,(result) => void 可从回调函数中拿到执行函数的返回值

    Returns:

    Promise <any> :返回Promise,从then()中可取出函数执行结果

    Example:

import { throttle }  from 'candy-bag'

const foo = () => {
  return 'foo 函数被执行';
};

const fooThrottle = throttle(foo, 1000, {
  leading: true,
  trailing: false
});

fooThrottle().then(res => {
  console.log(res) // "foo 函数被执行"
})

关于:

本项目基于tools-base开发。

另招募大佬一起维护本项目。一起造轮子,我们不仅制造轮子,我们还要做轮子的搬运工

联系方式:wx:coder7915

觉得还不戳的话请留下一个star吧~

日志:

v0.0.3 更新于 2022/07/18:

  1. 加入数组求和方法
  2. 完善项目文档
  3. 完善部分参数类型