Skip to content

Commit

Permalink
massive refactor to use ES6 modules under the hood so we can split th…
Browse files Browse the repository at this point in the history
…is into pieces in the future
  • Loading branch information
caridy committed Sep 5, 2014
1 parent ce0a12a commit 1b4b292
Show file tree
Hide file tree
Showing 18 changed files with 4,718 additions and 3,279 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ cldr/

# NPM packages installed locally
node_modules

lib/
node_modules/
tmp/
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ cldr/
# (It doesn't need anything used during development of this library.)
tools/
tests/

coverage/
tasks/
tmp/
.travis.yml
Gruntfile.js
56 changes: 47 additions & 9 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,69 @@ module.exports = function (grunt) {

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

clean: {
dist: 'dist/',
lib : 'lib/',
tmp : 'tmp/'
},

copy: {
tmp: {
expand : true,
flatten: true,
src : ['tmp/src/*.js'],
dest : 'lib/'
}
},

concat: {
complete: {
src: ['dist/Intl.min.js', 'locale-data/complete.js'],
dest: 'dist/Intl.complete.js',
}
},

jshint: {
all: ['Intl.js']
all: ['index.js', 'src/*.js', '!src/en.js']
},

bundle_jsnext: {
dest: 'dist/Intl.js',
options: {
namespace: 'IntlPolyfill'
}
},

cjs_jsnext: {
dest: 'tmp/'
},

uglify: {
options: {
preserveComments: 'some'
},
build: {
files: {
'Intl.min.js': ['Intl.js']
'dist/Intl.min.js': ['dist/Intl.js']
}
}
}

});

grunt.loadTasks('./tasks');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-bundle-jsnext-lib');

grunt.registerTask('default', function () {
grunt.task.run('jshint');
grunt.task.run('uglify');
grunt.registerTask('build', [
'bundle_jsnext', 'uglify', 'cjs_jsnext', 'copy', 'concat'
]);

if (grunt.option('complete'))
grunt.task.run('compile-data');
});
grunt.registerTask('cldr', ['compile-data']);

grunt.registerTask('default', ['jshint', 'clean', 'build']);
};
3,070 changes: 0 additions & 3,070 deletions Intl.complete.js

This file was deleted.

11 changes: 0 additions & 11 deletions Intl.min.js

This file was deleted.

709 changes: 709 additions & 0 deletions dist/Intl.complete.js

Large diffs are not rendered by default.

3,033 changes: 3,033 additions & 0 deletions dist/Intl.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/Intl.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/Intl.min.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var m = require('./lib/core.js'),
IntlPolyfill = m.default;

// add locale data for all locales into runtime
global.IntlPolyfill = IntlPolyfill;
require('./locale-data/complete.js');

// hack to export the polyfill as global Intl if needed
if (!global.Intl) {
global.Intl = IntlPolyfill;
IntlPolyfill.__applyLocaleSensitivePrototypes();
}

// providing an idiomatic api for the nodejs version of this module
module.exports = exports = IntlPolyfill;
// preserving the original api in case another module is relying on that
exports.default = IntlPolyfill;
708 changes: 708 additions & 0 deletions locale-data/complete.js

Large diffs are not rendered by default.

