@zag-js/i18n-utils
Advanced tools
Comparing version 0.71.0 to 0.72.0
@@ -0,1 +1,11 @@ | ||
interface FilterReturn { | ||
startsWith(string: string, substring: string): boolean; | ||
endsWith(string: string, substring: string): boolean; | ||
contains(string: string, substring: string): boolean; | ||
} | ||
interface FilterOptions extends Intl.CollatorOptions { | ||
locale?: string; | ||
} | ||
declare function filter(options?: FilterOptions): FilterReturn; | ||
interface FormatBytesOptions { | ||
@@ -41,2 +51,2 @@ unit?: "bit" | "byte"; | ||
export { type FormatBytesOptions, type Locale, type LocaleOptions, formatBytes, formatDate, formatList, formatNumber, formatRelativeTime, getDefaultLocale, getLocaleDir, isRTL, trackLocale }; | ||
export { type FilterOptions, type FilterReturn, type FormatBytesOptions, type Locale, type LocaleOptions, filter, formatBytes, formatDate, formatList, formatNumber, formatRelativeTime, getDefaultLocale, getLocaleDir, isRTL, trackLocale }; |
@@ -19,2 +19,47 @@ 'use strict'; | ||
// src/filter.ts | ||
var collatorCache = i18nCache(Intl.Collator); | ||
function filter(options) { | ||
const { locale, ...rest } = options || {}; | ||
const collator = collatorCache(locale || "en-US", { usage: "search", ...rest }); | ||
function normalize(string) { | ||
string = string.normalize("NFC"); | ||
if (collator.resolvedOptions().ignorePunctuation) { | ||
string = string.replace(/\p{P}/gu, ""); | ||
} | ||
return string; | ||
} | ||
function startsWith(string, substring) { | ||
if (substring.length === 0) return true; | ||
string = normalize(string); | ||
substring = normalize(substring); | ||
return collator.compare(string.slice(0, substring.length), substring) === 0; | ||
} | ||
function endsWith(string, substring) { | ||
if (substring.length === 0) return true; | ||
string = normalize(string); | ||
substring = normalize(substring); | ||
return collator.compare(string.slice(-substring.length), substring) === 0; | ||
} | ||
function contains(string, substring) { | ||
if (substring.length === 0) return true; | ||
string = normalize(string); | ||
substring = normalize(substring); | ||
let scan = 0; | ||
let sliceLen = substring.length; | ||
for (; scan + sliceLen <= string.length; scan++) { | ||
let slice = string.slice(scan, scan + sliceLen); | ||
if (collator.compare(substring, slice) === 0) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
return { | ||
startsWith, | ||
endsWith, | ||
contains | ||
}; | ||
} | ||
// src/format-number.ts | ||
@@ -394,2 +439,3 @@ var getNumberFormatter = i18nCache(Intl.NumberFormat); | ||
exports.filter = filter; | ||
exports.formatBytes = formatBytes; | ||
@@ -396,0 +442,0 @@ exports.formatDate = formatDate; |
{ | ||
"name": "@zag-js/i18n-utils", | ||
"version": "0.71.0", | ||
"version": "0.72.0", | ||
"description": "Interationalization utilities for Zag.js", | ||
@@ -27,3 +27,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/dom-query": "0.71.0" | ||
"@zag-js/dom-query": "0.72.0" | ||
}, | ||
@@ -30,0 +30,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31155
904
+ Added@zag-js/dom-query@0.72.0(transitive)
- Removed@zag-js/dom-query@0.71.0(transitive)
Updated@zag-js/dom-query@0.72.0