messageformat
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.2
@@ -6,2 +6,21 @@ # Change Log | ||
# [3.0.0-beta.2](https://github.com/messageformat/messageformat/compare/messageformat@3.0.0-beta.1...messageformat@3.0.0-beta.2) (2020-04-12) | ||
### Bug Fixes | ||
* Update make-plural dependency to 6.0.1 ([fb5ceaf](https://github.com/messageformat/messageformat/commit/fb5ceafccfc75bfcda6941e815ffbba18a419b9d)) | ||
### Features | ||
* **build:** Replace Webpack with Rollup as messageformat bundler ([#278](https://github.com/messageformat/messageformat/issues/278)) ([a6b7a34](https://github.com/messageformat/messageformat/commit/a6b7a347d7fc26c61f2dca628fca91908f504f18)) | ||
* **compiler:** Add requireAllArguments option to compiler ([#267](https://github.com/messageformat/messageformat/issues/267)) ([eb4f194](https://github.com/messageformat/messageformat/commit/eb4f194759629332c80e695a0a9ef64b6e51a422)) | ||
* **messageformat:** Add support for date skeletons ([#279](https://github.com/messageformat/messageformat/issues/279)) ([6283a68](https://github.com/messageformat/messageformat/commit/6283a689eeb1b32a937441715181460d86d01ade)) | ||
* **messageformat:** Add support for number patterns & skeletons ([#272](https://github.com/messageformat/messageformat/issues/272)) ([c1aef99](https://github.com/messageformat/messageformat/commit/c1aef998ee2417f319bd2e426e1e56c3e73ede3b)) | ||
# [3.0.0-beta.1](https://github.com/messageformat/messageformat/compare/messageformat@3.0.0-beta.0...messageformat@3.0.0-beta.1) (2019-10-15) | ||
@@ -8,0 +27,0 @@ |
@@ -1,1 +0,1 @@ | ||
module.exports = require('./lib/compile-module').default; | ||
module.exports = require('./lib/compile-module'); |
@@ -1,14 +0,8 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = compileModule; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var _safeIdentifier = require("safe-identifier"); | ||
var safeIdentifier = require('safe-identifier'); | ||
var Compiler = _interopDefault(require('./compiler')); | ||
var _compiler = _interopRequireDefault(require("./compiler")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function stringifyRuntime(runtime) { | ||
@@ -38,3 +32,3 @@ const imports = {}; | ||
const v = stringifyObject(obj[key], level + 1); | ||
return `\n${indent} ${(0, _safeIdentifier.property)(null, key)}: ${v}`; | ||
return `\n${indent} ${safeIdentifier.property(null, key)}: ${v}`; | ||
}); | ||
@@ -93,3 +87,3 @@ return `{${o.join(',')}\n${indent}}`; | ||
if (plurals.length > 1) for (const pl of plurals) cp[pl.lc] = cp[pl.locale] = pl; | ||
const compiler = new _compiler.default(messageformat.options); | ||
const compiler = new Compiler(messageformat.options); | ||
const msgObj = compiler.compile(messages, plurals[0], cp); | ||
@@ -99,2 +93,4 @@ const msgStr = stringifyObject(msgObj); | ||
return `${rtStr}\nexport default ${msgStr}`; | ||
} | ||
} | ||
module.exports = compileModule; |
@@ -1,20 +0,110 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var _compiler = _interopRequireDefault(require("./compiler")); | ||
var safeIdentifier = require('safe-identifier'); | ||
var Compiler = _interopDefault(require('./compiler')); | ||
var Cardinals = require('make-plural/cardinals'); | ||
var PluralCategories = require('make-plural/pluralCategories'); | ||
var Plurals = require('make-plural/plurals'); | ||
var _plurals = require("./plurals"); | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function normalize(locale) { | ||
if (typeof locale !== 'string' || locale.length < 2) throw new RangeError(`Invalid language tag: ${locale}`); // The only locale for which anything but the primary subtag matters is | ||
// Portuguese as spoken in Portugal. | ||
if (locale.startsWith('pt-PT')) return 'pt-PT'; | ||
const m = locale.match(/.+?(?=[-_])/); | ||
return m ? m[0] : locale; | ||
} | ||
function getPlural(locale) { | ||
if (typeof locale === 'function') { | ||
const lc = normalize(locale.name); | ||
return { | ||
isDefault: false, | ||
id: safeIdentifier.identifier(lc), | ||
lc, | ||
locale: locale.name, | ||
getPlural: locale, | ||
cardinals: locale.cardinals || [], | ||
ordinals: locale.ordinals || [] | ||
}; | ||
} | ||
const lc = normalize(locale); | ||
if (lc in Plurals) { | ||
return { | ||
isDefault: true, | ||
id: safeIdentifier.identifier(lc), | ||
lc, | ||
locale, | ||
getCardinal: Cardinals[lc], | ||
getPlural: Plurals[lc], | ||
cardinals: PluralCategories[lc].cardinal, | ||
ordinals: PluralCategories[lc].ordinal | ||
}; | ||
} | ||
return null; | ||
} | ||
function getAllPlurals(firstLocale) { | ||
const keys = Object.keys(Plurals).filter(key => key !== firstLocale); | ||
keys.unshift(firstLocale); | ||
return keys.map(getPlural); | ||
} | ||
function hasPlural(locale) { | ||
const lc = normalize(locale); | ||
return lc in Plurals; | ||
} | ||
class MessageFormat { | ||
@@ -54,3 +144,3 @@ /** | ||
const la = Array.isArray(locales) ? locales : [locales]; | ||
return la.filter(_plurals.hasPlural); | ||
return la.filter(hasPlural); | ||
} | ||
@@ -60,5 +150,2 @@ /** | ||
* that may be used as the second argument of the constructor. | ||
* @property {('string'|'values')} [returnType='string'] - Return type of | ||
* compiled functions; either a concatenated string or an array (possibly | ||
* hierarchical) of values | ||
* @property {boolean} [biDiSupport=false] - Add Unicode control characters to | ||
@@ -71,2 +158,7 @@ * all input parts to preserve the integrity of the output when mixing LTR | ||
* to include. See the {@tutorial guide} for more details. | ||
* @property {boolean} [requireAllArguments=false] - Require all message | ||
* arguments to be set with a defined value | ||
* @property {('string'|'values')} [returnType='string'] - Return type of | ||
* compiled functions; either a concatenated string or an array (possibly | ||
* hierarchical) of values | ||
* @property {boolean} [strictNumberSign=false] - Allow `#` only directly | ||
@@ -116,7 +208,7 @@ * within a plural or selectordinal case, rather than in any inner select | ||
if (locale === '*') { | ||
this.plurals = (0, _plurals.getAllPlurals)(MessageFormat.defaultLocale); | ||
this.plurals = getAllPlurals(MessageFormat.defaultLocale); | ||
} else if (Array.isArray(locale)) { | ||
this.plurals = locale.map(_plurals.getPlural).filter(Boolean); | ||
this.plurals = locale.map(getPlural).filter(Boolean); | ||
} else if (locale) { | ||
const pl = (0, _plurals.getPlural)(locale); | ||
const pl = getPlural(locale); | ||
if (pl) this.plurals = [pl]; | ||
@@ -126,3 +218,3 @@ } | ||
if (!this.plurals || this.plurals.length === 0) { | ||
const pl = (0, _plurals.getPlural)(MessageFormat.defaultLocale); | ||
const pl = getPlural(MessageFormat.defaultLocale); | ||
this.plurals = [pl]; | ||
@@ -154,3 +246,3 @@ } | ||
resolvedOptions() { | ||
return _objectSpread({}, this.options, { | ||
return _objectSpread2({}, this.options, { | ||
locale: this.plurals[0].locale, | ||
@@ -181,3 +273,3 @@ plurals: this.plurals | ||
compile(message) { | ||
const compiler = new _compiler.default(this.options); | ||
const compiler = new Compiler(this.options); | ||
const fnBody = 'return ' + compiler.compile(message, this.plurals[0]); | ||
@@ -197,4 +289,4 @@ const nfArgs = []; | ||
} | ||
MessageFormat.defaultLocale = 'en'; | ||
exports.default = MessageFormat; | ||
MessageFormat.defaultLocale = 'en'; | ||
module.exports = MessageFormat; |
{ | ||
"name": "messageformat", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.2", | ||
"description": "PluralFormat and SelectFormat Message and i18n Tool - A JavaScript Implemenation of the ICU standards.", | ||
@@ -20,5 +20,9 @@ "keywords": [ | ||
"license": "MIT", | ||
"homepage": "https://messageformat.github.io/messageformat/", | ||
"repository": "messageformat/messageformat", | ||
"main": "index.js", | ||
"homepage": "https://messageformat.github.io/messageformat/v3/", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/messageformat/messageformat.git", | ||
"directory": "packages/messageformat" | ||
}, | ||
"main": "lib/messageformat.js", | ||
"browser": "./messageformat.js", | ||
@@ -28,3 +32,3 @@ "files": [ | ||
"index.d.ts", | ||
"lib", | ||
"lib/", | ||
"messageformat.js", | ||
@@ -67,2 +71,13 @@ "messageformat.js.map" | ||
"files": [ | ||
"rollup.config.js" | ||
], | ||
"env": { | ||
"node": true | ||
}, | ||
"parserOptions": { | ||
"sourceType": "module" | ||
} | ||
}, | ||
{ | ||
"files": [ | ||
"webpack.config.js" | ||
@@ -77,12 +92,13 @@ ], | ||
"dependencies": { | ||
"make-plural": "^6.0.0-beta.3", | ||
"messageformat-parser": "^4.1.2", | ||
"messageformat-runtime": "^3.0.0-beta.0", | ||
"safe-identifier": "^0.2.0" | ||
"make-plural": "^6.2.1", | ||
"messageformat-date-skeleton": "^0.1.1", | ||
"messageformat-number-skeleton": "^0.2.1", | ||
"messageformat-parser": "^4.1.3", | ||
"messageformat-runtime": "^3.0.0-beta.1", | ||
"safe-identifier": "^0.4.1" | ||
}, | ||
"scripts": { | ||
"prebuild": "babel src -d lib", | ||
"build": "webpack --mode none" | ||
"build": "rollup -c" | ||
}, | ||
"gitHead": "50213d12a076cb9e844634ec018e9992b68f8eff" | ||
"gitHead": "dd10833d8d39155b005ea2ba6ec7a87f4daf0cd2" | ||
} |
@@ -55,3 +55,3 @@ <div class="main-title"> | ||
``` | ||
npm install --save-dev messageformat | ||
npm install --save-dev messageformat@next | ||
npm install --save messageformat-runtime | ||
@@ -62,4 +62,4 @@ ``` | ||
[format guide]: https://messageformat.github.io/messageformat/page-guide | ||
[usage guide]: https://messageformat.github.io/messageformat/page-build | ||
[format guide]: https://messageformat.github.io/messageformat/v3/page-guide | ||
[usage guide]: https://messageformat.github.io/messageformat/v3/page-build | ||
@@ -66,0 +66,0 @@ --- |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
No website
QualityPackage does not have a website.
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
10029
0
4
319715
6
10
2
+ Addedmessageformat-date-skeleton@0.1.1(transitive)
+ Addedmessageformat-number-skeleton@0.2.1(transitive)
+ Addedsafe-identifier@0.4.2(transitive)
- Removedsafe-identifier@0.2.0(transitive)
Updatedmake-plural@^6.2.1
Updatedmessageformat-parser@^4.1.3
Updatedsafe-identifier@^0.4.1