@nemigo/helpers 0.3.0 → 0.3.2
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.d.ts +6 -0
- package/dist/format.js +6 -0
- package/dist/xod.js +9 -6
- package/package.json +1 -1
package/dist/format.d.ts
CHANGED
|
@@ -28,3 +28,9 @@ export declare const FormatNumberRegExp: RegExp;
|
|
|
28
28
|
* @example "1 234" или "1 234,56"
|
|
29
29
|
*/
|
|
30
30
|
export declare const formatNumber: (amount: CanBeNullable<number | string>, { fraction, fallback, zero, postfix }?: FormatNumberConfig) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Форматирование в RUB-формат
|
|
33
|
+
*
|
|
34
|
+
* @example "1 234 ₽" или "1 234,56 ₽"
|
|
35
|
+
*/
|
|
36
|
+
export declare const formatRUB: (amount: CanBeNullable<number | string>, { fraction, fallback, zero }?: Omit<FormatNumberConfig, "postfix">) => string;
|
package/dist/format.js
CHANGED
|
@@ -18,3 +18,9 @@ export const formatNumber = (amount, { fraction = 2, fallback = "---", zero = "v
|
|
|
18
18
|
const formatted = fractional ? `${result},${fractional}` : result;
|
|
19
19
|
return postfix ? formatted + " " + postfix : formatted;
|
|
20
20
|
});
|
|
21
|
+
/**
|
|
22
|
+
* Форматирование в RUB-формат
|
|
23
|
+
*
|
|
24
|
+
* @example "1 234 ₽" или "1 234,56 ₽"
|
|
25
|
+
*/
|
|
26
|
+
export const formatRUB = (amount, { fraction = 2, fallback = "---", zero = "value" } = {}) => formatNumber(amount, { fraction, fallback, zero, postfix: "₽" });
|
package/dist/xod.js
CHANGED
|
@@ -43,12 +43,15 @@ export const numberSchema = z.unknown().transform((value, ctx) => caseNumber(val
|
|
|
43
43
|
: result));
|
|
44
44
|
export const numberSchemaOptional = z.union([nullSchema, numberSchema]);
|
|
45
45
|
//...
|
|
46
|
-
export const stringSchema = z.unknown().transform((value, ctx) => caseString(value, (result) =>
|
|
47
|
-
?
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
export const stringSchema = z.unknown().transform((value, ctx) => caseString(value, (result) => {
|
|
47
|
+
const trimmed = result === null ? "" : result.trim();
|
|
48
|
+
return trimmed === ""
|
|
49
|
+
? invalid(value, ctx, {
|
|
50
|
+
message: "It isn't a string or empty string",
|
|
51
|
+
expected: "string (or number)",
|
|
52
|
+
})
|
|
53
|
+
: trimmed;
|
|
54
|
+
}));
|
|
52
55
|
export const stringSchemaOptional = z.union([nullSchema, stringSchema]);
|
|
53
56
|
//...
|
|
54
57
|
export default {
|