Skip to content

Commit

Permalink
perf: lowerCase when necessary (#3492)
Browse files Browse the repository at this point in the history
  • Loading branch information
hchlq authored Oct 27, 2022
1 parent b22449b commit 4379ad0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/validator/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ const registry = {

const getISOCode = (language: string) => {
let isoCode = registry.locales.language
const lang = lowerCase(language)
if (registry.locales.messages[language]) {
return language
}
const lang = lowerCase(language)
each(
registry.locales.messages,
(messages: IRegistryLocaleMessages, key: string) => {
Expand All @@ -69,15 +69,18 @@ export const setValidateLanguage = (lang: string) => {

export const getValidateLanguage = () => registry.locales.language

export const getLocaleByPath = (path: string, lang: string = registry.locales.language) => getIn(
registry.locales.messages,
`${getISOCode(lang)}.${path}`
)

export const getLocaleByPath = (
path: string,
lang: string = registry.locales.language
) => getIn(registry.locales.messages, `${getISOCode(lang)}.${path}`)

export const getValidateLocale = (path: string) => {
const message = getLocaleByPath(path);
return message || getLocaleByPath('pattern') || getLocaleByPath('pattern', defaultLanguage)
const message = getLocaleByPath(path)
return (
message ||
getLocaleByPath('pattern') ||
getLocaleByPath('pattern', defaultLanguage)
)
}

export const getValidateMessageTemplateEngine = () => registry.template
Expand Down

0 comments on commit 4379ad0

Please sign in to comment.