@pistonite/pure 0.26.1 → 0.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/pref/locale.ts +17 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pistonite/pure",
3
- "version": "0.26.1",
3
+ "version": "0.26.2",
4
4
  "type": "module",
5
5
  "description": "Pure TypeScript libraries for my projects",
6
6
  "homepage": "https://github.com/Pistonite/pure",
@@ -224,14 +224,27 @@ export const setLocale = (newLocale: string): boolean => {
224
224
  export const convertToSupportedLocale = (
225
225
  newLocale: string,
226
226
  ): string | undefined => {
227
- if (supportedLocales.includes(newLocale)) {
227
+ return convertToSupportedLocaleIn(newLocale, supportedLocales);
228
+ };
229
+
230
+ /**
231
+ * See {@link convertToSupportedLocale}
232
+ *
233
+ * This takes the supported locale array so it can be used
234
+ * outside of the locale system
235
+ */
236
+ export const convertToSupportedLocaleIn = (
237
+ newLocale: string,
238
+ supportedLocalesToCheck: string[] | readonly string[],
239
+ ): string | undefined => {
240
+ if (supportedLocalesToCheck.includes(newLocale)) {
228
241
  return newLocale;
229
242
  }
230
243
  const language = newLocale.split("-", 2)[0];
231
- const len = supportedLocales.length;
244
+ const len = supportedLocalesToCheck.length;
232
245
  for (let i = 0; i < len; i++) {
233
- if (supportedLocales[i].startsWith(language)) {
234
- return supportedLocales[i];
246
+ if (supportedLocalesToCheck[i].startsWith(language)) {
247
+ return supportedLocalesToCheck[i];
235
248
  }
236
249
  }
237
250
  return undefined;