MCPcopy Create free account
hub / github.com/arktypeio/arktype / normalizeLocale

Function normalizeLocale

ark/schema/shared/render.ts:246–259  ·  view source on GitHub ↗
(locale: Locale<string>)

Source from the content-addressed store, hash-verified

244
245/** a locale completed from en where it lacks a part */
246export const normalizeLocale = (locale: Locale<string>): Locale.Resolved => {
247 if (typeof locale !== "object" || locale === null || Array.isArray(locale))
248 throwParseError(writeInvalidLocaleObjectMessage(locale))
249 // en, once arktype's config has resolved, or before then as it will be,
250 // so a locale is never kept as complete before there's en to complete it
251 const en = (defaultLocale ??= $ark.defaultConfig.locale)
252 if (locale === en) return en
253 let normalized = normalizedLocales.get(locale)
254 if (normalized === undefined) {
255 normalized = completeFrom(en, locale)
256 normalizedLocales.set(locale, normalized)
257 }
258 return normalized
259}
260
261const completeFrom = (
262 en: Locale.Resolved,

Callers 4

configureLocaleFunction · 0.85
selectFunction · 0.85
writeFunction · 0.85

Calls 5

throwParseErrorFunction · 0.90
completeFromFunction · 0.85
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected