/
opt
/
alt
/
alt-nodejs10
/
root
/
usr
/
share
/
doc
/
alt-nodejs10-nodejs-10.24.1
/
html
/
api
/
Upload Filee
HOME
{ "type": "module", "source": "doc/api/intl.md", "introduced_in": "v8.2.0", "miscs": [ { "textRaw": "Internationalization Support", "name": "Internationalization Support", "introduced_in": "v8.2.0", "type": "misc", "desc": "<p>Node.js has many features that make it easier to write internationalized\nprograms. Some of them are:</p>\n<ul>\n<li>\n<p>Locale-sensitive or Unicode-aware functions in the <a href=\"https://tc39.github.io/ecma262/\">ECMAScript Language\nSpecification</a>:</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize\"><code>String.prototype.normalize()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase\"><code>String.prototype.toLowerCase()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase\"><code>String.prototype.toUpperCase()</code></a></li>\n</ul>\n</li>\n<li>\n<p>All functionality described in the <a href=\"https://tc39.github.io/ecma402/\">ECMAScript Internationalization API\nSpecification</a> (aka ECMA-402):</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl\"><code>Intl</code></a> object</li>\n<li>Locale-sensitive methods like <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare\"><code>String.prototype.localeCompare()</code></a> and\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString\"><code>Date.prototype.toLocaleString()</code></a></li>\n</ul>\n</li>\n<li>The <a href=\"url.html#url_the_whatwg_url_api\">WHATWG URL parser</a>'s <a href=\"https://en.wikipedia.org/wiki/Internationalized_domain_name\">internationalized domain names</a> (IDNs) support</li>\n<li><a href=\"buffer.html#buffer_buffer_transcode_source_fromenc_toenc\"><code>require('buffer').transcode()</code></a></li>\n<li>More accurate <a href=\"repl.html#repl_repl\">REPL</a> line editing</li>\n<li><a href=\"util.html#util_class_util_textdecoder\"><code>require('util').TextDecoder</code></a></li>\n<li><a href=\"https://github.com/tc39/proposal-regexp-unicode-property-escapes\"><code>RegExp</code> Unicode Property Escapes</a></li>\n</ul>\n<p>Node.js (and its underlying V8 engine) uses <a href=\"http://site.icu-project.org/\">ICU</a> to implement these features\nin native C/C++ code. However, some of them require a very large ICU data file\nin order to support all locales of the world. Because it is expected that most\nNode.js users will make use of only a small portion of ICU functionality, only\na subset of the full ICU data set is provided by Node.js by default. Several\noptions are provided for customizing and expanding the ICU data set either when\nbuilding or running Node.js.</p>", "miscs": [ { "textRaw": "Options for building Node.js", "name": "options_for_building_node.js", "desc": "<p>To control how ICU is used in Node.js, four <code>configure</code> options are available\nduring compilation. Additional details on how to compile Node.js are documented\nin <a href=\"https://github.com/nodejs/node/blob/master/BUILDING.md\">BUILDING.md</a>.</p>\n<ul>\n<li><code>--with-intl=none</code>/<code>--without-intl</code></li>\n<li><code>--with-intl=system-icu</code></li>\n<li><code>--with-intl=small-icu</code> (default)</li>\n<li><code>--with-intl=full-icu</code></li>\n</ul>\n<p>An overview of available Node.js and JavaScript features for each <code>configure</code>\noption:</p>\n<table>\n<thead>\n<tr>\n<th></th>\n<th><code>none</code></th>\n<th><code>system-icu</code></th>\n<th><code>small-icu</code></th>\n<th><code>full-icu</code></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize\"><code>String.prototype.normalize()</code></a></td>\n<td>none (function is no-op)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><code>String.prototype.to*Case()</code></td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl\"><code>Intl</code></a></td>\n<td>none (object does not exist)</td>\n<td>partial/full (depends on OS)</td>\n<td>partial (English-only)</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare\"><code>String.prototype.localeCompare()</code></a></td>\n<td>partial (not locale-aware)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><code>String.prototype.toLocale*Case()</code></td>\n<td>partial (not locale-aware)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString\"><code>Number.prototype.toLocaleString()</code></a></td>\n<td>partial (not locale-aware)</td>\n<td>partial/full (depends on OS)</td>\n<td>partial (English-only)</td>\n<td>full</td>\n</tr>\n<tr>\n<td><code>Date.prototype.toLocale*String()</code></td>\n<td>partial (not locale-aware)</td>\n<td>partial/full (depends on OS)</td>\n<td>partial (English-only)</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"url.html#url_the_whatwg_url_api\">WHATWG URL Parser</a></td>\n<td>partial (no IDN support)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"buffer.html#buffer_buffer_transcode_source_fromenc_toenc\"><code>require('buffer').transcode()</code></a></td>\n<td>none (function does not exist)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"repl.html#repl_repl\">REPL</a></td>\n<td>partial (inaccurate line editing)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"util.html#util_class_util_textdecoder\"><code>require('util').TextDecoder</code></a></td>\n<td>partial (basic encodings support)</td>\n<td>partial/full (depends on OS)</td>\n<td>partial (Unicode-only)</td>\n<td>full</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/tc39/proposal-regexp-unicode-property-escapes\"><code>RegExp</code> Unicode Property Escapes</a></td>\n<td>none (invalid <code>RegExp</code> error)</td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n</tbody>\n</table>\n<p>The \"(not locale-aware)\" designation denotes that the function carries out its\noperation just like the non-<code>Locale</code> version of the function, if one\nexists. For example, under <code>none</code> mode, <code>Date.prototype.toLocaleString()</code>'s\noperation is identical to that of <code>Date.prototype.toString()</code>.</p>", "modules": [ { "textRaw": "Disable all internationalization features (`none`)", "name": "disable_all_internationalization_features_(`none`)", "desc": "<p>If this option is chosen, most internationalization features mentioned above\nwill be <strong>unavailable</strong> in the resulting <code>node</code> binary.</p>", "type": "module", "displayName": "Disable all internationalization features (`none`)" }, { "textRaw": "Build with a pre-installed ICU (`system-icu`)", "name": "build_with_a_pre-installed_icu_(`system-icu`)", "desc": "<p>Node.js can link against an ICU build already installed on the system. In fact,\nmost Linux distributions already come with ICU installed, and this option would\nmake it possible to reuse the same set of data used by other components in the\nOS.</p>\n<p>Functionalities that only require the ICU library itself, such as\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize\"><code>String.prototype.normalize()</code></a> and the <a href=\"url.html#url_the_whatwg_url_api\">WHATWG URL parser</a>, are fully\nsupported under <code>system-icu</code>. Features that require ICU locale data in\naddition, such as <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat\"><code>Intl.DateTimeFormat</code></a> <em>may</em> be fully or partially\nsupported, depending on the completeness of the ICU data installed on the\nsystem.</p>", "type": "module", "displayName": "Build with a pre-installed ICU (`system-icu`)" }, { "textRaw": "Embed a limited set of ICU data (`small-icu`)", "name": "embed_a_limited_set_of_icu_data_(`small-icu`)", "desc": "<p>This option makes the resulting binary link against the ICU library statically,\nand includes a subset of ICU data (typically only the English locale) within\nthe <code>node</code> executable.</p>\n<p>Functionalities that only require the ICU library itself, such as\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize\"><code>String.prototype.normalize()</code></a> and the <a href=\"url.html#url_the_whatwg_url_api\">WHATWG URL parser</a>, are fully\nsupported under <code>small-icu</code>. Features that require ICU locale data in addition,\nsuch as <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat\"><code>Intl.DateTimeFormat</code></a>, generally only work with the English locale:</p>\n<pre><code class=\"language-js\">const january = new Date(9e8);\nconst english = new Intl.DateTimeFormat('en', { month: 'long' });\nconst spanish = new Intl.DateTimeFormat('es', { month: 'long' });\n\nconsole.log(english.format(january));\n// Prints \"January\"\nconsole.log(spanish.format(january));\n// Prints \"M01\" on small-icu\n// Should print \"enero\"\n</code></pre>\n<p>This mode provides a good balance between features and binary size, and it is\nthe default behavior if no <code>--with-intl</code> flag is passed. The official binaries\nare also built in this mode.</p>", "modules": [ { "textRaw": "Providing ICU data at runtime", "name": "providing_icu_data_at_runtime", "desc": "<p>If the <code>small-icu</code> option is used, one can still provide additional locale data\nat runtime so that the JS methods would work for all ICU locales. Assuming the\ndata file is stored at <code>/some/directory</code>, it can be made available to ICU\nthrough either:</p>\n<ul>\n<li>\n<p>The <a href=\"cli.html#cli_node_icu_data_file\"><code>NODE_ICU_DATA</code></a> environment variable:</p>\n<pre><code class=\"language-shell\">env NODE_ICU_DATA=/some/directory node\n</code></pre>\n</li>\n<li>\n<p>The <a href=\"cli.html#cli_icu_data_dir_file\"><code>--icu-data-dir</code></a> CLI parameter:</p>\n<pre><code class=\"language-shell\">node --icu-data-dir=/some/directory\n</code></pre>\n</li>\n</ul>\n<p>(If both are specified, the <code>--icu-data-dir</code> CLI parameter takes precedence.)</p>\n<p>ICU is able to automatically find and load a variety of data formats, but the\ndata must be appropriate for the ICU version, and the file correctly named.\nThe most common name for the data file is <code>icudt6X[bl].dat</code>, where <code>6X</code> denotes\nthe intended ICU version, and <code>b</code> or <code>l</code> indicates the system's endianness.\nCheck <a href=\"http://userguide.icu-project.org/icudata\">\"ICU Data\"</a> article in the ICU User Guide for other supported formats\nand more details on ICU data in general.</p>\n<p>The <a href=\"https://www.npmjs.com/package/full-icu\">full-icu</a> npm module can greatly simplify ICU data installation by\ndetecting the ICU version of the running <code>node</code> executable and downloading the\nappropriate data file. After installing the module through <code>npm i full-icu</code>,\nthe data file will be available at <code>./node_modules/full-icu</code>. This path can be\nthen passed either to <code>NODE_ICU_DATA</code> or <code>--icu-data-dir</code> as shown above to\nenable full <code>Intl</code> support.</p>", "type": "module", "displayName": "Providing ICU data at runtime" } ], "type": "module", "displayName": "Embed a limited set of ICU data (`small-icu`)" }, { "textRaw": "Embed the entire ICU (`full-icu`)", "name": "embed_the_entire_icu_(`full-icu`)", "desc": "<p>This option makes the resulting binary link against ICU statically and include\na full set of ICU data. A binary created this way has no further external\ndependencies and supports all locales, but might be rather large. See\n<a href=\"https://github.com/nodejs/node/blob/master/BUILDING.md#build-with-full-icu-support-all-locales-supported-by-icu\">BUILDING.md</a> on how to compile a binary using this mode.</p>", "type": "module", "displayName": "Embed the entire ICU (`full-icu`)" } ], "type": "misc", "displayName": "Options for building Node.js" }, { "textRaw": "Detecting internationalization support", "name": "detecting_internationalization_support", "desc": "<p>To verify that ICU is enabled at all (<code>system-icu</code>, <code>small-icu</code>, or\n<code>full-icu</code>), simply checking the existence of <code>Intl</code> should suffice:</p>\n<pre><code class=\"language-js\">const hasICU = typeof Intl === 'object';\n</code></pre>\n<p>Alternatively, checking for <code>process.versions.icu</code>, a property defined only\nwhen ICU is enabled, works too:</p>\n<pre><code class=\"language-js\">const hasICU = typeof process.versions.icu === 'string';\n</code></pre>\n<p>To check for support for a non-English locale (i.e. <code>full-icu</code> or\n<code>system-icu</code>), <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat\"><code>Intl.DateTimeFormat</code></a> can be a good distinguishing factor:</p>\n<pre><code class=\"language-js\">const hasFullICU = (() => {\n try {\n const january = new Date(9e8);\n const spanish = new Intl.DateTimeFormat('es', { month: 'long' });\n return spanish.format(january) === 'enero';\n } catch (err) {\n return false;\n }\n})();\n</code></pre>\n<p>For more verbose tests for <code>Intl</code> support, the following resources may be found\nto be helpful:</p>\n<ul>\n<li><a href=\"https://github.com/srl295/btest402\">btest402</a>: Generally used to check whether Node.js with <code>Intl</code> support is\nbuilt correctly.</li>\n<li><a href=\"https://github.com/tc39/test262/tree/master/test/intl402\">Test262</a>: ECMAScript's official conformance test suite includes a section\ndedicated to ECMA-402.</li>\n</ul>", "type": "misc", "displayName": "Detecting internationalization support" } ] } ] }