From 816f1e8ca9c06c1f64dd2504a5039d349ea03f50 Mon Sep 17 00:00:00 2001 From: Johan Linderoth Date: Mon, 28 Jun 2021 11:03:08 +0200 Subject: [PATCH] review fixes + don't recurse if split length is 1 --- src/index.js | 2 +- test/plugin/localizedFormat.test.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index d9f93191a..c965dd004 100644 --- a/src/index.js +++ b/src/index.js @@ -21,7 +21,7 @@ const parseLocale = (preset, object, isLocal) => { l = presetLower } const presetSplit = preset.split('-') - if (!l && presetSplit.length) { + if (!l && presetSplit.length > 1) { return parseLocale(presetSplit[0]) } } else { diff --git a/test/plugin/localizedFormat.test.js b/test/plugin/localizedFormat.test.js index 3a6f77084..da5b219e0 100644 --- a/test/plugin/localizedFormat.test.js +++ b/test/plugin/localizedFormat.test.js @@ -97,13 +97,13 @@ it('Uses the localized lowercase formats if defined', () => { }) it('Uses fallback to xx if xx-yy not available', () => { - expect(dayjs('2019-02-01').locale('es-yy').format('L')) - .toBe('01/02/2019') + expect(dayjs('2019-02-01').locale('en-yy').format('MMMM')) + .toBe('February') }) it('Uses xx-yy if xx-YY is provided', () => { - expect(dayjs('2019-02-01').locale('es-US').format('L')) - .toBe('01/02/2019') + expect(dayjs('2019-02-01').locale('es-US').format('MMMM')) + .toBe('febrero') }) it('Uses the localized uppercase formats as a base for lowercase formats, if not defined', () => {