Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

luren-schema

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

luren-schema

schema for luren

latest
Source
npmnpm
Version
0.2.8
Version published
Maintainers
1
Created
Source

luren-schema

npm version Dependencies Status Build Status Coverage Status

Luren-Schema is a typescript module for Luren, it uses metadata to store type info and validate data.It use decorators to inject metadata, so decorator must be enabled .

Built-in data types:

string, boolean, number, integer, date, array,object

@Schema({title: 'person', additionalProperties: true})
class Person {
      @Prop({ required: true, type: 'string' })
      public name: string
      @Prop({ required: true })
      public password: string
      constructor(name: string, passowrd: string) {
        this.name = name
        this.passowrd = passowrd
      }
      public greeting() {
        console.log(`Hi, I'm ${this.name}`)
      }
    }
const person = new Person('My Name', 'my_passoword')
const schema = getJsSchema(Person)

// validation
//result: [true, undefined]
const [valid, errorMsg] = JsTypes.validate(person, schema)
//serialize to json
// result: {name: 'My Name'}
const data = JsTypes.serialize(person, schema)
//deserialize from json
//result: Person {name: 'John', password: 'encrypted_passwd'}
const p = JsTypes.deserialize({name: 'John', password: 'encrypted_passwd'}, schema)
// result: Hi, I'm John
p.greeting()

FAQs

Package last updated on 09 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts