itlab-internal-services 2.14.1 → 2.14.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/functions/index.d.ts +0 -1
- package/dist/models/filter/limit.property.js +1 -1
- package/dist/models/filter/skip.property.js +1 -1
- package/dist/models/filter/sort-direction.property.js +1 -1
- package/dist/models/filter/sort-field.property.js +2 -1
- package/dist/models/thumbnail/alt.property.js +2 -1
- package/dist/models/thumbnail/background.property.js +1 -1
- package/dist/models/thumbnail/contain.property.js +2 -1
- package/dist/models/thumbnail/src.property.js +1 -1
- package/dist/transform/{to-boolean.transform.d.ts → boolean.transform.d.ts} +2 -2
- package/dist/transform/{to-boolean.transform.js → boolean.transform.js} +3 -8
- package/dist/transform/{to-image-url.transform.d.ts → image-url.transform.d.ts} +1 -1
- package/dist/transform/{to-image-url.transform.js → image-url.transform.js} +3 -4
- package/dist/transform/index.d.ts +6 -8
- package/dist/transform/index.js +13 -17
- package/dist/transform/{to-number.transform.d.ts → number.transform.d.ts} +1 -1
- package/dist/transform/{to-number.transform.js → number.transform.js} +2 -2
- package/dist/transform/string-array.transform.d.ts +15 -0
- package/dist/transform/string-array.transform.js +27 -0
- package/dist/transform/{to-string.transform.d.ts → string.transform.d.ts} +5 -2
- package/dist/transform/{to-string.transform.js → string.transform.js} +3 -4
- package/dist/transform/{to-timestamp.transform.d.ts → timestamp.transform.d.ts} +2 -2
- package/dist/transform/{to-timestamp.transform.js → timestamp.transform.js} +2 -2
- package/package.json +1 -1
- package/dist/functions/string-like.functions.d.ts +0 -21
- package/dist/functions/string-like.functions.js +0 -35
- package/dist/transform/cast-to-array.transform.d.ts +0 -20
- package/dist/transform/cast-to-array.transform.js +0 -32
- package/dist/transform/to-string-array.transform.d.ts +0 -16
- package/dist/transform/to-string-array.transform.js +0 -34
- package/dist/transform/to-string-like.transform.d.ts +0 -24
- package/dist/transform/to-string-like.transform.js +0 -31
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { configureAxiosInstance } from './configure-axios-instance.function';
|
|
2
2
|
export { createDuplicateChecker } from './create-duplicate-checker.function';
|
|
3
3
|
export { createSchemaTransformer } from './create-schema-transformer.function';
|
|
4
|
-
export {} from './string-like.functions';
|
|
@@ -9,5 +9,5 @@ const transform_1 = require("../../transform");
|
|
|
9
9
|
* Creates a PropertyLimitDecorator with the given options.
|
|
10
10
|
*/
|
|
11
11
|
function PropertyLimit() {
|
|
12
|
-
return (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({ minimum: 0, default: 10, description: 'Die maximale Anzahl der Ergebnisse' }), (0, transform_1.
|
|
12
|
+
return (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({ minimum: 0, default: 10, description: 'Die maximale Anzahl der Ergebnisse' }), (0, transform_1.NumberTransform)({ default: 10, min: 0 }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.Min)(0));
|
|
13
13
|
}
|
|
@@ -9,5 +9,5 @@ const transform_1 = require("../../transform");
|
|
|
9
9
|
* Creates a PropertySkipDecorator with the given options.
|
|
10
10
|
*/
|
|
11
11
|
function PropertySkip() {
|
|
12
|
-
return (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({ minimum: 0, default: 0, description: 'Die Anzahl der zu überspringenden Ergebnisse' }), (0, transform_1.
|
|
12
|
+
return (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({ minimum: 0, default: 0, description: 'Die Anzahl der zu überspringenden Ergebnisse' }), (0, transform_1.NumberTransform)({ default: 0, min: 0 }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.Min)(0));
|
|
13
13
|
}
|
|
@@ -15,5 +15,5 @@ function PropertySortDirection() {
|
|
|
15
15
|
asc: { value: 1, summary: 'Aufsteigend' },
|
|
16
16
|
desc: { value: -1, summary: 'Absteigend (Standard)' },
|
|
17
17
|
},
|
|
18
|
-
}), (0, transform_1.
|
|
18
|
+
}), (0, transform_1.NumberTransform)({ default: -1, min: -1, max: 1 }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.IsIn)([-1, 1]));
|
|
19
19
|
}
|
|
@@ -4,6 +4,7 @@ exports.PropertySortField = PropertySortField;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
6
|
const class_validator_1 = require("class-validator");
|
|
7
|
+
const transform_1 = require("../../transform");
|
|
7
8
|
/**
|
|
8
9
|
* Creates a PropertySortFieldDecorator with the given options.
|
|
9
10
|
*/
|
|
@@ -12,5 +13,5 @@ function PropertySortField() {
|
|
|
12
13
|
description: 'Das Feld, nach dem sortiert werden soll',
|
|
13
14
|
default: '_id',
|
|
14
15
|
example: 'title',
|
|
15
|
-
}), (0, class_validator_1.IsOptional)(), (0, class_validator_1.MinLength)(1));
|
|
16
|
+
}), (0, transform_1.StringTransform)({ trim: true }), (0, class_validator_1.IsOptional)(), (0, class_validator_1.MinLength)(1));
|
|
16
17
|
}
|
|
@@ -4,6 +4,7 @@ exports.ThumbnailAlt = ThumbnailAlt;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
6
|
const class_validator_1 = require("class-validator");
|
|
7
|
+
const transform_1 = require("../../transform");
|
|
7
8
|
/**
|
|
8
9
|
* Creates a ThumbnailAltDecorator with the given options.
|
|
9
10
|
*
|
|
@@ -13,7 +14,7 @@ const class_validator_1 = require("class-validator");
|
|
|
13
14
|
function ThumbnailAlt(options = {}) {
|
|
14
15
|
return (0, common_1.applyDecorators)(
|
|
15
16
|
/** ApiProperty with the given options */
|
|
16
|
-
(0, swagger_1.ApiProperty)(Object.assign({ example: 'Eine Person mit einem Kissen' }, options)),
|
|
17
|
+
(0, swagger_1.ApiProperty)(Object.assign({ example: 'Eine Person mit einem Kissen' }, options)), (0, transform_1.StringTransform)({ trim: true }),
|
|
17
18
|
/** Check if the length is at least 3 */
|
|
18
19
|
(0, class_validator_1.MinLength)(3, { message: 'Der Alternativtext muss mindestens 3 Zeichen lang sein' }));
|
|
19
20
|
}
|
|
@@ -20,7 +20,7 @@ function ThumbnailBackground(options = {}) {
|
|
|
20
20
|
Farbverlauf: { value: ['#e74c3c', '#c0392b'] },
|
|
21
21
|
} }, options)),
|
|
22
22
|
/** Transform the string array */
|
|
23
|
-
(0, transform_1.
|
|
23
|
+
(0, transform_1.StringArrayTransform)({ trim: true }),
|
|
24
24
|
/** Check if the value is a HEX color */
|
|
25
25
|
(0, class_validator_1.IsHexColor)({ each: true, message: 'Die Hintergrundfarbe muss eine HEX Farbe sein' }),
|
|
26
26
|
/** Check if the value is an array */
|
|
@@ -4,6 +4,7 @@ exports.ThumbnailContain = ThumbnailContain;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
6
|
const class_validator_1 = require("class-validator");
|
|
7
|
+
const transform_1 = require("../../transform");
|
|
7
8
|
/**
|
|
8
9
|
* Creates a ThumbnailContainDecorator with the given options.
|
|
9
10
|
*
|
|
@@ -13,7 +14,7 @@ const class_validator_1 = require("class-validator");
|
|
|
13
14
|
function ThumbnailContain(options = {}) {
|
|
14
15
|
return (0, common_1.applyDecorators)(
|
|
15
16
|
/** ApiProperty with the given options */
|
|
16
|
-
(0, swagger_1.ApiProperty)(Object.assign({ description: 'Gibt an, ob das Bild gecroppt oder komplett angezeigt werden soll', example: false }, options)),
|
|
17
|
+
(0, swagger_1.ApiProperty)(Object.assign({ description: 'Gibt an, ob das Bild gecroppt oder komplett angezeigt werden soll', example: false }, options)), (0, transform_1.BooleanTransform)(),
|
|
17
18
|
/** Check if the value is a boolean */
|
|
18
19
|
(0, class_validator_1.IsBoolean)({ message: 'Contain muss als Boolean übergeben werden' }));
|
|
19
20
|
}
|
|
@@ -16,7 +16,7 @@ function ThumbnailSrc(options = {}) {
|
|
|
16
16
|
/** ApiProperty with the given options */
|
|
17
17
|
(0, swagger_1.ApiProperty)(Object.assign({ example: 'https://example.com/image' }, options)),
|
|
18
18
|
/** Transform the URL */
|
|
19
|
-
(0, transform_1.
|
|
19
|
+
(0, transform_1.ImageUrlTransform)(),
|
|
20
20
|
/** Check if the URL starts with https */
|
|
21
21
|
(0, class_validator_1.IsUrl)({ protocols: ['https'], require_protocol: true }, { message: 'Die URL muss mit https beginnen' }));
|
|
22
22
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Class-level comment block:
|
|
3
|
-
* This module provides a property decorator function,
|
|
3
|
+
* This module provides a property decorator function, BooleanTransform, which is used to convert
|
|
4
4
|
* various input types into boolean values. It handles strings, numbers, and boolean inputs,
|
|
5
5
|
* ensuring they are correctly interpreted as true or false. This decorator is useful for
|
|
6
6
|
* sanitizing and standardizing input data in class properties.
|
|
@@ -11,4 +11,4 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @returns {PropertyDecorator} - A decorator function for transforming property values.
|
|
13
13
|
*/
|
|
14
|
-
export declare function
|
|
14
|
+
export declare function BooleanTransform(): PropertyDecorator;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.BooleanTransform = BooleanTransform;
|
|
4
4
|
const class_transformer_1 = require("class-transformer");
|
|
5
|
-
const string_like_functions_1 = require("../functions/string-like.functions");
|
|
6
5
|
/**
|
|
7
6
|
* Class-level comment block:
|
|
8
|
-
* This module provides a property decorator function,
|
|
7
|
+
* This module provides a property decorator function, BooleanTransform, which is used to convert
|
|
9
8
|
* various input types into boolean values. It handles strings, numbers, and boolean inputs,
|
|
10
9
|
* ensuring they are correctly interpreted as true or false. This decorator is useful for
|
|
11
10
|
* sanitizing and standardizing input data in class properties.
|
|
@@ -16,12 +15,8 @@ const string_like_functions_1 = require("../functions/string-like.functions");
|
|
|
16
15
|
*
|
|
17
16
|
* @returns {PropertyDecorator} - A decorator function for transforming property values.
|
|
18
17
|
*/
|
|
19
|
-
function
|
|
18
|
+
function BooleanTransform() {
|
|
20
19
|
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
21
|
-
// Check if the value is string-like and trim it if necessary.
|
|
22
|
-
if ((0, string_like_functions_1.isStringLike)(value)) {
|
|
23
|
-
value = String((0, string_like_functions_1.trimStringLike)(value)).toLowerCase();
|
|
24
|
-
}
|
|
25
20
|
// Convert the value to a boolean if it matches any of the true or false representations.
|
|
26
21
|
if (value === true || value === 'true' || value === 1 || value === '1') {
|
|
27
22
|
return true;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ImageUrlTransform = ImageUrlTransform;
|
|
4
4
|
const class_transformer_1 = require("class-transformer");
|
|
5
5
|
const class_validator_1 = require("class-validator");
|
|
6
6
|
const itlab_functions_1 = require("itlab-functions");
|
|
7
|
-
const string_like_functions_1 = require("../functions/string-like.functions");
|
|
8
7
|
/**
|
|
9
8
|
* Class-level comment:
|
|
10
9
|
* This module provides a decorator function for transforming image URLs.
|
|
@@ -16,11 +15,11 @@ const string_like_functions_1 = require("../functions/string-like.functions");
|
|
|
16
15
|
*
|
|
17
16
|
* @returns {PropertyDecorator} - A decorator function that transforms the property value.
|
|
18
17
|
*/
|
|
19
|
-
function
|
|
18
|
+
function ImageUrlTransform() {
|
|
20
19
|
// Use the Transform decorator to apply the transformation logic to the property value.
|
|
21
20
|
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
22
21
|
// Check if the value is a string. If so, trim and transform it into a cleaned image URL.
|
|
23
22
|
// Otherwise, return the original value.
|
|
24
|
-
return (0, class_validator_1.isString)(value) ? (0, itlab_functions_1.transformImage)(
|
|
23
|
+
return (0, class_validator_1.isString)(value) ? (0, itlab_functions_1.transformImage)(value.trim()) : value;
|
|
25
24
|
});
|
|
26
25
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { TransformToString } from './to-string.transform';
|
|
8
|
-
export { TransformToTimestamp } from './to-timestamp.transform';
|
|
1
|
+
export { BooleanTransform } from './boolean.transform';
|
|
2
|
+
export { ImageUrlTransform } from './image-url.transform';
|
|
3
|
+
export { NumberTransform } from './number.transform';
|
|
4
|
+
export { StringArrayTransform } from './string-array.transform';
|
|
5
|
+
export { StringTransform } from './string.transform';
|
|
6
|
+
export { TimestampTransform } from './timestamp.transform';
|
package/dist/transform/index.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "
|
|
10
|
-
var
|
|
11
|
-
Object.defineProperty(exports, "
|
|
12
|
-
var
|
|
13
|
-
Object.defineProperty(exports, "
|
|
14
|
-
var
|
|
15
|
-
Object.defineProperty(exports, "
|
|
16
|
-
var to_string_transform_1 = require("./to-string.transform");
|
|
17
|
-
Object.defineProperty(exports, "TransformToString", { enumerable: true, get: function () { return to_string_transform_1.TransformToString; } });
|
|
18
|
-
var to_timestamp_transform_1 = require("./to-timestamp.transform");
|
|
19
|
-
Object.defineProperty(exports, "TransformToTimestamp", { enumerable: true, get: function () { return to_timestamp_transform_1.TransformToTimestamp; } });
|
|
3
|
+
exports.TimestampTransform = exports.StringTransform = exports.StringArrayTransform = exports.NumberTransform = exports.ImageUrlTransform = exports.BooleanTransform = void 0;
|
|
4
|
+
var boolean_transform_1 = require("./boolean.transform");
|
|
5
|
+
Object.defineProperty(exports, "BooleanTransform", { enumerable: true, get: function () { return boolean_transform_1.BooleanTransform; } });
|
|
6
|
+
var image_url_transform_1 = require("./image-url.transform");
|
|
7
|
+
Object.defineProperty(exports, "ImageUrlTransform", { enumerable: true, get: function () { return image_url_transform_1.ImageUrlTransform; } });
|
|
8
|
+
var number_transform_1 = require("./number.transform");
|
|
9
|
+
Object.defineProperty(exports, "NumberTransform", { enumerable: true, get: function () { return number_transform_1.NumberTransform; } });
|
|
10
|
+
var string_array_transform_1 = require("./string-array.transform");
|
|
11
|
+
Object.defineProperty(exports, "StringArrayTransform", { enumerable: true, get: function () { return string_array_transform_1.StringArrayTransform; } });
|
|
12
|
+
var string_transform_1 = require("./string.transform");
|
|
13
|
+
Object.defineProperty(exports, "StringTransform", { enumerable: true, get: function () { return string_transform_1.StringTransform; } });
|
|
14
|
+
var timestamp_transform_1 = require("./timestamp.transform");
|
|
15
|
+
Object.defineProperty(exports, "TimestampTransform", { enumerable: true, get: function () { return timestamp_transform_1.TimestampTransform; } });
|
|
@@ -17,5 +17,5 @@ interface NumberOptions {
|
|
|
17
17
|
* @param {NumberOptions} opts - Options to configure the transformation.
|
|
18
18
|
* @returns {PropertyDecorator} - A decorator function for property transformation.
|
|
19
19
|
*/
|
|
20
|
-
export declare function
|
|
20
|
+
export declare function NumberTransform(opts?: NumberOptions): PropertyDecorator;
|
|
21
21
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.NumberTransform = NumberTransform;
|
|
4
4
|
const class_transformer_1 = require("class-transformer");
|
|
5
5
|
/**
|
|
6
6
|
* Transforms the input value into a number, applying constraints such as default,
|
|
@@ -10,7 +10,7 @@ const class_transformer_1 = require("class-transformer");
|
|
|
10
10
|
* @param {NumberOptions} opts - Options to configure the transformation.
|
|
11
11
|
* @returns {PropertyDecorator} - A decorator function for property transformation.
|
|
12
12
|
*/
|
|
13
|
-
function
|
|
13
|
+
function NumberTransform(opts = {}) {
|
|
14
14
|
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
15
15
|
// Attempt to parse the value as an integer, using the default if necessary
|
|
16
16
|
let parsedNumber = Number.parseInt(value || String(opts.default), 10);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface defining options for transforming string arrays.
|
|
3
|
+
*/
|
|
4
|
+
interface StringArrayOptions {
|
|
5
|
+
trim?: boolean;
|
|
6
|
+
unique?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Transforms an array of values into an array of strings, applying options such as trimming and uniqueness.
|
|
10
|
+
*
|
|
11
|
+
* @param {StringArrayOptions} opts - Options for transformation including trimming and ensuring uniqueness.
|
|
12
|
+
* @returns {PropertyDecorator} - A decorator function for transforming the property value.
|
|
13
|
+
*/
|
|
14
|
+
export declare function StringArrayTransform(opts?: StringArrayOptions): PropertyDecorator;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringArrayTransform = StringArrayTransform;
|
|
4
|
+
const class_transformer_1 = require("class-transformer");
|
|
5
|
+
const class_validator_1 = require("class-validator");
|
|
6
|
+
/**
|
|
7
|
+
* Transforms an array of values into an array of strings, applying options such as trimming and uniqueness.
|
|
8
|
+
*
|
|
9
|
+
* @param {StringArrayOptions} opts - Options for transformation including trimming and ensuring uniqueness.
|
|
10
|
+
* @returns {PropertyDecorator} - A decorator function for transforming the property value.
|
|
11
|
+
*/
|
|
12
|
+
function StringArrayTransform(opts = {}) {
|
|
13
|
+
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
14
|
+
// If the value is not an array, return it unchanged
|
|
15
|
+
if (!(0, class_validator_1.isArray)(value))
|
|
16
|
+
return value;
|
|
17
|
+
const stringArray = value.map((element) => {
|
|
18
|
+
const str = String(element);
|
|
19
|
+
return opts.trim ? str.trim() : str;
|
|
20
|
+
});
|
|
21
|
+
// Ensure uniqueness if specified
|
|
22
|
+
if (opts.unique) {
|
|
23
|
+
return [...new Set(stringArray)];
|
|
24
|
+
}
|
|
25
|
+
return stringArray;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Class-level comment:
|
|
3
|
-
* The
|
|
3
|
+
* The StringTransform function is a property decorator designed to consistently format string properties in a class.
|
|
4
4
|
* It checks if the input value is a string and applies transformations such as trimming, converting to lowercase, or uppercase.
|
|
5
5
|
* If the input is not a string, it returns the original value unchanged.
|
|
6
6
|
* This decorator ensures that string properties adhere to specified formatting options.
|
|
7
7
|
*/
|
|
8
|
+
/**
|
|
9
|
+
* Interface defining options for transforming strings.
|
|
10
|
+
*/
|
|
8
11
|
interface StringOptions {
|
|
9
12
|
trim?: boolean;
|
|
10
13
|
lowercase?: boolean;
|
|
@@ -17,5 +20,5 @@ interface StringOptions {
|
|
|
17
20
|
* @param {StringOptions} opts - Options to specify string transformations (trim, lowercase, uppercase).
|
|
18
21
|
* @returns {PropertyDecorator} - A decorator function that applies the specified transformations.
|
|
19
22
|
*/
|
|
20
|
-
export declare function
|
|
23
|
+
export declare function StringTransform(opts?: StringOptions): PropertyDecorator;
|
|
21
24
|
export {};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.StringTransform = StringTransform;
|
|
4
4
|
const class_transformer_1 = require("class-transformer");
|
|
5
5
|
const class_validator_1 = require("class-validator");
|
|
6
|
-
const string_like_functions_1 = require("../functions/string-like.functions");
|
|
7
6
|
/**
|
|
8
7
|
* Transforms the input value to a formatted string based on provided options.
|
|
9
8
|
* If the value is not a string, it returns the original value.
|
|
@@ -11,7 +10,7 @@ const string_like_functions_1 = require("../functions/string-like.functions");
|
|
|
11
10
|
* @param {StringOptions} opts - Options to specify string transformations (trim, lowercase, uppercase).
|
|
12
11
|
* @returns {PropertyDecorator} - A decorator function that applies the specified transformations.
|
|
13
12
|
*/
|
|
14
|
-
function
|
|
13
|
+
function StringTransform(opts = {}) {
|
|
15
14
|
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
16
15
|
// Check if the value is a string; if not, return it unchanged
|
|
17
16
|
if (!(0, class_validator_1.isString)(value))
|
|
@@ -20,7 +19,7 @@ function TransformToString(opts = {}) {
|
|
|
20
19
|
let formattedString = String(value);
|
|
21
20
|
// Apply transformations based on options
|
|
22
21
|
if (opts.trim)
|
|
23
|
-
formattedString =
|
|
22
|
+
formattedString = formattedString.trim();
|
|
24
23
|
if (opts.lowercase)
|
|
25
24
|
formattedString = formattedString.toLowerCase();
|
|
26
25
|
if (opts.uppercase)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Interface defining options for
|
|
2
|
+
* Interface defining options for timestamp transformation.
|
|
3
3
|
*/
|
|
4
4
|
interface NumberOptions {
|
|
5
5
|
/** Default value if the provided value is not a number */
|
|
@@ -20,5 +20,5 @@ interface NumberOptions {
|
|
|
20
20
|
* @param {NumberOptions} opts - Options for transformation including default value, min/max bounds, and rounding unit.
|
|
21
21
|
* @returns {PropertyDecorator} - A decorator function for transforming the property value.
|
|
22
22
|
*/
|
|
23
|
-
export declare function
|
|
23
|
+
export declare function TimestampTransform(opts?: NumberOptions): PropertyDecorator;
|
|
24
24
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TimestampTransform = TimestampTransform;
|
|
4
4
|
const class_transformer_1 = require("class-transformer");
|
|
5
5
|
/**
|
|
6
6
|
* Transforms a value into a number, applying constraints and rounding options.
|
|
@@ -11,7 +11,7 @@ const class_transformer_1 = require("class-transformer");
|
|
|
11
11
|
* @param {NumberOptions} opts - Options for transformation including default value, min/max bounds, and rounding unit.
|
|
12
12
|
* @returns {PropertyDecorator} - A decorator function for transforming the property value.
|
|
13
13
|
*/
|
|
14
|
-
function
|
|
14
|
+
function TimestampTransform(opts = {}) {
|
|
15
15
|
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
16
16
|
// Parse the value as an integer, using the default if value is not provided
|
|
17
17
|
let parsedNumber = Number.parseInt(value || String(opts.default), 10);
|
package/package.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for handling values that can be either strings or numbers.
|
|
3
|
-
* This module provides methods to check if a value is string-like and to trim
|
|
4
|
-
* whitespace from such values. It interacts with the class-validator library
|
|
5
|
-
* to determine the type of values.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Checks if the provided value is either a string or a number.
|
|
9
|
-
*
|
|
10
|
-
* @param {unknown} value - The value to be checked.
|
|
11
|
-
* @returns {boolean} - Returns true if the value is a string or a number, false otherwise.
|
|
12
|
-
*/
|
|
13
|
-
export declare function isStringLike(value: unknown): value is string | number;
|
|
14
|
-
/**
|
|
15
|
-
* Trims whitespace from a string-like value (string or number).
|
|
16
|
-
* If the value is not string-like, it returns the original value.
|
|
17
|
-
*
|
|
18
|
-
* @param {T} value - The value to be trimmed.
|
|
19
|
-
* @returns {string | T} - The trimmed string-like value or the original value if not string-like.
|
|
20
|
-
*/
|
|
21
|
-
export declare function trimStringLike<T = any>(value: T): string | T;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isStringLike = isStringLike;
|
|
4
|
-
exports.trimStringLike = trimStringLike;
|
|
5
|
-
const class_validator_1 = require("class-validator");
|
|
6
|
-
/**
|
|
7
|
-
* Utility functions for handling values that can be either strings or numbers.
|
|
8
|
-
* This module provides methods to check if a value is string-like and to trim
|
|
9
|
-
* whitespace from such values. It interacts with the class-validator library
|
|
10
|
-
* to determine the type of values.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Checks if the provided value is either a string or a number.
|
|
14
|
-
*
|
|
15
|
-
* @param {unknown} value - The value to be checked.
|
|
16
|
-
* @returns {boolean} - Returns true if the value is a string or a number, false otherwise.
|
|
17
|
-
*/
|
|
18
|
-
function isStringLike(value) {
|
|
19
|
-
// Utilize class-validator to determine if the value is a string or a number
|
|
20
|
-
return (0, class_validator_1.isString)(value) || (0, class_validator_1.isNumber)(value);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Trims whitespace from a string-like value (string or number).
|
|
24
|
-
* If the value is not string-like, it returns the original value.
|
|
25
|
-
*
|
|
26
|
-
* @param {T} value - The value to be trimmed.
|
|
27
|
-
* @returns {string | T} - The trimmed string-like value or the original value if not string-like.
|
|
28
|
-
*/
|
|
29
|
-
function trimStringLike(value) {
|
|
30
|
-
// Check if the value is string-like using the isStringLike function
|
|
31
|
-
if (!isStringLike(value))
|
|
32
|
-
return value;
|
|
33
|
-
// Convert the value to a string, replace multiple spaces with a single space, and trim the result
|
|
34
|
-
return String(value).replace(/\s+/g, ' ').trim();
|
|
35
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface defining options for the CastToArray decorator.
|
|
3
|
-
* - onlyStringLike: If true, filters the array to include only string-like values.
|
|
4
|
-
* - unique: If true, ensures all elements in the array are unique.
|
|
5
|
-
*/
|
|
6
|
-
interface ArrayOptions {
|
|
7
|
-
onlyStringLike?: boolean;
|
|
8
|
-
unique?: boolean;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* The CastToArray decorator function ensures that the decorated property is always an array.
|
|
12
|
-
* It checks the input value and returns it as an array, wrapping non-array values in an array.
|
|
13
|
-
* This decorator is useful for maintaining consistent data types when processing input data,
|
|
14
|
-
* particularly when the input can vary between single values and arrays.
|
|
15
|
-
*
|
|
16
|
-
* @param {ArrayOptions} opts - Options to customize the behavior of the array transformation.
|
|
17
|
-
* @returns {PropertyDecorator} - A decorator function that transforms the property value into an array.
|
|
18
|
-
*/
|
|
19
|
-
export declare function CastToArray(opts?: ArrayOptions): PropertyDecorator;
|
|
20
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CastToArray = CastToArray;
|
|
4
|
-
const class_transformer_1 = require("class-transformer");
|
|
5
|
-
const string_like_functions_1 = require("../functions/string-like.functions");
|
|
6
|
-
/**
|
|
7
|
-
* The CastToArray decorator function ensures that the decorated property is always an array.
|
|
8
|
-
* It checks the input value and returns it as an array, wrapping non-array values in an array.
|
|
9
|
-
* This decorator is useful for maintaining consistent data types when processing input data,
|
|
10
|
-
* particularly when the input can vary between single values and arrays.
|
|
11
|
-
*
|
|
12
|
-
* @param {ArrayOptions} opts - Options to customize the behavior of the array transformation.
|
|
13
|
-
* @returns {PropertyDecorator} - A decorator function that transforms the property value into an array.
|
|
14
|
-
*/
|
|
15
|
-
function CastToArray(opts = {}) {
|
|
16
|
-
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
17
|
-
// Ensure the value is an array; wrap non-array values in an array
|
|
18
|
-
let resultArray = Array.isArray(value) ? value : [value];
|
|
19
|
-
// If onlyStringLike option is enabled, filter and normalize the array
|
|
20
|
-
if (opts.onlyStringLike) {
|
|
21
|
-
resultArray = resultArray
|
|
22
|
-
.filter((element) => (0, string_like_functions_1.isStringLike)(element)) // Filter out non-string-like values
|
|
23
|
-
.map((element) => (0, string_like_functions_1.trimStringLike)(element)) // Trim and normalize the values
|
|
24
|
-
.filter((element) => String(element).length); // Remove empty values
|
|
25
|
-
}
|
|
26
|
-
// If unique option is enabled, remove duplicate elements
|
|
27
|
-
if (opts.unique) {
|
|
28
|
-
resultArray = [...new Set(resultArray)];
|
|
29
|
-
}
|
|
30
|
-
return resultArray;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TransformToStringArray is a decorator function designed to transform a property value
|
|
3
|
-
* into an array of trimmed strings.
|
|
4
|
-
*
|
|
5
|
-
* Key Responsibilities:
|
|
6
|
-
* - Validates if the input value is an array.
|
|
7
|
-
* - Filters the array to retain only elements that are string-like (strings or numbers).
|
|
8
|
-
* - Trims each element and removes any empty strings from the array.
|
|
9
|
-
* - Returns the original value unchanged if it is not an array.
|
|
10
|
-
*
|
|
11
|
-
* This decorator is useful for ensuring that properties meant to be arrays of strings
|
|
12
|
-
* are consistently formatted and free of extraneous whitespace or empty entries.
|
|
13
|
-
*
|
|
14
|
-
* @returns {PropertyDecorator} A decorator function that applies the transformation.
|
|
15
|
-
*/
|
|
16
|
-
export declare function TransformToStringArray(): PropertyDecorator;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TransformToStringArray = TransformToStringArray;
|
|
4
|
-
const class_transformer_1 = require("class-transformer");
|
|
5
|
-
const class_validator_1 = require("class-validator");
|
|
6
|
-
const string_like_functions_1 = require("../functions/string-like.functions");
|
|
7
|
-
/**
|
|
8
|
-
* TransformToStringArray is a decorator function designed to transform a property value
|
|
9
|
-
* into an array of trimmed strings.
|
|
10
|
-
*
|
|
11
|
-
* Key Responsibilities:
|
|
12
|
-
* - Validates if the input value is an array.
|
|
13
|
-
* - Filters the array to retain only elements that are string-like (strings or numbers).
|
|
14
|
-
* - Trims each element and removes any empty strings from the array.
|
|
15
|
-
* - Returns the original value unchanged if it is not an array.
|
|
16
|
-
*
|
|
17
|
-
* This decorator is useful for ensuring that properties meant to be arrays of strings
|
|
18
|
-
* are consistently formatted and free of extraneous whitespace or empty entries.
|
|
19
|
-
*
|
|
20
|
-
* @returns {PropertyDecorator} A decorator function that applies the transformation.
|
|
21
|
-
*/
|
|
22
|
-
function TransformToStringArray() {
|
|
23
|
-
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
24
|
-
// If the value is not an array, return it unchanged
|
|
25
|
-
if (!(0, class_validator_1.isArray)(value))
|
|
26
|
-
return value;
|
|
27
|
-
// Process the array: filter, trim, and remove empty strings
|
|
28
|
-
const processedArray = value
|
|
29
|
-
.filter((element) => (0, string_like_functions_1.isStringLike)(element)) // Retain only string-like elements
|
|
30
|
-
.map((element) => (0, string_like_functions_1.trimStringLike)(element)) // Trim each element
|
|
31
|
-
.filter((element) => String(element).length); // Remove elements that are empty strings
|
|
32
|
-
return processedArray;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Class-level comment block:
|
|
3
|
-
* This module provides a transformation decorator for use with class-transformer.
|
|
4
|
-
* The TransformToStringLike function is designed to automatically transform values
|
|
5
|
-
* that are considered "string-like" (either strings or numbers) according to specified options.
|
|
6
|
-
* It ensures that any string-like property of a class is stored in a consistent format,
|
|
7
|
-
* enhancing data uniformity. It interacts with other components by being applied as a
|
|
8
|
-
* decorator to class properties.
|
|
9
|
-
*/
|
|
10
|
-
interface StringLikeOptions {
|
|
11
|
-
trim?: boolean;
|
|
12
|
-
lowercase?: boolean;
|
|
13
|
-
uppercase?: boolean;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Transforms the input value to a formatted string if it's a string or a number.
|
|
17
|
-
* Applies trimming, lowercase, or uppercase transformations based on the provided options.
|
|
18
|
-
* If the value is not string-like, it returns the original value.
|
|
19
|
-
*
|
|
20
|
-
* @param {StringLikeOptions} [opts={}] - Options to specify transformations like trim, lowercase, or uppercase.
|
|
21
|
-
* @return {PropertyDecorator} - A transformation function for class-transformer.
|
|
22
|
-
*/
|
|
23
|
-
export declare function TransformToStringLike(opts?: StringLikeOptions): PropertyDecorator;
|
|
24
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TransformToStringLike = TransformToStringLike;
|
|
4
|
-
const class_transformer_1 = require("class-transformer");
|
|
5
|
-
const string_like_functions_1 = require("../functions/string-like.functions");
|
|
6
|
-
/**
|
|
7
|
-
* Transforms the input value to a formatted string if it's a string or a number.
|
|
8
|
-
* Applies trimming, lowercase, or uppercase transformations based on the provided options.
|
|
9
|
-
* If the value is not string-like, it returns the original value.
|
|
10
|
-
*
|
|
11
|
-
* @param {StringLikeOptions} [opts={}] - Options to specify transformations like trim, lowercase, or uppercase.
|
|
12
|
-
* @return {PropertyDecorator} - A transformation function for class-transformer.
|
|
13
|
-
*/
|
|
14
|
-
function TransformToStringLike(opts = {}) {
|
|
15
|
-
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
16
|
-
// Check if the value is string-like (either a string or a number)
|
|
17
|
-
if (!(0, string_like_functions_1.isStringLike)(value))
|
|
18
|
-
return value;
|
|
19
|
-
// Convert the value to a string for consistent processing
|
|
20
|
-
let formattedString = String(value);
|
|
21
|
-
// Apply transformations based on options
|
|
22
|
-
if (opts.trim)
|
|
23
|
-
formattedString = (0, string_like_functions_1.trimStringLike)(formattedString);
|
|
24
|
-
if (opts.lowercase)
|
|
25
|
-
formattedString = formattedString.toLowerCase();
|
|
26
|
-
if (opts.uppercase)
|
|
27
|
-
formattedString = formattedString.toUpperCase();
|
|
28
|
-
// Return the transformed string-like value
|
|
29
|
-
return formattedString;
|
|
30
|
-
});
|
|
31
|
-
}
|