Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

Commit 1b4b292

Browse files
committed
massive refactor to use ES6 modules under the hood so we can split this into pieces in the future
1 parent ce0a12a commit 1b4b292

18 files changed

+4718
-3279
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ cldr/
1212

1313
# NPM packages installed locally
1414
node_modules
15+
16+
lib/
17+
node_modules/
18+
tmp/

.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ cldr/
1414
# (It doesn't need anything used during development of this library.)
1515
tools/
1616
tests/
17+
18+
coverage/
19+
tasks/
20+
tmp/
21+
.travis.yml
22+
Gruntfile.js

Gruntfile.js

+47-9
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,69 @@ module.exports = function (grunt) {
22

33
grunt.initConfig({
44
pkg: grunt.file.readJSON('package.json'),
5+
6+
clean: {
7+
dist: 'dist/',
8+
lib : 'lib/',
9+
tmp : 'tmp/'
10+
},
11+
12+
copy: {
13+
tmp: {
14+
expand : true,
15+
flatten: true,
16+
src : ['tmp/src/*.js'],
17+
dest : 'lib/'
18+
}
19+
},
20+
21+
concat: {
22+
complete: {
23+
src: ['dist/Intl.min.js', 'locale-data/complete.js'],
24+
dest: 'dist/Intl.complete.js',
25+
}
26+
},
27+
528
jshint: {
6-
all: ['Intl.js']
29+
all: ['index.js', 'src/*.js', '!src/en.js']
730
},
31+
32+
bundle_jsnext: {
33+
dest: 'dist/Intl.js',
34+
options: {
35+
namespace: 'IntlPolyfill'
36+
}
37+
},
38+
39+
cjs_jsnext: {
40+
dest: 'tmp/'
41+
},
42+
843
uglify: {
944
options: {
1045
preserveComments: 'some'
1146
},
1247
build: {
1348
files: {
14-
'Intl.min.js': ['Intl.js']
49+
'dist/Intl.min.js': ['dist/Intl.js']
1550
}
1651
}
1752
}
18-
1953
});
2054

2155
grunt.loadTasks('./tasks');
56+
grunt.loadNpmTasks('grunt-contrib-clean');
57+
grunt.loadNpmTasks('grunt-contrib-copy');
58+
grunt.loadNpmTasks('grunt-contrib-concat');
2259
grunt.loadNpmTasks('grunt-contrib-jshint');
2360
grunt.loadNpmTasks('grunt-contrib-uglify');
61+
grunt.loadNpmTasks('grunt-bundle-jsnext-lib');
2462

25-
grunt.registerTask('default', function () {
26-
grunt.task.run('jshint');
27-
grunt.task.run('uglify');
63+
grunt.registerTask('build', [
64+
'bundle_jsnext', 'uglify', 'cjs_jsnext', 'copy', 'concat'
65+
]);
2866

29-
if (grunt.option('complete'))
30-
grunt.task.run('compile-data');
31-
});
67+
grunt.registerTask('cldr', ['compile-data']);
68+
69+
grunt.registerTask('default', ['jshint', 'clean', 'build']);
3270
};

Intl.complete.js

-3,070
This file was deleted.

Intl.min.js

-11
This file was deleted.

dist/Intl.complete.js

+709
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Intl.js

+3,033
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Intl.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Intl.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var m = require('./lib/core.js'),
2+
IntlPolyfill = m.default;
3+
4+
// add locale data for all locales into runtime
5+
global.IntlPolyfill = IntlPolyfill;
6+
require('./locale-data/complete.js');
7+
8+
// hack to export the polyfill as global Intl if needed
9+
if (!global.Intl) {
10+
global.Intl = IntlPolyfill;
11+
IntlPolyfill.__applyLocaleSensitivePrototypes();
12+
}
13+
14+
// providing an idiomatic api for the nodejs version of this module
15+
module.exports = exports = IntlPolyfill;
16+
// preserving the original api in case another module is relying on that
17+
exports.default = IntlPolyfill;

locale-data/complete.js

