factorial-i18n
Advanced tools
Comparing version 0.1.0 to 0.2.0
module.exports = { | ||
parser: 'babel-eslint', | ||
plugins: [ 'flowtype' ], | ||
parser: '@typescript-eslint/parser', | ||
plugins: [ '@typescript-eslint' ], | ||
@@ -16,8 +16,12 @@ env: { | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
experimentalObjectRestSpread: true | ||
} | ||
}, | ||
extends: [ | ||
'plugin:flowtype/recommended', | ||
'standard' | ||
] | ||
rules: { | ||
'object-curly-spacing': ['warn', 'always'], | ||
'prefer-promise-reject-errors': 'off', | ||
'no-duplicate-imports': 'off' | ||
} | ||
}; |
# Changelog | ||
## `0.2.0` | ||
Updated `formatNumber` function to handle currency formatting. | ||
`formatNumber` no longer takes `format` as an argument. | ||
Switched to typescript + rollup like all the other factorial packages. | ||
## `0.1.0` | ||
@@ -4,0 +10,0 @@ |
@@ -1,3 +0,2 @@ | ||
{"/Users/pauramonrevilla/Sites/factorial-i18n/src/index.js": {"path":"/Users/pauramonrevilla/Sites/factorial-i18n/src/index.js","statementMap":{"0":{"start":{"line":14,"column":4},"end":{"line":14,"column":26}},"1":{"start":{"line":18,"column":4},"end":{"line":18,"column":36}},"2":{"start":{"line":22,"column":4},"end":{"line":22,"column":24}},"3":{"start":{"line":24,"column":4},"end":{"line":27,"column":5}},"4":{"start":{"line":25,"column":6},"end":{"line":25,"column":56}},"5":{"start":{"line":26,"column":6},"end":{"line":26,"column":28}},"6":{"start":{"line":34,"column":4},"end":{"line":34,"column":41}},"7":{"start":{"line":41,"column":4},"end":{"line":41,"column":56}},"8":{"start":{"line":54,"column":18},"end":{"line":54,"column":35}},"9":{"start":{"line":55,"column":4},"end":{"line":57,"column":5}},"10":{"start":{"line":56,"column":6},"end":{"line":56,"column":51}},"11":{"start":{"line":58,"column":18},"end":{"line":58,"column":33}},"12":{"start":{"line":60,"column":4},"end":{"line":63,"column":6}},"13":{"start":{"line":61,"column":6},"end":{"line":61,"column":26}},"14":{"start":{"line":61,"column":17},"end":{"line":61,"column":26}},"15":{"start":{"line":62,"column":6},"end":{"line":62,"column":32}},"16":{"start":{"line":75,"column":16},"end":{"line":75,"column":26}},"17":{"start":{"line":77,"column":4},"end":{"line":79,"column":5}},"18":{"start":{"line":78,"column":6},"end":{"line":78,"column":57}},"19":{"start":{"line":81,"column":17},"end":{"line":81,"column":41}},"20":{"start":{"line":82,"column":23},"end":{"line":82,"column":40}},"21":{"start":{"line":84,"column":4},"end":{"line":84,"column":35}},"22":{"start":{"line":96,"column":20},"end":{"line":96,"column":41}},"23":{"start":{"line":97,"column":4},"end":{"line":97,"column":32}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":13,"column":2},"end":{"line":13,"column":3}},"loc":{"start":{"line":13,"column":17},"end":{"line":15,"column":3}},"line":13},"1":{"name":"(anonymous_1)","decl":{"start":{"line":17,"column":2},"end":{"line":17,"column":3}},"loc":{"start":{"line":17,"column":53},"end":{"line":19,"column":3}},"line":17},"2":{"name":"(anonymous_2)","decl":{"start":{"line":21,"column":2},"end":{"line":21,"column":3}},"loc":{"start":{"line":21,"column":35},"end":{"line":28,"column":3}},"line":21},"3":{"name":"(anonymous_3)","decl":{"start":{"line":33,"column":2},"end":{"line":33,"column":3}},"loc":{"start":{"line":33,"column":56},"end":{"line":35,"column":3}},"line":33},"4":{"name":"(anonymous_4)","decl":{"start":{"line":40,"column":2},"end":{"line":40,"column":3}},"loc":{"start":{"line":40,"column":40},"end":{"line":42,"column":3}},"line":40},"5":{"name":"(anonymous_5)","decl":{"start":{"line":53,"column":2},"end":{"line":53,"column":3}},"loc":{"start":{"line":53,"column":60},"end":{"line":64,"column":3}},"line":53},"6":{"name":"(anonymous_6)","decl":{"start":{"line":60,"column":32},"end":{"line":60,"column":33}},"loc":{"start":{"line":60,"column":50},"end":{"line":63,"column":5}},"line":60},"7":{"name":"(anonymous_7)","decl":{"start":{"line":74,"column":2},"end":{"line":74,"column":3}},"loc":{"start":{"line":74,"column":60},"end":{"line":85,"column":3}},"line":74},"8":{"name":"(anonymous_8)","decl":{"start":{"line":95,"column":2},"end":{"line":95,"column":3}},"loc":{"start":{"line":95,"column":79},"end":{"line":98,"column":3}},"line":95}},"branchMap":{"0":{"loc":{"start":{"line":24,"column":4},"end":{"line":27,"column":5}},"type":"if","locations":[{"start":{"line":24,"column":4},"end":{"line":27,"column":5}},{"start":{"line":24,"column":4},"end":{"line":27,"column":5}}],"line":24},"1":{"loc":{"start":{"line":55,"column":4},"end":{"line":57,"column":5}},"type":"if","locations":[{"start":{"line":55,"column":4},"end":{"line":57,"column":5}},{"start":{"line":55,"column":4},"end":{"line":57,"column":5}}],"line":55},"2":{"loc":{"start":{"line":61,"column":6},"end":{"line":61,"column":26}},"type":"if","locations":[{"start":{"line":61,"column":6},"end":{"line":61,"column":26}},{"start":{"line":61,"column":6},"end":{"line":61,"column":26}}],"line":61},"3":{"loc":{"start":{"line":77,"column":4},"end":{"line":79,"column":5}},"type":"if","locations":[{"start":{"line":77,"column":4},"end":{"line":79,"column":5}},{"start":{"line":77,"column":4},"end":{"line":79,"column":5}}],"line":77}},"s":{"0":11,"1":11,"2":10,"3":10,"4":5,"5":5,"6":2,"7":13,"8":13,"9":13,"10":2,"11":11,"12":11,"13":8,"14":1,"15":7,"16":8,"17":7,"18":1,"19":6,"20":6,"21":6,"22":2,"23":2},"f":{"0":11,"1":11,"2":10,"3":2,"4":13,"5":13,"6":8,"7":8,"8":2},"b":{"0":[5,5],"1":[2,11],"2":[1,7],"3":[1,6]},"_coverageSchema":"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c","hash":"3831421fd502c546ffc2d6d0656424bb0c703106"} | ||
,"/Users/pauramonrevilla/Sites/factorial-i18n/src/numeralLanguages.js": {"path":"/Users/pauramonrevilla/Sites/factorial-i18n/src/numeralLanguages.js","statementMap":{"0":{"start":{"line":20,"column":16},"end":{"line":20,"column":27}},"1":{"start":{"line":22,"column":6},"end":{"line":26,"column":78}}},"fnMap":{},"branchMap":{"0":{"loc":{"start":{"line":22,"column":13},"end":{"line":26,"column":78}},"type":"cond-expr","locations":[{"start":{"line":23,"column":10},"end":{"line":23,"column":14}},{"start":{"line":24,"column":10},"end":{"line":26,"column":78}}],"line":22},"1":{"loc":{"start":{"line":22,"column":13},"end":{"line":22,"column":31}},"type":"binary-expr","locations":[{"start":{"line":22,"column":13},"end":{"line":22,"column":20}},{"start":{"line":22,"column":24},"end":{"line":22,"column":31}}],"line":22},"2":{"loc":{"start":{"line":24,"column":10},"end":{"line":26,"column":78}},"type":"cond-expr","locations":[{"start":{"line":25,"column":12},"end":{"line":25,"column":16}},{"start":{"line":26,"column":12},"end":{"line":26,"column":78}}],"line":24},"3":{"loc":{"start":{"line":26,"column":12},"end":{"line":26,"column":78}},"type":"cond-expr","locations":[{"start":{"line":26,"column":33},"end":{"line":26,"column":37}},{"start":{"line":26,"column":40},"end":{"line":26,"column":78}}],"line":26},"4":{"loc":{"start":{"line":26,"column":12},"end":{"line":26,"column":30}},"type":"binary-expr","locations":[{"start":{"line":26,"column":12},"end":{"line":26,"column":19}},{"start":{"line":26,"column":23},"end":{"line":26,"column":30}}],"line":26},"5":{"loc":{"start":{"line":26,"column":40},"end":{"line":26,"column":78}},"type":"cond-expr","locations":[{"start":{"line":26,"column":50},"end":{"line":26,"column":54}},{"start":{"line":26,"column":57},"end":{"line":26,"column":78}}],"line":26},"6":{"loc":{"start":{"line":26,"column":57},"end":{"line":26,"column":78}},"type":"cond-expr","locations":[{"start":{"line":26,"column":67},"end":{"line":26,"column":71}},{"start":{"line":26,"column":74},"end":{"line":26,"column":78}}],"line":26}},"s":{"0":0,"1":0},"f":{},"b":{"0":[0,0],"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0]},"_coverageSchema":"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c","hash":"1b5cf8a42b8d3e0caebf7ef68366cdb0bc76a155"} | ||
{"/Users/pauramonrevilla/Sites/factorial-i18n/src/index.js": {"path":"/Users/pauramonrevilla/Sites/factorial-i18n/src/index.js","statementMap":{"0":{"start":{"line":1,"column":13},"end":{"line":1,"column":75}},"1":{"start":{"line":1,"column":94},"end":{"line":1,"column":623}},"2":{"start":{"line":1,"column":149},"end":{"line":1,"column":414}},"3":{"start":{"line":1,"column":206},"end":{"line":1,"column":214}},"4":{"start":{"line":1,"column":215},"end":{"line":1,"column":270}},"5":{"start":{"line":1,"column":270},"end":{"line":1,"column":301}},"6":{"start":{"line":1,"column":301},"end":{"line":1,"column":355}},"7":{"start":{"line":1,"column":328},"end":{"line":1,"column":355}},"8":{"start":{"line":1,"column":355},"end":{"line":1,"column":413}},"9":{"start":{"line":1,"column":415},"end":{"line":1,"column":620}},"10":{"start":{"line":1,"column":471},"end":{"line":1,"column":539}},"11":{"start":{"line":1,"column":487},"end":{"line":1,"column":539}},"12":{"start":{"line":1,"column":539},"end":{"line":1,"column":599}},"13":{"start":{"line":1,"column":556},"end":{"line":1,"column":599}},"14":{"start":{"line":1,"column":599},"end":{"line":1,"column":618}},"15":{"start":{"line":1,"column":638},"end":{"line":1,"column":658}},"16":{"start":{"line":1,"column":674},"end":{"line":1,"column":705}},"17":{"start":{"line":2,"column":19},"end":{"line":2,"column":42}},"18":{"start":{"line":2,"column":63},"end":{"line":2,"column":99}},"19":{"start":{"line":2,"column":138},"end":{"line":2,"column":192}},"20":{"start":{"line":2,"column":242},"end":{"line":2,"column":341}},"21":{"start":{"line":2,"column":283},"end":{"line":2,"column":340}},"22":{"start":{"line":6,"column":7},"end":{"line":97,"column":25}},"23":{"start":{"line":10,"column":19},"end":{"line":10,"column":47}},"24":{"start":{"line":11,"column":4},"end":{"line":11,"column":27}},"25":{"start":{"line":12,"column":3},"end":{"line":97,"column":10}},"26":{"start":{"line":15,"column":6},"end":{"line":15,"column":39}},"27":{"start":{"line":19,"column":6},"end":{"line":19,"column":27}},"28":{"start":{"line":26,"column":19},"end":{"line":26,"column":21}},"29":{"start":{"line":27,"column":6},"end":{"line":27,"column":38}},"30":{"start":{"line":27,"column":17},"end":{"line":27,"column":38}},"31":{"start":{"line":28,"column":6},"end":{"line":28,"column":47}},"32":{"start":{"line":28,"column":20},"end":{"line":28,"column":47}},"33":{"start":{"line":30,"column":6},"end":{"line":33,"column":21}},"34":{"start":{"line":40,"column":6},"end":{"line":40,"column":76}},"35":{"start":{"line":53,"column":18},"end":{"line":53,"column":35}},"36":{"start":{"line":54,"column":6},"end":{"line":56,"column":7}},"37":{"start":{"line":55,"column":8},"end":{"line":55,"column":59}},"38":{"start":{"line":57,"column":18},"end":{"line":57,"column":33}},"39":{"start":{"line":59,"column":6},"end":{"line":62,"column":9}},"40":{"start":{"line":60,"column":8},"end":{"line":60,"column":29}},"41":{"start":{"line":60,"column":19},"end":{"line":60,"column":29}},"42":{"start":{"line":61,"column":8},"end":{"line":61,"column":35}},"43":{"start":{"line":74,"column":16},"end":{"line":74,"column":26}},"44":{"start":{"line":76,"column":6},"end":{"line":78,"column":7}},"45":{"start":{"line":77,"column":8},"end":{"line":77,"column":60}},"46":{"start":{"line":80,"column":17},"end":{"line":80,"column":61}},"47":{"start":{"line":81,"column":23},"end":{"line":81,"column":40}},"48":{"start":{"line":83,"column":6},"end":{"line":83,"column":38}},"49":{"start":{"line":95,"column":20},"end":{"line":95,"column":41}},"50":{"start":{"line":96,"column":6},"end":{"line":96,"column":35}},"51":{"start":{"line":97,"column":10},"end":{"line":97,"column":22}},"52":{"start":{"line":97,"column":26},"end":{"line":97,"column":49}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":1,"column":94},"end":{"line":1,"column":95}},"loc":{"start":{"line":1,"column":106},"end":{"line":1,"column":621}},"line":1},"1":{"name":"defineProperties","decl":{"start":{"line":1,"column":116},"end":{"line":1,"column":132}},"loc":{"start":{"line":1,"column":148},"end":{"line":1,"column":415}},"line":1},"2":{"name":"(anonymous_2)","decl":{"start":{"line":1,"column":422},"end":{"line":1,"column":423}},"loc":{"start":{"line":1,"column":470},"end":{"line":1,"column":619}},"line":1},"3":{"name":"_interopRequireDefault","decl":{"start":{"line":2,"column":109},"end":{"line":2,"column":131}},"loc":{"start":{"line":2,"column":137},"end":{"line":2,"column":193}},"line":2},"4":{"name":"_classCallCheck","decl":{"start":{"line":2,"column":202},"end":{"line":2,"column":217}},"loc":{"start":{"line":2,"column":241},"end":{"line":2,"column":342}},"line":2},"5":{"name":"(anonymous_5)","decl":{"start":{"line":6,"column":7},"end":{"line":6,"column":8}},"loc":{"start":{"line":6,"column":19},"end":{"line":97,"column":23}},"line":6},"6":{"name":"I18n","decl":{"start":{"line":10,"column":11},"end":{"line":10,"column":15}},"loc":{"start":{"line":10,"column":18},"end":{"line":12,"column":3}},"line":10},"7":{"name":"setTranslations","decl":{"start":{"line":12,"column":65},"end":{"line":12,"column":80}},"loc":{"start":{"line":14,"column":18},"end":{"line":16,"column":5}},"line":14},"8":{"name":"setLocale","decl":{"start":{"line":16,"column":45},"end":{"line":16,"column":54}},"loc":{"start":{"line":18,"column":12},"end":{"line":20,"column":5}},"line":18},"9":{"name":"formatNumber","decl":{"start":{"line":24,"column":52},"end":{"line":24,"column":64}},"loc":{"start":{"line":25,"column":29},"end":{"line":34,"column":5}},"line":25},"10":{"name":"getKey","decl":{"start":{"line":38,"column":46},"end":{"line":38,"column":52}},"loc":{"start":{"line":39,"column":10},"end":{"line":41,"column":5}},"line":39},"11":{"name":"t","decl":{"start":{"line":51,"column":41},"end":{"line":51,"column":42}},"loc":{"start":{"line":52,"column":16},"end":{"line":63,"column":5}},"line":52},"12":{"name":"(anonymous_12)","decl":{"start":{"line":59,"column":34},"end":{"line":59,"column":35}},"loc":{"start":{"line":59,"column":58},"end":{"line":62,"column":7}},"line":59},"13":{"name":"tp","decl":{"start":{"line":72,"column":42},"end":{"line":72,"column":44}},"loc":{"start":{"line":73,"column":16},"end":{"line":84,"column":5}},"line":73},"14":{"name":"tx","decl":{"start":{"line":93,"column":42},"end":{"line":93,"column":44}},"loc":{"start":{"line":94,"column":26},"end":{"line":97,"column":5}},"line":94}},"branchMap":{"0":{"loc":{"start":{"line":1,"column":239},"end":{"line":1,"column":269}},"type":"binary-expr","locations":[{"start":{"line":1,"column":239},"end":{"line":1,"column":260}},{"start":{"line":1,"column":264},"end":{"line":1,"column":269}}],"line":1},"1":{"loc":{"start":{"line":1,"column":301},"end":{"line":1,"column":355}},"type":"if","locations":[{"start":{"line":1,"column":301},"end":{"line":1,"column":355}},{"start":{"line":1,"column":301},"end":{"line":1,"column":355}}],"line":1},"2":{"loc":{"start":{"line":1,"column":471},"end":{"line":1,"column":539}},"type":"if","locations":[{"start":{"line":1,"column":471},"end":{"line":1,"column":539}},{"start":{"line":1,"column":471},"end":{"line":1,"column":539}}],"line":1},"3":{"loc":{"start":{"line":1,"column":539},"end":{"line":1,"column":599}},"type":"if","locations":[{"start":{"line":1,"column":539},"end":{"line":1,"column":599}},{"start":{"line":1,"column":539},"end":{"line":1,"column":599}}],"line":1},"4":{"loc":{"start":{"line":2,"column":145},"end":{"line":2,"column":191}},"type":"cond-expr","locations":[{"start":{"line":2,"column":169},"end":{"line":2,"column":172}},{"start":{"line":2,"column":175},"end":{"line":2,"column":191}}],"line":2},"5":{"loc":{"start":{"line":2,"column":145},"end":{"line":2,"column":166}},"type":"binary-expr","locations":[{"start":{"line":2,"column":145},"end":{"line":2,"column":148}},{"start":{"line":2,"column":152},"end":{"line":2,"column":166}}],"line":2},"6":{"loc":{"start":{"line":2,"column":242},"end":{"line":2,"column":341}},"type":"if","locations":[{"start":{"line":2,"column":242},"end":{"line":2,"column":341}},{"start":{"line":2,"column":242},"end":{"line":2,"column":341}}],"line":2},"7":{"loc":{"start":{"line":27,"column":6},"end":{"line":27,"column":38}},"type":"if","locations":[{"start":{"line":27,"column":6},"end":{"line":27,"column":38}},{"start":{"line":27,"column":6},"end":{"line":27,"column":38}}],"line":27},"8":{"loc":{"start":{"line":28,"column":6},"end":{"line":28,"column":47}},"type":"if","locations":[{"start":{"line":28,"column":6},"end":{"line":28,"column":47}},{"start":{"line":28,"column":6},"end":{"line":28,"column":47}}],"line":28},"9":{"loc":{"start":{"line":54,"column":6},"end":{"line":56,"column":7}},"type":"if","locations":[{"start":{"line":54,"column":6},"end":{"line":56,"column":7}},{"start":{"line":54,"column":6},"end":{"line":56,"column":7}}],"line":54},"10":{"loc":{"start":{"line":60,"column":8},"end":{"line":60,"column":29}},"type":"if","locations":[{"start":{"line":60,"column":8},"end":{"line":60,"column":29}},{"start":{"line":60,"column":8},"end":{"line":60,"column":29}}],"line":60},"11":{"loc":{"start":{"line":76,"column":6},"end":{"line":78,"column":7}},"type":"if","locations":[{"start":{"line":76,"column":6},"end":{"line":78,"column":7}},{"start":{"line":76,"column":6},"end":{"line":78,"column":7}}],"line":76}},"s":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0},"f":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0},"b":{"0":[0,0],"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0]}} | ||
} |
152
lib/index.js
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var plural = _interopDefault(require('plurals-cldr')); | ||
var _lodash = require('lodash'); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
var _numeral = require('numeral'); | ||
var _numeral2 = _interopRequireDefault(_numeral); | ||
var _pluralsCldr = require('plurals-cldr'); | ||
var _pluralsCldr2 = _interopRequireDefault(_pluralsCldr); | ||
var _numeralLanguages = require('./numeralLanguages'); | ||
var _numeralLanguages2 = _interopRequireDefault(_numeralLanguages); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var I18n = function () { | ||
function I18n() { | ||
_classCallCheck(this, I18n); | ||
this.translations = {}; | ||
} | ||
_createClass(I18n, [{ | ||
key: 'setTranslations', | ||
value: function setTranslations(translations) { | ||
this.translations = translations; | ||
var at = require('lodash.at'); | ||
var I18n = /** @class */ (function () { | ||
function I18n() { | ||
this.translations = {}; | ||
} | ||
}, { | ||
key: 'setLocale', | ||
value: function setLocale(locale) { | ||
this.locale = locale; | ||
if (_numeralLanguages2.default[locale]) { | ||
_numeral2.default.locales[locale] = _numeralLanguages2.default[locale]; | ||
_numeral2.default.locale(locale); | ||
} | ||
} | ||
I18n.prototype.setTranslations = function (translations) { | ||
this.translations = translations; | ||
}; | ||
I18n.prototype.setLocale = function (locale) { | ||
this.locale = locale; | ||
}; | ||
/** | ||
* Leverages `numeral` for number formatting | ||
* Leverages Intl.NumberFormat for currency formatting | ||
*/ | ||
}, { | ||
key: 'formatNumber', | ||
value: function formatNumber(format, number) { | ||
return (0, _numeral2.default)(number).format(format); | ||
} | ||
I18n.prototype.formatNumber = function (num, style, currency) { | ||
return new global.Intl.NumberFormat(this.locale, { style: style, currency: currency }).format(num); | ||
}; | ||
/** | ||
* Retrieves a key from the translations object. | ||
*/ | ||
}, { | ||
key: 'getKey', | ||
value: function getKey(path) { | ||
return _lodash2.default.at(this.translations[this.locale], path)[0]; | ||
} | ||
I18n.prototype.getKey = function (path) { | ||
return at(this.translations[this.locale], path)[0]; | ||
}; | ||
/** | ||
@@ -81,18 +39,14 @@ * Translate a key | ||
*/ | ||
}, { | ||
key: 't', | ||
value: function t(path, opts) { | ||
var value = this.getKey(path); | ||
if (typeof value !== 'string') { | ||
throw new Error('Key "' + path + '"is not a leaf'); | ||
} | ||
var MATCH = /%\{([^}]+)\}/g; | ||
return value.replace(MATCH, function (match, subst) { | ||
if (!opts) return ''; | ||
return String(opts[subst]); | ||
}); | ||
} | ||
I18n.prototype.t = function (path, opts) { | ||
var value = this.getKey(path); | ||
if (typeof value !== 'string') { | ||
throw new Error("Key \"" + path + "\"is not a leaf"); | ||
} | ||
var MATCH = /%\{([^}]+)\}/g; | ||
return value.replace(MATCH, function (match, subst) { | ||
if (!opts) | ||
return ''; | ||
return String(opts[subst]); | ||
}); | ||
}; | ||
/** | ||
@@ -106,18 +60,11 @@ * Translate singular o plural copies | ||
*/ | ||
}, { | ||
key: 'tp', | ||
value: function tp(path, opts) { | ||
var num = opts.count; | ||
if (typeof num !== 'number') { | ||
throw new Error('You must have a `count` property'); | ||
} | ||
var form = (0, _pluralsCldr2.default)(this.locale, num); | ||
var pluralPath = path + '.' + form; | ||
return this.t(pluralPath, opts); | ||
} | ||
I18n.prototype.tp = function (path, opts) { | ||
var num = opts.count; | ||
if (typeof num !== 'number') { | ||
throw new Error('You must have a `count` property'); | ||
} | ||
var form = plural(this.locale, num); | ||
var pluralPath = path + "." + form; | ||
return this.t(pluralPath, opts); | ||
}; | ||
/** | ||
@@ -131,14 +78,9 @@ * Conditional copies, made easy. | ||
*/ | ||
I18n.prototype.tx = function (path, variable, opts) { | ||
var newPath = path + "." + variable; | ||
return this.t(newPath, opts); | ||
}; | ||
return I18n; | ||
}()); | ||
}, { | ||
key: 'tx', | ||
value: function tx(path, variable, opts) { | ||
var newPath = path + '.' + variable; | ||
return this.t(newPath, opts); | ||
} | ||
}]); | ||
return I18n; | ||
}(); | ||
exports.default = I18n; | ||
module.exports = I18n; |
{ | ||
"name": "factorial-i18n", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Factorial i18n library", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:factorial/factorial-i18n.git" | ||
"url": "git@github.com:factorialco/factorial-i18n.git" | ||
}, | ||
"license": "MIT", | ||
"jest": { | ||
"collectCoverage": true, | ||
"testRegex": "/__tests__/.*\\.spec\\.js$", | ||
"collectCoverageFrom": [ | ||
"src/**/*.js" | ||
] | ||
}, | ||
"standard": { | ||
"parser": "babel-eslint", | ||
"globals": [ | ||
"it", | ||
"describe", | ||
"beforeEach", | ||
"expect", | ||
"Class", | ||
"jest" | ||
] | ||
}, | ||
"jest": { "preset": "ts-jest" }, | ||
"dependencies": { | ||
"lodash": "^4.17.4", | ||
"numeral": "2.0.6", | ||
"lodash.at": "4.6.0", | ||
"plurals-cldr": "1.0.3" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-core": "^6.25.0", | ||
"babel-eslint": "^7.2.3", | ||
"babel-jest": "^20.0.3", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-preset-stage-1": "^6.24.1", | ||
"babel-register": "^6.24.1", | ||
"eslint": "^3.19.0", | ||
"eslint-config-standard": "^10.2.1", | ||
"eslint-plugin-flowtype": "2.34.0", | ||
"eslint-plugin-import": "^2.3.0", | ||
"eslint-plugin-node": "^5.0.0", | ||
"eslint-plugin-promise": "^3.5.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"flow-bin": "^0.47.0", | ||
"flow-copy-source": "^1.1.0", | ||
"husky": "^0.13.4", | ||
"jest": "^20.0.4", | ||
"lint-staged": "^3.6.0", | ||
"prettier-standard": "^5.0.0", | ||
"rimraf": "^2.6.1" | ||
"@types/jest": "24.0.13", | ||
"@typescript-eslint/eslint-plugin": "1.9.0", | ||
"@typescript-eslint/parser": "1.9.0", | ||
"eslint": "5.16.0", | ||
"husky": "0.13.4", | ||
"jest": "24.8.0", | ||
"lint-staged": "3.6.0", | ||
"rimraf": "2.6.1", | ||
"rollup": "1.12.1", | ||
"rollup-plugin-node-resolve": "5.0.0", | ||
"rollup-plugin-typescript2": "^0.21.1", | ||
"ts-jest": "24.0.2", | ||
"tslib": "1.9.3", | ||
"typescript": "3.4.5" | ||
}, | ||
"main": "lib", | ||
"scripts": { | ||
"build": "yarn build:clean && rollup --config", | ||
"build:clean": "rimraf lib", | ||
"build:lib": "babel -d lib src --ignore '**/__tests__/**'", | ||
"build:flow": "flow-copy-source -v -i '**/__tests__/**' src lib", | ||
"build": "npm run build:clean && npm run build:lib && npm run build:flow", | ||
"prepublish": "npm run build", | ||
"jest": "BABEL_ENV=test NODE_PATH=src jest --no-cache", | ||
"lint": "eslint src __tests__", | ||
"flow": "flow", | ||
"test": "npm run flow && npm run lint && npm run jest", | ||
"format": "prettier-standard --print-width 60 \"{src,__tests__}/**/*.js\"", | ||
"prepush": "npm test", | ||
"jest": "NODE_PATH=src jest --no-cache", | ||
"lint": "eslint --ext .ts --cache src/ __tests__/", | ||
"prepublish": "yarn build", | ||
"prepush": "yarn test", | ||
"test": "yarn lint && yarn jest", | ||
"watch": "rollup --config -w", | ||
"lint-staged": { | ||
"linters": { | ||
"{src|__tests__}/**/*.js": [ | ||
"prettier-standard", | ||
"{src|__tests__}/**/*.ts": [ | ||
"git add" | ||
@@ -75,0 +45,0 @@ ] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
2
14
0
159625
47
792
1
+ Addedlodash.at@4.6.0
+ Addedlodash.at@4.6.0(transitive)
- Removedlodash@^4.17.4
- Removednumeral@2.0.6
- Removedlodash@4.17.21(transitive)
- Removednumeral@2.0.6(transitive)