npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vicis/decorators

v1.2.18

Published

JavaScript's Vicis Decorators create serializable objects without a configuration.

Downloads

83

Readme

Vicis

Vicis Decorators

JavaScript's Vicis Decorators create serializable objects without a configuration.

Vicis Documentation

npm downloads types build lgtm


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)

Configuration

@Serialize({
  pick: ["id", "login"]
})
class MyClass {
  protected id: number | string;
  protected login: string;
}

Cast (class)

Cast →

@Cast({ id: Vicis.INTEGER })
class MyClass {
  protected id: number | string;
}

Defaults (class)

Defaults →

@Defaults({ active: false })
class MyClass {
  protected id: number | string;
  protected login: string;
}

Exclude (class)

Exclude →

@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 →

@Nullish({ active: null })
class MyClass {
  protected id: number | string;
  protected login: string;
}

Omit (class)

Omit →

@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 →

@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 →

@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 →

@Rename({ _uuid: "id" })
class MyClass {
  protected _uuid: string;
}

Required (class)

Required →

@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 →

@Replace({ local: false })
class MyClass {
  protected local: string = "yes";
}

Transform (class)

Transform →

@Transform({ date: (value) => new Date(value) })
class MyClass {
  protected date: string = "2025-06-15";
}

Properties

serialize (property)

Serialize configuration →

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)

Cast →

import { Vicis } from "vicis";
@Serialize()
class MyClass {
  @cast(Vicis.INTEGER)
  protected id: number | string;
}

defaults (property)

Defaults →

@Serialize()
class MyClass {
  @defaults(false)
  protected active: any;
}

defined (property)

Defined →

@Serialize()
class MyClass {
  @defined
  protected email: string;
}

exclude (property)

Exclude →

@Serialize()
class MyClass {
  @exclude
  protected password: string;
}

nullish (property)

Nullish →

@Serialize()
class MyClass {
  @nullish("ok")
  protected active: any;
}

omit (property)

Omit →

@Serialize()
class MyClass {
  @omit
  protected secret: string;
}

pick (property)

Pick →

@Serialize()
class MyClass {
  @pick
  protected id: number | string;
}

rename (property)

Rename →

@Serialize()
class MyClass {
  @rename("firstName")
  protected first_name: string;
}

replace (property)

Replace →

@Serialize()
class MyClass {
  @replace("*****")
  protected hasInformation: string;
}

required (property)

Required →

@Serialize()
class MyClass {
  @required
  protected id: number | string;
}

transform (property)

Transform →

@Serialize()
class MyClass {
  @transform((text) => text.toUpperCase())
  protected abbreviation: string;
}

See also

My Other Projects