@js-soft/ts-serval
TypeScript icon, indicating that this package has built-in type declarations

2.0.10 • Public • Published

TS SerVal

GitHub Actions CI npm version

TS SerVal (TypeScript Serialization and Validation) is a TypeScript library for runtime serialization and validation of JSON objects to/from JavaScript classes. It is using TypeScript decorators (e.g. @serialize()) to mark classes and properties for serialization and validation. It heavily uses reflection and TypeScript decorators.

Documentation

The documentation for this package is currently under construction.

Features

JSONWrapper & JSONWrapperAsync

If you require to set any JSON content to a Serializable property, you can use JSONWrapper or JSONWrapperAsync. They enable the (de-)serialization with serialize(), toJSON(), from() or deserialize() in a generic way.

The wrappers store all content into a generic value property as JSON. This property is transparent, meaning that value won't appear in the serialized output. However, accessing the value is required while using the wrappers programmatically.

The wrappers are automatically used if ts-serval encounters a property of type Serializable (=> JSONWrapper) or SerializableAsync (=> JSONWrapperAsync).

Type any

If you would like to allow any type (be it any object, boolean, string, number), set {any:true} within the @serialize() descriptor. This will disable most of the parsing and (de-)serialization logic.

@validate()
@serialize({any:true})
public content:any

If you would also like to allow null values, use {nullable:true} within the @validate() descriptor.

@validate({nullable:true})
@serialize({any:true})
public content:any

Contribute

Currently contribution to this project is not possible. This will change soon.

License

MIT

/@js-soft/ts-serval/

    Package Sidebar

    Install

    npm i @js-soft/ts-serval

    Weekly Downloads

    1,240

    Version

    2.0.10

    License

    MIT

    Unpacked Size

    2.73 MB

    Total Files

    68

    Last publish

    Collaborators

    • js-soft_ci