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.12.1 to 0.13.0

16

CHANGELOG.md

@@ -6,2 +6,18 @@ # Change Log

# [0.13.0](https://github.com/ing-bank/lion/compare/@lion/localize@0.12.1...@lion/localize@0.13.0) (2020-07-07)
### Bug Fixes
* **localize:** format hungarian & bulgarian dates ([cddd51a](https://github.com/ing-bank/lion/commit/cddd51adcb1b64da3f6850c8bd7f38830abb8aa8)), closes [#540](https://github.com/ing-bank/lion/issues/540)
### BREAKING CHANGES
* **localize:** N
## [0.12.1](https://github.com/ing-bank/lion/compare/@lion/localize@0.12.0...@lion/localize@0.12.1) (2020-06-18)

@@ -8,0 +24,0 @@

4

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

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

},
"gitHead": "8958b2fa02d3b0c39120d405c5284aa01990a524"
"gitHead": "c2b77664921d08b9e1e83e97967296c125dd5f0e"
}

@@ -13,4 +13,4 @@ import { splitDate } from './splitDate.js';

const delimiter = dateParts ? dateParts[2] : '';
const uniformDateString = dateString.replace(/[.\-/\s]/g, delimiter);
const dateArray = uniformDateString.split && uniformDateString.split(delimiter);
const dateArray =
dateString.split && dateString.split(delimiter).filter(str => str.trim().length > 0);
if (!dateArray || dateArray.length !== 3) {

@@ -17,0 +17,0 @@ // prevent fail on invalid dates

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

export function pad(n) {
const v = Math.abs(n);
const digitRegex = /^\d+$/;
const v = digitRegex.test(n) ? Math.abs(n) : n;
return String(v < 10 ? `0${v}` : v);
}

@@ -5,5 +5,5 @@ import { localize } from '../localize.js';

const memoize = (fn, parm) => {
const memoize = fn => {
const cache = {};
return () => {
return parm => {
const n = parm;

@@ -19,3 +19,3 @@ if (n in cache) {

const memoizedGetDateFormatBasedOnLocale = memoize(getDateFormatBasedOnLocale, localize.locale);
const memoizedGetDateFormatBasedOnLocale = memoize(getDateFormatBasedOnLocale);

@@ -31,3 +31,3 @@ /**

let parsedString;
switch (memoizedGetDateFormatBasedOnLocale()) {
switch (memoizedGetDateFormatBasedOnLocale(localize.locale)) {
case 'day-month-year':

@@ -34,0 +34,0 @@ parsedString = `${stringToParse.slice(6, 10)}/${stringToParse.slice(

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

it('displays Hungarian dates correctly', async () => {
const options = {
weekday: 'long',
year: 'numeric',
month: 'long',
day: '2-digit',
locale: 'en-US',
};
localize.locale = 'hu-HU';
let date = parseDate('2018-5-28');
expect(formatDate(date)).to.equal('2018. 05. 28.');
date = parseDate('1970-11-3');
expect(formatDate(date, options)).to.equal('Tuesday, November 03, 1970');
});
it('displays Bulgarian dates correctly', async () => {

@@ -80,9 +96,9 @@ const options = {

localize.locale = 'en-US';
let date = parseDate('29-12-1940');
let date = parseDate('12-29-1940');
expect(formatDate(date)).to.equal('12/29/1940');
date = parseDate('13-01-1940');
date = parseDate('1-13-1940');
expect(formatDate(date)).to.equal('01/13/1940');
date = parseDate('3-11-1970');
date = parseDate('11-3-1970');
expect(formatDate(date, options)).to.equal('Tuesday, November 03, 1970');

@@ -89,0 +105,0 @@ });

@@ -32,7 +32,7 @@ import { expect } from '@open-wc/testing';

it('handles all kind of delimiters', () => {
expect(equalsDate(parseDate('12.12.1976'), new Date('1976/12/12'))).to.equal(true);
expect(equalsDate(parseDate('13.12.1976'), new Date('1976/12/13'))).to.equal(true);
expect(equalsDate(parseDate('12-12-1976'), new Date('1976/12/12'))).to.equal(true);
expect(equalsDate(parseDate('13 12 1976'), new Date('1976/12/13'))).to.equal(true);
expect(equalsDate(parseDate('14.12.1976'), new Date('1976/12/14'))).to.equal(true);
expect(equalsDate(parseDate('14.12-1976'), new Date('1976/12/14'))).to.equal(true);
expect(equalsDate(parseDate('14-12/1976'), new Date('1976/12/14'))).to.equal(true);
expect(equalsDate(parseDate('14. 12. 1976.'), new Date('1976/12/14'))).to.equal(true);
expect(equalsDate(parseDate('14.12.1976 r.'), new Date('1976/12/14'))).to.equal(true);
});

@@ -39,0 +39,0 @@ it('return undefined when no valid date provided', () => {

import { expect } from '@open-wc/testing';
import { localize } from '../../src/localize.js';
import { formatNumber } from '../../src/number/formatNumber.js';
import { localizeTearDown } from '../../test-helpers.js';
import { formatNumber } from '../../src/number/formatNumber.js';
const currencyCode = currency => ({ style: 'currency', currencyDisplay: 'code', currency });

@@ -313,13 +312,15 @@ const currencySymbol = currency => ({ style: 'currency', currencyDisplay: 'symbol', currency });

describe('tr-TR', () => {
localize.locale = 'tr-TR';
expect(formatNumber(123456.789, currencyCode('EUR'))).to.equal('123.456,79 EUR');
expect(formatNumber(123456.789, currencyCode('USD'))).to.equal('123.456,79 USD');
expect(formatNumber(123456.789, currencyCode('JPY'))).to.equal('123.457 JPY');
expect(formatNumber(123456.789, currencyCode('TRY'))).to.equal('123.456,79 TL');
expect(formatNumber(123456.789, currencySymbol('EUR'))).to.equal('€123.456,79');
expect(formatNumber(123456.789, currencySymbol('USD'))).to.equal('$123.456,79');
expect(formatNumber(123456.789, currencySymbol('JPY'))).to.equal('¥123.457');
expect(formatNumber(123456.789, currencySymbol('TRY'))).to.equal('₺123.456,79');
it('supports basics', () => {
localize.locale = 'tr-TR';
expect(formatNumber(123456.789, currencyCode('EUR'))).to.equal('123.456,79 EUR');
expect(formatNumber(123456.789, currencyCode('USD'))).to.equal('123.456,79 USD');
expect(formatNumber(123456.789, currencyCode('JPY'))).to.equal('123.457 JPY');
expect(formatNumber(123456.789, currencyCode('TRY'))).to.equal('123.456,79 TL');
expect(formatNumber(123456.789, currencySymbol('EUR'))).to.equal('€123.456,79');
expect(formatNumber(123456.789, currencySymbol('USD'))).to.equal('$123.456,79');
expect(formatNumber(123456.789, currencySymbol('JPY'))).to.equal('¥123.457');
expect(formatNumber(123456.789, currencySymbol('TRY'))).to.equal('₺123.456,79');
});
});
});
});
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