@uxf/core 11.91.0 → 11.95.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/README.md +32 -0
- package/package.json +1 -1
- package/utils/cn.d.ts +1 -0
- package/utils/cn.js +6 -0
- package/utils/cn.test.d.ts +1 -0
- package/utils/cn.test.js +7 -0
- package/utils/plural.d.ts +10 -0
- package/utils/plural.js +15 -0
- package/utils/plural.test.d.ts +1 -0
- package/utils/plural.test.js +37 -0
package/README.md
CHANGED
|
@@ -171,6 +171,16 @@ import { capitalize } from "@uxf/core/utils/capitalize";
|
|
|
171
171
|
const example = capitalize("hello world"); /* returns "Hello world" */
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
+
## cn
|
|
175
|
+
|
|
176
|
+
A simple tag for template literals that returns the string as-is. Useful for tooling (e.g. Tailwind CSS IntelliSense) to recognize class strings.
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
import { cn } from "@uxf/core/utils/cn";
|
|
180
|
+
|
|
181
|
+
const className = cn`flex items-center justify-center`;
|
|
182
|
+
```
|
|
183
|
+
|
|
174
184
|
## composeRefs
|
|
175
185
|
|
|
176
186
|
```tsx
|
|
@@ -529,6 +539,28 @@ numberOrNull(null); /* returns null */
|
|
|
529
539
|
numberOrNull(undefined); /* returns null */
|
|
530
540
|
```
|
|
531
541
|
|
|
542
|
+
## plural
|
|
543
|
+
|
|
544
|
+
Simple pluralization function for a specific language and set of terms.
|
|
545
|
+
|
|
546
|
+
```tsx
|
|
547
|
+
import { createPlural } from "@uxf/core/utils/plural";
|
|
548
|
+
|
|
549
|
+
const terms = {
|
|
550
|
+
items: {
|
|
551
|
+
one: "položka",
|
|
552
|
+
few: "položky",
|
|
553
|
+
other: "položek",
|
|
554
|
+
},
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
const t = createPlural(terms, "cs");
|
|
558
|
+
|
|
559
|
+
t("items", 1); // returns "položka"
|
|
560
|
+
t("items", 3); // returns "položky"
|
|
561
|
+
t("items", 5); // returns "položek"
|
|
562
|
+
```
|
|
563
|
+
|
|
532
564
|
## slugify
|
|
533
565
|
|
|
534
566
|
```tsx
|
package/package.json
CHANGED
package/utils/cn.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cn([className]: TemplateStringsArray): string;
|
package/utils/cn.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/utils/cn.test.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface PluralOptions {
|
|
2
|
+
zero?: string;
|
|
3
|
+
one?: string;
|
|
4
|
+
two?: string;
|
|
5
|
+
few?: string;
|
|
6
|
+
many?: string;
|
|
7
|
+
other: string;
|
|
8
|
+
}
|
|
9
|
+
export type PluralTerms<T extends string> = Record<T, PluralOptions>;
|
|
10
|
+
export declare function createPlural<T extends string>(terms: PluralTerms<T>, locale: string): (key: T, count: number) => string;
|
package/utils/plural.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPlural = createPlural;
|
|
4
|
+
function plural(count, options, locale) {
|
|
5
|
+
var _a;
|
|
6
|
+
const rules = new Intl.PluralRules(locale);
|
|
7
|
+
const category = rules.select(count);
|
|
8
|
+
return (_a = options[category]) !== null && _a !== void 0 ? _a : options.other;
|
|
9
|
+
}
|
|
10
|
+
function createPlural(terms, locale) {
|
|
11
|
+
return (key, count) => {
|
|
12
|
+
const options = terms[key];
|
|
13
|
+
return plural(count, options, locale);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const plural_1 = require("./plural");
|
|
4
|
+
describe("pluralization", () => {
|
|
5
|
+
describe("createPlural", () => {
|
|
6
|
+
test("creates a typed plural function", () => {
|
|
7
|
+
const terms = {
|
|
8
|
+
items: {
|
|
9
|
+
one: "item",
|
|
10
|
+
other: "items",
|
|
11
|
+
},
|
|
12
|
+
apples: {
|
|
13
|
+
one: "apple",
|
|
14
|
+
other: "apples",
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
const t = (0, plural_1.createPlural)(terms, "en");
|
|
18
|
+
expect(t("items", 1)).toBe("item");
|
|
19
|
+
expect(t("items", 5)).toBe("items");
|
|
20
|
+
expect(t("apples", 1)).toBe("apple");
|
|
21
|
+
expect(t("apples", 10)).toBe("apples");
|
|
22
|
+
});
|
|
23
|
+
test("works with czech terms", () => {
|
|
24
|
+
const terms = {
|
|
25
|
+
items: {
|
|
26
|
+
one: "položka",
|
|
27
|
+
few: "položky",
|
|
28
|
+
other: "položek",
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const t = (0, plural_1.createPlural)(terms, "cs");
|
|
32
|
+
expect(t("items", 1)).toBe("položka");
|
|
33
|
+
expect(t("items", 3)).toBe("položky");
|
|
34
|
+
expect(t("items", 5)).toBe("položek");
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|