For AI agents: the complete documentation index is available at https://canary.gukhanmun.org/llms.txt, the full documentation bundle is available at https://canary.gukhanmun.org/llms-full.txt, and this page is available as Markdown at https://canary.gukhanmun.org/guide/javascript/dictionary.md.

Dictionaries

Pass an array of DictionarySource objects in the dictionaries option. Dictionary sources are either compiled artifacts (FileDictionarySource) or entry lists computed at runtime (MapDictionarySource). The default reference-authorized policy ranks candidates by source role and explicit dictionary relations. Use sourcePolicy: "ordered" for legacy array precedence.

Standard Korean Dictionary packages

@gukhanmun/stdict-fst and @gukhanmun/stdict-cdb both ship the bundled Standard Korean Dictionary (標準國語大辭典) in different binary formats.

import { 
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
} from "@gukhanmun/wasm";
import {
function stdictFst(): Promise<FileDictionarySource>

Loads the bundled Standard Korean Language Dictionary as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "fst" and role: "reference".
stdictFst
} from "@gukhanmun/stdict-fst";
import {
function stdictCdb(): Promise<FileDictionarySource>

Loads the bundled Standard Korean Language Dictionary as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "cdb" and role: "reference".
stdictCdb
} from "@gukhanmun/stdict-cdb";
// FST — preferred; smaller on disk, better for lattice segmentation const
const g: Gukhanmun
g
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [await
function stdictFst(): Promise<FileDictionarySource>

Loads the bundled Standard Korean Language Dictionary as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "fst" and role: "reference".
stdictFst
()] });
// CDB — indexed lookup; simpler on-disk layout const
const g: Gukhanmun
g
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [await
function stdictCdb(): Promise<FileDictionarySource>

Loads the bundled Standard Korean Language Dictionary as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "cdb" and role: "reference".
stdictCdb
()] });

Both stdictFst() and stdictCdb() return a Promise<FileDictionarySource>.

Reuse a loaded dictionary

Call loadDictionary() once when several converters use the same dictionary. Import it from the same package as load(): either @gukhanmun/wasm or @gukhanmun/napi.

import { 
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
,
function loadDictionary(source: DictionarySource): Promise<LoadedDictionary>

Loads one immutable dictionary snapshot for reuse by this backend.

loadDictionary
} from "@gukhanmun/wasm";
import {
function stdictFst(): Promise<FileDictionarySource>

Loads the bundled Standard Korean Language Dictionary as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "fst" and role: "reference".
stdictFst
} from "@gukhanmun/stdict-fst";
const
const reference: LoadedDictionary
reference
= await
function loadDictionary(source: DictionarySource): Promise<LoadedDictionary>

Loads one immutable dictionary snapshot for reuse by this backend.

loadDictionary
(await
function stdictFst(): Promise<FileDictionarySource>

Loads the bundled Standard Korean Language Dictionary as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "fst" and role: "reference".
stdictFst
());
const
const overrides: {
    entries: {
        hanja: string;
        reading: string;
    }[];
}
overrides
= {
entries: {
    hanja: string;
    reading: string;
}[]
entries
: [{
hanja: string
hanja
: "東京",
reading: string
reading
: "도쿄" }] };
const
const plain: Gukhanmun
plain
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [
const overrides: {
    entries: {
        hanja: string;
        reading: string;
    }[];
}
overrides
,
const reference: LoadedDictionary
reference
] });
const
const ruby: Gukhanmun
ruby
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [
const overrides: {
    entries: {
        hanja: string;
        reading: string;
    }[];
}
overrides
,
const reference: LoadedDictionary
reference
],
rendering?: RenderMode | undefined

How annotations are rendered into output text or markup. Defaults to "hangul-only".

@seeRenderMode
rendering
: "ruby-on-hangul",
});

The handle captures the source's contents and role. Each converter retains its own reference and applies its own source order and options. Load a new handle to pick up source changes. Handles cannot be moved between backend instances; there is no process-wide dictionary cache.

Use GukhanmunLoadOptions to annotate options containing handles. GukhanmunOptions and GukhanmunFactory still describe raw-source inputs.

Open Korean Dictionary packages

