Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@internationalized/message

Package Overview
Dependencies
Maintainers
2
Versions
764
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@internationalized/message - npm Package Compare versions

Comparing version 3.0.0-nightly.2703 to 3.0.0-nightly-086ad3115-240911

dist/import.mjs

118

dist/main.js

@@ -1,9 +0,11 @@

var _intlMessageformat = $parcel$interopDefault(require("intl-messageformat"));
var $9a5a7b8408290694$exports = require("./MessageDictionary.main.js");
var $7a31ee9993c13f0b$exports = require("./MessageFormatter.main.js");
var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));
function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$export(module.exports, "MessageDictionary", () => $9a5a7b8408290694$exports.MessageDictionary);
$parcel$export(module.exports, "MessageFormatter", () => $7a31ee9993c13f0b$exports.MessageFormatter);
/*

@@ -19,112 +21,6 @@ * Copyright 2020 Adobe. All rights reserved.

* governing permissions and limitations under the License.
*/
*/
/**
* Stores a mapping of localized strings. Can be used to find the
* closest available string for a given locale.
*/
class MessageDictionary {
constructor(messages, defaultLocale) {
if (defaultLocale === void 0) {
defaultLocale = 'en-US';
}
this.messages = void 0;
this.defaultLocale = void 0;
// Clone messages so we don't modify the original object.
this.messages = _babelRuntimeHelpersExtends({}, messages);
this.defaultLocale = defaultLocale;
}
getStringForLocale(key, locale) {
let strings = this.messages[locale];
if (!strings) {
strings = $defc888dbd27849217e7ac080e7d$var$getStringsForLocale(locale, this.messages, this.defaultLocale);
this.messages[locale] = strings;
}
let string = strings[key];
if (!string) {
throw new Error("Could not find intl message " + key + " in " + locale + " locale");
}
return string;
}
}
exports.MessageDictionary = MessageDictionary;
function $defc888dbd27849217e7ac080e7d$var$getStringsForLocale(locale, strings, defaultLocale) {
if (defaultLocale === void 0) {
defaultLocale = 'en-US';
}
// If there is an exact match, use it.
if (strings[locale]) {
return strings[locale];
} // Attempt to find the closest match by language.
// For example, if the locale is fr-CA (French Canadian), but there is only
// an fr-FR (France) set of strings, use that.
// This could be replaced with Intl.LocaleMatcher once it is supported.
// https://github.com/tc39/proposal-intl-localematcher
let language = $defc888dbd27849217e7ac080e7d$var$getLanguage(locale);
for (let key in strings) {
if (key.startsWith(language + '-')) {
return strings[key];
}
} // Nothing close, use english.
return strings[defaultLocale];
}
function $defc888dbd27849217e7ac080e7d$var$getLanguage(locale) {
// @ts-ignore
if (Intl.Locale) {
// @ts-ignore
return new Intl.Locale(locale).language;
}
return locale.split('-')[0];
}
/**
* Formats ICU Message strings to create localized strings from a MessageDictionary.
*/
class MessageFormatter {
constructor(locale, messages) {
this.locale = void 0;
this.messages = void 0;
this.cache = void 0;
this.locale = locale;
this.messages = messages;
this.cache = {};
}
format(key, variables) {
let message = this.cache[key];
if (!message) {
let msg = this.messages.getStringForLocale(key, this.locale);
if (!msg) {
throw new Error("Could not find intl message " + key + " in " + this.locale + " locale");
}
message = new _intlMessageformat(msg, this.locale);
this.cache[key] = message;
}
return message.format(variables);
}
}
exports.MessageFormatter = MessageFormatter;
//# sourceMappingURL=main.js.map

@@ -1,3 +0,3 @@

import _intlMessageformat from "intl-messageformat";
import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
import {MessageDictionary as $d6fd23bc337660df$export$64839e615120df17} from "./MessageDictionary.module.js";
import {MessageFormatter as $972eb555d604f491$export$526ebc05ff964723} from "./MessageFormatter.module.js";

