Comparing version 25.0.9 to 25.0.10
85
index.js
@@ -11,13 +11,68 @@ /** | ||
var MAIN_FILES = ["ca-buddhist", "ca-chinese", "ca-coptic", "ca-dangi", | ||
"ca-ethiopic-amete-alem", "ca-ethiopic", "ca-generic", "ca-gregorian", | ||
"ca-hebrew", "ca-indian", "ca-islamic-civil", "ca-islamic", "ca-islamic-rgsa", | ||
"ca-islamic-tbla", "ca-islamic-umalqura", "ca-japanese", "ca-persian", "ca-roc", | ||
"characters", "currencies", "dateFields", "delimiters", "languages", "layout", | ||
"listPatterns", "localeDisplayNames", "measurementSystemNames", "numbers", | ||
"posix", "scripts", "territories", "timeZoneNames", "units", "variants" | ||
]; | ||
var SUPPLEMENTAL_FILES = ["aliases", "calendarData", "calendarPreferenceData", | ||
"characterFallbacks", "codeMappings", "currencyData", "gender", | ||
"languageData", "languageMatching", "likelySubtags", "measurementData", | ||
"metaZones", "numberingSystems", "ordinals", "parentLocales", "plurals", | ||
"postalCodeData", "primaryZones", "references", "telephoneCodeData", | ||
"territoryContainment", "territoryInfo", "timeData", "weekData", | ||
"windowsZones" | ||
]; | ||
var assert = require("assert"); | ||
var _path = require("path"); | ||
function cldrData(path) { | ||
function argsToArray(arg) { | ||
return [].slice.call(arg, 0); | ||
} | ||
function flatten(obj) { | ||
var arr = []; | ||
function _flatten(obj, arr) { | ||
if(Array.isArray(obj)) { | ||
return obj.forEach(function(obj) { | ||
_flatten(obj, arr); | ||
}); | ||
} | ||
arr.push(obj); | ||
} | ||
_flatten(obj, arr); | ||
return arr; | ||
} | ||
function cldrData(path/*, ...*/) { | ||
assert(typeof path === "string", "must include path (e.g., " + | ||
"\"main/en/numbers\" or \"supplemental/likelySubtags\")"); | ||
path = _path.join("json", path); | ||
if (arguments.length > 1) { | ||
return argsToArray(arguments).reduce(function(sum, path) { | ||
sum.push(cldrData(path)); | ||
return sum; | ||
}, []); | ||
} | ||
return require("./" + path); | ||
} | ||
function mainPathsFor(locales) { | ||
return locales.reduce(function(sum, locale) { | ||
MAIN_FILES.forEach(function(mainFile) { | ||
sum.push(_path.join("main", locale, mainFile)); | ||
}); | ||
return sum; | ||
}, []); | ||
} | ||
function supplementalPaths() { | ||
return SUPPLEMENTAL_FILES.map(function(supplementalFile) { | ||
return _path.join("supplemental", supplementalFile); | ||
}); | ||
} | ||
Object.defineProperty(cldrData, "availableLocales", { | ||
@@ -29,21 +84,17 @@ get: function() { | ||
cldrData.forEachMain = function(callback) { | ||
assert(typeof callback === "function", "must include callback function"); | ||
cldrData.all = function() { | ||
var paths = supplementalPaths().concat(mainPathsFor(this.availableLocales)); | ||
return cldrData.apply({}, paths); | ||
} | ||
cldrData.availableLocales.forEach(function(locale) { | ||
callback(function(path) { | ||
return cldrData(_path.join("main", locale, path)); | ||
}); | ||
}); | ||
}; | ||
cldrData.entireMainFor = function(locale/*, ...*/) { | ||
assert(typeof locale === "string", "must include locale (e.g., " + | ||
"\"en\")"); | ||
return cldrData.apply({}, mainPathsFor(argsToArray(arguments))); | ||
} | ||
cldrData.main = function(path) { | ||
assert(typeof path === "string", "must include path (e.g., " + | ||
"\"numbers\" or \"ca-gregorian\")"); | ||
return cldrData.availableLocales.map(function(locale) { | ||
return cldrData(_path.join("main", locale, path)); | ||
}); | ||
cldrData.entireSupplemental = function() { | ||
return cldrData.apply({}, supplementalPaths()); | ||
} | ||
module.exports = cldrData; |
@@ -11,34 +11,40 @@ /** | ||
var coverage, parentPackage, srcUrl; | ||
var cldrDownloader = require("cldr-data-downloader"); | ||
var path = require("path"); | ||
var urls = require("./urls"); | ||
var parentPackage; | ||
var url; | ||
try { | ||
parentPackage = require("../../package.json"); | ||
} | ||
catch(error) {} | ||
var options = {}; | ||
url = urls[process.env.CLDR_COVERAGE || "core"]; | ||
if (process.env.CLDR_URL) { | ||
srcUrl = srcUrl.replace( | ||
"http://www.unicode.org/Public/cldr", | ||
process.env.CLDR_URL.replace(/\/$/, "") | ||
); | ||
if (parentPackage) { | ||
if (parentPackage["cldr-data-coverage"] && parentPackage.dependencies["cldr-data"]) { | ||
if (!/^full|core$/.test(parentPackage["cldr-data-coverage"])) { | ||
throw new TypeError("Your `cldr-data-coverage` setting must have the value \"core\" or \"full\"."); | ||
} else { | ||
srcUrl = path.join(__dirname, "./urls.json"); | ||
try { | ||
parentPackage = require("../../package.json"); | ||
if (parentPackage["cldr-data-coverage"] && parentPackage.dependencies["cldr-data"]) { | ||
coverage = parentPackage["cldr-data-coverage"]; | ||
} | ||
url = urls[parentPackage["cldr-data-coverage"]]; | ||
} | ||
} | ||
catch(error) {} | ||
if (process.env.CLDR_URL) { | ||
url = url.replace( | ||
"http://www.unicode.org/Public/cldr", | ||
process.env.CLDR_URL.replace(/\/$/, "") | ||
); | ||
if (process.env.CLDR_COVERAGE) { | ||
coverage = process.env.CLDR_COVERAGE; | ||
} | ||
if (coverage) { | ||
options.srcUrlKey = coverage; | ||
} | ||
} | ||
cldrDownloader( | ||
url, | ||
srcUrl, | ||
__dirname, | ||
options, | ||
function(error) { | ||
@@ -45,0 +51,0 @@ if (error) { |
{ | ||
"name": "cldr-data", | ||
"version": "25.0.9", | ||
"version": "25.0.10", | ||
"keywords": [ | ||
@@ -33,3 +33,3 @@ "unicode", | ||
"dependencies": { | ||
"cldr-data-downloader": "0.1.x" | ||
"cldr-data-downloader": "0.2.x" | ||
}, | ||
@@ -36,0 +36,0 @@ "devDependencies": { |
@@ -21,5 +21,7 @@ # Npm's cldr-data | ||
On the `package.json` of your i18n library, define its CLDR data dependency. | ||
compatible with. | ||
### For libraries | ||
On the `package.json` of your i18n library, define its CLDR data dependency by | ||
using the *peerDependencies* property. | ||
"peerDependencies": { | ||
@@ -32,6 +34,4 @@ "cldr-data": ">=25" | ||
```javascript | ||
cldr = require("cldr-data"); | ||
function Pluralize(locale) { | ||
var plurals = cldr("supplemental/plurals"); | ||
var plurals = require("cldr-data/supplemental/plurals"); | ||
var language = extractLanguageFrom(locale); | ||
@@ -56,9 +56,22 @@ | ||
### Locale coverage | ||
### For applications | ||
By default, the locale coverage installed is `core`, which Unicode defines as | ||
the top tier languages and is equivalent to the `json.zip` content. There exists two solutions to get the full coverage: either by setting the environmental variable `CLDR_COVERAGE` to `full` or define the coverage in your `package.json`. | ||
On the `package.json` of your applications, define its CLDR data dependency by | ||
using the *dependencies* or *devDependencies*property. | ||
#### Environmental variable | ||
In this example we are installing `cldr-data` by setting the `CLDR_COVERAGE` to `full`: | ||
"dependencies": { | ||
"cldr-data": "26", | ||
"libraries-that-use-cldr-data": "x" | ||
} | ||
#### Locale coverage | ||
By default, the locale coverage installed is **core**, which Unicode defines as | ||
the top tier languages and is equivalent to the `json.zip` content. There are | ||
two ways to modify the installation and get the **full** coverage instead. | ||
*Use the environment variable `CLDR_COVERAGE`* | ||
On the command line, set the locale coverage using the environment variable. | ||
``` | ||
@@ -68,4 +81,7 @@ $ CLDR_COVERAGE=full npm install | ||
#### package.json | ||
Define your coverage by setting the property `cldr-data-coverage` in your `package.json: | ||
*Use the package.json `cldr-data-coverage` property* | ||
On the `package.json` of you application, set the locale coverage using the | ||
`cldr-data-coverage` property. | ||
``` | ||
@@ -72,0 +88,0 @@ { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11871
181
94
5
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@0.2.01.0.0(transitive)
+ Addedasync@2.6.4(transitive)
+ Addedaws-sign2@0.6.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbl@1.1.2(transitive)
+ Addedcaseless@0.11.0(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcldr-data-downloader@0.2.5(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@1.0.1(transitive)
+ Addedgenerate-function@2.3.1(transitive)
+ Addedgenerate-object-property@1.2.0(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-validator@2.0.6(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhawk@3.1.3(transitive)
+ Addedhttp-signature@1.1.1(transitive)
+ Addedis-my-ip-valid@1.0.1(transitive)
+ Addedis-my-json-valid@2.20.6(transitive)
+ Addedis-property@1.0.2(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjsonpointer@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.8.2(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedprocess-nextick-args@1.0.7(transitive)
+ Addedpunycode@1.4.1(transitive)
+ Addedqs@6.2.4(transitive)
+ Addedreadable-stream@2.0.6(transitive)
+ Addedrequest@2.74.0(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtough-cookie@2.3.4(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedasn1@0.1.11(transitive)
- Removedassert-plus@0.1.5(transitive)
- Removedasync@0.9.2(transitive)
- Removedaws-sign2@0.5.0(transitive)
- Removedbl@0.9.5(transitive)
- Removedcaseless@0.9.0(transitive)
- Removedcldr-data-downloader@0.1.3(transitive)
- Removedcombined-stream@0.0.7(transitive)
- Removedctype@0.5.3(transitive)
- Removeddelayed-stream@0.0.5(transitive)
- Removedforever-agent@0.5.2(transitive)
- Removedform-data@0.2.0(transitive)
- Removedhawk@2.3.1(transitive)
- Removedhttp-signature@0.10.1(transitive)
- Removedisarray@0.0.1(transitive)
- Removedmime-db@1.12.0(transitive)
- Removedmime-types@2.0.14(transitive)
- Removedoauth-sign@0.6.0(transitive)
- Removedqs@2.3.3(transitive)
- Removedreadable-stream@1.0.34(transitive)
- Removedrequest@2.53.0(transitive)
- Removedtldts@6.1.69(transitive)
- Removedtldts-core@6.1.69(transitive)
- Removedtough-cookie@5.0.0(transitive)
Updatedcldr-data-downloader@0.2.x