@molopos/shared 2.0.29 → 2.0.30
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/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/validator/index.d.ts +25 -0
- package/validator/index.js +40 -0
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.
|
|
1
|
+
{"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.30","description":"Shared between backend and frontend repos","license":"ISC","repository":{"type":"git","url":"https://github.com/unicubate/molopos-shared.git"},"dependencies":{"class-transformer":"^0.5.1","date-fns":"^4.3.0","luxon":"^3.7.2"}}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transforme les chaînes 'true'/'false' en booléens, tout en conservant
|
|
3
|
+
* les valeurs déjà booléennes ou undefined/null.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* class MyDto {
|
|
7
|
+
* @TransformBooleanString()
|
|
8
|
+
* isClosed?: boolean;
|
|
9
|
+
* }
|
|
10
|
+
*/
|
|
11
|
+
export declare function TransformBooleanString(): PropertyDecorator;
|
|
12
|
+
/**
|
|
13
|
+
* Transforme une valeur falsy (undefined, null, empty string, false, 0, NaN)
|
|
14
|
+
* en null. Sinon, retourne la valeur inchangée.
|
|
15
|
+
* Utile pour normaliser les champs optionnels envoyés vides.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* class MyDto {
|
|
19
|
+
* @IsOptional()
|
|
20
|
+
* @IsUUID()
|
|
21
|
+
* @TransformToNullIfFalsy()
|
|
22
|
+
* projectId?: string | null;
|
|
23
|
+
* }
|
|
24
|
+
*/
|
|
25
|
+
export declare function TransformToNullIfFalsy(): PropertyDecorator;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransformBooleanString = TransformBooleanString;
|
|
4
|
+
exports.TransformToNullIfFalsy = TransformToNullIfFalsy;
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
/**
|
|
7
|
+
* Transforme les chaînes 'true'/'false' en booléens, tout en conservant
|
|
8
|
+
* les valeurs déjà booléennes ou undefined/null.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* class MyDto {
|
|
12
|
+
* @TransformBooleanString()
|
|
13
|
+
* isClosed?: boolean;
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
function TransformBooleanString() {
|
|
17
|
+
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
18
|
+
if (value === "true")
|
|
19
|
+
return true;
|
|
20
|
+
if (value === "false")
|
|
21
|
+
return false;
|
|
22
|
+
return value;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Transforme une valeur falsy (undefined, null, empty string, false, 0, NaN)
|
|
27
|
+
* en null. Sinon, retourne la valeur inchangée.
|
|
28
|
+
* Utile pour normaliser les champs optionnels envoyés vides.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* class MyDto {
|
|
32
|
+
* @IsOptional()
|
|
33
|
+
* @IsUUID()
|
|
34
|
+
* @TransformToNullIfFalsy()
|
|
35
|
+
* projectId?: string | null;
|
|
36
|
+
* }
|
|
37
|
+
*/
|
|
38
|
+
function TransformToNullIfFalsy() {
|
|
39
|
+
return (0, class_transformer_1.Transform)(({ value }) => (value ? value : null));
|
|
40
|
+
}
|