@@ -14,108 +14,7 @@ /*

* governing permissions and limitations under the License.
*/
*/
/**
* Stores a mapping of localized strings. Can be used to find the
* closest available string for a given locale.
*/
export class MessageDictionary {
constructor(messages, defaultLocale) {
if (defaultLocale === void 0) {
defaultLocale = 'en-US';
}
this.messages = void 0;
this.defaultLocale = void 0;
// Clone messages so we don't modify the original object.
this.messages = _babelRuntimeHelpersEsmExtends({}, messages);
this.defaultLocale = defaultLocale;
}
getStringForLocale(key, locale) {
let strings = this.messages[locale];
if (!strings) {
strings = $e73469445899f72bd9d935bbafe76d4$var$getStringsForLocale(locale, this.messages, this.defaultLocale);
this.messages[locale] = strings;
}
let string = strings[key];
if (!string) {
throw new Error("Could not find intl message " + key + " in " + locale + " locale");
}
return string;
}
}
function $e73469445899f72bd9d935bbafe76d4$var$getStringsForLocale(locale, strings, defaultLocale) {
if (defaultLocale === void 0) {
defaultLocale = 'en-US';
}
// If there is an exact match, use it.
if (strings[locale]) {
return strings[locale];
} // Attempt to find the closest match by language.
// For example, if the locale is fr-CA (French Canadian), but there is only
// an fr-FR (France) set of strings, use that.
// This could be replaced with Intl.LocaleMatcher once it is supported.
// https://github.com/tc39/proposal-intl-localematcher
let language = $e73469445899f72bd9d935bbafe76d4$var$getLanguage(locale);
for (let key in strings) {
if (key.startsWith(language + '-')) {
return strings[key];
}
} // Nothing close, use english.
return strings[defaultLocale];
}
function $e73469445899f72bd9d935bbafe76d4$var$getLanguage(locale) {
// @ts-ignore
if (Intl.Locale) {
// @ts-ignore
return new Intl.Locale(locale).language;
}
return locale.split('-')[0];
}
/**
* Formats ICU Message strings to create localized strings from a MessageDictionary.
*/
export class MessageFormatter {
constructor(locale, messages) {
this.locale = void 0;
this.messages = void 0;
this.cache = void 0;
this.locale = locale;
this.messages = messages;
this.cache = {};
}
format(key, variables) {
let message = this.cache[key];
if (!message) {
let msg = this.messages.getStringForLocale(key, this.locale);
if (!msg) {
throw new Error("Could not find intl message " + key + " in " + this.locale + " locale");
}
message = new _intlMessageformat(msg, this.locale);
this.cache[key] = message;
}
return message.format(variables);
}
}
export {$d6fd23bc337660df$export$64839e615120df17 as MessageDictionary, $972eb555d604f491$export$526ebc05ff964723 as MessageFormatter};
//# sourceMappingURL=module.js.map

@@ -0,1 +1,2 @@

import { FormatXMLElementFn, PrimitiveType } from "intl-messageformat/src/formatters";
export type LocalizedStrings = {

@@ -19,5 +20,5 @@ [lang: string]: {

constructor(locale: string, messages: MessageDictionary);
format(key: string, variables: object): string;
format<T = void>(key: string, variables: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined): string | T | (string | T)[];
}
//# sourceMappingURL=types.d.ts.map
{
"name": "@internationalized/message",
"version": "3.0.0-nightly.2703+ac27232f",
"version": "3.0.0-nightly-086ad3115-240911",
"description": "Internationalized message formatting and locale negotiation",

@@ -8,2 +8,7 @@ "license": "Apache-2.0",

"module": "dist/module.js",
"exports": {
"types": "./dist/types.d.ts",
"import": "./dist/import.mjs",
"require": "./dist/main.js"
},
"types": "dist/types.d.ts",

@@ -21,4 +26,4 @@ "source": "src/index.ts",

"dependencies": {
"@babel/runtime": "^7.6.2",
"intl-messageformat": "^2.2.0"
"@swc/helpers": "^0.5.0",
"intl-messageformat": "^10.1.0"
},

@@ -28,3 +33,3 @@ "publishConfig": {

},
"gitHead": "ac27232f81bc0b9430efbedb154131b7f0d26352"
}
"stableVersion": "3.1.4"
}

@@ -13,3 +13,4 @@ /*

export * from './MessageDictionary';
export * from './MessageFormatter';
export type {LocalizedStrings} from './MessageDictionary';
export {MessageDictionary} from './MessageDictionary';
export {MessageFormatter} from './MessageFormatter';

@@ -29,3 +29,6 @@ /*

// Clone messages so we don't modify the original object.
this.messages = {...messages};
// Filter out entries with falsy values which may have been caused by applying optimize-locales-plugin.
this.messages = Object.fromEntries(
Object.entries(messages).filter(([, v]) => v)
);
this.defaultLocale = defaultLocale;

@@ -62,2 +65,6 @@ }

let language = getLanguage(locale);
if (strings[language]) {
return strings[language];
}
for (let key in strings) {

@@ -64,0 +71,0 @@ if (key.startsWith(language + '-')) {

@@ -13,2 +13,3 @@ /*

import {FormatXMLElementFn, PrimitiveType} from 'intl-messageformat/src/formatters';
import IntlMessageFormat from 'intl-messageformat';

@@ -31,3 +32,3 @@ import {MessageDictionary} from './MessageDictionary';

format(key: string, variables: object) {
format<T = void>(key: string, variables: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined) {
let message = this.cache[key];

@@ -43,5 +44,12 @@ if (!message) {

}
let varCopy: Record<string, PrimitiveType | T | FormatXMLElementFn<T, string | T | (string | T)[]>> | undefined;
if (variables) {
varCopy = Object.keys(variables).reduce((acc, key) => {
acc[key] = variables[key] == null ? false : variables[key];
return acc;
}, {});
}
return message.format(variables);
return message.format(varCopy);
}
}

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