82 changes: 44 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
{
"name": "intl",
"version": "0.1.4",
"description": "Polyfill the ECMA-402 Intl API (except collation)",
"main": "Intl.complete.js",
"directories": {
"test": "tests"
},
"devDependencies": {
"async": "~0.2.9",
"grunt": "~0.4.2",
"grunt-cli": "~0.1.11",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-uglify": "~0.2.7",
"jshint": "~2.3.0",
"wd": "~0.2.8"
},
"scripts": {
"build": "grunt --complete",
"lint": "jshint Intl.js",
"test": "cd tests && node noderunner.js && node saucelabs.js"
},
"repository": {
"type": "git",
"url": "https://github.com/andyearnshaw/Intl.js"
},
"keywords": [
"intl",
"i18n",
"internationalization",
"ecma402",
"polyfill"
],
"author": "Andy Earnshaw",
"email": "andyearnshaw@gmail.com",
"license": "MIT",
"bugs": {
"url": "https://github.com/andyearnshaw/Intl.js/issues"
}
"name": "intl",
"version": "1.0.0-rc-1",
"description": "Polyfill the ECMA-402 Intl API (except collation)",
"main": "index.js",
"jsnext:main": "src/main.js",
"directories": {
"test": "tests"
},
"devDependencies": {
"async": "^0.9.0",
"grunt": "^0.4.5",
"grunt-cli": "~0.1.13",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-copy": "^0.5.0",
"grunt-contrib-concat": "^0.5.0",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-uglify": "^0.5.1",
"grunt-bundle-jsnext-lib": "^0.2.1",
"jshint": "^2.5.5",
"wd": "^0.3.6"
},
"scripts": {
"build": "grunt cldr",
"lint": "grunt jshint",
"pretest": "grunt jshint",
"test": "cd tests && node noderunner.js && node saucelabs.js"
},
"repository": {
"type": "git",
"url": "https://github.com/andyearnshaw/Intl.js"
},
"keywords": [
"intl",
"i18n",
"internationalization",
"ecma402",
"polyfill"
],
"author": "Andy Earnshaw",
"email": "andyearnshaw@gmail.com",
"license": "MIT",
"bugs": {
"url": "https://github.com/andyearnshaw/Intl.js/issues"
}
}
142 changes: 9 additions & 133 deletions Intl.js → src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,16 @@
*
* CLDR format locale data should be provided using IntlPolyfill.__addLocaleData().
*/
/*jshint proto:true, eqnull:true, boss:true, laxbreak:true, newcap:false, shadow:true, funcscope:true */
/*globals global, define, exports, module, window*/
/*jshint esnext: true, proto:true, eqnull:true, boss:true, laxbreak:true, newcap:false, shadow:true, funcscope:true */

