Socket
Socket
Sign inDemoInstall

@lion/localize

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lion/localize - npm Package Compare versions

Comparing version 0.14.6 to 0.14.7

14

CHANGELOG.md
# Change Log
## 0.14.7
### Patch Changes
- 20ba0ca8: Type enhancements
- LocalizeMixinTypes.d.ts extend from LitElement
- Make `slots` a getter in SlotMixin types
- selectedElement of type 'LionOption' in SelectRichInvoker
- 618f2698: Run tests also on webkit
- Updated dependencies [20ba0ca8]
- @lion/core@0.13.2
## 0.14.6

@@ -4,0 +18,0 @@

4

package.json
{
"name": "@lion/localize",
"version": "0.14.6",
"version": "0.14.7",
"description": "The localization system helps to manage localization data split into locales and automate its loading",

@@ -35,3 +35,3 @@ "license": "MIT",

"@bundled-es-modules/message-format": "6.0.4",
"@lion/core": "0.13.1",
"@lion/core": "0.13.2",
"singleton-manager": "1.1.2"

@@ -38,0 +38,0 @@ },

@@ -36,3 +36,3 @@ import { getLocale } from './getLocale.js';

}
return normalizeIntlDate(formattedDate);
return normalizeIntlDate(formattedDate, computedLocale, formatOptions);
}

@@ -5,4 +5,6 @@ /**

* @param {string} str
* @param {string} [locale='']
* @param {import('@lion/localize/types/LocalizeMixinTypes').FormatDateOptions} [options] Intl options are available
* @returns {string}
*/
export function normalizeIntlDate(str: string): string;
export function normalizeIntlDate(str: string, locale?: string | undefined, { weekday, year, month, day }?: import("../../types/LocalizeMixinTypes").FormatDateOptions | undefined): string;