+708
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+44-38
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,46 @@
11
{
2-
"name": "intl",
3-
"version": "0.1.4",
4-
"description": "Polyfill the ECMA-402 Intl API (except collation)",
5-
"main": "Intl.complete.js",
6-
"directories": {
7-
"test": "tests"
8-
},
9-
"devDependencies": {
10-
"async": "~0.2.9",
11-
"grunt": "~0.4.2",
12-
"grunt-cli": "~0.1.11",
13-
"grunt-contrib-jshint": "~0.7.2",
14-
"grunt-contrib-uglify": "~0.2.7",
15-
"jshint": "~2.3.0",
16-
"wd": "~0.2.8"
17-
},
18-
"scripts": {
19-
"build": "grunt --complete",
20-
"lint": "jshint Intl.js",
21-
"test": "cd tests && node noderunner.js && node saucelabs.js"
22-
},
23-
"repository": {
24-
"type": "git",
25-
"url": "https://github.com/andyearnshaw/Intl.js"
26-
},
27-
"keywords": [
28-
"intl",
29-
"i18n",
30-
"internationalization",
31-
"ecma402",
32-
"polyfill"
33-
],
34-
"author": "Andy Earnshaw",
35-
"email": "andyearnshaw@gmail.com",
36-
"license": "MIT",
37-
"bugs": {
38-
"url": "https://github.com/andyearnshaw/Intl.js/issues"
39-
}
2+
"name": "intl",
3+
"version": "1.0.0-rc-1",
4+
"description": "Polyfill the ECMA-402 Intl API (except collation)",
5+
"main": "index.js",
6+
"jsnext:main": "src/main.js",
7+
"directories": {
8+
"test": "tests"
9+
},
10+
"devDependencies": {
11+
"async": "^0.9.0",
12+
"grunt": "^0.4.5",
13+
"grunt-cli": "~0.1.13",
14+
"grunt-contrib-clean": "^0.6.0",
15+
"grunt-contrib-copy": "^0.5.0",
16+
"grunt-contrib-concat": "^0.5.0",
17+
"grunt-contrib-jshint": "^0.10.0",
18+
"grunt-contrib-uglify": "^0.5.1",
19+
"grunt-bundle-jsnext-lib": "^0.2.1",
20+
"jshint": "^2.5.5",
21+
"wd": "^0.3.6"
22+
},
23+
"scripts": {
24+
"build": "grunt cldr",
25+
"lint": "grunt jshint",
26+
"pretest": "grunt jshint",
27+
"test": "cd tests && node noderunner.js && node saucelabs.js"
28+
},
29+
"repository": {
30+
"type": "git",
31+
"url": "https://github.com/andyearnshaw/Intl.js"
32+
},
33+
"keywords": [
34+
"intl",
35+
"i18n",
36+
"internationalization",
37+
"ecma402",
38+
"polyfill"
39+
],
40+
"author": "Andy Earnshaw",
41+
"email": "andyearnshaw@gmail.com",
42+
"license": "MIT",
43+
"bugs": {
44+
"url": "https://github.com/andyearnshaw/Intl.js/issues"
45+
}
4046
}

Intl.js src/core.js

+9-133
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,16 @@
88
*
99
* CLDR format locale data should be provided using IntlPolyfill.__addLocaleData().
1010
*/
11-
/*jshint proto:true, eqnull:true, boss:true, laxbreak:true, newcap:false, shadow:true, funcscope:true */
12-
/*globals global, define, exports, module, window*/
11+
/*jshint esnext: true, proto:true, eqnull:true, boss:true, laxbreak:true, newcap:false, shadow:true, funcscope:true */
1312