(function (global, factory) {
var IntlPolyfill = factory();

// register in -all- the module systems (at once)
if (typeof define === 'function' && define.amd)
define(IntlPolyfill);

if (typeof exports === 'object')
module.exports = IntlPolyfill;

if (!global.Intl) {
global.Intl = IntlPolyfill;
IntlPolyfill.__applyLocaleSensitivePrototypes();
}

global.IntlPolyfill = IntlPolyfill;
import {
expBCP47Syntax,
expExtSequences,
expVariantDupes,
expSingletonDupes
} from './exp';

})(typeof global !== 'undefined' ? global : this, function() {
"use strict";
var
Intl = {},
var Intl = {},

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

expBCP47Syntax,
expExtSequences,
expVariantDupes,
expSingletonDupes,

// IANA Subtag Registry redundant tag and subtag maps
redundantTags = {
tags: {
Expand Down Expand Up @@ -229,110 +210,6 @@ var
OMR: 3, PYG: 0, RWF: 0, TND: 3, UGX: 0, UYI: 0, VUV: 0, VND: 0
};

/**
* Defines regular expressions for various operations related to the BCP 47 syntax,
* as defined at http://tools.ietf.org/html/bcp47#section-2.1
*/
(function () {
var
// extlang = 3ALPHA ; selected ISO 639 codes
// *2("-" 3ALPHA) ; permanently reserved
extlang = '[a-z]{3}(?:-[a-z]{3}){0,2}',

// language = 2*3ALPHA ; shortest ISO 639 code
// ["-" extlang] ; sometimes followed by
// ; extended language subtags
// / 4ALPHA ; or reserved for future use
// / 5*8ALPHA ; or registered language subtag
language = '(?:[a-z]{2,3}(?:-' + extlang + ')?|[a-z]{4}|[a-z]{5,8})',

// script = 4ALPHA ; ISO 15924 code
script = '[a-z]{4}',

// region = 2ALPHA ; ISO 3166-1 code
// / 3DIGIT ; UN M.49 code
region = '(?:[a-z]{2}|\\d{3})',

// variant = 5*8alphanum ; registered variants
// / (DIGIT 3alphanum)
variant = '(?:[a-z0-9]{5,8}|\\d[a-z0-9]{3})',

// ; Single alphanumerics
// ; "x" reserved for private use
// singleton = DIGIT ; 0 - 9
// / %x41-57 ; A - W
// / %x59-5A ; Y - Z
// / %x61-77 ; a - w
// / %x79-7A ; y - z
singleton = '[0-9a-wy-z]',

// extension = singleton 1*("-" (2*8alphanum))
extension = singleton + '(?:-[a-z0-9]{2,8})+',

// privateuse = "x" 1*("-" (1*8alphanum))
privateuse = 'x(?:-[a-z0-9]{1,8})+',

// irregular = "en-GB-oed" ; irregular tags do not match
// / "i-ami" ; the 'langtag' production and
// / "i-bnn" ; would not otherwise be
// / "i-default" ; considered 'well-formed'
// / "i-enochian" ; These tags are all valid,
// / "i-hak" ; but most are deprecated
// / "i-klingon" ; in favor of more modern
// / "i-lux" ; subtags or subtag
// / "i-mingo" ; combination
// / "i-navajo"
// / "i-pwn"
// / "i-tao"
// / "i-tay"
// / "i-tsu"
// / "sgn-BE-FR"
// / "sgn-BE-NL"
// / "sgn-CH-DE"
irregular = '(?:en-GB-oed'
+ '|i-(?:ami|bnn|default|enochian|hak|klingon|lux|mingo|navajo|pwn|tao|tay|tsu)'
+ '|sgn-(?:BE-FR|BE-NL|CH-DE))',

// regular = "art-lojban" ; these tags match the 'langtag'
// / "cel-gaulish" ; production, but their subtags
// / "no-bok" ; are not extended language
// / "no-nyn" ; or variant subtags: their meaning
// / "zh-guoyu" ; is defined by their registration
// / "zh-hakka" ; and all of these are deprecated
// / "zh-min" ; in favor of a more modern
// / "zh-min-nan" ; subtag or sequence of subtags
// / "zh-xiang"
regular = '(?:art-lojban|cel-gaulish|no-bok|no-nyn'
+ '|zh-(?:guoyu|hakka|min|min-nan|xiang))',

// grandfathered = irregular ; non-redundant tags registered
// / regular ; during the RFC 3066 era
grandfathered = '(?:' + irregular + '|' + regular + ')',

// langtag = language
// ["-" script]
// ["-" region]
// *("-" variant)
// *("-" extension)
// ["-" privateuse]
langtag = language + '(?:-' + script + ')?(?:-' + region + ')?(?:-'
+ variant + ')*(?:-' + extension + ')*(?:-' + privateuse + ')?';

// Language-Tag = langtag ; normal language tags
// / privateuse ; private use tag
// / grandfathered ; grandfathered tags
expBCP47Syntax = RegExp('^(?:'+langtag+'|'+privateuse+'|'+grandfathered+')$', 'i');

// Match duplicate variants in a language tag
expVariantDupes = RegExp('^(?!x).*?-('+variant+')-(?:\\w{4,8}-(?!x-))*\\1\\b', 'i');

// Match duplicate singletons in a language tag (except in private use)
expSingletonDupes = RegExp('^(?!x).*?-('+singleton+')-(?:\\w+-(?!x-))*\\1\\b', 'i');

// Match all extension sequences
expExtSequences = RegExp('-'+extension, 'ig');
})();

// Sect 6.2 Language Tags
// ======================

Expand Down Expand Up @@ -3065,5 +2942,4 @@ function getInternalProperties (obj) {
return objCreate(null);
}

return Intl;
});
export default Intl;
Loading

0 comments on commit 1b4b292

Please sign in to comment.