@gukhanmun/opendict-fst and @gukhanmun/opendict-cdb ship the Open Korean Dictionary (우리말샘) as separate general (一般語), North Korean (北韓語), dialect (方言), and archaic (옛말) category dictionaries. JavaScript presets do not auto-load these packages, so pass the categories you want explicitly:

import { 
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
} from "@gukhanmun/wasm";
import {
function opendictDialectFst(): Promise<FileDictionarySource>

Loads the bundled Open Korean Dictionary 방언 dictionary.

@returnsA FileDictionarySource with format: "fst" and role: "reference".
opendictDialectFst
,
function opendictNorthKoreanFst(): Promise<FileDictionarySource>

Loads the bundled Open Korean Dictionary 북한어 dictionary.

@returnsA FileDictionarySource with format: "fst" and role: "reference".
opendictNorthKoreanFst
,
} from "@gukhanmun/opendict-fst"; const
const g: Gukhanmun
g
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
preset?: Preset | undefined

Named configuration preset. Defaults to "ko-kr".

@seePreset
preset
: "ko-kp",
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [
await
function opendictNorthKoreanFst(): Promise<FileDictionarySource>

Loads the bundled Open Korean Dictionary 북한어 dictionary.

@returnsA FileDictionarySource with format: "fst" and role: "reference".
opendictNorthKoreanFst
(),
await
function opendictDialectFst(): Promise<FileDictionarySource>

Loads the bundled Open Korean Dictionary 방언 dictionary.

@returnsA FileDictionarySource with format: "fst" and role: "reference".
opendictDialectFst
(),
], });

Use the CDB package when you want the same categories in CDB format:

import { 
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

The native addon is synchronously ready; compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched or read from disk, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
} from "@gukhanmun/napi";
import {
function opendictNorthKoreanCdb(): Promise<FileDictionarySource>

Loads the bundled Open Korean Dictionary 북한어 dictionary.

@returnsA FileDictionarySource with format: "cdb" and role: "reference".
opendictNorthKoreanCdb
} from "@gukhanmun/opendict-cdb";
const
const g: Gukhanmun
g
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

The native addon is synchronously ready; compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched or read from disk, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
preset?: Preset | undefined

Named configuration preset. Defaults to "ko-kr".

@seePreset
preset
: "ko-kp",
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [await
function opendictNorthKoreanCdb(): Promise<FileDictionarySource>

Loads the bundled Open Korean Dictionary 북한어 dictionary.

@returnsA FileDictionarySource with format: "cdb" and role: "reference".
opendictNorthKoreanCdb
()],
});

Loanword spelling examples packages

@gukhanmun/loanwords-fst and @gukhanmun/loanwords-cdb provide the National Institute of Korean Language's Loanword spelling examples dictionary. Both "ko-kr" and "ko-kp" require explicit loading; presets never add it for you. The official loaders identify reference and loanword sources, so their relative order does not change which source class takes priority under the default "reference-authorized" policy:

import { 
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
} from "@gukhanmun/wasm";
import {
function loanwordsFst(): Promise<FileDictionarySource>

Loads the bundled NIKL loanword examples as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "fst" and role: "loanword".
loanwordsFst
} from "@gukhanmun/loanwords-fst";
import {
function stdictFst(): Promise<FileDictionarySource>

Loads the bundled Standard Korean Language Dictionary as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "fst" and role: "reference".
stdictFst
} from "@gukhanmun/stdict-fst";
const
const g: Gukhanmun
g
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
preset?: Preset | undefined

Named configuration preset. Defaults to "ko-kr".

@seePreset
preset
: "ko-kr",
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [await
function loanwordsFst(): Promise<FileDictionarySource>

Loads the bundled NIKL loanword examples as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "fst" and role: "loanword".
loanwordsFst
(), await
function stdictFst(): Promise<FileDictionarySource>

Loads the bundled Standard Korean Language Dictionary as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "fst" and role: "reference".
stdictFst
()],
});
const g: Gukhanmun
g
.
Gukhanmun.convert(source: string, format?: MediaType): string (+2 overloads)

Converts source to hangul in one shot. Buffers the entire input before returning.

@paramsource - The text to convert.@paramformat - Input/output media type. Defaults to "text/plain".@returnsThe converted text.@throws{@linkGukhanmunError } on conversion failure.
convert
("香港"); // "홍콩"

