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

@jupjs/utils

v0.1.0

Published

utils library

Downloads

9

Readme

@jupiter/utils

前端工具库,提供一组可复用的小能力函数与浏览器侧工具模块。

安装

pnpm add @jupiter/utils

当前导出模块

  • common:通用小函数集合(类型判断、对象处理、格式化、节流防抖等)
  • ResourceLoader:动态加载 JS/CSS 资源(script/link
  • EventBus:页面内发布订阅
  • LocalStorageStore:本地存储操作封装

使用示例

1) common

import { formatCurrency, debounce, deepMerge } from '@jupiter/utils'

const money = formatCurrency(12345) // ¥ 12,345.00

const merged = deepMerge(
  { feature: { a: true } },
  { feature: { b: true } }
)

const onResize = debounce(() => {
  console.log('resize')
}, 200)

common API

类型判断

import { isString, isObject, isFunction, isPlainObject } from '@jupiter/utils'

isString('a') // true
isObject({}) // true
isFunction(() => {}) // true
isPlainObject({ a: 1 }) // true

对象处理

import { hasOwn, extend, deepClone, deepMerge, shallowEqual } from '@jupiter/utils'

hasOwn({ a: 1 }, 'a') // true
extend({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }
deepClone({ a: { b: 1 } })
deepMerge({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }
shallowEqual({ a: 1 }, { a: 1 }) // true

字符串与数字

import { format, formatOrThrow, formatCurrency, parseNumber } from '@jupiter/utils'

format('{1}-{2}', 'a', 'b') // 'a-b'
formatOrThrow('{1}', 'x') // 'x'
formatCurrency(12345) // '¥ 12,345.00'
parseNumber('8.5K') // 8500

函数控制

import { once, debounce, noop } from '@jupiter/utils'

const onlyOnce = once(() => 1)
onlyOnce() // 1
onlyOnce() // 1

const fn = debounce(() => console.log('trigger'), 300)
noop()

其他工具

import { getUUID, def, setPropertyReadonly, distributeEvenly } from '@jupiter/utils'

getUUID() // UID-...
const obj: Record<string, unknown> = {}
def(obj, 'name', 'jupiter')
setPropertyReadonly(obj, 'name')
distributeEvenly(10, 3) // [4, 3, 3]

2) ResourceLoader

import { ResourceLoader } from '@jupiter/utils'

ResourceLoader(
  ['https://cdn.example.com/a.js', 'https://cdn.example.com/a.css'],
  () => {
    console.log('资源加载流程完成')
  }
)

注意:ResourceLoader 仅支持基于 script/link 的资源注入,不支持 ESM 模块语义加载(import/exporttype="module"import())。

3) EventBus

import { EventBus } from '@jupiter/utils'

const bus = new EventBus()

const off = bus.subscribe('user:update', (payload) => {
  console.log('收到更新', payload)
})

bus.publish('user:update', { id: 1, name: 'zekai' })
off()

4) LocalStorageStore

import { LocalStorageStore } from '@jupiter/utils'

const store = new LocalStorageStore({
  key: 'app:user',
  initData: () => ({ id: 0, name: '' })
})

store.update({ id: 1, name: 'zekai' })
const name = store.getter('name')
console.log(name)

本地开发

packages/utils 目录执行:

npm run test
npm run lint
npm run build:prod

按文件执行测试:

npx jest test/EventBus.spec.ts --no-cache
npx jest test/ResourceLoader.spec.ts --no-cache