14-
(function (global, factory) {
15-
var IntlPolyfill = factory();
16-
17-
// register in -all- the module systems (at once)
18-
if (typeof define === 'function' && define.amd)
19-
define(IntlPolyfill);
20-
21-
if (typeof exports === 'object')
22-
module.exports = IntlPolyfill;
23-
24-
if (!global.Intl) {
25-
global.Intl = IntlPolyfill;
26-
IntlPolyfill.__applyLocaleSensitivePrototypes();
27-
}
28-
29-
global.IntlPolyfill = IntlPolyfill;
13+
import {
14+
expBCP47Syntax,
15+
expExtSequences,
16+
expVariantDupes,
17+
expSingletonDupes
18+
} from './exp';
3019

31-
})(typeof global !== 'undefined' ? global : this, function() {
32-
"use strict";
33-
var
34-
Intl = {},
20+
var Intl = {},
3521

3622
realDefineProp = (function () {
3723
try { return !!Object.defineProperty({}, 'a', {}); }
@@ -133,11 +119,6 @@ var
133119
expCurrencyCode = /^[A-Z]{3}$/,
134120
expUnicodeExSeq = /-u(?:-[0-9a-z]{2,8})+/gi, // See `extension` below
135121

136-
expBCP47Syntax,
137-
expExtSequences,
138-
expVariantDupes,
139-
expSingletonDupes,
140-
141122
// IANA Subtag Registry redundant tag and subtag maps
142123
redundantTags = {
143124
tags: {
@@ -229,110 +210,6 @@ var
229210
OMR: 3, PYG: 0, RWF: 0, TND: 3, UGX: 0, UYI: 0, VUV: 0, VND: 0
230211
};
231212

232-
/**
233-
* Defines regular expressions for various operations related to the BCP 47 syntax,
234-
* as defined at http://tools.ietf.org/html/bcp47#section-2.1
235-
*/
236-
(function () {
237-
var
238-
// extlang = 3ALPHA ; selected ISO 639 codes
239-
// *2("-" 3ALPHA) ; permanently reserved
240-
extlang = '[a-z]{3}(?:-[a-z]{3}){0,2}',
241-
242-
// language = 2*3ALPHA ; shortest ISO 639 code
243-
// ["-" extlang] ; sometimes followed by
244-
// ; extended language subtags
245-
// / 4ALPHA ; or reserved for future use
246-
// / 5*8ALPHA ; or registered language subtag
247-
language = '(?:[a-z]{2,3}(?:-' + extlang + ')?|[a-z]{4}|[a-z]{5,8})',
248-
249-
// script = 4ALPHA ; ISO 15924 code
250-
script = '[a-z]{4}',
251-
252-
// region = 2ALPHA ; ISO 3166-1 code
253-
// / 3DIGIT ; UN M.49 code
254-
region = '(?:[a-z]{2}|\\d{3})',
255-
256-
// variant = 5*8alphanum ; registered variants
257-
// / (DIGIT 3alphanum)
258-
variant = '(?:[a-z0-9]{5,8}|\\d[a-z0-9]{3})',
259-
260-
// ; Single alphanumerics
261-
// ; "x" reserved for private use
262-
// singleton = DIGIT ; 0 - 9
263-
// / %x41-57 ; A - W
264-
// / %x59-5A ; Y - Z
265-
// / %x61-77 ; a - w
266-
// / %x79-7A ; y - z
267-
singleton = '[0-9a-wy-z]',
268-
269-
// extension = singleton 1*("-" (2*8alphanum))
270-
extension = singleton + '(?:-[a-z0-9]{2,8})+',
271-
272-
// privateuse = "x" 1*("-" (1*8alphanum))
273-
privateuse = 'x(?:-[a-z0-9]{1,8})+',
274-
275-
// irregular = "en-GB-oed" ; irregular tags do not match
276-
// / "i-ami" ; the 'langtag' production and
277-
// / "i-bnn" ; would not otherwise be
278-
// / "i-default" ; considered 'well-formed'
279-
// / "i-enochian" ; These tags are all valid,
280-
// / "i-hak" ; but most are deprecated
281-
// / "i-klingon" ; in favor of more modern
282-
// / "i-lux" ; subtags or subtag
283-
// / "i-mingo" ; combination
284-
// / "i-navajo"
285-
// / "i-pwn"
286-
// / "i-tao"
287-
// / "i-tay"
288-
// / "i-tsu"
289-
// / "sgn-BE-FR"
290-
// / "sgn-BE-NL"
291-
// / "sgn-CH-DE"
292-
irregular = '(?:en-GB-oed'
293-
+ '|i-(?:ami|bnn|default|enochian|hak|klingon|lux|mingo|navajo|pwn|tao|tay|tsu)'
294-
+ '|sgn-(?:BE-FR|BE-NL|CH-DE))',
295-
296-
// regular = "art-lojban" ; these tags match the 'langtag'
297-
// / "cel-gaulish" ; production, but their subtags
298-
// / "no-bok" ; are not extended language
299-
// / "no-nyn" ; or variant subtags: their meaning
300-
// / "zh-guoyu" ; is defined by their registration
301-
// / "zh-hakka" ; and all of these are deprecated
302-
// / "zh-min" ; in favor of a more modern
303-
// / "zh-min-nan" ; subtag or sequence of subtags
304-
// / "zh-xiang"
305-
regular = '(?:art-lojban|cel-gaulish|no-bok|no-nyn'
306-
+ '|zh-(?:guoyu|hakka|min|min-nan|xiang))',
307-
308-
// grandfathered = irregular ; non-redundant tags registered
309-
// / regular ; during the RFC 3066 era
310-
grandfathered = '(?:' + irregular + '|' + regular + ')',
311-
312-
// langtag = language
313-
// ["-" script]
314-
// ["-" region]
315-
// *("-" variant)
316-
// *("-" extension)
317-
// ["-" privateuse]
318-
langtag = language + '(?:-' + script + ')?(?:-' + region + ')?(?:-'
319-
+ variant + ')*(?:-' + extension + ')*(?:-' + privateuse + ')?';
320-
321-
// Language-Tag = langtag ; normal language tags
322-
// / privateuse ; private use tag
323-
// / grandfathered ; grandfathered tags
324-
expBCP47Syntax = RegExp('^(?:'+langtag+'|'+privateuse+'|'+grandfathered+')$', 'i');
325-
326-
// Match duplicate variants in a language tag
327-
expVariantDupes = RegExp('^(?!x).*?-('+variant+')-(?:\\w{4,8}-(?!x-))*\\1\\b', 'i');
328-
329-
// Match duplicate singletons in a language tag (except in private use)
330-
expSingletonDupes = RegExp('^(?!x).*?-('+singleton+')-(?:\\w+-(?!x-))*\\1\\b', 'i');
331-
332-
// Match all extension sequences
333-
expExtSequences = RegExp('-'+extension, 'ig');
334-
})();
335-
336213
// Sect 6.2 Language Tags
337214
// ======================
338215

@@ -3065,5 +2942,4 @@ function getInternalProperties (obj) {
30652942
return objCreate(null);
30662943
}
30672944

3068-
return Intl;
3069-
});
2945+
export default Intl;

0 commit comments

Comments
 (0)