嵌入 ICU 数据的有界集(small-icu)


此选项静态地生成针对 ICU 库的二进制链接,并在 node 可执行文件中包含 ICU 数据的子集(通常只有英文区域设置)。

small-icu 完全支持仅需要 ICU 库本身的功能,例如 String.prototype.normalize()WHATWG 网址解析器。 另外需要 ICU 语言环境数据的特性,比如 Intl.DateTimeFormat,一般只适用于英文语言环境:

const january = new Date(9e8);
const english = new Intl.DateTimeFormat('en', { month: 'long' });
const spanish = new Intl.DateTimeFormat('es', { month: 'long' });

console.log(english.format(january));
// 打印 "January"
console.log(spanish.format(january));
// 在 small-icu 上打印 "M01"
// 应该打印 "enero"

官方的二进制文件也是以这种模式构建的。

This option makes the resulting binary link against the ICU library statically, and includes a subset of ICU data (typically only the English locale) within the node executable.

Functionalities that only require the ICU library itself, such as String.prototype.normalize() and the WHATWG URL parser, are fully supported under small-icu. Features that require ICU locale data in addition, such as Intl.DateTimeFormat, generally only work with the English locale:

const january = new Date(9e8);
const english = new Intl.DateTimeFormat('en', { month: 'long' });
const spanish = new Intl.DateTimeFormat('es', { month: 'long' });

console.log(english.format(january));
// Prints "January"
console.log(spanish.format(january));
// Prints "M01" on small-icu
// Should print "enero"

This mode provides a good balance between features and binary size, and it is the default behavior if no --with-intl flag is passed. The official binaries are also built in this mode.