For CDB format, import loanwordsCdb from @gukhanmun/loanwords-cdb instead. Both loaders return a Promise<FileDictionarySource> and work with @gukhanmun/wasm and @gukhanmun/napi. Installing the package alone does not change conversion; include its loader's result in dictionaries.

Custom dictionaries

A FileDictionarySource specifies the binary format and the data to load from:

interface FileDictionarySource {
  
FileDictionarySource.format: "fst" | "cdb"
format
: "fst" | "cdb";
FileDictionarySource.data: string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | URL
data
: ArrayBuffer |
interface ArrayBufferView<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>
ArrayBufferView
| URL | string;
}

The data field accepts:

TypeWhereNotes
ArrayBuffer/ArrayBufferViewAll environmentsBytes already in memory
URLAll environmentsRemote or local URL; loaded via fetch()
stringNode.js, Deno, BunFilesystem path

Load from a URL

const 
const g: Gukhanmun
g
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [{
FileDictionarySource.format: "fst" | "cdb"

The on-disk format of the dictionary file.

  • "fst" — Gukhanmun FST file (*.gukfst); preferred for small WebAssembly bundles. Supported in all runtimes.
  • "cdb" — Gukhanmun CDB-trie file (*.gukcdb); preferred when code auditability or trivial mmap support matters. Requires a filesystem or in-memory bytes; supported in Node-API and (with from_bytes) in WASM builds that include the cdb feature.

The "tsv" format is reserved and never accepted. Pass entries in memory through MapDictionarySource instead of compiling a table.

format
: "fst",
FileDictionarySource.data: string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | URL

The binary dictionary data or a reference to where it can be loaded.

Pass a BufferSource for data already in memory, a URL for a remote or local URL (resolved via fetch or readFile), or a path string for filesystem paths (Node.js / Deno 2.0+ / Bun only).

data
: new
var URL: new (url: string | URL, base?: string | URL) => URL

The URL interface is used to parse, construct, normalize, and encode URLs. It works by providing properties which allow you to easily read and modify the components of a URL.

MDN Reference

URL class is a global reference for import { URL } from 'url' https://nodejs.org/api/url.html#the-whatwg-url-api

@sincev10 .0.0
URL
("./legal.gukfst", import.meta.
ImportMeta.url: string

The absolute file: URL of the module.

This is defined exactly the same as it is in browsers providing the URL of the current module file.

This enables useful patterns such as relative file loading:

import { readFileSync } from 'node:fs';
const buffer = readFileSync(new URL('./data.proto', import.meta.url));
url
),
}], });

In a browser the URL is fetched with fetch(). In Node.js, Deno, and Bun a file:// URL is read from disk.

Load from bytes

const 
const response: Response
response
= await
function fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> (+1 overload)
fetch
("/custom.gukcdb");
const
const buf: ArrayBuffer
buf
= await
const response: Response
response
.
Body.arrayBuffer(): Promise<ArrayBuffer>
arrayBuffer
();
const
const g: Gukhanmun
g
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [{
FileDictionarySource.format: "fst" | "cdb"

The on-disk format of the dictionary file.

  • "fst" — Gukhanmun FST file (*.gukfst); preferred for small WebAssembly bundles. Supported in all runtimes.
  • "cdb" — Gukhanmun CDB-trie file (*.gukcdb); preferred when code auditability or trivial mmap support matters. Requires a filesystem or in-memory bytes; supported in Node-API and (with from_bytes) in WASM builds that include the cdb feature.

The "tsv" format is reserved and never accepted. Pass entries in memory through MapDictionarySource instead of compiling a table.

format
: "cdb",
FileDictionarySource.data: string | URL | ArrayBuffer | ArrayBufferView<ArrayBufferLike>

The binary dictionary data or a reference to where it can be loaded.

Pass a BufferSource for data already in memory, a URL for a remote or local URL (resolved via fetch or readFile), or a path string for filesystem paths (Node.js / Deno 2.0+ / Bun only).

data
:
const buf: ArrayBuffer
buf
}],
});

Load from a file path (Node.js/Deno/Bun)

const 
const g: Gukhanmun
g
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

