@solid-aria/i18n
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -42,2 +42,9 @@ import { Accessor, JSX } from 'solid-js'; | ||
/** | ||
* Provides localized string collation for the current locale. Automatically updates when the locale changes, | ||
* and handles caching of the collator for performance. | ||
* @param options - Collator options. | ||
*/ | ||
declare function createCollator(options?: Intl.CollatorOptions): Accessor<Intl.Collator>; | ||
declare const RTL_LANGS: Set<string>; | ||
@@ -51,2 +58,2 @@ /** | ||
export { I18nProvider, Locale, RTL_LANGS, createDefaultLocale, getDefaultLocale, getReadingDirection, isRTL, useLocale }; | ||
export { I18nProvider, Locale, RTL_LANGS, createCollator, createDefaultLocale, getDefaultLocale, getReadingDirection, isRTL, useLocale }; |
@@ -115,5 +115,29 @@ // src/context.tsx | ||
} | ||
// src/createCollator.ts | ||
import { createMemo as createMemo3 } from "solid-js"; | ||
var cache = /* @__PURE__ */ new Map(); | ||
function createCollator(options) { | ||
const locale = useLocale(); | ||
const cacheKey = createMemo3(() => { | ||
return locale().locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : ""); | ||
}); | ||
const formatter = createMemo3(() => { | ||
const key = cacheKey(); | ||
let collator; | ||
if (cache.has(key)) { | ||
collator = cache.get(key); | ||
} | ||
if (!collator) { | ||
collator = new Intl.Collator(locale().locale, options); | ||
cache.set(key, collator); | ||
} | ||
return collator; | ||
}); | ||
return formatter; | ||
} | ||
export { | ||
I18nProvider, | ||
RTL_LANGS, | ||
createCollator, | ||
createDefaultLocale, | ||
@@ -120,0 +144,0 @@ getDefaultLocale, |
{ | ||
"name": "@solid-aria/i18n", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"private": false, | ||
@@ -34,4 +34,4 @@ "description": "Primitives for dealing with locale and layout direction.", | ||
"dependencies": { | ||
"@solid-aria/types": "^0.0.1", | ||
"@solid-aria/utils": "^0.0.1" | ||
"@solid-aria/types": "^0.0.2", | ||
"@solid-aria/utils": "^0.0.2" | ||
}, | ||
@@ -38,0 +38,0 @@ "peerDependencies": { |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
15479
367
0
+ Added@solid-aria/types@0.0.2(transitive)
+ Added@solid-aria/utils@0.0.2(transitive)
- Removed@solid-aria/types@0.0.1(transitive)
- Removed@solid-aria/utils@0.0.1(transitive)
Updated@solid-aria/types@^0.0.2
Updated@solid-aria/utils@^0.0.2