README
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;
}