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

@gm-mobile/c-tool

v3.12.13

Published

> TODO: description

Readme

@gm-mobile/c-tool

简介

工具函数库 - gm-mobile 组件库的底层工具包,提供环境判断、存储、拼音转换、UUID 等通用工具函数。

安装

npm install @gm-mobile/c-tool

使用

快速开始

import { is, UUID, pinyin, getCharLength } from '@gm-mobile/c-tool'

// 环境判断
if (is.weixin()) {
  console.log('微信环境')
}

// 生成 UUID
const id = UUID.generate()

// 汉字转拼音
const py = pinyin('你好') // "nihao"

// 计算字符长度(中文算2个字符)
const len = getCharLength('你好ab') // 6

API

导出列表

| 导出项 | 类型 | 说明 | |--------|------|------| | is | 对象 | 环境判断工具 | | UUID | 对象 | UUID 生成器 | | pinyin | 函数 | 汉字转拼音 | | getCharLength | 函数 | 计算字符长度(中文算2个字符) | | groupByWithIndex | 函数 | 带索引的分组 | | StorageFactory | 类 | 存储工厂类 | | warn | 函数 | 开发环境警告 | | devWarn | 函数 | 开发环境回调 | | devWarnForHook | 函数 | Hook 中开发环境回调 |

is

| 方法 | 说明 | 返回值 | |------|------|--------| | is.web() | 是否为 Web 环境 | boolean | | is.weApp() | 是否为微信小程序环境 | boolean | | is.iOS() | 是否为 iOS 设备 | boolean | | is.weixin() | 是否为微信浏览器 | boolean | | is.phone() | 是否为移动设备 | boolean | | is.promise(arg) | 是否为 Promise | boolean | | is.chinese(value) | 是否包含中文 | boolean |

UUID

| 方法 | 说明 | 返回值 | |------|------|--------| | UUID.generate() | 生成 UUID v4 | string |

pinyin(source, style?)

将汉字转为拼音。

| 参数 | 说明 | 类型 | 必填 | |------|------|------|------| | source | 汉字文本 | string | 是 | | style | 转换风格,'first_letter' 返回首字母 | string | 否 |

返回值string

getCharLength(text)

计算字符长度,中文算 2 个字符,其他算 1 个字符。

| 参数 | 说明 | 类型 | 必填 | |------|------|------|------| | text | 文本 | string | 是 |

返回值number

groupByWithIndex(list, cb)

带索引的分组函数,类似 _.groupBy 但回调支持 index 参数。

| 参数 | 说明 | 类型 | 必填 | |------|------|------|------| | list | 数组 | any[] | 是 | | cb | 分组回调 | (value, index) => any | 是 |

返回值object

StorageFactory

存储工厂类,用于创建统一的存储操作实例。

warn / devWarn / devWarnForHook

| 函数 | 说明 | |------|------| | warn(...args) | 仅开发环境输出 console.warn | | devWarn(callback) | 仅开发环境执行回调 | | devWarnForHook(callback) | 仅开发环境执行 useEffect 回调 |

注意事项

  • is.weApp() 通过 process.env.TARO_ENV 判断
  • pinyin 使用内置的汉字-拼音映射表,采用二分查找实现
  • warn 系列函数仅在非生产环境下执行,生产环境自动忽略

相关包