polish-pluralize 1.0.0 → 1.1.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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +21 -14
- package/dist/index.mjs +21 -14
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -23,22 +23,29 @@ __export(index_exports, {
|
|
|
23
23
|
pluralize: () => pluralize
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
|
-
function pluralize(count, forms) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
function pluralize(count, forms, includeNumber = false) {
|
|
27
|
+
if (!Array.isArray(forms) || forms.length !== 3) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
"Biblioteka polish-pluralize wymaga parametru 'forms' jako tablicy z dok\u0142adnie 3 formami s\u0142owa (np. ['plik', 'pliki', 'plik\xF3w'])."
|
|
30
|
+
);
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return forms[0];
|
|
35
|
-
case 2:
|
|
36
|
-
case 3:
|
|
37
|
-
case 4:
|
|
38
|
-
return forms[1];
|
|
39
|
-
default:
|
|
40
|
-
return forms[2];
|
|
32
|
+
if (typeof count !== "number" || Number.isNaN(count)) {
|
|
33
|
+
throw new Error("Parametr 'count' musi by\u0107 poprawn\u0105 liczb\u0105.");
|
|
41
34
|
}
|
|
35
|
+
const absoluteCount = Math.floor(Math.abs(count));
|
|
36
|
+
let form;
|
|
37
|
+
if (absoluteCount === 1 && count === 1) {
|
|
38
|
+
form = forms[0];
|
|
39
|
+
} else {
|
|
40
|
+
const remainder100 = absoluteCount % 100;
|
|
41
|
+
const remainder10 = absoluteCount % 10;
|
|
42
|
+
if (remainder10 >= 2 && remainder10 <= 4 && (remainder100 < 10 || remainder100 >= 20)) {
|
|
43
|
+
form = forms[1];
|
|
44
|
+
} else {
|
|
45
|
+
form = forms[2];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return includeNumber ? `${count} ${form}` : form;
|
|
42
49
|
}
|
|
43
50
|
// Annotate the CommonJS export names for ESM import in node:
|
|
44
51
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
function pluralize(count, forms) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
function pluralize(count, forms, includeNumber = false) {
|
|
3
|
+
if (!Array.isArray(forms) || forms.length !== 3) {
|
|
4
|
+
throw new Error(
|
|
5
|
+
"Biblioteka polish-pluralize wymaga parametru 'forms' jako tablicy z dok\u0142adnie 3 formami s\u0142owa (np. ['plik', 'pliki', 'plik\xF3w'])."
|
|
6
|
+
);
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return forms[0];
|
|
11
|
-
case 2:
|
|
12
|
-
case 3:
|
|
13
|
-
case 4:
|
|
14
|
-
return forms[1];
|
|
15
|
-
default:
|
|
16
|
-
return forms[2];
|
|
8
|
+
if (typeof count !== "number" || Number.isNaN(count)) {
|
|
9
|
+
throw new Error("Parametr 'count' musi by\u0107 poprawn\u0105 liczb\u0105.");
|
|
17
10
|
}
|
|
11
|
+
const absoluteCount = Math.floor(Math.abs(count));
|
|
12
|
+
let form;
|
|
13
|
+
if (absoluteCount === 1 && count === 1) {
|
|
14
|
+
form = forms[0];
|
|
15
|
+
} else {
|
|
16
|
+
const remainder100 = absoluteCount % 100;
|
|
17
|
+
const remainder10 = absoluteCount % 10;
|
|
18
|
+
if (remainder10 >= 2 && remainder10 <= 4 && (remainder100 < 10 || remainder100 >= 20)) {
|
|
19
|
+
form = forms[1];
|
|
20
|
+
} else {
|
|
21
|
+
form = forms[2];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return includeNumber ? `${count} ${form}` : form;
|
|
18
25
|
}
|
|
19
26
|
export {
|
|
20
27
|
pluralize
|