@u27n/js 0.2.0 → 0.2.1

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.
@@ -0,0 +1,4 @@
1
+ export declare function detectExactLocale(locales: string[]): string | undefined;
2
+ export declare function detectLocalePrefix(locales: string[]): string | undefined;
3
+ export declare function detectLocale(locales: string[]): string;
4
+ //# sourceMappingURL=detect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AACA,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAMvE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAOxE;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAEtD"}
package/dist/detect.js ADDED
@@ -0,0 +1,19 @@
1
+ export function detectExactLocale(locales) {
2
+ for (const code of navigator.languages) {
3
+ if (locales.includes(code)) {
4
+ return code;
5
+ }
6
+ }
7
+ }
8
+ export function detectLocalePrefix(locales) {
9
+ for (const code of navigator.languages) {
10
+ const locale = locales.find(l => l === code || code.startsWith(l + "-"));
11
+ if (locale !== undefined) {
12
+ return locale;
13
+ }
14
+ }
15
+ }
16
+ export function detectLocale(locales) {
17
+ return detectExactLocale(locales) ?? detectLocalePrefix(locales) ?? locales[0];
18
+ }
19
+ //# sourceMappingURL=detect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.js","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,iBAAiB,CAAC,OAAiB;IAClD,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;QACxC,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;AACF,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,OAAiB;IACnD,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;QACxC,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACzE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,MAAM,CAAC;QACf,CAAC;IACF,CAAC;AACF,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAiB;IAC7C,OAAO,iBAAiB,CAAC,OAAO,CAAC,IAAI,kBAAkB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;AAChF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./core.js";
2
+ export * from "./detect.js";
2
3
  export * from "./format.js";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./core.js";
2
+ export * from "./detect.js";
2
3
  export * from "./format.js";
3
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@u27n/js",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://codeberg.org/mxjp/u27n.git",
9
+ "directory": "runtime-js"
10
+ },
6
11
  "exports": {
7
12
  "default": "./dist/index.js"
8
13
  },
package/src/detect.ts ADDED
@@ -0,0 +1,21 @@
1
+
2
+ export function detectExactLocale(locales: string[]): string | undefined {
3
+ for (const code of navigator.languages) {
4
+ if (locales.includes(code)) {
5
+ return code;
6
+ }
7
+ }
8
+ }
9
+
10
+ export function detectLocalePrefix(locales: string[]): string | undefined {
11
+ for (const code of navigator.languages) {
12
+ const locale = locales.find(l => l === code || code.startsWith(l + "-"));
13
+ if (locale !== undefined) {
14
+ return locale;
15
+ }
16
+ }
17
+ }
18
+
19
+ export function detectLocale(locales: string[]): string {
20
+ return detectExactLocale(locales) ?? detectLocalePrefix(locales) ?? locales[0];
21
+ }
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./core.js";
2
+ export * from "./detect.js";
2
3
  export * from "./format.js";