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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rsc-utils

v0.0.6

Published

rsc-utils

Readme

rsc-utils

一些实用的工具函数,支持浏览器和node两端使用

install

npm i rsc-utils

or

yarn add rsc-utils

usage

// 例如需要引用camel2Underscore方法
import { camel2Underscore } from 'rsc-utils'

api

camel2Underscore

将驼峰式字符串转换为下划线式字符串

const result = camel2Underscore('helloWorld');
console.log(result); // 输出: hello_world

tFObjWithCamelKey2Underscore

将对象的key从驼峰式转为下划线式。适用于统一处理请求对象。这样在拦截器里统一处理就行

const obj = { helloWorld: 'example' };
const result = tFObjWithCamelKey2Underscore(obj);
console.log(result); // 输出: { hello_world: 'example' }

removeEmptyObjForArr

从数组中移除空对象。

const arr = [{}, { a: 1 }, {}];
const result = removeEmptyObjForArr(arr);
console.log(result); // 输出: [{ a: 1 }]

isEmptyObject

判断一个对象是否为空

const obj = {};
const result = isEmptyObject(obj);
console.log(result); // 输出: true

rmEmptyValKey

从对象中移除值为空的键值对。

const obj = { a: 1, b: null, c: undefined};
const result = rmEmptyValKey(obj);
console.log(result); // 输出: { a: 1}

getTypeof

获取对象的类型。

const obj = { a: 1 };
const result = getTypeof(obj);
console.log(result); // 输出: object

isObject

判断一个值是否为对象。

const obj = { a: 1 };
const result = isObject(obj);
console.log(result); // 输出: true

isNotEmptyObj

判断一个值是否为对象且非空。

const obj = { a: 1 };
const result = isNotEmptyObj(obj);
console.log(result); // 输出: true

tranformObjToTree

将对象转换为树形结构。

const obj = { a: { b: 1, c: 2 }, d: 3 };
const result = tranformObjToTree(obj, 'root');
console.log(result); // 输出: { header: 'root', children: [...] }

tranformObjInArrToTree

将数组中的对象转换为树形结构。

const list = [{ a: 1 }, { b: 2 }];
const result = tranformObjInArrToTree(list, 'root', true);
console.log(result); // 输出: [{ header: 'root_0', children: [...] }, { header: 'root_1', children: [...] }]

changeParamsFiedsMap

将对象中的key改成传入的映射key。

const obj = { a: 1, b: 2 };
const map = { a: 'x', b: 'y' };
const result = changeParamsFiedsMap(obj, map);
console.log(result); // 输出: { x: 1, y: 2 }

objectToTableArr

将对象转数组。

const obj = { x0: '1,2,3', x1: '4,5,6' };
const result = objectToTableArr(obj);
console.log(result); // 输出: [{ x0: 1, x1: 4 }, { x0: 2, x1: 5 }, { x0: 3, x1: 6 }]

str2ArrOrObj

将字符串转换为数组或对象。

const str = '{"a": 1, "b": [2, 3]}';
const result = str2ArrOrObj(str);
console.log(result); // 输出: { a: 1, b: [2, 3] }

renderSize

将字节大小转换为可读的字符串格式

const value = 1024;
const result = renderSize(value);
console.log(result); // 输出: 1.00 KB

mergeNotEmpty

合并非空参数。

const params = { a: '  ', b: 'example' };
const result = mergeNotEmpty(params);
console.log(result); // 输出: { b: 'example' }

拍平数组键值

const list = [
  {
    id: "1",
    name: "name-1",
    children: [
      {
        id: "1-1",
        name: "name-1-1"
      },
      {
        id: "1-2",
        name: "name-1-2"
      },
      {
        id: "1-3",
        name: "name-1-3"
      }
    ]
  },
  {
    id: "2",
    name: "name-2",
    children: [
      {
        id: "2-1",
        name: "name-2-1"
      },
      {
        id: "2-2",
        name: "name-2-2"
      },
      {
        id: "2-3",
        name: "name-2-3"
      }
    ]
  }
];
const resId = concllectKeysKey(list);
console.log("resId", resId);

const resName = concllectKeysKey(list, "name");
console.log("resName", resName);