The native addon is synchronously ready; compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched or read from disk, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [{
FileDictionarySource.format: "fst" | "cdb"

The on-disk format of the dictionary file.

  • "fst" — Gukhanmun FST file (*.gukfst); preferred for small WebAssembly bundles. Supported in all runtimes.
  • "cdb" — Gukhanmun CDB-trie file (*.gukcdb); preferred when code auditability or trivial mmap support matters. Requires a filesystem or in-memory bytes; supported in Node-API and (with from_bytes) in WASM builds that include the cdb feature.

The "tsv" format is reserved and never accepted. Pass entries in memory through MapDictionarySource instead of compiling a table.

format
: "fst",
FileDictionarySource.data: string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | URL

The binary dictionary data or a reference to where it can be loaded.

Pass a BufferSource for data already in memory, a URL for a remote or local URL (resolved via fetch or readFile), or a path string for filesystem paths (Node.js / Deno 2.0+ / Bun only).

data
: "/data/domain.gukfst" }],
});

Passing a plain string path in a browser throws GukhanmunError with code "io".

Combining multiple dictionaries

const 
const g: Gukhanmun
g
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

The native addon is synchronously ready; compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched or read from disk, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [
{
FileDictionarySource.format: "fst" | "cdb"

The on-disk format of the dictionary file.

  • "fst" — Gukhanmun FST file (*.gukfst); preferred for small WebAssembly bundles. Supported in all runtimes.
  • "cdb" — Gukhanmun CDB-trie file (*.gukcdb); preferred when code auditability or trivial mmap support matters. Requires a filesystem or in-memory bytes; supported in Node-API and (with from_bytes) in WASM builds that include the cdb feature.

The "tsv" format is reserved and never accepted. Pass entries in memory through MapDictionarySource instead of compiling a table.

format
: "fst",
FileDictionarySource.data: string | ArrayBuffer | ArrayBufferView<ArrayBufferLike> | URL

The binary dictionary data or a reference to where it can be loaded.

Pass a BufferSource for data already in memory, a URL for a remote or local URL (resolved via fetch or readFile), or a path string for filesystem paths (Node.js / Deno 2.0+ / Bun only).

data
: "/data/legal.gukfst" }, // checked first
await
function stdictFst(): Promise<FileDictionarySource>

Loads the bundled Standard Korean Language Dictionary as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "fst" and role: "reference".
stdictFst
(), // fallback
], });

Building a custom dictionary

The .gukfst and .gukcdb files loaded above are compiled artifacts, built from a plain text table with the gukhanmun-mkdict tool. See Building a custom dictionary in the CLI guide for how to author and compile dictionary sources. When the entries are computed at runtime rather than stored on disk, pass them directly as shown in the next section.

Entries computed at runtime

A MapDictionarySource carries entries in memory. Use it when a caller derives readings while building a document, in a browser, or in an edge runtime where neither a TSV file nor gukhanmun-mkdict is available:

const 
const converter: Gukhanmun
converter
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [
{
MapDictionarySource.entries: readonly DictionaryEntry[]

The entries of this dictionary.

Repeated hanja keys append competing readings instead of replacing each other, and DictionaryEntry.preference decides which reading is the context-free default. Several readings for one key also let the engine pick a reading from a following particle (東京을 versus 東京를).

An empty list contributes nothing, which is a convenient way to express "this document has no overrides".

entries
: [
{
DictionaryEntry.hanja: string

The hanja form (dictionary key), e.g. "漢字".

hanja
: "高橋",
DictionaryEntry.reading: string

The word-initial hangul reading, e.g. "한자".

reading
: "다카하시" },
{
DictionaryEntry.hanja: string

The hanja form (dictionary key), e.g. "漢字".

hanja
: "東京",
DictionaryEntry.reading: string

The word-initial hangul reading, e.g. "한자".

reading
: "도쿄",
DictionaryEntry.preference?: number | undefined

Relative default preference for this reading within its hanja key, a non-negative integer. Larger values win, so an entry listed twice with different preferences keeps competing readings and uses the higher one by default. Absent means 0.

List order never selects the default: when two readings share a preference the tie is broken by reading spelling. Set distinct preferences to choose a default deliberately.

Corresponds to Rust ReadingCandidate::preference.

preference
: 10 },
{
DictionaryEntry.hanja: string

The hanja form (dictionary key), e.g. "漢字".

hanja
: "年代",
DictionaryEntry.reading: string

The word-initial hangul reading, e.g. "한자".

reading
: "연대",
DictionaryEntry.suffixReading?: string | undefined

The reading used when the match is not word-initial, when it differs from

reading . For example a 年代 entry with reading: "연대" and suffixReading: "년대" reads 1990年代 as 1990년대 but 年代 alone as 연대.

Corresponds to Rust ReadingCandidate::suffix_reading.

suffixReading
: "년대" },
], }, await
function stdictFst(): Promise<FileDictionarySource>

Loads the bundled Standard Korean Language Dictionary as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "fst" and role: "reference".
stdictFst
(),
], });

