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

@x1a0f3n9/dsh-util-values

v0.1.5-rc.5

Published

Duplicate-install-safe value primitives for the DeepSeek Harness

Readme


description: "供运行时包使用的无损 JSON 校验、分离式快照、深度冻结、结构相等与穷尽联合类型辅助函数。" kind: "package-library"

@x1a0f3n9/dsh-util-values

English | 中文

概述

dsh-util-values 为运行时包提供统一的无损 JSON 值、不可变对象图、JSON 结构相等和封闭联合类型穷尽失败实现。调用方可以校验不受信任的值、创建分离的 JSON 快照、冻结待发布值、比较 JSON 兼容数据,或终止不可达分支,而无需导入某个能力包。这些 helper 不持有共享注册表、constructor identity 或可变模块状态。

目录


使用本包

校验 JSON 数据或创建快照

需要 predicate 时使用 isJsonValue(),还需要分离副本时使用 snapshotJsonValue()。两者只接受无损 JSON 根值:null、布尔值、除负零外的有限数字、字符串、稠密的内建数组,以及只含可枚举字符串键的普通或 null-prototype 记录。循环、稀疏数组、自有 symbol 属性或自有不可枚举属性、函数和 class 实例都会被拒绝。

import { isJsonValue, snapshotJsonValue, type JsonValue } from '@x1a0f3n9/dsh-util-values'

declare const input: unknown

if (!isJsonValue(input)) throw new TypeError('expected lossless JSON')
const snapshot = snapshotJsonValue(input) as JsonValue

发布或比较值

deepFreeze(value) 原地冻结对象图并返回同一个值。它遍历可枚举字符串键的子项,并刻意让活跃 AbortSignal 对象保持可变。deepEqualJson(a, b) 按结构比较 JSON 兼容数组与记录;调用方必须先校验恶意或不受约束的值,再进行比较。

封闭可辨识联合类型

在封闭可辨识联合类型的 default 分支中使用 assertNever(value, context?)。新增变体会让每个穷尽 switch 在 TypeScript 编译时失败;如果某个运行时值逃过了声明类型,该函数会抛出带可选上下文标签的错误。


理解实现

JSON 校验器使用显式工作栈,并只跟踪当前祖先链,因此深层嵌套值不会消耗 JavaScript 调用栈,重复但无循环的引用仍然有效。快照写入使用自有数据属性,包括 __proto__ 等名称。其他 helper 的结果只取决于传入参数,不在调用之间保留状态。

源码地图

| 文件 | 职责 | |---|---| | src/index.ts | JSON 值类型、校验与快照遍历、结构相等、深度冻结和穷尽联合类型失败 | | — | 不发布运行时不变量伴生入口;这些值操作没有共享运行时状态,其代数行为由单元测试覆盖。 |


进一步探索


已知限制与延期工作

  • deepEqualJson 假定输入兼容 JSON——它不是通用对象比较器,不为 prototype、symbol、accessor、循环、map 或 set 定义语义。
  • deepFreeze 沿可枚举字符串键遍历子项——它不会把任意宿主对象变成不可变数据,并会刻意跳过活跃 AbortSignal 实例。

开发备注

无。