@zag-js/i18n-utils 0.71.0 → 0.73.0

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.
package/dist/index.d.mts CHANGED
@@ -1,3 +1,13 @@
1
+ interface FilterReturn {
2
+ startsWith(string: string, substring: string): boolean;
3
+ endsWith(string: string, substring: string): boolean;
4
+ contains(string: string, substring: string): boolean;
5
+ }
6
+ interface FilterOptions extends Intl.CollatorOptions {
7
+ locale?: string;
8
+ }
9
+ declare function filter(options?: FilterOptions): FilterReturn;
10
+
1
11
  interface FormatBytesOptions {
2
12
  unit?: "bit" | "byte";
3
13
  unitDisplay?: "long" | "short" | "narrow";
@@ -38,4 +48,4 @@ interface LocaleOptions {
38
48
  }
39
49
  declare function trackLocale(options?: LocaleOptions): () => void;
40
50
 
41
- export { type FormatBytesOptions, type Locale, type LocaleOptions, formatBytes, formatDate, formatList, formatNumber, formatRelativeTime, getDefaultLocale, getLocaleDir, isRTL, trackLocale };
51
+ export { type FilterOptions, type FilterReturn, type FormatBytesOptions, type Locale, type LocaleOptions, filter, formatBytes, formatDate, formatList, formatNumber, formatRelativeTime, getDefaultLocale, getLocaleDir, isRTL, trackLocale };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,13 @@
1
+ interface FilterReturn {
2
+ startsWith(string: string, substring: string): boolean;
3
+ endsWith(string: string, substring: string): boolean;
4
+ contains(string: string, substring: string): boolean;
5
+ }
6
+ interface FilterOptions extends Intl.CollatorOptions {
7
+ locale?: string;
8
+ }
9
+ declare function filter(options?: FilterOptions): FilterReturn;
10
+
1
11
  interface FormatBytesOptions {
2
12
  unit?: "bit" | "byte";
3
13
  unitDisplay?: "long" | "short" | "narrow";
@@ -38,4 +48,4 @@ interface LocaleOptions {
38
48
  }
39
49
  declare function trackLocale(options?: LocaleOptions): () => void;
40
50
 
41
- export { type FormatBytesOptions, type Locale, type LocaleOptions, formatBytes, formatDate, formatList, formatNumber, formatRelativeTime, getDefaultLocale, getLocaleDir, isRTL, trackLocale };
51
+ export { type FilterOptions, type FilterReturn, type FormatBytesOptions, type Locale, type LocaleOptions, filter, formatBytes, formatDate, formatList, formatNumber, formatRelativeTime, getDefaultLocale, getLocaleDir, isRTL, trackLocale };
package/dist/index.js CHANGED
@@ -16,6 +16,51 @@ function i18nCache(Ins) {
16
16
  };
17
17
  }
18
18
 
19
+ // src/filter.ts
20
+ var collatorCache = i18nCache(Intl.Collator);
21
+ function filter(options) {
22
+ const { locale, ...rest } = options || {};
23
+ const collator = collatorCache(locale || "en-US", { usage: "search", ...rest });
24
+ function normalize(string) {
25
+ string = string.normalize("NFC");
26
+ if (collator.resolvedOptions().ignorePunctuation) {
27
+ string = string.replace(/\p{P}/gu, "");
28
+ }
29
+ return string;
30
+ }
31
+ function startsWith(string, substring) {
32
+ if (substring.length === 0) return true;
33
+ string = normalize(string);
34
+ substring = normalize(substring);
35
+ return collator.compare(string.slice(0, substring.length), substring) === 0;
36
+ }
37
+ function endsWith(string, substring) {
38
+ if (substring.length === 0) return true;
39
+ string = normalize(string);
40
+ substring = normalize(substring);
41
+ return collator.compare(string.slice(-substring.length), substring) === 0;
42
+ }
43
+ function contains(string, substring) {
44
+ if (substring.length === 0) return true;
45
+ string = normalize(string);
46
+ substring = normalize(substring);
47
+ let scan = 0;
48
+ let sliceLen = substring.length;
49
+ for (; scan + sliceLen <= string.length; scan++) {
50
+ let slice = string.slice(scan, scan + sliceLen);
51
+ if (collator.compare(substring, slice) === 0) {
52
+ return true;
53
+ }
54
+ }
55
+ return false;
56
+ }
57
+ return {
58
+ startsWith,
59
+ endsWith,
60
+ contains
61
+ };
62
+ }
63
+
19
64
  // src/format-number.ts
20
65
  var getNumberFormatter = i18nCache(Intl.NumberFormat);
21
66
  function formatNumber(v, locale, options = {}) {
@@ -390,6 +435,7 @@ function trackLocale(options = {}) {
390
435
  };
391
436
  }
392
437
 
438
+ exports.filter = filter;
393
439
  exports.formatBytes = formatBytes;
394
440
  exports.formatDate = formatDate;
395
441
  exports.formatList = formatList;
package/dist/index.mjs CHANGED
@@ -14,6 +14,51 @@ function i18nCache(Ins) {
14
14
  };
15
15
  }