The fields mirror the Rust ReadingCandidate type plus the hanja key:

FieldMeaning
hanjaThe dictionary key
readingThe word-initial hangul reading
suffixReadingThe reading used when the match is not word-initial, when it differs
preferenceRelative default preference within the key; larger wins, absent is 0
requireHanjaAlways show the original hanja alongside the reading
requireHangulAlways show a hangul gloss alongside the original hanja

Entry lists default to the "override" role. Cooperating policies consider them before reference and loanword sources for the same spelling and consumed length; earlier overrides win. With sourcePolicy: "ordered", all sources follow array precedence, so place the entry list before a compiled dictionary to override that dictionary's keys in this mode.

Repeating a hanja key appends another reading instead of replacing the earlier one. Several readings for one headword stay available to the engine, which then selects one from a following particle when the particle is decisive:

const 
const g: Gukhanmun
g
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [
{
MapDictionarySource.entries: readonly DictionaryEntry[]

The entries of this dictionary.

Repeated hanja keys append competing readings instead of replacing each other, and DictionaryEntry.preference decides which reading is the context-free default. Several readings for one key also let the engine pick a reading from a following particle (東京을 versus 東京를).

An empty list contributes nothing, which is a convenient way to express "this document has no overrides".

entries
: [
{
DictionaryEntry.hanja: string

The hanja form (dictionary key), e.g. "漢字".

hanja
: "東京",
DictionaryEntry.reading: string

The word-initial hangul reading, e.g. "한자".

reading
: "동경" },
{
DictionaryEntry.hanja: string

The hanja form (dictionary key), e.g. "漢字".

hanja
: "東京",
DictionaryEntry.reading: string

The word-initial hangul reading, e.g. "한자".

reading
: "도쿄",
DictionaryEntry.preference?: number | undefined

Relative default preference for this reading within its hanja key, a non-negative integer. Larger values win, so an entry listed twice with different preferences keeps competing readings and uses the higher one by default. Absent means 0.

List order never selects the default: when two readings share a preference the tie is broken by reading spelling. Set distinct preferences to choose a default deliberately.

Corresponds to Rust ReadingCandidate::preference.

preference
: 10 },
], }, ], });
const g: Gukhanmun
g
.
Gukhanmun.convert(source: string, format?: MediaType): string (+2 overloads)

Converts source to hangul in one shot. Buffers the entire input before returning.

@paramsource - The text to convert.@paramformat - Input/output media type. Defaults to "text/plain".@returnsThe converted text.@throws{@linkGukhanmunError } on conversion failure.
convert
("東京"); // "도쿄": the higher preference
const g: Gukhanmun
g
.
Gukhanmun.convert(source: string, format?: MediaType): string (+2 overloads)

Converts source to hangul in one shot. Buffers the entire input before returning.

@paramsource - The text to convert.@paramformat - Input/output media type. Defaults to "text/plain".@returnsThe converted text.@throws{@linkGukhanmunError } on conversion failure.
convert
("東京을"); // "동경을": the particle selects the other reading
const g: Gukhanmun
g
.
Gukhanmun.convert(source: string, format?: MediaType): string (+2 overloads)

Converts source to hangul in one shot. Buffers the entire input before returning.

@paramsource - The text to convert.@paramformat - Input/output media type. Defaults to "text/plain".@returnsThe converted text.@throws{@linkGukhanmunError } on conversion failure.
convert
("東京를"); // "도쿄를"

