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

@polyv/utils

v2.19.0

Published

Utility functions of Polyv frontend development.

Readme

POLYV 工具函数库

本项目提供 Web 前端常用的底层工具函数库,主要用于 POLYV 各类 Web 产品。

安装

npm install @polyv/utils

NPM 包同时提供了 ES 模块以及 CommonJS 模块,分别位于 escjs 两个文件夹。它们使用上的区别和优缺点在于:

| 模块类型 | Tree shaking | Babel 编译 | | --- | --- | --- | | ES 模块 | 有效,只有用到的代码会被打包 | 需要 | | CommonJS 模块 | 无效,依赖的文件会被整个打包 | 不需要 |

使用

在基于 Vue.js 框架的项目中使用

以 Vue CLI 3.x 创建的项目为例,编辑 vue.config.js 增加相关配置:

module.exports = {
  // 省略其他配置

  configureWebpack: {
    resolve: {
      alias: {
        // 配置别名缩短引用路径
        '@utils': path.resolve(__dirname, './node_modules/@polyv/utils/es')
      }
    }
  },

  // ES 模块需要 Babel 转译
  transpileDependencies: [
    '@polyv/utils'
  ]
};

在项目代码中引入:

import { cutStr } from '@utils/string';
import Countdown from '@utils/countdown';

在基于 Nuxt.js 框架的项目中使用

以 create-nuxt-app 创建的项目为例,编辑 nuxt.config.js 增加相关配置:

module.exports = {
  // 省略其他配置

  build: {
    // ES 模块需要 Babel 转译
    transpile: [
      '@polyv/utils'
    ]
  },

  extend(config, ctx) {
    // 配置别名缩短引用路径
    config.resolve.alias['@utils'] = path.resolve(
      __dirname, './node_modules/@polyv/utils/es'
    );
  }
};

在项目代码中引入:

import { cutStr } from '@utils/string';
import { Countdown } from '@utils/countdown';

兼容性

  • IE >= 9
  • iOS >= 9 (未测试更低版本)
  • Android >= 5 (未测试更低版本)

其他

2.0.0 版本的变更

2.0.0 与 1.x 相比有较大的变更,如需升级,请参阅下方变更说明:

  • 模块变更:
  • 部分 API 的变更:
    • boolean 模块的 ynToBool 支持指定默认值。
    • countdown 模块的 Countdown 类增加 pause 方法。
    • string 模块的 cutStrstrLen 两个方法的选项,不再支持 mode 属性。
    • string 模块新增 uuidV4 方法。
    • validate 模块的 isPhoneNO 方法改名为 isChsPhoneNO
  • CommonJS 模块的路径是 cjs(原来是 dist),ES 模块的路径是 es(原来是 src)。