@pogodisco/ts-kit 0.1.0 → 0.2.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/format/extended-json.d.ts +23 -0
- package/dist/format/extended-json.js +72 -0
- package/dist/format/index.d.ts +1 -0
- package/dist/format/index.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lang/index.d.ts +1 -0
- package/dist/lang/index.js +1 -0
- package/dist/lang/pl/index.d.ts +1 -0
- package/dist/lang/pl/index.js +1 -0
- package/dist/lang/pl/noun-form.d.ts +1 -0
- package/dist/lang/pl/noun-form.js +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SanitizerEntry } from "./sanitize.js";
|
|
2
|
+
export declare function oid(value: string | string[], fallback?: any): any;
|
|
3
|
+
export declare function numberDecimal(value: string | number, fallback?: string | number): {
|
|
4
|
+
$numberDecimal: string | number;
|
|
5
|
+
};
|
|
6
|
+
export declare function date(value: string | Date): {
|
|
7
|
+
$date: string | Date;
|
|
8
|
+
};
|
|
9
|
+
export declare function numberInt(value: string | number, fallback?: string | number): {
|
|
10
|
+
$numberInt: string | number;
|
|
11
|
+
};
|
|
12
|
+
export declare function numberLong(value: string | number, fallback?: string | number): {
|
|
13
|
+
$numberLong: string | number;
|
|
14
|
+
};
|
|
15
|
+
export declare function uppercase(value: string | string[], fallback?: any): any;
|
|
16
|
+
export declare function lowercase(value: string | string[], fallback?: any): any;
|
|
17
|
+
export declare const toDecimal: (key: string) => SanitizerEntry;
|
|
18
|
+
export declare const toInt: (key: string) => SanitizerEntry;
|
|
19
|
+
export declare const toOid: (key: string) => SanitizerEntry;
|
|
20
|
+
export declare const toDate: (key: string) => SanitizerEntry;
|
|
21
|
+
export declare const toLong: (key: string) => SanitizerEntry;
|
|
22
|
+
export declare const toLc: (key: string) => SanitizerEntry;
|
|
23
|
+
export declare const toUc: (key: string) => SanitizerEntry;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export function oid(value, fallback = null) {
|
|
2
|
+
if (!value || (typeof value === "string" && value.trim() === ""))
|
|
3
|
+
return fallback;
|
|
4
|
+
if (Array.isArray(value)) {
|
|
5
|
+
if (!value.length)
|
|
6
|
+
return [];
|
|
7
|
+
return value.map((v) => ({
|
|
8
|
+
$oid: v,
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
11
|
+
return { $oid: value };
|
|
12
|
+
}
|
|
13
|
+
export function numberDecimal(value, fallback = 0) {
|
|
14
|
+
return { $numberDecimal: value || fallback };
|
|
15
|
+
}
|
|
16
|
+
export function date(value) {
|
|
17
|
+
return { $date: value };
|
|
18
|
+
}
|
|
19
|
+
export function numberInt(value, fallback = 0) {
|
|
20
|
+
return { $numberInt: value || fallback };
|
|
21
|
+
}
|
|
22
|
+
export function numberLong(value, fallback = 0) {
|
|
23
|
+
return { $numberLong: value || fallback };
|
|
24
|
+
}
|
|
25
|
+
export function uppercase(value, fallback = null) {
|
|
26
|
+
if (!value || (typeof value === "string" && value.trim() === ""))
|
|
27
|
+
return fallback;
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
if (!value.length)
|
|
30
|
+
return [];
|
|
31
|
+
return value.map((v) => v.toUpperCase());
|
|
32
|
+
}
|
|
33
|
+
return value.toUpperCase();
|
|
34
|
+
}
|
|
35
|
+
export function lowercase(value, fallback = null) {
|
|
36
|
+
if (!value || (typeof value === "string" && value.trim() === ""))
|
|
37
|
+
return fallback;
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
if (!value.length)
|
|
40
|
+
return [];
|
|
41
|
+
return value.map((v) => v.toLowerCase());
|
|
42
|
+
}
|
|
43
|
+
return value.toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
export const toDecimal = (key) => [
|
|
46
|
+
key,
|
|
47
|
+
({ value }) => numberDecimal(value),
|
|
48
|
+
];
|
|
49
|
+
export const toInt = (key) => [
|
|
50
|
+
key,
|
|
51
|
+
({ value }) => numberInt(value),
|
|
52
|
+
];
|
|
53
|
+
export const toOid = (key) => [
|
|
54
|
+
key,
|
|
55
|
+
({ value }) => oid(value),
|
|
56
|
+
];
|
|
57
|
+
export const toDate = (key) => [
|
|
58
|
+
key,
|
|
59
|
+
({ value }) => date(value),
|
|
60
|
+
];
|
|
61
|
+
export const toLong = (key) => [
|
|
62
|
+
key,
|
|
63
|
+
({ value }) => numberLong(value),
|
|
64
|
+
];
|
|
65
|
+
export const toLc = (key) => [
|
|
66
|
+
key,
|
|
67
|
+
({ value }) => lowercase(value),
|
|
68
|
+
];
|
|
69
|
+
export const toUc = (key) => [
|
|
70
|
+
key,
|
|
71
|
+
({ value }) => uppercase(value),
|
|
72
|
+
];
|
package/dist/format/index.d.ts
CHANGED
package/dist/format/index.js
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./pl/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./pl/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./noun-form.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./noun-form.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function nounForm(n: number, forms: [string, string, string]): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function nounForm(n, forms) {
|
|
2
|
+
const absN = Math.abs(n);
|
|
3
|
+
const lastTwo = absN % 100;
|
|
4
|
+
const lastDigit = absN % 10;
|
|
5
|
+
if (lastDigit === 1 && !(lastTwo >= 11 && lastTwo <= 14))
|
|
6
|
+
return forms[0]; // singular
|
|
7
|
+
if (lastDigit >= 2 && lastDigit <= 4 && !(lastTwo >= 12 && lastTwo <= 14))
|
|
8
|
+
return forms[1]; // few
|
|
9
|
+
return forms[2]; // many
|
|
10
|
+
}
|