konjingjing

December 14, 2025 · View on GitHub

Thai Citizen ID validation library available in Rust, Python, Node.js, and WebAssembly.

The library name 'kon-jing-jing' (คนจริงจริง) means 'real person' in Thai.

📖 Documentation

Packages

LanguagePackageInstall
Rustpackages/konjingjingcargo add konjingjing
Pythonpackages/konjingjing-pythonpip install konjingjing
Node.jspackages/konjingjing-nodenpm install konjingjing
WASMpackages/konjingjing-wasmnpm install konjingjing-wasm

Node.js vs WASM: Which to use?

Use CasePackageWhy
Node.js / Bun / DenokonjingjingNative binding, fastest performance
Browserkonjingjing-wasmRuns in browser, no server needed
Edge / Serverlesskonjingjing-wasmPortable, no native dependencies
Cloudflare Workerskonjingjing-wasmWASM supported, native bindings not

TL;DR: Use konjingjing for server-side Node.js. Use konjingjing-wasm for browsers and edge runtimes.

API

All packages export these functions:

verify_id(id: string) -> boolean

Validates a Thai National ID checksum.

get_id_meaning(id: string) -> IdMeaning | null

Extracts meaning from a Thai National ID:

FieldTypeDescription
person_type_codenumberPerson type (1-8)
person_type_descriptionstringThai description
person_type_description_enstringEnglish description
province_codenumber?Province code (10-96)
province_name_thstring?Thai province name
province_name_enstring?English province name
amphoe_codenumber?District code
amphoe_namestring?District name (Thai)
is_validbooleanChecksum validity

Returns null if the ID format is invalid (not 13 digits).

Development

Uses mise for task running.

mise run test          # Run all tests
mise run test:rust     # Run Rust tests
mise run test:python   # Run Python tests
mise run test:node     # Run Node tests

Algorithm

  1. Validate input is exactly 13 digits
  2. Calculate weighted checksum: sum(digit[i] * (13 - i)) for i in 0..12
  3. Verify: (11 - sum % 11) % 10 == digit[12]

Support

Ko-fi

License

ISC