{"_rev":"3-5b666ca60f05834d871b93124135f781","time":{"created":"2026-07-08T10:14:25.110Z","modified":"2026-07-08T10:14:25.577Z","1.0.0":"2026-07-08T09:57:26.205Z","1.0.1":"2026-07-08T10:14:25.380Z"},"_id":"@chettapong/dayjs-plugin-buddhist-localized-format","name":"@chettapong/dayjs-plugin-buddhist-localized-format","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@chettapong/dayjs-plugin-buddhist-localized-format","version":"1.0.1","description":"Day.js plugin combining Buddhist Era (B.E.) year conversion with LocalizedFormat tokens, with a per-call override option.","keywords":["dayjs","dayjs-plugin","buddhist-era","localized-format","thai","date"],"bugs":{"url":"https://github.com/chettapong/dayjs-plugin-buddhist-localized-format/issues"},"repository":{"type":"git","url":"git+https://github.com/chettapong/dayjs-plugin-buddhist-localized-format.git"},"license":"MIT","type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"scripts":{"build":"tsup src/index.ts --format esm,cjs --dts --clean","test":"vitest run","test:watch":"vitest","typecheck":"tsc --noEmit","lint":"eslint .","lint:fix":"eslint . --fix","format":"prettier --write .","format:check":"prettier --check .","prepublishOnly":"bun run build","release":"bun run lint && bun run test && bun run build && bunx changelogen --release && bun publish && git push --follow-tags"},"peerDependencies":{"dayjs":"^1.11.0"},"devDependencies":{"@eslint/js":"^10.0.1","changelogen":"^0.6.2","dayjs":"^1.11.13","eslint":"^10.6.0","eslint-config-prettier":"^10.1.8","prettier":"^3.9.4","tsup":"^8.0.2","typescript":"^6.0.3","typescript-eslint":"^8.63.0","vitest":"^2.0.5"},"_id":"@chettapong/dayjs-plugin-buddhist-localized-format@1.0.1","_integrity":"sha512-dHDh1oVQcENnFO4Qk5MPjGjs0geo/KSbx3zaP9Ob4Gl8cy3gQqZ9wCoBPHSyiz7JdvDqxwmZnKT/cdmqf1VWoA==","_nodeVersion":"24.3.0","_npmVersion":"10.8.3","shasum":"ae9e1b41bb4beb11773fe8fd32b0300052700a56","dist":{"integrity":"sha512-dHDh1oVQcENnFO4Qk5MPjGjs0geo/KSbx3zaP9Ob4Gl8cy3gQqZ9wCoBPHSyiz7JdvDqxwmZnKT/cdmqf1VWoA==","shasum":"ae9e1b41bb4beb11773fe8fd32b0300052700a56","tarball":"https://registry.npmjs.org/@chettapong/dayjs-plugin-buddhist-localized-format/-/dayjs-plugin-buddhist-localized-format-1.0.1.tgz","fileCount":7,"unpackedSize":18097,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIF8/Z1ycP7rPZIedHKsd/23fsvJ6G5GQh6q5/pIMVEJUAiEA3ZY1V5U4zKNzT3tX1XX0zhXWJxlJxgR1nQcDcUW6Ql4="}]},"_npmUser":{"name":"chettapong","email":"chettapong.work@gmail.com"},"directories":{},"maintainers":[{"name":"chettapong","email":"chettapong.work@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/dayjs-plugin-buddhist-localized-format_1.0.1_1783505665241_0.4330299849602184"},"_hasShrinkwrap":false}},"maintainers":[{"name":"chettapong","email":"chettapong.work@gmail.com"}],"description":"Day.js plugin combining Buddhist Era (B.E.) year conversion with LocalizedFormat tokens, with a per-call override option.","keywords":["dayjs","dayjs-plugin","buddhist-era","localized-format","thai","date"],"repository":{"type":"git","url":"git+https://github.com/chettapong/dayjs-plugin-buddhist-localized-format.git"},"bugs":{"url":"https://github.com/chettapong/dayjs-plugin-buddhist-localized-format/issues"},"license":"MIT","readme":"# dayjs-plugin-buddhist-localized-format\r\n\r\n[![npm version][npm-version-src]][npm-version-href]\r\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\r\n[![License][license-src]][license-href]\r\n\r\nA [Day.js](https://day.js.org/) plugin that combines the behavior of the\r\nofficial `buddhistEra` and `localizedFormat` plugins into one, and adds\r\nsomething neither of them supports: a **per-call override** to force-enable\r\nor force-disable Buddhist Era (B.E. / พ.ศ.) year conversion.\r\n\r\n## Features\r\n\r\n- **Locale-aware** — years are shown as B.E. (Gregorian year + 543)\r\n  automatically when the active locale is Thai (`th`), or any locale you\r\n  register.\r\n- **Full `localizedFormat` support** — `LT`, `LTS`, `L`, `LL`, `LLL`, `LLLL`\r\n  all work, expanded using the active locale's own format strings.\r\n- **Dynamic toggle** — pass `{ be: true | false }` as a second argument to\r\n  `format()` to override the locale default for that call only.\r\n- Zero runtime dependencies beyond `dayjs` itself (peer dependency).\r\n- Ships as ESM + CJS + TypeScript declarations.\r\n\r\n## Install\r\n\r\n```bash\r\nnpm install @chettapong/dayjs-plugin-buddhist-localized-format\r\n```\r\n\r\n`dayjs` is a peer dependency — make sure it's installed too:\r\n\r\n```bash\r\nnpm install dayjs\r\n```\r\n\r\n## Setup\r\n\r\n```ts\r\nimport dayjs from 'dayjs';\r\nimport 'dayjs/locale/th';\r\nimport buddhistLocalizedFormat from '@chettapong/dayjs-plugin-buddhist-localized-format';\r\n\r\n// `buddhistLocales` is optional and defaults to ['th']\r\ndayjs.extend(buddhistLocalizedFormat, { buddhistLocales: ['th'] });\r\n```\r\n\r\n> **Do not** also `dayjs.extend(require('dayjs/plugin/buddhistEra'))` or\r\n> `dayjs/plugin/localizedFormat`. This plugin replaces both; stacking them\r\n> would double-wrap `format()` and produce incorrect output.\r\n\r\n## Usage\r\n\r\n### 1. Locale-aware auto conversion\r\n\r\n```ts\r\ndayjs.locale('en');\r\ndayjs('2026-07-07').format('LL'); // \"July 7, 2026\"\r\n\r\ndayjs.locale('th');\r\ndayjs('2026-07-07').format('LL'); // \"7 กรกฎาคม 2569\"\r\n```\r\n\r\n### 2. LocalizedFormat tokens\r\n\r\n```ts\r\ndayjs.locale('th');\r\ndayjs('2026-07-07T14:30:00').format('LLLL');\r\n// \"วันอังคารที่ 7 กรกฎาคม 2569 เวลา 14:30\"\r\n```\r\n\r\n### 3. Force-disable B.E. on a Thai locale\r\n\r\n```ts\r\ndayjs.locale('th');\r\ndayjs('2026-07-07').format('L LT', { be: false });\r\n// \"07/07/2026 14:30\" — Gregorian year, overriding the locale default\r\n```\r\n\r\n### 4. Force-enable B.E. on a non-Thai locale\r\n\r\n```ts\r\ndayjs.locale('en');\r\ndayjs('2026-07-07').format('LL', { be: true });\r\n// \"July 7, 2569\"\r\n```\r\n\r\n### 5. Registering additional Buddhist-Era locales\r\n\r\n```ts\r\ndayjs.extend(buddhistLocalizedFormat, { buddhistLocales: ['th', 'lo', 'km'] });\r\n```\r\n\r\n## TypeScript\r\n\r\n`format()`'s extra parameter is type-checked automatically once this\r\npackage has been imported anywhere in your program (it augments Day.js's\r\nown `Dayjs` interface):\r\n\r\n```ts\r\ndayjs().format('L LT', { be: false }); // ✅ type-checks\r\n```\r\n\r\n## API\r\n\r\n### `dayjs.extend(buddhistLocalizedFormat, options?)`\r\n\r\n| Option              | Type       | Default  | Description                                     |\r\n| ------------------- | ---------- | -------- | ----------------------------------------------- |\r\n| `buddhistLocales`   | `string[]` | `['th']` | Locale codes that default to Buddhist Era.      |\r\n\r\n### `dayjs(...).format(formatStr?, options?)`\r\n\r\n| Option | Type      | Description                                                |\r\n| ------ | --------- | ---------------------------------------------------------- |\r\n| `be`   | `boolean` | Force-enable/disable B.E. conversion for this call only.   |\r\n\r\n## Development\r\n\r\n```bash\r\nnpm install     # install dependencies\r\nnpm test        # run the vitest suite\r\nnpm run typecheck\r\nnpm run build   # produce dist/ (ESM + CJS + .d.ts) via tsup\r\n```\r\n\r\n## How it works\r\n\r\nDay.js's core `format(formatStr)` only accepts a single argument, and the\r\nofficial `buddhistEra`/`localizedFormat` plugins each independently wrap\r\n`proto.format`. There's no seam to thread a second `options` argument\r\nthrough two separately-wrapped functions, and the order they'd need to run\r\nin (expand `L`-style tokens first, *then* swap the year) has to be\r\nguaranteed. This plugin reimplements both behaviors in a single wrapper, in\r\nthe correct order:\r\n\r\n1. Expand `LT` / `LTS` / `L` / `LL` / `LLL` / `LLLL` into raw Day.js tokens\r\n   using the active locale's `formats` object (falling back to English\r\n   defaults).\r\n2. Decide whether B.E. applies: the `{ be }` call option wins if provided,\r\n   otherwise fall back to whether the active locale is in\r\n   `buddhistLocales`.\r\n3. If B.E. applies, replace `YYYY`/`YY` with the Buddhist Era year\r\n   (Gregorian year + 543) as literal digits before calling the original\r\n   `format()`.\r\n\r\nText inside literal Day.js escapes (`[...]`) is protected at every step, so\r\n`format('[Year:] YYYY')` never has \"Year\" mistaken for a token.\r\n\r\n## License\r\n\r\n[MIT License](./LICENSE)\r\n\r\nCopyright (c) 2026 Chettapong Pinsuwan\r\n\r\n<!-- Badges -->\r\n[npm-version-src]: https://img.shields.io/npm/v/@chettapong/dayjs-plugin-buddhist-localized-format/latest.svg\r\n[npm-version-href]: https://npmjs.com/package/@chettapong/dayjs-plugin-buddhist-localized-format\r\n\r\n[npm-downloads-src]: https://img.shields.io/npm/dt/@chettapong/dayjs-plugin-buddhist-localized-format.svg\r\n[npm-downloads-href]: https://npmjs.com/package/@chettapong/dayjs-plugin-buddhist-localized-format\r\n\r\n[license-src]: https://img.shields.io/npm/l/@chettapong/dayjs-plugin-buddhist-localized-format.svg\r\n[license-href]: https://npmjs.com/package/@chettapong/dayjs-plugin-buddhist-localized-format\r\n","readmeFilename":"README.md"}