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

@yanqirenshi/model.core

v0.1.0

Published

Shared building blocks for the @yanqirenshi/model.* diagram models — ModelError, JSON Merge Patch helpers, inspector input readers (toColor / toLength / toDegree …), changedValues and graph (nodes / edges) checks. Pure functions: no React / d3 dependency

Readme

@yanqirenshi/model.core

図ごとのモデル(@yanqirenshi/model.*)が共通で使う部品です。 react / d3 に依存しない、純粋な関数だけを持ちます。

| 持つもの | 入口 | |---|---| | 入力の検証エラー(利用者向けのメッセージ) | ModelError | | JSON Merge Patch(RFC 7386)の道具 | mergePatch(record, patch) / getByPath(obj, path) / put(patch, path, value) | | ドラッグの移動量を position の patch にする | movePatch(record, move, collection) | | インスペクタの入力のうち、描いている値から変わった項目だけ | changedValues(effective, values, fields) | | インスペクタの入力(文字列)の読み取り | isColor / toColor / toWidth / toLength / toDegree / toOption / toOptionNumber / toOptionNumberOrNull / toBoolean / toOptionalText / toNumber | | ノードと線の図(graph 系)に共通の整合性ルール | checkGraph(data, prefix) / flattenNodes / checkUnique / findById |

位置づけ

利用側(iHub / デモ) ──▶ model.unchi / model.er / model.tm / model.sitemap / model.deployment ──▶ model.core

利用側がこのパッケージを直接 import する必要はありません。 各 model.* が ModelError / mergePatch / getByPath / isColor を再 export し、check / movePatch には自分の型を付けて公開しています。 図ごとの知識(JSON Schema・withDefaults・fieldsOf・図ごとの check・applyPatch)は各 model.* にあり、ここには置きません。

Foolsgolds/Assholes#151 で、5 つの model.* に複製されていた部分を切り出したものです。

各 model.* から使うとき

import {
  ModelError, changedValues, movePatch, put, toColor, toLength, toWidth,
} from '@yanqirenshi/model.core';

// 読み取り部品は、図ごとの規則の違いを引数で受ける
toWidth(value, '枠線の太さ');                       // 0 より大きい数(0 は view が既定に倒すとき)
toWidth(value, '枠線の太さ', { allowZero: true }); // 0 以上(0 = 線なし)
toLength(value, '幅', { min: 1 });                 // 「幅は 1 以上の数で入力してください。」
toLength(value, '幅', { hint: '(0 で子に合わせる)' });

// ドラッグの終わり → patch(collection は図ごとに固定して公開する)
export function movePatchForMyDiagram(node, move) { return movePatch(node, move, 'nodes'); }

// 適用 → 変わった項目だけを読み取って patch にする
for (const [path, value] of changedValues(withDefaults(record), values, fieldsOf(record))) {
  switch (path) {
    case 'border.color': put(patch, path, toColor(value, '枠線の色')); break;
    // ...
  }
}

読み取り部品が投げる ModelError の文言は、各 model.* のテストが見ているものと同じです(tests/read.test.ts)。

配布形式

ESM(dist/)に加えて CommonJS 版(dist/cjs/)も出します。 各 model.* の CommonJS 版(Babel 系の view を jest で試験するためのもの)がこれを require するためで、すべての model.* が CommonJS 版を出さなくなったら外せます。

コマンド

npm run build     -w @yanqirenshi/model.core   # tsc で dist/(ESM + d.ts)と dist/cjs/(CommonJS)へビルド
npm run typecheck -w @yanqirenshi/model.core
npm test          -w @yanqirenshi/model.core   # vitest

各 model.* のビルド・テスト・Babel 系 view の jest は、このパッケージの dist/ を先に作っておく必要があります(npm install の prepare で作られます)。