UNPKG

@wilcosp/rex

Version:

Rex is an automated command manager for discord js

36 lines (35 loc) 1.12 kB
/*! * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { Locale } from "discord-api-types/v10"; import { isDeepStrictEqual } from "node:util"; export function parseLocalizations(localizations, asMap = false) { const locals = new Map(); for (const [key, localizedName] of Object.entries(localizations)) { locals.set(getLocale(key), localizedName ?? undefined); } if (asMap) { return locals; } return Object.fromEntries(locals); } export function getLocale(value) { if (isLanguageName(value)) { return Locale[value]; } if (isLocaleCode(value)) { return value; } throw TypeError(`${value} is not a valid LanguageName or Locale`); } function isLanguageName(value) { return Object.keys(Locale).includes(value); } function isLocaleCode(value) { return Object.values(Locale).includes(value); } export function LocalsEqual(one, two) { return isDeepStrictEqual(one, two); }