Socket
Socket
Sign inDemoInstall

@formatjs/icu-messageformat-parser

Package Overview
Dependencies
Maintainers
3
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formatjs/icu-messageformat-parser - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

lib/no-parser.d.ts

3

index.d.ts
import { ParserOptions } from './parser';
export declare function parse(message: string, opts?: ParserOptions): import("./types").MessageFormatElement[];
import { MessageFormatElement } from './types';
export declare function parse(message: string, opts?: ParserOptions): MessageFormatElement[];
export * from './types';
//# sourceMappingURL=index.d.ts.map

@@ -7,13 +7,40 @@ "use strict";

var parser_1 = require("./parser");
var types_1 = require("./types");
function pruneLocation(els) {
els.forEach(function (el) {
delete el.location;
if (types_1.isSelectElement(el) || types_1.isPluralElement(el)) {
for (var k in el.options) {
delete el.options[k].location;
pruneLocation(el.options[k].value);
}
}
else if (types_1.isNumberElement(el) && types_1.isNumberSkeleton(el.style)) {
delete el.style.location;
}
else if ((types_1.isDateElement(el) || types_1.isTimeElement(el)) &&
types_1.isDateTimeSkeleton(el.style)) {
delete el.style.location;
}
else if (types_1.isTagElement(el)) {
pruneLocation(el.children);
}
});
}
function parse(message, opts) {
if (opts === void 0) { opts = {}; }
opts = tslib_1.__assign({ shouldParseSkeletons: true }, opts);
var result = new parser_1.Parser(message, opts).parse();
if (result.val) {
return result.val;
if (result.err) {
var error = SyntaxError(error_1.ErrorKind[result.err.kind]);
// @ts-expect-error Assign to error object
error.location = result.err.location;
throw error;
}
var error = Error(error_1.ErrorKind[result.err.kind]);
// @ts-expect-error Assign to error object
error.location = result.err.location;
throw error;
if (!(opts === null || opts === void 0 ? void 0 : opts.captureLocation)) {
pruneLocation(result.val);
}
return result.val;
}
exports.parse = parse;
tslib_1.__exportStar(require("./types"), exports);
import { ParserOptions } from './parser';
export declare function parse(message: string, opts?: ParserOptions): import("./types").MessageFormatElement[];
import { MessageFormatElement } from './types';
export declare function parse(message: string, opts?: ParserOptions): MessageFormatElement[];
export * from './types';
//# sourceMappingURL=index.d.ts.map

@@ -0,13 +1,41 @@

import { __assign } from "tslib";
import { ErrorKind } from './error';
import { Parser } from './parser';
import { isDateElement, isDateTimeSkeleton, isNumberElement, isNumberSkeleton, isPluralElement, isSelectElement, isTagElement, isTimeElement, } from './types';
function pruneLocation(els) {
els.forEach(function (el) {
delete el.location;
if (isSelectElement(el) || isPluralElement(el)) {
for (var k in el.options) {
delete el.options[k].location;
pruneLocation(el.options[k].value);
}
}
else if (isNumberElement(el) && isNumberSkeleton(el.style)) {
delete el.style.location;
}
else if ((isDateElement(el) || isTimeElement(el)) &&
isDateTimeSkeleton(el.style)) {
delete el.style.location;
}
else if (isTagElement(el)) {
pruneLocation(el.children);
}
});
}
export function parse(message, opts) {
if (opts === void 0) { opts = {}; }
opts = __assign({ shouldParseSkeletons: true }, opts);
var result = new Parser(message, opts).parse();
if (result.val) {
return result.val;
if (result.err) {
var error = SyntaxError(ErrorKind[result.err.kind]);
// @ts-expect-error Assign to error object
error.location = result.err.location;
throw error;
}
var error = Error(ErrorKind[result.err.kind]);
// @ts-expect-error Assign to error object
error.location = result.err.location;
throw error;
if (!(opts === null || opts === void 0 ? void 0 : opts.captureLocation)) {
pruneLocation(result.val);
}
return result.val;
}
export * from './types';

@@ -41,9 +41,2 @@ import { ParserError } from './error';

};
export declare function parse(...args: ConstructorParameters<typeof Parser>): {
val: MessageFormatElement[];
err: null;
} | {
val: null;
err: ParserError;
};
export declare class Parser {

@@ -50,0 +43,0 @@ private message;

@@ -1,4 +0,4 @@

import { __assign, __spreadArray } from "tslib";
import { __assign } from "tslib";
import { ErrorKind } from './error';
import { isDateElement, isDateTimeSkeleton, isNumberElement, isNumberSkeleton, isPluralElement, isSelectElement, isTagElement, isTimeElement, SKELETON_TYPE, TYPE, } from './types';
import { SKELETON_TYPE, TYPE, } from './types';
import { SPACE_SEPARATOR_END_REGEX, SPACE_SEPARATOR_START_REGEX, } from './regex.generated';

@@ -149,38 +149,2 @@ import { parseNumberSkeleton, parseNumberSkeletonFromString, parseDateTimeSkeleton, } from '@formatjs/icu-skeleton-parser';

}
function pruneLocation(els) {
els.forEach(function (el) {
delete el.location;
if (isSelectElement(el) || isPluralElement(el)) {
for (var k in el.options) {
delete el.options[k].location;
pruneLocation(el.options[k].value);
}
}
else if (isNumberElement(el) && isNumberSkeleton(el.style)) {
delete el.style.location;
}
else if ((isDateElement(el) || isTimeElement(el)) &&
isDateTimeSkeleton(el.style)) {
delete el.style.location;
}
else if (isTagElement(el)) {
pruneLocation(el.children);
}
});
}
export function parse() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _ = args[0], opts = args[1];
var result = new (Parser.bind.apply(Parser, __spreadArray([void 0], args)))().parse();
if (result.err) {
return result;
}
if (!(opts === null || opts === void 0 ? void 0 : opts.captureLocation)) {
pruneLocation(result.val);
}
return result;
}
var Parser = /** @class */ (function () {

@@ -279,5 +243,4 @@ function Parser(message, options) {

val: {
type: TYPE.tag,
value: tagName,
children: [],
type: TYPE.literal,
value: "<" + tagName + "/>",
location: createLocation(startPosition, this.clonePosition()),

@@ -284,0 +247,0 @@ },

MIT License
Copyright (c) 2019 FormatJS
Copyright (c) 2021 FormatJS

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

{
"name": "@formatjs/icu-messageformat-parser",
"version": "0.2.0",
"version": "0.2.1",
"main": "index.js",

@@ -5,0 +5,0 @@ "types": "index.d.ts",

@@ -41,9 +41,2 @@ import { ParserError } from './error';

};
export declare function parse(...args: ConstructorParameters<typeof Parser>): {
val: MessageFormatElement[];
err: null;
} | {
val: null;
err: ParserError;
};
export declare class Parser {

@@ -50,0 +43,0 @@ private message;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Parser = exports.parse = void 0;
exports.Parser = void 0;
var tslib_1 = require("tslib");

@@ -152,39 +152,2 @@ var error_1 = require("./error");

}
function pruneLocation(els) {
els.forEach(function (el) {
delete el.location;
if (types_1.isSelectElement(el) || types_1.isPluralElement(el)) {
for (var k in el.options) {
delete el.options[k].location;
pruneLocation(el.options[k].value);
}
}
else if (types_1.isNumberElement(el) && types_1.isNumberSkeleton(el.style)) {
delete el.style.location;
}
else if ((types_1.isDateElement(el) || types_1.isTimeElement(el)) &&
types_1.isDateTimeSkeleton(el.style)) {
delete el.style.location;
}
else if (types_1.isTagElement(el)) {
pruneLocation(el.children);
}
});
}
function parse() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _ = args[0], opts = args[1];
var result = new (Parser.bind.apply(Parser, tslib_1.__spreadArray([void 0], args)))().parse();
if (result.err) {
return result;
}
if (!(opts === null || opts === void 0 ? void 0 : opts.captureLocation)) {
pruneLocation(result.val);
}
return result;
}
exports.parse = parse;
var Parser = /** @class */ (function () {

@@ -283,5 +246,4 @@ function Parser(message, options) {

val: {
type: types_1.TYPE.tag,
value: tagName,
children: [],
type: types_1.TYPE.literal,
value: "<" + tagName + "/>",
location: createLocation(startPosition, this.clonePosition()),

@@ -288,0 +250,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc