@first-ch/tools-mcp 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/case-convert.mjs +390 -0
- package/package.json +11 -3
- package/server.mjs +46 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @first-ch/tools-mcp
|
|
2
2
|
|
|
3
|
-
MCP server exposing [First CH Tools](https://tools.first-ch.com)' free web-tool logic — WCAG contrast, JP character/X-weight counting, WebP conversion, JSON-LD generation, llms.txt generation, encoding/line-ending conversion, Marp Markdown→slide rendering, Japanese/English test-data generation, text/code diffing, cron-expression explanation, Base64/data-URI encoding, URL query-parameter editing, HTML entity escaping/unescaping, JSON⇄YAML conversion, px ⇄ rem/em unit conversion, colour-code conversion with alpha compositing, MD5/SHA-1/SHA-256/SHA-384/SHA-512 hashing, JWT decoding with expiry and signature checks, User-Agent parsing with device/bot detection, bulk UUID v4 / ULID generation,
|
|
3
|
+
MCP server exposing [First CH Tools](https://tools.first-ch.com)' free web-tool logic — WCAG contrast, JP character/X-weight counting, WebP conversion, JSON-LD generation, llms.txt generation, encoding/line-ending conversion, Marp Markdown→slide rendering, Japanese/English test-data generation, text/code diffing, cron-expression explanation, Base64/data-URI encoding, URL query-parameter editing, HTML entity escaping/unescaping, JSON⇄YAML conversion, px ⇄ rem/em unit conversion, colour-code conversion with alpha compositing, MD5/SHA-1/SHA-256/SHA-384/SHA-512 hashing, JWT decoding with expiry and signature checks, User-Agent parsing with device/bot detection, bulk UUID v4 / ULID generation, aspect-ratio calculation with responsive sizing, and case conversion between camelCase, snake_case and kebab-case — to AI agents such as Claude Code.
|
|
4
4
|
|
|
5
5
|
日本語版は [後半セクション](#日本語) を参照してください。
|
|
6
6
|
|
|
@@ -71,6 +71,7 @@ This server is also registered in the [MCP Registry](https://registry.modelconte
|
|
|
71
71
|
| `qr_generate` | Turns a URL or any text into a QR code and returns it as SVG (vector), PNG or terminal-friendly text art — the same logic as the browser tool at tools.first-ch.com/qr/. Encoding (numeric, alphanumeric or UTF-8 byte mode, picked automatically from the input), Reed–Solomon error correction, the layout of finder, timing and alignment patterns, version information and the choice between the eight mask patterns are all implemented here (JIS X 0510 / ISO 18004, versions 1–40); there is no external API or image service. `ecLevel` trades capacity for damage tolerance (L about 7%, M about 15%, Q about 25%, H about 30% — use Q or H for print), `size` is the edge length in pixels, and `margin` is the quiet zone in modules (4 is the recommended default; 0 can break scanning over a patterned background). Wi-Fi (`WIFI:T:WPA;S:…;P:…;;`), `mailto:`, `tel:`, `SMSTO:` and `geo:` strings just go in as `text`. `outputPath` writes the file instead of returning the body; `format="png"` without it returns a data URI. Capacity tops out at 7,089 digits, 4,296 alphanumeric characters or 2,953 bytes (all at level L) | `text`, `ecLevel?` (`L` / `M` default / `Q` / `H`), `size?` (64–4096, default 320), `margin?` (0–32, default 4), `format?` (`svg` default / `png` / `text`), `mode?` (`auto` default / `numeric` / `alnum` / `byte`), `mask?` (0–7), `minVersion?`, `outputPath?` |
|
|
72
72
|
| `unixtime_convert` | Converts Unix seconds, milliseconds, microseconds and nanoseconds to and from ISO 8601 and ordinary date strings — the same logic as the browser tool at tools.first-ch.com/unixtime/. The unit of a plain number is detected from its digit count (up to 10 digits seconds, up to 13 milliseconds, up to 16 microseconds, longer nanoseconds); `unit` states it outright instead. Digits below the millisecond are dropped and reported in `notes`. On the date side it accepts `2026-08-24T09:30:00Z` (ISO 8601), `2026-08-24 18:30`, `2026/8/24 9:05`, the Japanese `2026年8月24日 18時30分`, `Sun, 24 Aug 2026 03:00:00 GMT` (HTTP-date) and `now`, stripping the quotes, brackets and trailing commas that come with a paste from CSV or JSON. `input` takes one value per line, up to 500 lines at a time, and every row comes back with Unix seconds, milliseconds, ISO 8601 in UTC, local time in `timeZone` (with weekday and UTC offset) and a relative reading ("30分後" / "in 30 minutes"); a line that cannot be read fails on its own without taking the others down. **A date with no offset is read as a wall-clock time in `timeZone`** and always says so in `notes`; an explicit `+09:00` or `Z` in the input wins over `timeZone`. A wall-clock time that daylight saving skips is moved forward to the moment after the change, also noted. An 8-digit number such as `20260824` is Unix seconds here, so it is flagged in case a date was meant. Negative values (before 1970) and fractional seconds work | `input`, `timeZone?` (IANA name, default `UTC`), `unit?` (`auto` default / `s` / `ms` / `us` / `ns`), `now?` (Unix milliseconds or a date string, default the current time), `lang?` (`ja` default / `en`) |
|
|
73
73
|
| `robotstxt_generate` | Assembles a robots.txt from crawl rules, sitemap declarations and a preset for AI crawlers — the same logic as the browser tool at tools.first-ch.com/robots-txt/. `ai.preset` decides how 24 known AI crawlers are treated in one move: `training` (the default: refuse the ones that collect training data — GPTBot, ClaudeBot, Google-Extended, Bytespider, CCBot and the rest — while allowing AI search and on-demand fetchers such as OAI-SearchBot, Claude-SearchBot, PerplexityBot and ChatGPT-User), `allow`, `block`, `none` (leave AI crawlers out) or `custom` with `ai.overrides` naming them one by one. **A crawler obeys exactly one matching group**, so writing a group for GPTBot stops the `User-agent: *` rules from ever reaching it; by default the shared disallow paths are copied into the AI groups to close that gap (`ai.inherit: false` turns it off). Paths get a leading slash added and full URLs reduced to their path, and `warnings` reports spaces inside a path, non-ASCII paths that need percent-encoding, wildcards that not every crawler supports, a `Crawl-delay` Googlebot will ignore, a missing sitemap, a User-agent listed twice and a site blocked in full. `listCrawlers: true` returns just the crawler list (name, vendor, purpose) without generating anything | `siteUrl?`, `disallow?`, `allow?`, `userAgents?` (default `*`), `crawlDelay?`, `blockCrawlers?`, `sitemaps?`, `ai?` (`preset?`, `overrides?`, `inherit?`), `groups?`, `comments?` (default true), `allowStyle?` (`disallow-empty` default / `allow-slash`), `listCrawlers?`, `lang?` (`ja` default / `en`), `outputPath?` |
|
|
74
|
+
| `case_convert` | Converts identifiers between eleven cases — camelCase, PascalCase, snake_case, CONSTANT_CASE, kebab-case, Train-Case, dot.case, Title Case, Sentence case, lower case and UPPER CASE — the same logic as the browser tool at tools.first-ch.com/case/. Built for the mechanical jobs at the boundary between layers: renaming variables in bulk, moving between `snake_case` database columns and `camelCase` JSON keys, tidying CSV headers. `scope` sets the unit of work: `lines` (the default, one item per line), `items` (every comma or tab separated field of a line, for CSV header rows) or `whole`. **Leading and trailing spaces, indentation, line endings (LF/CRLF) and the separators are preserved**, so only the names change. A run of capitals is broken only before a capital followed by a lower-case letter (`XMLHttpRequest` → `XML` / `Http` / `Request`), and digits stay attached to the word before them (`sha256Hash` → `sha256` / `Hash`; `splitDigits` splits them). Acronyms fold to `parseXmlData` by default and stay capitalised with `keepAcronyms`, except the first word of a camelCase name, which is always lower-cased (`URLParser` → `urlParser`). Characters with no letter case (Japanese, for example) pass through rather than being transliterated. `notes` reports **names that collide after conversion** (`first name` and `first_name` both become `first_name`, which is how a column silently disappears on import), results starting with a digit that cannot be identifiers, and items containing acronyms; `items[].detected` names the case each input was written in. `allFormats` expands every item into all eleven cases, `listFormats` returns just the list of cases with what each is used for | `text?` or `path?`, `outputPath?`, `format?` (`camel` default), `scope?` (`lines` default / `items` / `whole`), `splitDigits?`, `keepAcronyms?`, `allFormats?`, `listFormats?`, `lang?` (`ja` default / `en`) |
|
|
74
75
|
|
|
75
76
|
See [`server.mjs`](./server.mjs) for the exact Zod input schemas.
|
|
76
77
|
|
|
@@ -115,7 +116,7 @@ Release rule: a push to `main` automatically publishes a new package version thr
|
|
|
115
116
|
|
|
116
117
|
## 日本語
|
|
117
118
|
|
|
118
|
-
`@first-ch/tools-mcp` は、[First CH Tools](https://tools.first-ch.com)(無料Webツール集)の計算ロジック — WCAGコントラスト比・日本語文字数/Xウェイト計測・WebP変換・JSON-LD生成・llms.txt生成・文字コード/改行コード変換・Marp Markdown→スライド レンダリング・テストデータ生成・テキスト/コード差分・Cron式の解説・Base64/Data URI変換・URLパラメータの分解/編集/再構築・HTML特殊文字のエスケープ/エンティティのデコード・JSON⇄YAMLの相互変換・px⇄rem/emの単位換算とCSSの一括変換・カラーコードの相互変換とアルファ透過の合成・MD5/SHA-1/SHA-256/SHA-384/SHA-512のハッシュ生成と照合・JWTのデコードと有効期限/署名の検証・User-Agent文字列の解析とデバイス判定・UUID v4 / ULID
|
|
119
|
+
`@first-ch/tools-mcp` は、[First CH Tools](https://tools.first-ch.com)(無料Webツール集)の計算ロジック — WCAGコントラスト比・日本語文字数/Xウェイト計測・WebP変換・JSON-LD生成・llms.txt生成・文字コード/改行コード変換・Marp Markdown→スライド レンダリング・テストデータ生成・テキスト/コード差分・Cron式の解説・Base64/Data URI変換・URLパラメータの分解/編集/再構築・HTML特殊文字のエスケープ/エンティティのデコード・JSON⇄YAMLの相互変換・px⇄rem/emの単位換算とCSSの一括変換・カラーコードの相互変換とアルファ透過の合成・MD5/SHA-1/SHA-256/SHA-384/SHA-512のハッシュ生成と照合・JWTのデコードと有効期限/署名の検証・User-Agent文字列の解析とデバイス判定・UUID v4 / ULIDの一括生成・アスペクト比の計算とレスポンシブサイズの算出・camelCase / snake_case / kebab-case などの文字列ケース変換 — をAIエージェント(Claude Code等)向けMCPツールとして提供するサーバーです。
|
|
119
120
|
|
|
120
121
|
### インストール
|
|
121
122
|
|
|
@@ -184,6 +185,7 @@ claude mcp add firstch-tools -- npx -y @first-ch/tools-mcp
|
|
|
184
185
|
| `qr_generate` | URL・テキストからQRコードを作り、SVG(ベクター)・PNG・端末に貼れる文字の図で返す。tools.first-ch.com/qr/ と同一の仕様。符号化(数字 / 英数字 / UTF-8のバイトモードを入力に応じて自動選択)・リード・ソロモン符号による誤り訂正・位置検出/タイミング/位置合わせパターンと型番情報の配置・8種類のマスクからの自動選択まで自前で実装しており(JIS X 0510 / ISO 18004・型番1〜40)、外部のAPIも画像生成サーバーも使わない。`ecLevel` は容量と汚れへの強さの取引(L 約7% / M 約15% / Q 約25% / H 約30%。印刷物はQ以上を推奨)、`size` は出力の一辺(px)、`margin` は余白=クワイエットゾーンのモジュール数(規格の推奨は4。0にすると背景の柄によっては読めなくなる)。Wi-Fi(`WIFI:T:WPA;S:…;P:…;;`)・`mailto:`・`tel:`・`SMSTO:`・`geo:` はその文字列をそのまま `text` に渡す。`outputPath` を渡すとファイルへ書き出す(本文は返さない)。`format="png"` で省いた場合は data URI で返る。容量の上限は数字7089桁・英数字4296文字・バイト2953文字(いずれもレベルL) | `text`、`ecLevel?`(`L` / 既定 `M` / `Q` / `H`)、`size?`(64〜4096・既定 320)、`margin?`(0〜32・既定 4)、`format?`(既定 `svg` / `png` / `text`)、`mode?`(既定 `auto` / `numeric` / `alnum` / `byte`)、`mask?`(0〜7)、`minVersion?`、`outputPath?` |
|
|
185
186
|
| `unixtime_convert` | UNIX秒・ミリ秒・マイクロ秒・ナノ秒と、ISO 8601や日時文字列を相互に変換する。tools.first-ch.com/unixtime/ と同一の仕様。数値の単位は桁数から自動判定し(10桁までを秒 / 13桁までをミリ秒 / 16桁までをマイクロ秒 / それ以上をナノ秒)、`unit` を渡せばその単位で読む。ミリ秒より下の桁は切り捨て、その旨を `notes` で返す。日時側は `2026-08-24T09:30:00Z`(ISO 8601)・`2026-08-24 18:30`・`2026/8/24 9:05`・`2026年8月24日 18時30分`・`Sun, 24 Aug 2026 03:00:00 GMT`(HTTP-date)・`now` を受け付け、CSVやJSONから貼ったときの引用符・角括弧・行末カンマは自動で外す。`input` は1行1件で最大500行までまとめて変換し、行ごとにUNIX秒・ミリ秒・ISO 8601(UTC)・`timeZone` の現地時刻(曜日・UTCオフセット付き)・相対表示(○分前 / ○日後)を返す。読めなかった行は他の行を巻き込まずその行だけ `error` になる。**オフセットを持たない日時は `timeZone` の壁時計として解釈**し、必ず `notes` で明示する(入力に `+09:00` や `Z` があればそちらが優先)。夏時間で存在しない時刻は切り替え後へ繰り上げ、これも `notes` に出す。8桁の数字(`20260824`)はUNIX秒として読むため、日付のつもりの入力には注意を返す。負の値(1970年より前)と小数点付きの秒にも対応 | `input`、`timeZone?`(IANA名・既定 `UTC`)、`unit?`(既定 `auto` / `s` / `ms` / `us` / `ns`)、`now?`(UNIXミリ秒か日時文字列・既定は実行時刻)、`lang?`(既定 `ja` / `en`) |
|
|
186
187
|
| `robotstxt_generate` | クロールの許可/禁止ルール・サイトマップ宣言・AIクローラーの許可プリセットから robots.txt を組み立てる。tools.first-ch.com/robots-txt/ と同一の仕様。`ai.preset` で24種のAIクローラーの扱いをまとめて決められる: `training`(既定=GPTBot・ClaudeBot・Google-Extended・Bytespider・CCBot など**学習用データを集めるクローラーだけを拒否**し、OAI-SearchBot・Claude-SearchBot・PerplexityBot・ChatGPT-User などAI検索と都度取得は許可)/ `allow` / `block` / `none`(AIクローラーを書かない)/ `custom`(`ai.overrides` で1件ずつ指定)。**クローラーは自分に一致するグループを1つだけ読む**ため、GPTBot 用のグループを作った時点で `User-agent: *` の禁止ルールはそのクローラーへ届かなくなる。既定では共通の禁止パスをAI側のグループへ書き写してこの取りこぼしを防ぐ(`ai.inherit: false` で止められる)。パスは先頭の `/` を補い、絶対URLからはパス部分だけを取り出す。`warnings` では空白を含むパス・パーセントエンコードしていない日本語のパス・対応していないクローラーのあるワイルドカード・Googlebotが読まない `Crawl-delay`・サイトマップの宣言漏れ・同じUser-agentの重複・サイト全体の拒否を指摘する。`listCrawlers: true` を渡すと生成せずAIクローラーの一覧(名前・提供元・目的)だけを返す | `siteUrl?`、`disallow?`、`allow?`、`userAgents?`(既定 `*`)、`crawlDelay?`、`blockCrawlers?`、`sitemaps?`、`ai?`(`preset?` / `overrides?` / `inherit?`)、`groups?`、`comments?`(既定 true)、`allowStyle?`(既定 `disallow-empty` / `allow-slash`)、`listCrawlers?`、`lang?`(既定 `ja` / `en`)、`outputPath?` |
|
|
188
|
+
| `case_convert` | 識別子を camelCase / PascalCase / snake_case / CONSTANT_CASE / kebab-case・Train-Case・dot.case・Title Case・Sentence case・lower case・UPPER CASE の11形式へ相互変換する。tools.first-ch.com/case/ と同一ロジック。変数名の一括リネーム、`snake_case` のDB列名と `camelCase` のJSONキーの読み替え、CSVヘッダーの整形といった、層の境目で発生する定型処理のための道具。`scope` で処理の単位を選ぶ: `lines`(既定=1行1件)/ `items`(行内のカンマ・タブ区切りで1件ずつ=CSVヘッダー)/ `whole`(全体で1件)。**前後の空白・インデント・改行コード(LF/CRLF)・区切り記号はそのまま残す**ので、名前だけが置き換わる。大文字の連なりは直後に「大文字+小文字」が続くときだけ手前で切り(`XMLHttpRequest` → `XML` / `Http` / `Request`)、数字は既定で直前の語へ付く(`sha256Hash` → `sha256` / `Hash`。`splitDigits` で分けられる)。頭字語は既定で `parseXmlData` へ畳み、`keepAcronyms` で `parseXMLData` のまま残す(camelCase の先頭語はどちらでも小文字=`URLParser` → `urlParser`)。大文字小文字を持たない文字(日本語など)はそのまま出力し、ローマ字化はしない。`notes` では**変換後に同じ名前へ衝突する項目**(`first name` と `first_name` はどちらも `first_name`=インポート時に片方が黙って消える事故の元)・数字で始まって識別子にできない結果・頭字語を含む項目を指摘し、`items[].detected` では各入力がどの形式で書かれていたかを返す。`allFormats` で各項目を11形式すべてへ展開、`listFormats` で形式の一覧と使いどころだけを返す | `text?` または `path?`、`outputPath?`、`format?`(既定 `camel`)、`scope?`(既定 `lines` / `items` / `whole`)、`splitDigits?`、`keepAcronyms?`、`allFormats?`、`listFormats?`、`lang?`(既定 `ja` / `en`) |
|
|
187
189
|
|
|
188
190
|
正確な入力スキーマ(Zod定義)は [`server.mjs`](./server.mjs) を参照してください。
|
|
189
191
|
|
package/case-convert.mjs
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
// 文字列のケース変換(tools.first-ch.com/case/ と同一ロジック)
|
|
2
|
+
//
|
|
3
|
+
// 「変換コア」ブロックは site 側の site/case/app.js と同一の実装。
|
|
4
|
+
// 2箇所ルール: 片方を直したらもう片方も同じ内容で直す(site側が正本)。
|
|
5
|
+
// 使っているのは String/RegExp だけなので、ブラウザ版のコードをそのまま持ってこられる。
|
|
6
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
7
|
+
import { basename } from 'node:path';
|
|
8
|
+
|
|
9
|
+
/* ==================== ここから変換コア(site / MCP で同一) ==================== */
|
|
10
|
+
|
|
11
|
+
// 出力できるケースの一覧(表示名は呼び出し側で訳す)
|
|
12
|
+
export const CASE_FORMATS = ['camel', 'pascal', 'snake', 'constant', 'kebab', 'train', 'dot', 'title', 'sentence', 'lower', 'upper'];
|
|
13
|
+
|
|
14
|
+
// 形式ごとの見本。UIのボタンとMCPの説明で同じものを使う
|
|
15
|
+
export const CASE_EXAMPLES = {
|
|
16
|
+
camel: 'userName',
|
|
17
|
+
pascal: 'UserName',
|
|
18
|
+
snake: 'user_name',
|
|
19
|
+
constant: 'USER_NAME',
|
|
20
|
+
kebab: 'user-name',
|
|
21
|
+
train: 'User-Name',
|
|
22
|
+
dot: 'user.name',
|
|
23
|
+
title: 'User Name',
|
|
24
|
+
sentence: 'User name',
|
|
25
|
+
lower: 'user name',
|
|
26
|
+
upper: 'USER NAME',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// 語の分かち書き。大文字の連なり(頭字語)は「大文字+小文字」が続くときだけ手前で切るので、
|
|
30
|
+
// XMLHttpRequest → XML / Http / Request になる(XMLH / ttpRequest にはならない)。
|
|
31
|
+
// 最後の枝は「大文字でも小文字でもない文字」=仮名や漢字のように大小の別を持たない文字の連なり。
|
|
32
|
+
const CASE_TOKEN_RE = /\p{Lu}+(?=\p{Lu}\p{Ll})|\p{Lu}?\p{Ll}+|\p{Lu}+|\p{N}+|(?:(?!\p{Lu}|\p{Ll})\p{L})+/gu;
|
|
33
|
+
const CASE_SEP_RE = /[^\p{L}\p{N}]+/u;
|
|
34
|
+
const DIGITS_RE = /^\p{N}+$/u;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 識別子を単語へ割る。記号・空白はすべて区切りとして落とす。
|
|
38
|
+
* @param {string} str
|
|
39
|
+
* @param {object} [opts]
|
|
40
|
+
* @param {boolean} [opts.splitDigits=false] 数字を独立した語として扱う(false なら sha256 は1語)
|
|
41
|
+
*/
|
|
42
|
+
export function splitWords(str, opts) {
|
|
43
|
+
const splitDigits = Boolean((opts || {}).splitDigits);
|
|
44
|
+
const words = [];
|
|
45
|
+
for (const chunk of String(str).split(CASE_SEP_RE)) {
|
|
46
|
+
if (!chunk) continue;
|
|
47
|
+
const tokens = chunk.match(CASE_TOKEN_RE) || [];
|
|
48
|
+
const merged = [];
|
|
49
|
+
for (const token of tokens) {
|
|
50
|
+
if (!splitDigits && DIGITS_RE.test(token) && merged.length) {
|
|
51
|
+
// 区切りをまたいでいない数字は直前の語へ付ける(sha256 / user2 を割らない)
|
|
52
|
+
merged[merged.length - 1] += token;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
merged.push(token);
|
|
56
|
+
}
|
|
57
|
+
// 先頭の数字は付ける相手がいないので、続きが小文字始まりのときだけ後ろへ寄せる
|
|
58
|
+
// (2fa は1語、2FactorAuth は意図的な区切りとみなして割ったまま)
|
|
59
|
+
if (!splitDigits && merged.length > 1 && DIGITS_RE.test(merged[0]) && /^\p{Ll}/u.test(merged[1])) {
|
|
60
|
+
merged[1] = merged[0] + merged[1];
|
|
61
|
+
merged.shift();
|
|
62
|
+
}
|
|
63
|
+
for (const word of merged) words.push(word);
|
|
64
|
+
}
|
|
65
|
+
return words;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 全部が大文字(+数字)で2文字以上なら頭字語とみなす: ID / URL / HTTP2
|
|
69
|
+
export function isAcronym(word) {
|
|
70
|
+
return [...word].length >= 2 && /^\p{Lu}[\p{Lu}\p{N}]*$/u.test(word);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 先頭だけ大文字。サロゲートペアを割らないよう配列にしてから触る
|
|
74
|
+
export function capitalize(word) {
|
|
75
|
+
const chars = [...word];
|
|
76
|
+
return chars[0].toUpperCase() + chars.slice(1).join('').toLowerCase();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 単語列を1つの文字列へ組み立てる。
|
|
81
|
+
* @param {string[]} words
|
|
82
|
+
* @param {string} format CASE_FORMATS のいずれか
|
|
83
|
+
* @param {object} [opts]
|
|
84
|
+
* @param {boolean} [opts.keepAcronyms=false] 頭字語を大文字のまま残す(camel/pascal/train/title/sentence のみ)
|
|
85
|
+
*/
|
|
86
|
+
export function joinWords(words, format, opts) {
|
|
87
|
+
const keep = Boolean((opts || {}).keepAcronyms);
|
|
88
|
+
const cap = (word) => (keep && isAcronym(word) ? word : capitalize(word));
|
|
89
|
+
const low = (word) => word.toLowerCase();
|
|
90
|
+
const up = (word) => word.toUpperCase();
|
|
91
|
+
switch (format) {
|
|
92
|
+
// camelCase の先頭語は頭字語でも小文字にする(URLParser → urlParser)
|
|
93
|
+
case 'camel': return words.map((w, i) => (i === 0 ? low(w) : cap(w))).join('');
|
|
94
|
+
case 'pascal': return words.map(cap).join('');
|
|
95
|
+
case 'snake': return words.map(low).join('_');
|
|
96
|
+
case 'constant': return words.map(up).join('_');
|
|
97
|
+
case 'kebab': return words.map(low).join('-');
|
|
98
|
+
case 'train': return words.map(cap).join('-');
|
|
99
|
+
case 'dot': return words.map(low).join('.');
|
|
100
|
+
case 'title': return words.map(cap).join(' ');
|
|
101
|
+
case 'sentence': return words.map((w, i) => (i === 0 ? cap(w) : low(w))).join(' ');
|
|
102
|
+
case 'lower': return words.map(low).join(' ');
|
|
103
|
+
case 'upper': return words.map(up).join(' ');
|
|
104
|
+
default: return '';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 1件ぶんの変換(前後の空白は落とさずそのまま返す側で足す)
|
|
109
|
+
export function convertToken(token, format, opts) {
|
|
110
|
+
const words = splitWords(token, opts);
|
|
111
|
+
return words.length ? joinWords(words, format, opts) : token;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 入力がどの形式で書かれているかを推定する。
|
|
116
|
+
* 「その形式へ変換した結果が入力と一致するか」で判定するので、分かち書きの規則と必ず揃う。
|
|
117
|
+
* 候補が複数残る(user のような1語)ときは 'ambiguous' を返す。
|
|
118
|
+
*/
|
|
119
|
+
export function detectCase(str, opts) {
|
|
120
|
+
const s = String(str).trim();
|
|
121
|
+
if (!s) return 'empty';
|
|
122
|
+
const words = splitWords(s, opts);
|
|
123
|
+
if (!words.length) return 'unknown';
|
|
124
|
+
// 頭字語を残した書き方(XMLHttpRequest)も同じ形式とみなす
|
|
125
|
+
const matches = CASE_FORMATS.filter(
|
|
126
|
+
(f) => joinWords(words, f, opts) === s || joinWords(words, f, { keepAcronyms: true }) === s,
|
|
127
|
+
);
|
|
128
|
+
if (!matches.length) return 'mixed';
|
|
129
|
+
if (matches.length > 1) return words.length === 1 ? 'ambiguous' : matches[0];
|
|
130
|
+
return matches[0];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 行をセルへ割るときの区切り。タブがあればタブ、無ければカンマ(CSVヘッダー向け)
|
|
134
|
+
function pickDelimiter(line) {
|
|
135
|
+
return line.indexOf('\t') !== -1 ? '\t' : ',';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* テキストをまとめて変換する。
|
|
140
|
+
*
|
|
141
|
+
* @param {object} opts
|
|
142
|
+
* @param {string} opts.text 変換するテキスト
|
|
143
|
+
* @param {string} [opts.format='camel'] 変換先(CASE_FORMATS)
|
|
144
|
+
* @param {'lines'|'items'|'whole'} [opts.scope='lines'] 1行1件 / 行内をカンマ・タブで分ける / 全体で1件
|
|
145
|
+
* @param {boolean} [opts.splitDigits=false] 数字を独立した語として扱う
|
|
146
|
+
* @param {boolean} [opts.keepAcronyms=false] 頭字語を大文字のまま残す
|
|
147
|
+
* @returns {{format,scope,text,items,stats,notes}}
|
|
148
|
+
*/
|
|
149
|
+
export function caseConvert(opts) {
|
|
150
|
+
const o = opts || {};
|
|
151
|
+
const format = CASE_FORMATS.indexOf(o.format) !== -1 ? o.format : 'camel';
|
|
152
|
+
const scope = o.scope === 'items' || o.scope === 'whole' ? o.scope : 'lines';
|
|
153
|
+
const input = typeof o.text === 'string' ? o.text : '';
|
|
154
|
+
const items = [];
|
|
155
|
+
let caseless = 0;
|
|
156
|
+
let acronym = 0;
|
|
157
|
+
|
|
158
|
+
// 前後の空白を保ったまま中身だけ変換する(表の列やインデントを崩さないため)
|
|
159
|
+
const cell = (raw) => {
|
|
160
|
+
const m = /^(\s*)([\s\S]*?)(\s*)$/.exec(raw);
|
|
161
|
+
const body = m[2];
|
|
162
|
+
if (!body || !/[\p{L}\p{N}]/u.test(body)) return raw;
|
|
163
|
+
const words = splitWords(body, o);
|
|
164
|
+
const out = joinWords(words, format, o);
|
|
165
|
+
// 大小の別を持たない文字(仮名・漢字など)は変換しても変わらないので件数だけ数える
|
|
166
|
+
if (words.some((w) => /\p{L}/u.test(w) && w.toLowerCase() === w.toUpperCase())) caseless += 1;
|
|
167
|
+
if (!o.keepAcronyms && words.some(isAcronym)) acronym += 1;
|
|
168
|
+
items.push({ input: body, output: out, detected: detectCase(body, o), words: words.length });
|
|
169
|
+
return m[1] + out + m[3];
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
let text;
|
|
173
|
+
if (scope === 'whole') {
|
|
174
|
+
text = cell(input);
|
|
175
|
+
} else {
|
|
176
|
+
// 改行そのものを残したいので、キャプチャ付きの split で区切りごと配列に入れる
|
|
177
|
+
const parts = input.split(/(\r\n|\n|\r)/);
|
|
178
|
+
text = parts
|
|
179
|
+
.map((part, i) => {
|
|
180
|
+
if (i % 2 === 1) return part; // 改行はそのまま
|
|
181
|
+
if (scope !== 'items') return cell(part);
|
|
182
|
+
const delim = pickDelimiter(part);
|
|
183
|
+
return part.split(delim).map(cell).join(delim);
|
|
184
|
+
})
|
|
185
|
+
.join('');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const changed = items.filter((it) => it.input !== it.output).length;
|
|
189
|
+
const seen = new Map();
|
|
190
|
+
const duplicates = [];
|
|
191
|
+
for (const it of items) {
|
|
192
|
+
const n = (seen.get(it.output) || 0) + 1;
|
|
193
|
+
seen.set(it.output, n);
|
|
194
|
+
if (n === 2) duplicates.push(it.output);
|
|
195
|
+
}
|
|
196
|
+
const leadingDigit = items.filter((it) => /^\p{N}/u.test(it.output)).length;
|
|
197
|
+
|
|
198
|
+
// 推定した元の形式は最頻値を採る(1行ずつばらばらなら mixed が多数になる)
|
|
199
|
+
const tally = new Map();
|
|
200
|
+
for (const it of items) tally.set(it.detected, (tally.get(it.detected) || 0) + 1);
|
|
201
|
+
let detected = items.length ? 'unknown' : 'empty';
|
|
202
|
+
let best = 0;
|
|
203
|
+
for (const [key, n] of tally) {
|
|
204
|
+
if (n > best) {
|
|
205
|
+
best = n;
|
|
206
|
+
detected = key;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const notes = [];
|
|
211
|
+
if (!items.length) notes.push({ code: 'NOTHING' });
|
|
212
|
+
if (duplicates.length) notes.push({ code: 'DUPLICATE', count: duplicates.length, items: duplicates.slice(0, 8) });
|
|
213
|
+
if (leadingDigit) notes.push({ code: 'LEADING_DIGIT', count: leadingDigit });
|
|
214
|
+
if (caseless) notes.push({ code: 'CASELESS', count: caseless });
|
|
215
|
+
if (acronym) notes.push({ code: 'ACRONYM', count: acronym });
|
|
216
|
+
if (items.length && changed === 0) notes.push({ code: 'UNCHANGED' });
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
format,
|
|
220
|
+
scope,
|
|
221
|
+
text,
|
|
222
|
+
items,
|
|
223
|
+
stats: {
|
|
224
|
+
items: items.length,
|
|
225
|
+
changed,
|
|
226
|
+
unchanged: items.length - changed,
|
|
227
|
+
detected,
|
|
228
|
+
words: items.reduce((sum, it) => sum + it.words, 0),
|
|
229
|
+
duplicates: duplicates.length,
|
|
230
|
+
},
|
|
231
|
+
notes,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/* ==================== ここまで変換コア ==================== */
|
|
236
|
+
|
|
237
|
+
// 形式の呼び名(site側の FORMAT_NAMES と同じ)
|
|
238
|
+
const FORMAT_NAMES = {
|
|
239
|
+
camel: 'camelCase',
|
|
240
|
+
pascal: 'PascalCase',
|
|
241
|
+
snake: 'snake_case',
|
|
242
|
+
constant: 'CONSTANT_CASE',
|
|
243
|
+
kebab: 'kebab-case',
|
|
244
|
+
train: 'Train-Case',
|
|
245
|
+
dot: 'dot.case',
|
|
246
|
+
title: 'Title Case',
|
|
247
|
+
sentence: 'Sentence case',
|
|
248
|
+
lower: 'lower case',
|
|
249
|
+
upper: 'UPPER CASE',
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// 形式ごとの主な使いどころ(listFormats で返す。site側の「どの形式を使うか」タブと同じ内容)
|
|
253
|
+
const FORMAT_USES = {
|
|
254
|
+
camel: { ja: 'JavaScript・Java・Swift の変数と関数、JSONのキー', en: 'Variables and functions in JavaScript, Java and Swift; JSON keys' },
|
|
255
|
+
pascal: { ja: 'クラス名・型名、React / Vue のコンポーネント名、C# の公開メンバー', en: 'Class and type names, React / Vue components, public members in C#' },
|
|
256
|
+
snake: { ja: 'Python・Ruby・PHP の変数と関数、SQLのテーブル名と列名', en: 'Variables and functions in Python, Ruby and PHP; SQL tables and columns' },
|
|
257
|
+
constant: { ja: '定数、環境変数(.env)、Makefile の変数', en: 'Constants, environment variables (.env), Makefile variables' },
|
|
258
|
+
kebab: { ja: 'URLのパス、CSSのクラス名、HTMLの属性、npmパッケージ名、ファイル名', en: 'URL paths, CSS classes, HTML attributes, npm package names, file names' },
|
|
259
|
+
train: { ja: 'HTTPヘッダー名(Content-Type / X-Request-Id)', en: 'HTTP header names (Content-Type / X-Request-Id)' },
|
|
260
|
+
dot: { ja: '設定キー(application.properties)、名前空間、ログのフィールド名', en: 'Configuration keys (application.properties), namespaces, log field names' },
|
|
261
|
+
title: { ja: '見出し、表の列見出し、UIのラベル', en: 'Headings, table column headers, UI labels' },
|
|
262
|
+
sentence: { ja: '本文、説明文、フォームのラベル', en: 'Body copy, descriptions, form labels' },
|
|
263
|
+
lower: { ja: '検索用の正規化、タグ', en: 'Normalising for search, tags' },
|
|
264
|
+
upper: { ja: '見出しの強調、印刷物の項目名', en: 'Emphasised headings, printed field names' },
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// 指摘事項のコード → 文。site側は同じコードを日英それぞれの文へ訳している
|
|
268
|
+
const NOTE_TEXT = {
|
|
269
|
+
ja: {
|
|
270
|
+
NOTHING: () => '変換できる文字がありませんでした。',
|
|
271
|
+
DUPLICATE: (n, items) => `変換後に同じ名前になる組が ${n} 件あります: ${items.join(' / ')} — CSVのヘッダーや列名では衝突します。`,
|
|
272
|
+
LEADING_DIGIT: (n) => `結果のうち ${n} 件が数字で始まります。多くの言語では識別子を数字で始められません。`,
|
|
273
|
+
CASELESS: (n) => `大文字・小文字の区別を持たない文字(日本語など)を含む項目が ${n} 件あります。そのまま出力しています。`,
|
|
274
|
+
ACRONYM: (n) => `連続する大文字(ID・URL・XMLなど)を含む項目が ${n} 件あります。既定では Id / Url / Xml へ畳みます(keepAcronyms=true で残せます)。`,
|
|
275
|
+
UNCHANGED: () => 'すべての項目がすでにこの形式でした(変更はありません)。',
|
|
276
|
+
TRUNCATED: (n) => `項目が多いため、items には先頭 ${n} 件だけを入れています(text は全件を変換済みです)。`,
|
|
277
|
+
},
|
|
278
|
+
en: {
|
|
279
|
+
NOTHING: () => 'There was nothing to convert.',
|
|
280
|
+
DUPLICATE: (n, items) => `${n} name(s) end up identical after conversion: ${items.join(' / ')} — CSV headers and column names will collide.`,
|
|
281
|
+
LEADING_DIGIT: (n) => `${n} result(s) start with a digit. Most languages do not allow an identifier to start with a number.`,
|
|
282
|
+
CASELESS: (n) => `${n} item(s) contain characters that have no upper/lower case (Japanese, for example). They are passed through unchanged.`,
|
|
283
|
+
ACRONYM: (n) => `${n} item(s) contain a run of capitals (ID, URL, XML…), which is folded to Id / Url / Xml by default (keepAcronyms=true keeps them).`,
|
|
284
|
+
UNCHANGED: () => 'Every item was already written in this case, so nothing changed.',
|
|
285
|
+
TRUNCATED: (n) => `Only the first ${n} items are listed in items (text holds the full conversion).`,
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const MAX_ITEMS = 200; // items 配列に載せる上限(text は常に全件変換する)
|
|
290
|
+
const MAX_ALL_FORMATS = 20; // allFormats で全形式を展開する上限
|
|
291
|
+
|
|
292
|
+
export class CaseConvertError extends Error {}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* テキスト(または UTF-8 のテキストファイル)の識別子を、指定したケースへ変換する。
|
|
296
|
+
*
|
|
297
|
+
* @param {object} opts
|
|
298
|
+
* @param {string} [opts.text] 変換するテキスト(path と排他)
|
|
299
|
+
* @param {string} [opts.path] 変換するファイルの絶対パス(UTF-8として読む)
|
|
300
|
+
* @param {string} [opts.outputPath] 結果を書き出す絶対パス(指定すると text は返さない)
|
|
301
|
+
* @param {string} [opts.format='camel'] 変換先(camel/pascal/snake/constant/kebab/train/dot/title/sentence/lower/upper)
|
|
302
|
+
* @param {'lines'|'items'|'whole'} [opts.scope='lines'] 1行1件 / 行内をカンマ・タブで分ける / 全体で1件
|
|
303
|
+
* @param {boolean} [opts.splitDigits=false] 数字を独立した語として扱う(sha256 → sha_256)
|
|
304
|
+
* @param {boolean} [opts.keepAcronyms=false] 頭字語を大文字のまま残す(parseXMLData)
|
|
305
|
+
* @param {boolean} [opts.allFormats=false] 各項目を全形式へ展開して返す
|
|
306
|
+
* @param {boolean} [opts.listFormats=false] 変換せず、形式の一覧と使いどころだけを返す
|
|
307
|
+
* @param {'ja'|'en'} [opts.lang='ja'] 指摘事項の言語
|
|
308
|
+
*/
|
|
309
|
+
export async function caseConvertTool(opts = {}) {
|
|
310
|
+
const lang = opts.lang || 'ja';
|
|
311
|
+
if (lang !== 'ja' && lang !== 'en') throw new CaseConvertError(`lang は ja か en: ${opts.lang}`);
|
|
312
|
+
|
|
313
|
+
if (opts.listFormats) {
|
|
314
|
+
return {
|
|
315
|
+
count: CASE_FORMATS.length,
|
|
316
|
+
formats: CASE_FORMATS.map((id) => ({
|
|
317
|
+
id,
|
|
318
|
+
name: FORMAT_NAMES[id],
|
|
319
|
+
example: CASE_EXAMPLES[id],
|
|
320
|
+
used_for: FORMAT_USES[id][lang],
|
|
321
|
+
})),
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const format = opts.format === undefined ? 'camel' : opts.format;
|
|
326
|
+
if (CASE_FORMATS.indexOf(format) === -1) {
|
|
327
|
+
throw new CaseConvertError(`format は ${CASE_FORMATS.join(' / ')} のいずれか: ${opts.format}`);
|
|
328
|
+
}
|
|
329
|
+
const scope = opts.scope === undefined ? 'lines' : opts.scope;
|
|
330
|
+
if (['lines', 'items', 'whole'].indexOf(scope) === -1) {
|
|
331
|
+
throw new CaseConvertError(`scope は lines / items / whole のいずれか: ${opts.scope}`);
|
|
332
|
+
}
|
|
333
|
+
const hasText = typeof opts.text === 'string';
|
|
334
|
+
if (hasText === Boolean(opts.path)) throw new CaseConvertError('text か path のどちらか一方を渡してください');
|
|
335
|
+
|
|
336
|
+
const input = hasText ? opts.text : await readFile(opts.path, 'utf8');
|
|
337
|
+
const r = caseConvert({
|
|
338
|
+
text: input,
|
|
339
|
+
format,
|
|
340
|
+
scope,
|
|
341
|
+
splitDigits: Boolean(opts.splitDigits),
|
|
342
|
+
keepAcronyms: Boolean(opts.keepAcronyms),
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
const notes = r.notes.slice();
|
|
346
|
+
const shown = r.items.slice(0, MAX_ITEMS);
|
|
347
|
+
if (r.items.length > shown.length) notes.push({ code: 'TRUNCATED', count: shown.length });
|
|
348
|
+
|
|
349
|
+
const items = shown.map((it, i) => {
|
|
350
|
+
const entry = {
|
|
351
|
+
input: it.input,
|
|
352
|
+
output: it.output,
|
|
353
|
+
detected: it.detected,
|
|
354
|
+
words: it.words,
|
|
355
|
+
};
|
|
356
|
+
if (opts.allFormats && i < MAX_ALL_FORMATS) {
|
|
357
|
+
const words = splitWords(it.input, { splitDigits: Boolean(opts.splitDigits) });
|
|
358
|
+
entry.all = {};
|
|
359
|
+
for (const key of CASE_FORMATS) {
|
|
360
|
+
entry.all[key] = joinWords(words, key, { keepAcronyms: Boolean(opts.keepAcronyms) });
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return entry;
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
const result = {
|
|
367
|
+
format,
|
|
368
|
+
format_name: FORMAT_NAMES[format],
|
|
369
|
+
scope,
|
|
370
|
+
source: hasText ? { type: 'text' } : { path: opts.path, name: basename(opts.path) },
|
|
371
|
+
text: r.text,
|
|
372
|
+
items,
|
|
373
|
+
stats: r.stats,
|
|
374
|
+
options: {
|
|
375
|
+
split_digits: Boolean(opts.splitDigits),
|
|
376
|
+
keep_acronyms: Boolean(opts.keepAcronyms),
|
|
377
|
+
},
|
|
378
|
+
notes: notes.map((n) => ({
|
|
379
|
+
code: n.code,
|
|
380
|
+
message: NOTE_TEXT[lang][n.code] ? NOTE_TEXT[lang][n.code](n.count, n.items || []) : n.code,
|
|
381
|
+
})),
|
|
382
|
+
};
|
|
383
|
+
if (opts.outputPath) {
|
|
384
|
+
await writeFile(opts.outputPath, r.text, 'utf8');
|
|
385
|
+
result.output = opts.outputPath;
|
|
386
|
+
// ファイルに書けたなら本文は重複した重い情報でしかない
|
|
387
|
+
delete result.text;
|
|
388
|
+
}
|
|
389
|
+
return result;
|
|
390
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@first-ch/tools-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "First CH Tools の計算ロジック(WCAGコントラスト比・文字数/Xウェイト・WebP変換・JSON-LD生成・llms.txt生成・文字コード/改行コード変換・Marp Markdown→スライド レンダリング・テストデータ生成・テキスト/コード差分・Cron式の解説・Base64/Data URI変換・URLパラメータの分解/再構築・HTML特殊文字のエスケープ/エンティティのデコード・JSON⇄YAMLの相互変換・px⇄rem/emの単位換算とCSSの一括変換・カラーコードの相互変換とアルファ透過の合成・MD5/SHA-1/SHA-256/SHA-384/SHA-512のハッシュ生成と照合・JWTのデコードと有効期限/署名の検証・User-Agent文字列の解析とデバイス判定・UUID v4/ULIDの一括生成・アスペクト比の計算とレスポンシブサイズの算出・TSV/CSVからMarkdownテーブルへの整形と相互変換・SQLクエリの整形と予約語の大文字化・URL/テキストからのQRコード生成・UNIXタイムスタンプと日時表記の相互変換・robots.txtの生成(AI
|
|
3
|
+
"version": "0.26.0",
|
|
4
|
+
"description": "First CH Tools の計算ロジック(WCAGコントラスト比・文字数/Xウェイト・WebP変換・JSON-LD生成・llms.txt生成・文字コード/改行コード変換・Marp Markdown→スライド レンダリング・テストデータ生成・テキスト/コード差分・Cron式の解説・Base64/Data URI変換・URLパラメータの分解/再構築・HTML特殊文字のエスケープ/エンティティのデコード・JSON⇄YAMLの相互変換・px⇄rem/emの単位換算とCSSの一括変換・カラーコードの相互変換とアルファ透過の合成・MD5/SHA-1/SHA-256/SHA-384/SHA-512のハッシュ生成と照合・JWTのデコードと有効期限/署名の検証・User-Agent文字列の解析とデバイス判定・UUID v4/ULIDの一括生成・アスペクト比の計算とレスポンシブサイズの算出・TSV/CSVからMarkdownテーブルへの整形と相互変換・SQLクエリの整形と予約語の大文字化・URL/テキストからのQRコード生成・UNIXタイムスタンプと日時表記の相互変換・robots.txtの生成(AIクローラーの許可プリセット付き)・文字列のケース変換(camelCase/snake_case/kebab-case など11形式))をMCPツールとして提供するサーバー",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"firstch-tools-mcp": "server.mjs"
|
|
@@ -141,7 +141,14 @@
|
|
|
141
141
|
"gptbot",
|
|
142
142
|
"claudebot",
|
|
143
143
|
"ai-crawler",
|
|
144
|
-
"web-crawler"
|
|
144
|
+
"web-crawler",
|
|
145
|
+
"case-converter",
|
|
146
|
+
"camelcase",
|
|
147
|
+
"snake-case",
|
|
148
|
+
"kebab-case",
|
|
149
|
+
"pascalcase",
|
|
150
|
+
"identifier",
|
|
151
|
+
"rename"
|
|
145
152
|
],
|
|
146
153
|
"author": "First CH LLC (https://first-ch.com)",
|
|
147
154
|
"homepage": "https://tools.first-ch.com",
|
|
@@ -183,6 +190,7 @@
|
|
|
183
190
|
"qr.mjs",
|
|
184
191
|
"unixtime.mjs",
|
|
185
192
|
"robots-txt.mjs",
|
|
193
|
+
"case-convert.mjs",
|
|
186
194
|
"vendor/",
|
|
187
195
|
"README.md",
|
|
188
196
|
"LICENSE"
|
package/server.mjs
CHANGED
|
@@ -28,6 +28,7 @@ import { sqlFormatTool } from './sql-format.mjs';
|
|
|
28
28
|
import { qrGenerateTool } from './qr.mjs';
|
|
29
29
|
import { unixtimeConvert } from './unixtime.mjs';
|
|
30
30
|
import { robotsTxtGenerate } from './robots-txt.mjs';
|
|
31
|
+
import { caseConvertTool } from './case-convert.mjs';
|
|
31
32
|
|
|
32
33
|
const { version } = createRequire(import.meta.url)('./package.json');
|
|
33
34
|
const server = new McpServer({ name: 'firstch-tools', version });
|
|
@@ -1195,4 +1196,49 @@ server.registerTool(
|
|
|
1195
1196
|
},
|
|
1196
1197
|
);
|
|
1197
1198
|
|
|
1199
|
+
server.registerTool(
|
|
1200
|
+
'case_convert',
|
|
1201
|
+
{
|
|
1202
|
+
title: '文字列のケース変換(camelCase / snake_case / kebab-case)',
|
|
1203
|
+
description:
|
|
1204
|
+
'識別子を camelCase / PascalCase / snake_case / CONSTANT_CASE / kebab-case と、Train-Case・dot.case・' +
|
|
1205
|
+
'Title Case・Sentence case・lower case・UPPER CASE を合わせた11形式へ相互変換する' +
|
|
1206
|
+
'(tools.first-ch.com/case/ と同一ロジック)。変数名の一括リネーム、DBの列名とAPIのJSONキーの読み替え、' +
|
|
1207
|
+
'CSVヘッダーの整形といった定型処理に使う。' +
|
|
1208
|
+
'scope で処理の単位を選ぶ: lines(既定=1行1件) / items(行内のカンマ・タブ区切りで1件ずつ=CSVヘッダー) / whole(全体で1件)。' +
|
|
1209
|
+
'**前後の空白・インデント・改行コード(LF/CRLF)・区切り記号はそのまま残す**ので、表の列やコードの並びを崩さずに名前だけ置き換わる。' +
|
|
1210
|
+
'語の分かち書きは、大文字の連なりの直後に「大文字+小文字」が続くときだけ手前で切る(XMLHttpRequest → XML / Http / Request)。' +
|
|
1211
|
+
'数字は既定で直前の語に付ける(sha256Hash → sha256 / Hash。splitDigits=true で sha / 256 / Hash)。' +
|
|
1212
|
+
'頭字語は既定で畳んで parseXmlData にし、keepAcronyms=true なら parseXMLData のまま残す' +
|
|
1213
|
+
'(camelCase の先頭語はどちらでも小文字=URLParser → urlParser)。' +
|
|
1214
|
+
'大文字小文字を持たない文字(日本語など)はそのまま出力し、ローマ字化はしない。' +
|
|
1215
|
+
'**変換後に同じ名前へ衝突する項目**(first name と first_name はどちらも first_name)・数字で始まって識別子にできない結果・' +
|
|
1216
|
+
'頭字語を含む項目・入力の形式の推定を notes と stats で返す。' +
|
|
1217
|
+
'allFormats=true で各項目を全形式へ展開、listFormats=true で変換せず形式の一覧と使いどころだけを返す。' +
|
|
1218
|
+
'outputPath を渡すとそのパスへ書き出す。完全ローカル処理・ネットワーク送信なし。',
|
|
1219
|
+
inputSchema: {
|
|
1220
|
+
text: z.string().optional().describe('変換するテキスト(path と排他。複数行可)'),
|
|
1221
|
+
path: z.string().optional().describe('変換するファイルの絶対パス(UTF-8として読む。text と排他)'),
|
|
1222
|
+
outputPath: z.string().optional().describe('結果を書き出す絶対パス(指定すると本文は返さない)'),
|
|
1223
|
+
format: z
|
|
1224
|
+
.enum(['camel', 'pascal', 'snake', 'constant', 'kebab', 'train', 'dot', 'title', 'sentence', 'lower', 'upper'])
|
|
1225
|
+
.optional()
|
|
1226
|
+
.describe("変換先の形式(既定 'camel')"),
|
|
1227
|
+
scope: z
|
|
1228
|
+
.enum(['lines', 'items', 'whole'])
|
|
1229
|
+
.optional()
|
|
1230
|
+
.describe("処理の単位(既定 'lines'=1行1件 / 'items'=行内のカンマ・タブ区切り / 'whole'=全体で1件)"),
|
|
1231
|
+
splitDigits: z.boolean().optional().describe('数字の前で語を区切る(既定 false=sha256 は1語)'),
|
|
1232
|
+
keepAcronyms: z.boolean().optional().describe('頭字語を大文字のまま残す(既定 false=Id / Url / Xml へ畳む)'),
|
|
1233
|
+
allFormats: z.boolean().optional().describe('各項目を11形式すべてへ展開して返す(先頭20件まで)'),
|
|
1234
|
+
listFormats: z.boolean().optional().describe('変換せず、形式の一覧(名前・例・使いどころ)だけを返す'),
|
|
1235
|
+
lang: z.enum(['ja', 'en']).optional().describe("指摘事項の言語(既定 'ja')"),
|
|
1236
|
+
},
|
|
1237
|
+
},
|
|
1238
|
+
async (opts) => {
|
|
1239
|
+
await logUsage('case_convert');
|
|
1240
|
+
return asText(await caseConvertTool(opts));
|
|
1241
|
+
},
|
|
1242
|
+
);
|
|
1243
|
+
|
|
1198
1244
|
await server.connect(new StdioServerTransport());
|