@credo-ts/core
Version:
<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1
61 lines (60 loc) • 2.11 kB
JavaScript
import __decorateMetadata from "../../../../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorateMetadata.mjs";
import __decorate from "../../../../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorate.mjs";
import { Expose, Transform, TransformationType, instanceToPlain, plainToClassFromExist, plainToInstance } from "class-transformer";
import { IsEnum, IsOptional, IsString, isString } from "class-validator";
//#region src/modules/vc/models/credential/W3cV2LocalizedValue.ts
/**
* Represents a localized string.
*
* @see https://www.w3.org/TR/vc-data-model-2.0/#internationalization-considerations
*/
var W3cV2LocalizedValue = class {
constructor(options) {
if (options) {
const { value, language, direction, ...rest } = options;
plainToClassFromExist(this, rest);
this.value = value;
this.language = language;
this.direction = direction;
}
}
};
__decorate([
Expose({ name: "@value" }),
IsString(),
__decorateMetadata("design:type", String)
], W3cV2LocalizedValue.prototype, "value", void 0);
__decorate([
Expose({ name: "@language" }),
IsOptional(),
IsString(),
__decorateMetadata("design:type", Object)
], W3cV2LocalizedValue.prototype, "language", void 0);
__decorate([
Expose({ name: "@direction" }),
IsOptional(),
IsEnum([
"ltr",
"rtl",
null
]),
__decorateMetadata("design:type", Object)
], W3cV2LocalizedValue.prototype, "direction", void 0);
function W3cV2LocalizedValueTransformer() {
return Transform(({ value, type }) => {
if (type === TransformationType.PLAIN_TO_CLASS) {
if (isString(value)) return value;
if (Array.isArray(value)) return value.map((v) => plainToInstance(W3cV2LocalizedValue, v));
return plainToInstance(W3cV2LocalizedValue, value);
}
if (type === TransformationType.CLASS_TO_PLAIN) {
if (isString(value)) return value;
if (Array.isArray(value)) return value.map((v) => instanceToPlain(W3cV2LocalizedValue, v));
return instanceToPlain(value);
}
return value;
});
}
//#endregion
export { W3cV2LocalizedValue, W3cV2LocalizedValueTransformer };
//# sourceMappingURL=W3cV2LocalizedValue.mjs.map