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

@cclr/lang

v0.1.61

Published

js语言基础工具

Downloads

2,008

Readme

lang

常用 JS/TS 语言工具集合(数组、对象、断言、读写路径)。

Usage

npm i @cclr/lang
import {
  forEach,
  forEachReverse,
  get,
  set,
  isEmpty,
  isEqual,
  isPromise,
  isFormData,
  obj,
} from '@cclr/lang';

const list = [1, 2, 3];
forEach(list, (item) => console.log(item));
forEachReverse(list, (item) => console.log(item));

const state = set({}, 'user.profile.name', 'tom');
const name = get(state, 'user.profile.name', 'unknown');

const empty = isEmpty({});
const equal = isEqual({ a: 1 }, { a: 1 });
const maybePromise = isPromise(Promise.resolve(1));
const form = isFormData(new FormData());

const picked = obj.pick({ a: 1, b: 2 }, ['a']);

API 说明

数组

  • forEach(arr, callback, reverse?):遍历数组,支持可选反向遍历。
  • forEachReverse(arr, callback):从尾到头遍历数组。

路径读写

  • get(source, path, defaultValue?):按路径读取对象值(如 a.b.c)。
  • set(source, path, value):按路径设置对象值,不存在的节点会自动创建。

类型判断

  • getParamType(value):返回值类型标识(如 stringarrayobject)。
  • isType(value, type):判断值是否为指定类型。
  • isString(value):判断是否为字符串。
  • isNumber(value):判断是否为有限数字(排除 NaN/Infinity)。
  • isBoolean(value):判断是否为布尔值。
  • isSymbol(value):判断是否为 symbol
  • isNull(value):判断是否为 null
  • isUndefined(value):判断是否为 undefined
  • isUndefinedOrNull(value):判断是否为 undefinednull
  • isFunction(value):判断是否为函数。
  • isObject(value):判断是否为对象。
  • isPlainObject(value):判断是否为普通对象({})。
  • isArray(value):判断是否为数组。
  • isEmpty(value):判断是否为空值/空对象/空数组/空字符串。
  • isEqual(a, b):深度比较两个值是否相等。
  • isPromise(value):判断是否为 PromiseLike。

Web/DOM 类型判断

  • isArrayBuffer(value):安全判断是否为 ArrayBuffer(兼容无全局对象的环境)。
  • isBlob(value):安全判断是否为 Blob
  • isDOMException(value):安全判断是否为 DOMException
  • isFormData(value):安全判断是否为 FormData
  • isURLSearchParams(value):安全判断是否为 URLSearchParams

对象基础

  • hasOwn(obj, key):判断对象是否含有自身属性(非原型链)。
  • toString(value):获取值的原始 toString 标签(如 [object Array])。

对象工具(obj 命名空间)

  • obj.extend(sourceObj, injectObj):将 injectObj 的属性合并到 sourceObj
  • obj.filter(sourceObj, filter?):按条件过滤对象属性,返回新对象。
  • obj.forEach(obj, callback):同步遍历对象键值对。
  • obj.forEachAsync(obj, callback):串行异步遍历对象。
  • obj.forEachSync(obj, callback):并行异步遍历对象(Promise.all)。
  • obj.format(object, formatOptionList):按类型规则格式化对象字段。
  • obj.omit(sourceObj, omitKeys):返回剔除指定字段后的新对象。
  • obj.pick(sourceObj, keys):返回仅保留指定字段的新对象。

其它

  • noop():空函数。
  • defaultValue:各类型的默认值映射表。
  • VAL_TYPE:类型标识常量表。

类型

  • TAny:任意类型别名。
  • TPlainObject:普通对象类型。
  • TPlainFunction:普通函数类型。
  • TNoop:无参无返回值函数类型。
  • TUndefinedOrNullundefined | null 联合类型。
  • RequireRecursive<T>:递归将所有属性变为必填。
  • PartialRecursive<T>:递归将所有属性变为可选。