Skip to content

Commit

Permalink
feat(polyfill): adds polyfill for Intl.ListFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Jan 15, 2019
1 parent 96ce5f3 commit 1dce148
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ This will force-apply a polyfill for `Web Animations`.

#### The `locales` option for `Intl`

**This option only works with `intl`, `intl.core`, or `intl.relative-time-format`**.
**This option only works with `intl`, `intl.core`, `intl.list-format`, or `intl.relative-time-format`**.
The `Intl` family of polyfills rely on locale data for them to work. There are over 600 different locale files shipped. Sending all of them back over the network would take way too much bandwidth.
Instead, if you just ask for the `intl`, `intl.core`, or `intl.relative-time-format` features, they will be returned without any locale data.
Instead, if you just ask for the `intl`, `intl.core`, `intl.list-format`, or `intl.relative-time-format` features, they will be returned without any locale data.

To add one or more locales, use the `locales` option. For example:
`intl|locales=en`
Expand Down Expand Up @@ -497,6 +497,7 @@ And, if you request `performance.now`, `date.now` will also be included since th
- fetch
- intl
- intl.core
- intl.list-format
- intl.relative-time-format
- animation
- proxy
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
"@babel/preset-env": "^7.2.3",
"@babel/preset-stage-3": "^7.0.0",
"@babel/preset-typescript": "^7.1.0",
"@types/file-type": "^10.6.0",
"@types/astring": "^1.3.0",
"@types/file-type": "^10.6.0",
"@types/iltorb": "^2.3.0",
"@types/memory-fs": "^0.3.2",
"@types/mime": "^2.0.0",
Expand Down Expand Up @@ -93,7 +93,8 @@
"iltorb": "^2.4.1",
"intersection-observer": "^0.5.1",
"intl": "^1.2.5",
"intl-relative-time-format": "^1.0.0",
"intl-list-format": "^1.0.0",
"intl-relative-time-format": "^1.0.4",
"memory-fs": "^0.4.1",
"mime": "^2.4.0",
"mutationobserver-shim": "^0.3.2",
Expand All @@ -109,8 +110,8 @@
"resize-observer": "^1.0.0",
"rollup": "^1.1.0",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-multi-entry": "^2.1.0",
"rollup-plugin-node-resolve": "^4.0.0",
"scroll-behavior-polyfill": "^2.0.3",
"semver": "^5.6.0",
"setimmediate": "^1.0.5",
Expand Down
25 changes: 23 additions & 2 deletions src/constant/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2387,9 +2387,8 @@ export const constant: IConstant = {
intl: {
polyfills: [
"intl.core",
"intl.list-format",
"intl.relative-time-format"
// TODO: Add Intl.ListFormat
/*, "intl.list-format" */
]
},
"intl.core": {
Expand Down Expand Up @@ -2425,6 +2424,28 @@ export const constant: IConstant = {
"es.weak-map"
]
},
"intl.list-format": {
library: "intl-list-format",
relativePaths: [
"dist/index.js"
],
meta: {
localeDir: "locale-data"
},
features: [
// TODO: Add when MDN data gets updated
// "javascript.builtins.Intl.ListFormat"
],
version: environment.NPM_PACKAGE_DEPENDENCIES_INTL_LIST_FORMAT,
dependencies: [
"intl.core",
"es.array.includes",
"es.object.create",
"es.string.replace",
"es.symbol.to-string-tag",
"es.weak-map"
]
},
animation: {
library: "web-animations-js",
relativePaths: ["web-animations.min.js"],
Expand Down
1 change: 1 addition & 0 deletions src/environment/environment-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const environmentDefaults = {
NPM_PACKAGE_DEPENDENCIES_MUTATIONOBSERVER_SHIM: "",
NPM_PACKAGE_DEPENDENCIES_INTL: "",
NPM_PACKAGE_DEPENDENCIES_INTL_RELATIVE_TIME_FORMAT: "",
NPM_PACKAGE_DEPENDENCIES_INTL_LIST_FORMAT: "",
NPM_PACKAGE_DEPENDENCIES__WEBCOMPONENTS_CUSTOM_ELEMENTS: "",
NPM_PACKAGE_DEPENDENCIES__WESSBERG_POINTER_EVENTS: "",
NPM_PACKAGE_DEPENDENCIES_CORE_JS: "",
Expand Down
2 changes: 1 addition & 1 deletion src/polyfill/polyfill-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ export declare type PolyfillDealiasedName =
|"dom.collections.for-each"
|"fetch"
|"intl.core"
|"intl.list-format"
|"intl.relative-time-format"
// |"intl.list-format"
|"animation"
|"proxy"
|"window"
Expand Down
2 changes: 1 addition & 1 deletion src/service/polyfill-builder/polyfill-builder-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class PolyfillBuilderService implements IPolyfillBuilderService {
}

// If the Polyfill is "intl.core" and a localeDir is associated with it, also resolve the requested locales (if any)
if ((polyfillFeature.name === "intl.core" || polyfillFeature.name === "intl.relative-time-format") && meta != null && "localeDir" in meta && polyfillFeature.meta.locale != null) {
if (polyfillFeature.name.startsWith("intl.") && meta != null && "localeDir" in meta && polyfillFeature.meta.locale != null) {
// Normalize the requested locales to make sure we have an array to work with
const requestedLocales: string[] = ensureArray(polyfillFeature.meta.locale);

Expand Down

0 comments on commit 1dce148

Please sign in to comment.