intl-messageformat-parser
Advanced tools
Comparing version 2.1.0 to 2.1.2
@@ -6,2 +6,18 @@ # Change Log | ||
## [2.1.2](https://github.com/formatjs/formatjs/compare/intl-messageformat-parser@2.1.1...intl-messageformat-parser@2.1.2) (2019-07-23) | ||
### Bug Fixes | ||
* **intl-messageformat-parser:** add tests, fix offset printing ([bebdf95](https://github.com/formatjs/formatjs/commit/bebdf95)) | ||
* **intl-messageformat-parser:** Fix AST printer to print white-spaces, commas and element types… ([#120](https://github.com/formatjs/formatjs/issues/120)) ([37448e2](https://github.com/formatjs/formatjs/commit/37448e2)), closes [#117](https://github.com/formatjs/formatjs/issues/117) | ||
## [2.1.1](https://github.com/formatjs/formatjs/compare/intl-messageformat-parser@2.1.0...intl-messageformat-parser@2.1.1) (2019-07-12) | ||
**Note:** Version bump only for package intl-messageformat-parser | ||
# [2.1.0](https://github.com/formatjs/formatjs/compare/intl-messageformat-parser@2.0.1...intl-messageformat-parser@2.1.0) (2019-07-12) | ||
@@ -8,0 +24,0 @@ |
@@ -46,3 +46,3 @@ "use strict"; | ||
function printSimpleFormatElement(el) { | ||
return "{" + el.value + ", " + el.type + (el.style ? ", " + el.style : '') + "}"; | ||
return "{" + el.value + ", " + types_1.TYPE[el.type] + (el.style ? ", " + el.style : '') + "}"; | ||
} | ||
@@ -64,5 +64,5 @@ function printSelectElement(el) { | ||
type, | ||
el.offset ? "offset:" + el.offset : '', | ||
Object.keys(el.options) | ||
.map(function (id) { return id + "{" + printAST(el.options[id].value) + "}"; }) | ||
[ | ||
el.offset ? "offset:" + el.offset : '' | ||
].concat(Object.keys(el.options).map(function (id) { return id + "{" + printAST(el.options[id].value) + "}"; })).filter(Boolean) | ||
.join(' ') | ||
@@ -69,0 +69,0 @@ ].join(','); |
@@ -1,2 +0,2 @@ | ||
export declare const enum TYPE { | ||
export declare enum TYPE { | ||
/** | ||
@@ -3,0 +3,0 @@ * Raw text |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var TYPE; | ||
(function (TYPE) { | ||
/** | ||
* Raw text | ||
*/ | ||
TYPE[TYPE["literal"] = 0] = "literal"; | ||
/** | ||
* Variable w/o any format, e.g `var` in `this is a {var}` | ||
*/ | ||
TYPE[TYPE["argument"] = 1] = "argument"; | ||
/** | ||
* Variable w/ number format | ||
*/ | ||
TYPE[TYPE["number"] = 2] = "number"; | ||
/** | ||
* Variable w/ date format | ||
*/ | ||
TYPE[TYPE["date"] = 3] = "date"; | ||
/** | ||
* Variable w/ time format | ||
*/ | ||
TYPE[TYPE["time"] = 4] = "time"; | ||
/** | ||
* Variable w/ select format | ||
*/ | ||
TYPE[TYPE["select"] = 5] = "select"; | ||
/** | ||
* Variable w/ plural format | ||
*/ | ||
TYPE[TYPE["plural"] = 6] = "plural"; | ||
})(TYPE = exports.TYPE || (exports.TYPE = {})); | ||
/** | ||
@@ -7,27 +38,27 @@ * Type Guards | ||
function isLiteralElement(el) { | ||
return el.type === 0 /* literal */; | ||
return el.type === TYPE.literal; | ||
} | ||
exports.isLiteralElement = isLiteralElement; | ||
function isArgumentElement(el) { | ||
return el.type === 1 /* argument */; | ||
return el.type === TYPE.argument; | ||
} | ||
exports.isArgumentElement = isArgumentElement; | ||
function isNumberElement(el) { | ||
return el.type === 2 /* number */; | ||
return el.type === TYPE.number; | ||
} | ||
exports.isNumberElement = isNumberElement; | ||
function isDateElement(el) { | ||
return el.type === 3 /* date */; | ||
return el.type === TYPE.date; | ||
} | ||
exports.isDateElement = isDateElement; | ||
function isTimeElement(el) { | ||
return el.type === 4 /* time */; | ||
return el.type === TYPE.time; | ||
} | ||
exports.isTimeElement = isTimeElement; | ||
function isSelectElement(el) { | ||
return el.type === 5 /* select */; | ||
return el.type === TYPE.select; | ||
} | ||
exports.isSelectElement = isSelectElement; | ||
function isPluralElement(el) { | ||
return el.type === 6 /* plural */; | ||
return el.type === TYPE.plural; | ||
} | ||
@@ -37,3 +68,3 @@ exports.isPluralElement = isPluralElement; | ||
return { | ||
type: 0 /* literal */, | ||
type: TYPE.literal, | ||
value: value | ||
@@ -45,3 +76,3 @@ }; | ||
return { | ||
type: 2 /* number */, | ||
type: TYPE.number, | ||
value: value, | ||
@@ -48,0 +79,0 @@ style: style |
@@ -6,3 +6,3 @@ /* | ||
*/ | ||
import { isLiteralElement, isSelectElement, isArgumentElement, isDateElement, isTimeElement, isNumberElement, isPluralElement } from './types'; | ||
import { isLiteralElement, isSelectElement, isArgumentElement, isDateElement, isTimeElement, isNumberElement, isPluralElement, TYPE } from './types'; | ||
var ESCAPED_CHARS = { | ||
@@ -44,3 +44,3 @@ '\\': '\\\\', | ||
function printSimpleFormatElement(el) { | ||
return "{" + el.value + ", " + el.type + (el.style ? ", " + el.style : '') + "}"; | ||
return "{" + el.value + ", " + TYPE[el.type] + (el.style ? ", " + el.style : '') + "}"; | ||
} | ||
@@ -62,5 +62,5 @@ function printSelectElement(el) { | ||
type, | ||
el.offset ? "offset:" + el.offset : '', | ||
Object.keys(el.options) | ||
.map(function (id) { return id + "{" + printAST(el.options[id].value) + "}"; }) | ||
[ | ||
el.offset ? "offset:" + el.offset : '' | ||
].concat(Object.keys(el.options).map(function (id) { return id + "{" + printAST(el.options[id].value) + "}"; })).filter(Boolean) | ||
.join(' ') | ||
@@ -67,0 +67,0 @@ ].join(','); |
@@ -1,2 +0,2 @@ | ||
export declare const enum TYPE { | ||
export declare enum TYPE { | ||
/** | ||
@@ -3,0 +3,0 @@ * Raw text |
@@ -0,1 +1,32 @@ | ||
export var TYPE; | ||
(function (TYPE) { | ||
/** | ||
* Raw text | ||
*/ | ||
TYPE[TYPE["literal"] = 0] = "literal"; | ||
/** | ||
* Variable w/o any format, e.g `var` in `this is a {var}` | ||
*/ | ||
TYPE[TYPE["argument"] = 1] = "argument"; | ||
/** | ||
* Variable w/ number format | ||
*/ | ||
TYPE[TYPE["number"] = 2] = "number"; | ||
/** | ||
* Variable w/ date format | ||
*/ | ||
TYPE[TYPE["date"] = 3] = "date"; | ||
/** | ||
* Variable w/ time format | ||
*/ | ||
TYPE[TYPE["time"] = 4] = "time"; | ||
/** | ||
* Variable w/ select format | ||
*/ | ||
TYPE[TYPE["select"] = 5] = "select"; | ||
/** | ||
* Variable w/ plural format | ||
*/ | ||
TYPE[TYPE["plural"] = 6] = "plural"; | ||
})(TYPE || (TYPE = {})); | ||
/** | ||
@@ -5,25 +36,25 @@ * Type Guards | ||
export function isLiteralElement(el) { | ||
return el.type === 0 /* literal */; | ||
return el.type === TYPE.literal; | ||
} | ||
export function isArgumentElement(el) { | ||
return el.type === 1 /* argument */; | ||
return el.type === TYPE.argument; | ||
} | ||
export function isNumberElement(el) { | ||
return el.type === 2 /* number */; | ||
return el.type === TYPE.number; | ||
} | ||
export function isDateElement(el) { | ||
return el.type === 3 /* date */; | ||
return el.type === TYPE.date; | ||
} | ||
export function isTimeElement(el) { | ||
return el.type === 4 /* time */; | ||
return el.type === TYPE.time; | ||
} | ||
export function isSelectElement(el) { | ||
return el.type === 5 /* select */; | ||
return el.type === TYPE.select; | ||
} | ||
export function isPluralElement(el) { | ||
return el.type === 6 /* plural */; | ||
return el.type === TYPE.plural; | ||
} | ||
export function createLiteralElement(value) { | ||
return { | ||
type: 0 /* literal */, | ||
type: TYPE.literal, | ||
value: value | ||
@@ -34,3 +65,3 @@ }; | ||
return { | ||
type: 2 /* number */, | ||
type: TYPE.number, | ||
value: value, | ||
@@ -37,0 +68,0 @@ style: style |
{ | ||
"name": "intl-messageformat-parser", | ||
"version": "2.1.0", | ||
"version": "2.1.2", | ||
"description": "Parses ICU Message strings into an AST via JavaScript.", | ||
@@ -44,3 +44,3 @@ "main": "dist/index.js", | ||
"homepage": "https://github.com/formatjs/formatjs", | ||
"gitHead": "32078bc8d41e49050c8ba3288c51b3104a6da9e5" | ||
"gitHead": "daf961b0b7325dadeaecc384e9c08ab103b66df4" | ||
} |
@@ -5,3 +5,3 @@ # Intl MessageFormat Parser | ||
[![npm Version](https://badgen.net/npm/v/intl-messageformat-parser)(https://www.npmjs.com/package/intl-messageformat-parser) | ||
[![npm Version](https://badgen.net/npm/v/intl-messageformat-parser)](https://www.npmjs.com/package/intl-messageformat-parser) | ||
[![size](https://badgen.net/bundlephobia/minzip/intl-messageformat-parser)](https://bundlephobia.com/result?p=intl-messageformat-parser) | ||
@@ -138,2 +138,2 @@ | ||
[peg.js]: https://pegjs.org/ | ||
[license file]: https://github.com/formatjs/formatjs/blob/master/LICENSE | ||
[license file]: https://github.com/formatjs/formatjs/blob/master/LICENSE.md |
@@ -22,3 +22,4 @@ /* | ||
isNumberElement, | ||
isPluralElement | ||
isPluralElement, | ||
TYPE | ||
} from './types'; | ||
@@ -71,3 +72,3 @@ | ||
) { | ||
return `{${el.value}, ${el.type}${el.style ? `, ${el.style}` : ''}}`; | ||
return `{${el.value}, ${TYPE[el.type]}${el.style ? `, ${el.style}` : ''}}`; | ||
} | ||
@@ -90,5 +91,9 @@ function printSelectElement(el: SelectElement) { | ||
type, | ||
el.offset ? `offset:${el.offset}` : '', | ||
Object.keys(el.options) | ||
.map(id => `${id}{${printAST(el.options[id].value)}}`) | ||
[ | ||
el.offset ? `offset:${el.offset}` : '', | ||
...Object.keys(el.options).map( | ||
id => `${id}{${printAST(el.options[id].value)}}` | ||
) | ||
] | ||
.filter(Boolean) | ||
.join(' ') | ||
@@ -95,0 +100,0 @@ ].join(','); |
@@ -1,2 +0,2 @@ | ||
export const enum TYPE { | ||
export enum TYPE { | ||
/** | ||
@@ -3,0 +3,0 @@ * Raw text |
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
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
244727
6389