@fluent/bundle
Advanced tools
Comparing version 0.17.0 to 0.17.1
# Changelog | ||
## [@fluent/bundle 0.17.1](https://github.com/projectfluent/fluent.js/compare/@fluent/bundle@0.17.0...@fluent/bundle@0.17.1) (2021-12-21) | ||
- Add per locale Intl memoizer | ||
([#504](https://github.com/projectfluent/fluent.js/pull/504)) | ||
- The type of caught errors is validated at runtime | ||
([#575](https://github.com/projectfluent/fluent.js/pull/575)) | ||
## @fluent/bundle 0.17.0 (September 13, 2021) | ||
@@ -4,0 +11,0 @@ |
import { FluentResource } from "./resource.js"; | ||
import { FluentValue, FluentFunction } from "./types.js"; | ||
import { Message, Term, Pattern } from "./ast.js"; | ||
import { IntlCache } from "./memoizer.js"; | ||
export declare type TextTransform = (text: string) => string; | ||
@@ -18,15 +19,3 @@ declare type NativeValue = string | number | Date; | ||
_transform: TextTransform; | ||
_intls: WeakMap<{ | ||
(locales?: string | string[] | undefined, options?: Intl.NumberFormatOptions | undefined): Intl.NumberFormat; | ||
new (locales?: string | string[] | undefined, options?: Intl.NumberFormatOptions | undefined): Intl.NumberFormat; | ||
supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions | undefined): string[]; | ||
} | { | ||
(locales?: string | string[] | undefined, options?: Intl.DateTimeFormatOptions | undefined): Intl.DateTimeFormat; | ||
new (locales?: string | string[] | undefined, options?: Intl.DateTimeFormatOptions | undefined): Intl.DateTimeFormat; | ||
supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions | undefined): string[]; | ||
} | { | ||
(locales?: string | string[] | undefined, options?: Intl.PluralRulesOptions | undefined): Intl.PluralRules; | ||
new (locales?: string | string[] | undefined, options?: Intl.PluralRulesOptions | undefined): Intl.PluralRules; | ||
supportedLocalesOf(locales: string | string[], options?: Intl.PluralRulesOptions | undefined): string[]; | ||
}, Record<string, Intl.NumberFormat | Intl.DateTimeFormat | Intl.PluralRules>>; | ||
_intls: IntlCache; | ||
/** | ||
@@ -33,0 +22,0 @@ * Create an instance of `FluentBundle`. |
@@ -5,2 +5,3 @@ import { resolveComplexPattern } from "./resolver.js"; | ||
import { NUMBER, DATETIME } from "./builtins.js"; | ||
import { getMemoizerForLocale } from "./memoizer.js"; | ||
/** | ||
@@ -43,3 +44,2 @@ * Message bundles are single-language stores of translation resources. They are | ||
this._messages = new Map(); | ||
this._intls = new WeakMap(); | ||
this.locales = Array.isArray(locales) ? locales : [locales]; | ||
@@ -53,2 +53,3 @@ this._functions = { | ||
this._transform = transform; | ||
this._intls = getMemoizerForLocale(locales); | ||
} | ||
@@ -156,3 +157,3 @@ /** | ||
catch (err) { | ||
if (scope.errors) { | ||
if (scope.errors && err instanceof Error) { | ||
scope.errors.push(err); | ||
@@ -159,0 +160,0 @@ return new FluentNone().toString(scope); |
@@ -19,3 +19,3 @@ import { FluentBundle, FluentVariable } from "./bundle.js"; | ||
constructor(bundle: FluentBundle, errors: Array<Error> | null, args: Record<string, FluentVariable> | null); | ||
reportError(error: Error): void; | ||
reportError(error: unknown): void; | ||
memoizeIntlObject(ctor: typeof Intl.NumberFormat, opts: Intl.NumberFormatOptions): Intl.NumberFormat; | ||
@@ -22,0 +22,0 @@ memoizeIntlObject(ctor: typeof Intl.DateTimeFormat, opts: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; |
@@ -16,3 +16,3 @@ export class Scope { | ||
reportError(error) { | ||
if (!this.errors) { | ||
if (!this.errors || !(error instanceof Error)) { | ||
throw error; | ||
@@ -19,0 +19,0 @@ } |
25
index.js
@@ -1,7 +0,7 @@ | ||
/* @fluent/bundle@0.17.0 */ | ||
/* @fluent/bundle@0.17.1 */ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define('@fluent/bundle', ['exports'], factory) : | ||
(global = global || self, factory(global.FluentBundle = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.FluentBundle = {})); | ||
})(this, (function (exports) { 'use strict'; | ||
@@ -380,3 +380,3 @@ /** | ||
reportError(error) { | ||
if (!this.errors) { | ||
if (!this.errors || !(error instanceof Error)) { | ||
throw error; | ||
@@ -546,2 +546,13 @@ } | ||
const cache = new Map(); | ||
function getMemoizerForLocale(locales) { | ||
const stringLocale = Array.isArray(locales) ? locales.join(" ") : locales; | ||
let memoizer = cache.get(stringLocale); | ||
if (memoizer === undefined) { | ||
memoizer = new Map(); | ||
cache.set(stringLocale, memoizer); | ||
} | ||
return memoizer; | ||
} | ||
/** | ||
@@ -584,3 +595,2 @@ * Message bundles are single-language stores of translation resources. They are | ||
this._messages = new Map(); | ||
this._intls = new WeakMap(); | ||
this.locales = Array.isArray(locales) ? locales : [locales]; | ||
@@ -594,2 +604,3 @@ this._functions = { | ||
this._transform = transform; | ||
this._intls = getMemoizerForLocale(locales); | ||
} | ||
@@ -697,3 +708,3 @@ /** | ||
catch (err) { | ||
if (scope.errors) { | ||
if (scope.errors && err instanceof Error) { | ||
scope.errors.push(err); | ||
@@ -1154,2 +1165,2 @@ return new FluentNone().toString(scope); | ||
}))); | ||
})); |
{ | ||
"name": "@fluent/bundle", | ||
"description": "Localization library for expressive translations.", | ||
"version": "0.17.0", | ||
"version": "0.17.1", | ||
"homepage": "https://projectfluent.org", | ||
@@ -52,5 +52,4 @@ "author": "Mozilla <l10n-drivers@mozilla.org>", | ||
"devDependencies": { | ||
"@fluent/dedent": "file:../fluent-dedent", | ||
"sinon": "^4.2.2" | ||
"@fluent/dedent": "file:../fluent-dedent" | ||
} | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
133572
1
23
2748
0