UNPKG

@walletpass/pass-js

Version:

Apple Wallet Pass generating and pushing updates from Node.js

19 lines 844 B
// SPDX-License-Identifier: AGPL-3.0-or-later // Copyright (C) 2017-2026 Konstantin Vyatkin <tino@vtkn.io> /** * @see {@link https://stackoverflow.com/questions/8758340/regex-to-detect-locales} */ export function normalizeLocale(locale) { const match = /^(?<lang>[A-Za-z]{2,4})([-_](?<variant>[A-Za-z]{4}|\d{3}))?([-_](?<country>[A-Za-z]{2}|\d{3}))?$/.exec(locale); if (!match?.groups?.lang) throw new TypeError(`Invalid locale string: ${locale}`); let result = match.groups.lang.toLowerCase(); if (match.groups.variant) result += `-${match.groups.variant .charAt(0) .toUpperCase()}${match.groups.variant.slice(1).toLowerCase()}`; if (match.groups.country) result += `-${match.groups.country.toUpperCase()}`; return result; } //# sourceMappingURL=normalize-locale.js.map