@@ -5,5 +5,7 @@ /**

* @param {string} str
* @param {string} [locale='']
* @param {import('@lion/localize/types/LocalizeMixinTypes').FormatDateOptions} [options] Intl options are available
* @returns {string}
*/
export function normalizeIntlDate(str) {
export function normalizeIntlDate(str, locale = '', { weekday, year, month, day } = {}) {
const dateString = [];

@@ -22,3 +24,48 @@ for (let i = 0, n = str.length; i < n; i += 1) {

return dateString.join('');
const result = dateString.join('');
// Normalize webkit date formatting without year
if (!year && weekday === 'long' && month === 'long' && day === '2-digit') {
const CHINESE_LOCALES = [
// Webkit has a space while chrome and firefox not. Example: ("10月12日 星期六")
'zh-CN',
'zh-Hans',
'zh-Hans-CN',
'zh-Hans-HK',
'zh-Hans-MO',
'zh-Hans-SG',
// Skip 'zh-Hant' and 'zh-Hant-TW', since webkit/firefox/chromium are aligned.
// 'zh-Hant',
// 'zh-Hant-TW',
'zh-Hant-HK',
'zh-Hant-MO',
];
if (CHINESE_LOCALES.includes(locale)) {
return result.replace(' ', '');
}
if (result.indexOf(',') === -1 && locale === 'en-GB') {
// Saturday 12 October -> Saturday, 12 October
const match = result.match(/^(\w*) (\d*) (\w*)$/);
if (match !== null) {
return `${match[1]}, ${match[2]} ${match[3]}`;
}
}
if (result.indexOf(', ') !== -1 && locale === 'sk-SK') {
// sobota, 12. októbra -> sobota 12. októbra
return result.replace(', ', ' ');
}
if (locale === 'en-PH') {
// Saturday, October 12 -> Saturday, 12 October
const match = result.match(/^(\w*), (\w*) (\d*)$/);
if (match !== null) {
return `${match[1]}, ${match[3]} ${match[2]}`;
}
}
}
return result;
}

@@ -34,2 +34,3 @@ import { localize } from '../localize.js';

let parsedString;
switch (memoizedGetDateFormatBasedOnLocale(localize.locale)) {

@@ -57,9 +58,8 @@ case 'day-month-year':

}
const parsedDate = new Date(parsedString);
// Check if parsedDate is not `Invalid Date`
// eslint-disable-next-line no-restricted-globals
if (!isNaN(parsedDate.getTime())) {
return parsedDate;
const [year, month, day] = parsedString.split('/').map(Number);
if (year > 0 && month > 0 && day > 0) {
return new Date(Date.UTC(year, month - 1, day));
}
return undefined;
}

@@ -8,2 +8,36 @@ import { expect } from '@open-wc/testing';

const SUPPORTED_LOCALES = {
'bg-BG': 'Bulgarian',
'cs-CZ': 'Czech',
'de-DE': 'German (Germany)',
'en-AU': 'English (Australia)',
'en-GB': 'English (United Kingdom)',
'en-PH': 'English (Philippines)',
'en-US': 'English (United States)',
'es-ES': 'Spanish (Spain)',
'fr-FR': 'French (France)',
'fr-BE': 'French (Belgium)',
'hu-HU': 'Hungarian (Hungary)',
'id-ID': 'Indonesian (Indonesia)',
'it-IT': 'Italian (Italy)',
'nl-NL': 'Dutch (Netherlands)',
'nl-BE': 'Dutch (Belgium)',
'pl-PL': 'Polish (Poland)',
'ro-RO': 'Romanian (Romania)',
'ru-RU': 'Russian (Russia)',
'sk-SK': 'Slovak (Slovakia)',
'tr-TR': 'Turkish (Turkey)',
'uk-UA': 'Ukrainian (Ukraine)',
'zh-CN': 'Chinese (China)',
'zh-Hans': 'Chinese (Simplified Han)',
'zh-Hans-CN': 'Chinese (Simplified Han, China)',
'zh-Hans-HK': 'Chinese (Simplified Han, Hong Kong SAR China)',
'zh-Hans-MO': 'Chinese (Simplified Han, Macau SAR China)',
'zh-Hans-SG': 'Chinese (Simplified Han, Singapore)',
'zh-Hant': 'Chinese (Traditional Han)',
'zh-Hant-HK': 'Chinese (Traditional Han, Hong Kong SAR China)',
'zh-Hant-MO': 'Chinese (Traditional Han, Macau SAR China)',
'zh-Hant-TW': 'Chinese (Traditional Han, Taiwan)',
};
describe('formatDate', () => {

@@ -128,10 +162,49 @@ beforeEach(() => {

it('handles options without year', async () => {
const options = {
weekday: 'long',
month: 'long',
day: '2-digit',
describe('Date format options without "year"', () => {
const LOCALE_FORMATTED_DATE_MAP = {
'bg-BG': 'събота, 12 октомври',
'cs-CZ': 'sobota 12. října',
'de-DE': 'Samstag, 12. Oktober',
'en-AU': 'Saturday, 12 October',
'en-GB': 'Saturday, 12 October',
'en-PH': 'Saturday, 12 October',
'en-US': 'Saturday, October 12',
'es-ES': 'sábado, 12 de octubre',
'fr-FR': 'samedi 12 octobre',
'fr-BE': 'samedi 12 octobre',
'hu-HU': 'október 12., szombat',
'id-ID': 'Sabtu, 12 Oktober',
'it-IT': 'sabato 12 ottobre',
'nl-NL': 'zaterdag 12 oktober',
'nl-BE': 'zaterdag 12 oktober',
'pl-PL': 'sobota, 12 października',
'ro-RO': 'sâmbătă, 12 octombrie',
'ru-RU': 'суббота, 12 октября',
'sk-SK': 'sobota 12. októbra',
'tr-TR': '12 Ekim Cumartesi',
'uk-UA': 'субота, 12 жовтня',
'zh-CN': '10月12日星期六',
'zh-Hans': '10月12日星期六',
'zh-Hans-CN': '10月12日星期六',
'zh-Hans-HK': '10月12日星期六',
'zh-Hans-MO': '10月12日星期六',
'zh-Hans-SG': '10月12日星期六',
'zh-Hant': '10月12日 星期六',
'zh-Hant-HK': '10月12日星期六',
'zh-Hant-MO': '10月12日星期六',
'zh-Hant-TW': '10月12日 星期六',
};
const parsedDate = /** @type {Date} */ (parseDate('12.10.2019'));
expect(formatDate(parsedDate, options)).to.equal('Saturday, 12 October');
Object.keys(SUPPORTED_LOCALES).forEach(locale => {
it(`handles options without year for locale: ${locale}`, async () => {
const options = {
weekday: 'long',
month: 'long',
day: '2-digit',
locale,
};
const parsedDate = /** @type {Date} */ (parseDate('12.10.2019'));
expect(formatDate(parsedDate, options)).to.equal(LOCALE_FORMATTED_DATE_MAP[locale]);
});
});
});

@@ -138,0 +211,0 @@

@@ -6,2 +6,8 @@ import { expect } from '@open-wc/testing';

// TODO: This is broken only in Safari 13.1.2 Wait till ci is on 13.1.3 and remove
const isSafari = (() => {
const ua = navigator.userAgent.toLowerCase();
return ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1;
})();
const currencyCode = /** @param {string} currency */ currency => ({

@@ -217,2 +223,7 @@ style: 'currency',

describe('en-AU', () => {
// TODO: This is broken only in Safari 13.1.2 Wait till ci is on 13.1.3 and remove
if (isSafari) {
return;
}
it('supports basics', () => {

@@ -254,2 +265,7 @@ localize.locale = 'en-AU';

describe('nl-BE', () => {
// TODO: This is broken only in Safari 13.1.2 Wait till ci is on 13.1.3 and remove
if (isSafari) {
return;
}
it('supports basics', () => {

@@ -324,2 +340,7 @@ localize.locale = 'nl-BE';

describe('tr-TR', () => {
// TODO: This is broken only in Safari 13.1.2 Wait till ci is on 13.1.3 and remove
if (isSafari) {
return;
}
it('supports basics', () => {

@@ -326,0 +347,0 @@ localize.locale = 'tr-TR';

@@ -6,2 +6,8 @@ import { expect } from '@open-wc/testing';

// TODO: This is broken only in Safari 13.1.2 Wait till ci is on 13.1.3 and remove
const isSafari = (() => {
const ua = navigator.userAgent.toLowerCase();
return ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1;
})();
const c = /** @param {string} v */ v => ({

@@ -47,2 +53,7 @@ type: 'currency',

)}"`, () => {
// TODO: This is broken only in Safari 13.1.2 Wait till ci is on 13.1.3 and remove
if (isSafari) {
return;
}
expect(

@@ -49,0 +60,0 @@ formatNumberToParts(Number(amount), {

import { Constructor } from '@open-wc/dedupe-mixin';
import { LitElement } from '@lion/core';

@@ -71,3 +72,3 @@ export interface FormatNumberPart {

declare function LocalizeMixinImplementation<T extends Constructor<HTMLElement>>(
declare function LocalizeMixinImplementation<T extends Constructor<LitElement>>(
superclass: T,

@@ -74,0 +75,0 @@ ): T & Constructor<LocalizeMixinHost> & typeof LocalizeMixinHost;

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