16
16
 
17
+ // src/filter.ts
18
+ var collatorCache = i18nCache(Intl.Collator);
19
+ function filter(options) {
20
+ const { locale, ...rest } = options || {};
21
+ const collator = collatorCache(locale || "en-US", { usage: "search", ...rest });
22
+ function normalize(string) {
23
+ string = string.normalize("NFC");
24
+ if (collator.resolvedOptions().ignorePunctuation) {
25
+ string = string.replace(/\p{P}/gu, "");
26
+ }
27
+ return string;
28
+ }
29
+ function startsWith(string, substring) {
30
+ if (substring.length === 0) return true;
31
+ string = normalize(string);
32
+ substring = normalize(substring);
33
+ return collator.compare(string.slice(0, substring.length), substring) === 0;
34
+ }
35
+ function endsWith(string, substring) {
36
+ if (substring.length === 0) return true;
37
+ string = normalize(string);
38
+ substring = normalize(substring);
39
+ return collator.compare(string.slice(-substring.length), substring) === 0;
40
+ }
41
+ function contains(string, substring) {
42
+ if (substring.length === 0) return true;
43
+ string = normalize(string);
44
+ substring = normalize(substring);
45
+ let scan = 0;
46
+ let sliceLen = substring.length;
47
+ for (; scan + sliceLen <= string.length; scan++) {
48
+ let slice = string.slice(scan, scan + sliceLen);
49
+ if (collator.compare(substring, slice) === 0) {
50
+ return true;
51
+ }
52
+ }
53
+ return false;
54
+ }
55
+ return {
56
+ startsWith,
57
+ endsWith,
58
+ contains
59
+ };
60
+ }
61
+
17
62
  // src/format-number.ts
18
63
  var getNumberFormatter = i18nCache(Intl.NumberFormat);
19
64
  function formatNumber(v, locale, options = {}) {
@@ -388,4 +433,4 @@ function trackLocale(options = {}) {
388
433
  };
389
434
  }
390
435
 
391
- export { formatBytes, formatDate, formatList, formatNumber, formatRelativeTime, getDefaultLocale, getLocaleDir, isRTL, trackLocale };
436
+ export { filter, formatBytes, formatDate, formatList, formatNumber, formatRelativeTime, getDefaultLocale, getLocaleDir, isRTL, trackLocale };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/i18n-utils",
3
- "version": "0.71.0",
3
+ "version": "0.73.0",
4
4
  "description": "Interationalization utilities for Zag.js",
5
5
  "keywords": [
6
6
  "js",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "clean-package": "../../../clean-package.config.json",
26
26
  "dependencies": {
27
- "@zag-js/dom-query": "0.71.0"
27
+ "@zag-js/dom-query": "0.73.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "clean-package": "2.2.0",