1.2.18 • Published 5 years ago
@vicis/decorators v1.2.18

Vicis Decorators
JavaScript's Vicis Decorators create serializable objects without a configuration.
Usage
Require CommonJS.
const {
Cast, Defaults, Exclude, Nullish, Omit, Order, Pick, Rename,
Required, Replace, Serialize, Transform,
cast, defaults, defined, exclude, omit, rename,
replace, serializable, serialize, transform,
} = require("@vicis/decorators");Import as ECMAScript module.
import {
Cast, Defaults, Exclude, Nullish, Omit, Order, Pick, Rename,
Required, Replace, Serialize, Transform,
cast, defaults, defined, exclude, omit, rename,
replace, serializable, serialize, transform,
} from "@vicis/decorators";Classes
Serialize (class)
@Serialize({
pick: ["id", "login"]
})
class MyClass {
protected id: number | string;
protected login: string;
}Cast (class)
@Cast({ id: Vicis.INTEGER })
class MyClass {
protected id: number | string;
}Defaults (class)
@Defaults({ active: false })
class MyClass {
protected id: number | string;
protected login: string;
}Exclude (class)
@Exclude(["password", "email", /^(?:_)(?:_)?/])
class MyClass {
protected id: number | string;
protected login: string;
protected password: string;
protected email: string;
}@Exclude("password", "email", /^(?:_)(?:_)?/)
class MyClass {
protected id: number | string;
protected login: string;
protected password: string;
protected email: string;
}Nullish (class)
@Nullish({ active: null })
class MyClass {
protected id: number | string;
protected login: string;
}Omit (class)
@Omit(["password", "email"])
class MyClass {
protected id: number | string;
protected login: string;
protected password: string;
protected email: string;
}@Omit("password", "email")
class MyClass {
protected id: number | string;
protected login: string;
protected password: string;
protected email: string;
}Order (class)
@Order(["id", "login", "name"])
class MyClass {
protected id: number | string;
protected name: string;
protected login: string;
}@Order("id", "login", "name")
class MyClass {
protected id: number | string;
protected name: string;
protected login: string;
}Pick (class)
@Pick(["id", "name"])
class MyClass {
protected id: number | string;
protected name: string;
protected login: string;
}@Pick("id", "name")
class MyClass {
protected id: number | string;
protected name: string;
protected login: string;
}Rename (class)
@Rename({ _uuid: "id" })
class MyClass {
protected _uuid: string;
}Required (class)
@Required(["id", "login"])
class MyClass {
protected id: number | string;
protected name: string;
protected login: string;
}@Required("id", "login")
class MyClass {
protected id: number | string;
protected name: string;
protected login: string;
}Replace (class)
@Replace({ local: false })
class MyClass {
protected local: string = "yes";
}Transform (class)
@Transform({ date: (value) => new Date(value) })
class MyClass {
protected date: string = "2025-06-15";
}Properties
serialize (property)
Any decorator that does not remove the property mark it as serializable.
@Serialize()
class MyClass {
@serialize()
protected id: number | string;
}Passing string instead of object rename property.
@Serialize()
class MyClass {
@serialize("ID")
protected id: number | string;
}You can use a configuration object.
import { Vicis } from "vicis";
@Serialize()
class MyClass {
@serialize({
cast: Vicis.INTEGER,
required: true,
})
protected id: number | string;
}Or combine multiple decorators.
import { Vicis } from "vicis";
@Serialize()
class MyClass {
@required
@cast(Vicis.INTEGER)
protected id: number | string;
}cast (property)
import { Vicis } from "vicis";
@Serialize()
class MyClass {
@cast(Vicis.INTEGER)
protected id: number | string;
}defaults (property)
@Serialize()
class MyClass {
@defaults(false)
protected active: any;
}defined (property)
@Serialize()
class MyClass {
@defined
protected email: string;
}exclude (property)
@Serialize()
class MyClass {
@exclude
protected password: string;
}nullish (property)
@Serialize()
class MyClass {
@nullish("ok")
protected active: any;
}omit (property)
@Serialize()
class MyClass {
@omit
protected secret: string;
}pick (property)
@Serialize()
class MyClass {
@pick
protected id: number | string;
}rename (property)
@Serialize()
class MyClass {
@rename("firstName")
protected first_name: string;
}replace (property)
@Serialize()
class MyClass {
@replace("*****")
protected hasInformation: string;
}required (property)
@Serialize()
class MyClass {
@required
protected id: number | string;
}transform (property)
@Serialize()
class MyClass {
@transform((text) => text.toUpperCase())
protected abbreviation: string;
}See also
1.2.18
5 years ago
1.2.16
5 years ago
1.2.17
5 years ago
1.2.15
5 years ago
1.2.14
5 years ago
1.2.13
5 years ago
1.2.12
5 years ago
1.2.11
5 years ago
1.2.10
5 years ago
1.2.9
5 years ago
1.2.8
5 years ago
1.2.7
5 years ago
1.1.7
5 years ago
1.1.6
5 years ago
1.1.5
6 years ago
1.1.4
6 years ago
1.1.3
6 years ago
1.1.1
6 years ago
1.1.2
6 years ago
1.1.0
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago