react-i18nify
Advanced tools
Comparing version 6.0.0-beta.3 to 6.0.0-beta.4
@@ -34,13 +34,15 @@ "use strict"; | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
let locale = options.locale || (0, _settings.getLocale)(); | ||
if (locale === 'no') locale = 'nb'; // Bokmål as default Norwegian | ||
const locale = options.locale || (0, _settings.getLocale)(); | ||
if (options.dateFormat) { | ||
try { | ||
if (_dayjs.default.locale() !== locale) _dayjs.default.locale(locale); | ||
if (_dayjs.default.locale() !== locale) throw new Error('Invalid locale'); | ||
let dayJsLocale = locale; | ||
if (locale === 'no') dayJsLocale = 'nb'; // Bokmål as default Norwegian | ||
if (_dayjs.default.locale() !== dayJsLocale) _dayjs.default.locale(dayJsLocale); | ||
if (_dayjs.default.locale() !== dayJsLocale) throw new Error('Invalid locale'); | ||
const parsedDate = options.parseFormat ? (0, _dayjs.default)(value, (0, _translate.default)(options.parseFormat, {}, { | ||
locale, | ||
returnKeyOnError: true | ||
}), locale) : (0, _dayjs.default)(value); | ||
}), dayJsLocale) : (0, _dayjs.default)(value); | ||
if (!parsedDate.isValid()) throw new Error('Invalid date'); | ||
@@ -47,0 +49,0 @@ |
@@ -14,13 +14,15 @@ import dayjs from 'dayjs'; | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
let locale = options.locale || getLocale(); | ||
if (locale === 'no') locale = 'nb'; // Bokmål as default Norwegian | ||
const locale = options.locale || getLocale(); | ||
if (options.dateFormat) { | ||
try { | ||
if (dayjs.locale() !== locale) dayjs.locale(locale); | ||
if (dayjs.locale() !== locale) throw new Error('Invalid locale'); | ||
let dayJsLocale = locale; | ||
if (locale === 'no') dayJsLocale = 'nb'; // Bokmål as default Norwegian | ||
if (dayjs.locale() !== dayJsLocale) dayjs.locale(dayJsLocale); | ||
if (dayjs.locale() !== dayJsLocale) throw new Error('Invalid locale'); | ||
const parsedDate = options.parseFormat ? dayjs(value, translate(options.parseFormat, {}, { | ||
locale, | ||
returnKeyOnError: true | ||
}), locale) : dayjs(value); | ||
}), dayJsLocale) : dayjs(value); | ||
if (!parsedDate.isValid()) throw new Error('Invalid date'); | ||
@@ -27,0 +29,0 @@ |
{ | ||
"name": "react-i18nify", | ||
"version": "6.0.0-beta.3", | ||
"version": "6.0.0-beta.4", | ||
"description": "Simple i18n translation and localization components and helpers for React.", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/index.js", |
@@ -16,12 +16,14 @@ import dayjs from 'dayjs'; | ||
export default (value, options = {}) => { | ||
let locale = options.locale || getLocale(); | ||
if (locale === 'no') locale = 'nb'; // Bokmål as default Norwegian | ||
const locale = options.locale || getLocale(); | ||
if (options.dateFormat) { | ||
try { | ||
if (dayjs.locale() !== locale) dayjs.locale(locale); | ||
if (dayjs.locale() !== locale) throw new Error('Invalid locale'); | ||
let dayJsLocale = locale; | ||
if (locale === 'no') dayJsLocale = 'nb'; // Bokmål as default Norwegian | ||
const parsedDate = options.parseFormat ? dayjs(value, translate(options.parseFormat, {}, { locale, returnKeyOnError: true }), locale) : dayjs(value); | ||
if (dayjs.locale() !== dayJsLocale) dayjs.locale(dayJsLocale); | ||
if (dayjs.locale() !== dayJsLocale) throw new Error('Invalid locale'); | ||
const parsedDate = options.parseFormat ? dayjs(value, translate(options.parseFormat, {}, { locale, returnKeyOnError: true }), dayJsLocale) : dayjs(value); | ||
if (!parsedDate.isValid()) throw new Error('Invalid date'); | ||
@@ -28,0 +30,0 @@ |
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
49875
1014