Skip to content

Typescript SERialize and VALidate

License

Notifications You must be signed in to change notification settings

js-soft/ts-serval

Repository files navigation

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

About

Typescript SERialize and VALidate

Resources

License

Stars

Watchers

Forks

Languages