@electric-sql/pglite-icu-full

中文文档
0.1.0发布于 2026/06/02Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 9.5万

ICU support

原始使用文档
文档目录8 节
  1. Installation
  2. Usage
  3. Generating an ICU package for PGlite
  4. Download libicu code and data
  5. Create a filters.json file
  6. Build ICU
  7. Create an archive with the icu data
  8. Example

pglite-icu-full

A package containing all the data resources from libicu that can be used with PGlite to build localized applications.

Installation

npm install @electric-sql/pglite-icu-full
# or
yarn add @electric-sql/pglite-icu-full
# or
pnpm add @electric-sql/pglite-icu-full

Usage

This loads the entire locale set provided by libicu, which might be quite large.

import { PGlite } from '@electric-sql/pglite'
import { icuDataDir } from '@electric-sql/pglite-icu-full'

// Create a PGlite instance with the icu resources
const pg = await PGlite.create({
  icuDataDir: await icuDataDir(),
})

// just an example, query the available collations
const collations = await pg.exec('select * from pg_collation')

Generating an ICU package for PGlite

Following is a brief description on how to generate your own icu file that contains only the locales that you want in your PGlite enabled application.

Download libicu code and data

Currently PGlite is tested to work with libicu v76.1. Get the source and data for it:

wget https://github.com/unicode-org/icu/releases/download/release-76-1/icu4c-76_1-src.tgz wget https://github.com/unicode-org/icu/releases/download/release-78.3/icu4c-78.3-data.zip

Important: You must have the data sources in order to use the ICU Data Build Tool. Check for the file icu4c/source/data/locales/root.txt. If that file is missing, you need to download “icu4c-*-data.zip”, delete the old icu4c/source/data directory, and replace it with the data directory from the zip file. If there is a *.dat file in icu4c/source/data/in, that file will be used even if you gave ICU custom filter rules.

Create a filters.json file

This will allow you to only generate the data that you need.

Here's a simple example:

{
  "localeFilter": {
    "filterType": "locale",
    "includelist": [
      "en_US"
    ]
  }
}

For more info, see https://unicode-org.github.io/icu/userguide/icu_data/buildtool.html.

Build ICU

$ ICU_DATA_FILTER_FILE=<full_path_to_your_filters.json> ./icu/source/configure --with-data-packaging=files --disable-shared --enable-static --disable-tests --disable-samples --disable-extras --disable-icuio --disable-layoutex --prefix=<your_install_dir>

$ make -j && make install

Create an archive with the icu data

The previous steps have installed everything related to ICU in <your_install_dir>. You only need the data files:

$ cd <your_install_dir>/share/icu/76.1/ && tar cvfz icu_76.tgz icudt76l/

Now icu_76.tgz contains the localisation data that you can use with PGlite.

// load your newly generate icu archive
const icuDataDir = await fs.readFile(
  resolve(import.meta.dirname, 'icu_76.tgz'),
)
// now pass it to PGlite
pg = await PGlite.create({
  icuDataDir: new Blob([new Uint8Array(icuDataDir)]),
})

Example

The folder examples/Switzerland contains the filter.json and the generated data file that can be used with PGlite.

Documentation

https://www.postgresql.org/docs/current/locale.html https://unicode-org.github.io/icu/userguide/icu_data/buildtool.html

版本与发布记录

@electric-sql/pglite-icu-full 共发布 3 个版本,首次发布于 2026/05/25;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.0latest2026/06/025 个月前
0.0.22026/05/265 个月前
0.0.12026/05/255 个月前

关于 @electric-sql/pglite-icu-full 的常见问题

@electric-sql/pglite-icu-full 是什么?

ICU support

如何安装 @electric-sql/pglite-icu-full?

在项目目录运行 npm install @electric-sql/pglite-icu-full,或使用 pnpm add / yarn add / bun add。

@electric-sql/pglite-icu-full 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@electric-sql/pglite-icu-full 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@electric-sql/pglite-icu-full 可以商用吗?

@electric-sql/pglite-icu-full 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@electric-sql/pglite-icu-full 的下载量有多少?

根据 npm 官方下载统计,@electric-sql/pglite-icu-full 在 2026/10/14 – 2026/11/12 这 30 天内被下载 94,661 次,日均约 3,155 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@electric-sql/pglite-icu-full 还在维护吗?

最新版本 0.1.0 发布于 2026/06/02(5 个月前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/05/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。