Skip to content

Commit

Permalink
feat(dist): minimise the size of the package for browsers
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The fallback Intl package is no longer included in browsers.  To use it see https://github.com/andyearnshaw/Intl.js#intljs-and-ft-polyfill-service
  • Loading branch information
richardschneider committed Nov 4, 2016
1 parent ee51bae commit 389df68
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

require('babel-polyfill');
//require('babel-polyfill');

module.exports = require('./lib/money');
11 changes: 8 additions & 3 deletions lib/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

/* global Intl */

const fallbackIntl = require('intl'),
memoize = require('memoize-immutable');
const memoize = require('memoize-immutable');

/* The fallback Intl is not shipped to a browser. */
var fallbackIntl = require('intl');
if (!('NumberFormat' in fallbackIntl)) {
fallbackIntl = null;
}

var fallbackLanguage; // 'undefined' lets the enviroment determine the best language
var defaults = {
Expand All @@ -20,7 +25,7 @@ function currencyFormat(language, currency, options) {
currency = language;
language = fallbackLanguage;
}
if (language) {
if (language && fallbackIntl) {
let supported = i18n.NumberFormat.supportedLocalesOf(language)[0] === language;
if (!supported) {
i18n = fallbackIntl;
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"bugs": "https://github.com/richardschneider/money-works/issues",
"license": "MIT",
"main": "index.js",
"browser": "browser.js",
"browser": {
"index.js": "browser.js",
"intl": false
},
"browserify": {
"transform": [
[
Expand Down
4 changes: 4 additions & 0 deletions test/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ describe('Localisation', () => {
a.should.not.equal(c);
});

it('should accept any language', () => {
let a = l10n('xx-XX', 'EUR');
a.should.have.property('format');
});
});
24 changes: 24 additions & 0 deletions test/runner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Testing money-works</title>
<style>
body {
font: 18px/1.5 "Helvetica Neue", Helvetica, sans-serif;
padding-left: 20px;
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.css" />
</head>
<body>
<div id="mocha"></div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.js"></script>
<script>mocha.setup('bdd');</script>
<script src="../dist/money-works.spec.js"></script>
<script>
mocha.run();
</script>
</body>
</html>

0 comments on commit 389df68

Please sign in to comment.