preference decides the context-free default. List order never does: when two readings share a preference, the tie is broken by reading spelling, so set distinct preferences when the choice matters.

An empty entries list contributes nothing, which makes { entries: [] } a convenient placeholder for a document without overrides.

Cooperating sources

The default reference-authorized policy keeps reference and loanword candidate sets separate. A reference candidate authorizes a foreign form only when the source dictionary explicitly records the relevant synonym or formal redirect. The offline compiler intersects the permissions of every contributing sense; a shared hanja key or reading alone grants no permission. Missing evidence retains the reference form. Thus 東扶餘 reads 동부여, while the reference entry for 香港 authorizes 홍콩.

The resolver ranks complete forms before applying particle evidence once to the whole pool. An independent loanword can still match a particle even when it is not the default: 平 reads 평, but 平를 can select 다이라를. Dictionary preferences apply within each source; they are not comparable across sources. The lattice objective is unchanged.

PolicySource behavior
reference-authorizedAuthorized loanword forms, reference redirect/original forms, then independent loanwords
reference-firstOriginal reference forms before independent loanwords
loanword-firstIndependent loanwords before original reference forms
orderedLegacy dictionary array order; ignores roles and authorization

An authored override is exclusive for the same spelling and consumed length under every cooperating policy. It does not remove a longer dictionary match. For cooperating policies, referenceOnly removes independent loanwords from eligibility but retains reference-authorized forms, including forms supplied by a loanword dictionary.

Selected forms carry their own lexical identity, alias, positional form and annotation marks. First-occurrence handling uses the reference anchor when a reference authorizes a foreign form; homophone handling compares the reading actually emitted. Source-aware dictionary matches keep separate annotation boundaries, including matches next to fallback characters. This can change parenthetical grouping compared with ordered.

Set the policy and eligibility on the converter:

const 
const converter: Gukhanmun
converter
= await
function load(options?: GukhanmunLoadOptions): Promise<Gukhanmun>

Creates a Gukhanmun converter with the given options.

Initialises the WASM module on the first call (subsequent calls reuse the cached module). Compiled dictionaries supplied via GukhanmunOptions.dictionaries are fetched, while MapDictionarySource entry lists are serialised and built in memory as Rust MapDictionary values.

Note: unlike the Rust ko-kr preset, the JavaScript preset never includes a bundled dictionary. Pass dictionaries: [await stdictFst()] to include the Standard Korean Language Dictionary.

@paramoptions - Conversion options. All fields are optional; defaults match the ko-kr preset.@returnsA Gukhanmun instance.@throws{@linkGukhanmunError } on invalid options or dictionary load failure.
load
({
sourcePolicy?: SourcePolicy | undefined

Source cooperation policy. Defaults to "reference-authorized".

sourcePolicy
: "reference-authorized",
referenceOnly?: boolean | undefined

Excludes independent loanword choices while retaining reference-authorized realizations. Defaults to false; ignored by the "ordered" policy.

referenceOnly
: true,
dictionaries?: readonly (DictionarySource | LoadedDictionary)[] | undefined
dictionaries
: [await
function stdictFst(): Promise<FileDictionarySource>

Loads the bundled Standard Korean Language Dictionary as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "fst" and role: "reference".
stdictFst
(), await
function loanwordsFst(): Promise<FileDictionarySource>

Loads the bundled NIKL loanword examples as a

FileDictionarySource ready to pass to load({ dictionaries: [...] }).

@returnsA FileDictionarySource with format: "fst" and role: "loanword".
loanwordsFst
()],
});

Both file and entry descriptors accept role: "override" | "reference" | "loanword". Entry descriptors default to "override". File descriptors use the binary's embedded role when present, otherwise "override"; an explicit role replaces that metadata. Official loaders declare their roles. Overrides are considered before cooperating sources regardless of their array position; earlier overrides win. Set sourcePolicy: "ordered" to restore legacy array precedence for all descriptors.

The standard CDB loader downloads stdict.cdb.gz and decompresses it before returning a dictionary descriptor. A custom URL can serve either gzip or raw CDB bytes. The npm package retains the raw stdict.cdb export.

Dictionary roles do not change the lattice scoring objective. The JavaScript bindings buffer the complete document before conversion; see Streaming API.