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

@soybeanjs/utils

v0.0.1

Published

A collection of useful utility functions for JavaScript and TypeScript projects of SoybeanJS.

Readme

@soybeanjs/utils

English | 简体中文

一个用于 JavaScript 和 TypeScript 项目的实用工具函数集合。

特性

  • 🚀 轻量级且零依赖
  • 📦 ESM 格式
  • 🔧 完整的 TypeScript 类型支持
  • 🎯 提供常用的工具函数
  • 💾 浏览器存储封装

安装

# 使用 pnpm
pnpm add @soybeanjs/utils

# 使用 npm
npm install @soybeanjs/utils

# 使用 yarn
yarn add @soybeanjs/utils

使用方法

字符串工具

提供多种字符串命名格式转换函数:

import { kebabCase, pascalCase, camelCase, snakeCase } from '@soybeanjs/utils';

// 转换为短横线命名
kebabCase('helloWorld'); // 'hello-world'

// 转换为帕斯卡命名
pascalCase('hello-world'); // 'HelloWorld'

// 转换为驼峰命名
camelCase('hello-world'); // 'helloWorld'

// 转换为蛇形命名
snakeCase('helloWorld'); // 'hello_world'

对象工具

类型安全的对象操作函数:

import { keysOf, entriesOf, valuesOf } from '@soybeanjs/utils';

const obj = { name: 'John', age: 30 };

// 获取对象键(带类型推断)
const keys = keysOf(obj); // ('name' | 'age')[]

// 获取对象条目(带类型推断)
const entries = entriesOf(obj); // ['name' | 'age', string | number][]

// 获取对象值(带类型推断)
const values = valuesOf(obj); // (string | number)[]

存储工具

浏览器存储的类型安全封装(localStorage 和 sessionStorage):

import { createStorage } from '@soybeanjs/utils';

// 定义存储数据结构
interface StorageData {
  token: string;
  userInfo: {
    name: string;
    age: number;
  };
}

// 创建 localStorage 实例
const storage = createStorage<StorageData>('local', 'my-app-');

// 设置存储
storage.set('token', 'abc123');
storage.set('userInfo', { name: 'John', age: 30 });

// 获取存储
const token = storage.get('token'); // string | null
const userInfo = storage.get('userInfo'); // { name: string; age: number } | null

// 移除存储
storage.remove('token');

// 清空所有存储
storage.clear();

API 文档

字符串工具

  • kebabCase(str: string): string - 转换为短横线命名格式
  • pascalCase(str: string): string - 转换为帕斯卡命名格式
  • camelCase(str: string): string - 转换为驼峰命名格式
  • snakeCase(str: string): string - 转换为蛇形命名格式

对象工具

  • keysOf<T>(record: T): (keyof T)[] - 获取对象的键(类型安全)
  • entriesOf<T>(record: T): [keyof T, T[keyof T]][] - 获取对象的条目(类型安全)
  • valuesOf<T>(record: T): T[keyof T][] - 获取对象的值(类型安全)

存储工具

  • createStorage<T>(type: StorageType, storagePrefix: string) - 创建类型安全的存储实例
    • type: 'local''session'
    • storagePrefix: 存储键前缀
    • 返回对象包含以下方法:
      • set<K>(key: K, value: T[K]): void - 设置存储
      • get<K>(key: K): T[K] | null - 获取存储
      • remove(key: keyof T): void - 移除存储
      • clear(): void - 清空所有存储

开发

# 安装依赖
pnpm install

# 构建
pnpm build

# 代码检查
pnpm lint

# 类型检查
pnpm typecheck

许可证

MIT License © 2026 Soybean