Skip to content

@jsvision/i18n / jsonFileSource

Function: jsonFileSource()

jsonFileSource(input): CatalogSource

Defined in: json-file-source.ts:285

Create a Node-only source for rooted schema-1 JSON catalog files.

Paths use a portable relative grammar. Literal files retain declaration order and an immediate *.json glob expands lexically in place. Every file is canonicalized below the mandatory root, opened as a checked regular handle, read within its byte limit, decoded as fatal UTF-8, parsed with duplicate detection, and validated before the source returns any catalog. A source expands no more than 10,000 files and accepts no more than 16 MiB of checked file content in aggregate.

Parameters

input

JsonFileSourceOptions

Root, paths, required classification, and optional lower resource limits.

Returns

CatalogSource

Caller-independent catalog source suitable for loadI18n.

Throws

I18nError when factory options or attempted limit increases are invalid.

Example

ts
import { fileURLToPath } from 'node:url';

const source = jsonFileSource({
  root: fileURLToPath(new URL('./locales', import.meta.url)),
  paths: ['en.json', 'packages/*.json'],
});