hapin-utils
v5.0.0
Published
Hapin JavaScript(TypeScript) 开放工具包
Readme
hapin-utils
TypeScript utilities for Hapin, Kazakh Arabic/Cyrillic letters, and broad IPA_CNA.
Version
This documentation targets hapin-utils 5.0.0, with the context-v1 segmentation rules and compatibility wrappers for existing applications.
npm install [email protected]For migration from 4.x, review the compatibility notes below and CHANGELOG.md. Source-letter conversion is corrected in both API families; existing Hapin wrappers retain legacy segmentation.
New API
import { analyzeHapin, convert } from 'hapin-utils'
analyzeHapin('arzangha').units.filter(u => u.kind === 'letter').map(u => u.id)
// ['a', 'r', 'z', 'a', 'n', 'gh', 'a']
convert('арзанға', { from: 'cyrillic', to: 'arabic' }).text
// ارزانعا
convert('shanghai', { from: 'hapin', to: 'arabic' }).text
// شاڭحايconvert supports Hapin→Arabic/IPA_CNA, Arabic→Hapin/IPA_CNA, and Cyrillic→Hapin/Arabic/IPA_CNA. Other directions return status: 'error' and text: null.
The new API preserves whitespace, quoted literals, unknown characters and ordinary zero-width characters. It does not generate hidden boundary markers. Select inputFormat: 'legacy-boundaries' only when importing old machine-separated Hapin.
rules: 'context-v1' (default) ranks ngh as n+gh, with source-attested word-form exceptions such as shanghai. ngul and ngye keep competing analyses. status: 'ambiguous' has a preferred text plus bounded local alternatives; alternatives each replace one conflict, not every possible combination. maxCandidates is 1–64 (default 8, including the preferred path). Truncation is reported.
errors: 'strict' rejects warning diagnostics, including unresolved segmentation, unclosed quotes and unknown characters. Inspect diagnostics and losses: simplified Hapin cannot preserve every source spelling distinction. Spans are UTF-16 [start,end) offsets.
You may pass an analysis to convert(analysis, { from: analysis.source, to: 'arabic' }). To render a different candidate, replace units with a returned alternative's units; the original diagnostics remain available.
Existing functions
The seven transform* functions and three Array functions retain their signatures. They now share the structured source parser and word-local renderers. Hapin wrappers retain legacy segmentation: transformHapinToArabic('ngh') remains ڭح; use convert for the context rules.
clean=false keeps old U+200B serialization. transformArabicToHapin(input, clean, easy) additionally retains the legacy apostrophe display mode. Apostrophes are not a new input-boundary syntax. Array interfaces split that old serialization; use analyzeHapin().units for explicit letter units.
Source-boundary, quote, front-vowel and word-scope bugs are fixed even through the wrappers. Unknown y is preserved instead of silently discarded. These corrections can change previously incorrect output.
Development
pnpm test
pnpm typecheck
pnpm docs:generate
pnpm checkdocs-data/api-examples.json is generated from the built package and checked for staleness. The website consumes a fixed snapshot with the same package version, release channel and rules version. releaseStatus: 'stable' identifies the version channel; it does not indicate whether npm publication has already occurred. Raw desktop dictionaries are not included in the package or required by CI.
Release
Generate versioned documentation with pnpm docs:generate, authenticate with npm login --auth-type=web --registry=https://registry.npmjs.org/, then run pnpm publish:check and npm publish --dry-run. prepublishOnly first verifies the npm identity and listed maintainer, then runs the test, type, build, documentation and package-entry checks. Token-specific write scope and 2FA are still checked by npm during actual publication; a dry-run alone cannot prove those permissions. The actual publication is a separate npm publish command, run by the maintainer after reviewing the package contents. See docs/releasing.zh-CN.md for the release checklist.
