Skip to content

Some SchemaTypes to get you started with @protagonists/coerce

Notifications You must be signed in to change notification settings

ThePywon/coerce-basics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

A package to get you started with @protagonists/coerce!





Table of content

The content below may not correspond to the structure of the objects





How to use?

Description

This package contains a few basic SchemaTypes that try to stay consistent with javascript's existing type conversion
Those are meant to be an easy way to start using @protagonists/coerce
All of them of course extends from the SchemaType object


Import

Terminal

npm install @protagonists/coerce-basics

Node.js

const Basics = require("@protagonists/coerce-basics");

Example

Code:

// Imports
const { Schema } = require("@protagonists/coerce");
const { StringType, IntRange, DateType } = require("@protagonists/coerce-basics");

// Create schema 'Person'
const Person = new Schema({
  name: StringType,
  age: IntRange(0, 200),
  birthday: DateType,
  friends: [StringType]
});

// Coerce object into following the model
const John = new Person({
  name: "John",
  favColor: "Red",
  friends: ["Steve", "Carla", "Meep"],
  kids: 2,
  birthday: "1984",
  age: 37
});

// Log the result
console.log(John);

Output:

{
  name: 'John',
  age: 37,
  birthday: 1984-01-01T00:00:00.000Z,
  friends: [ 'Steve', 'Carla', 'Meep' ]
}






This is the bottom, there is nothing more.
Go back up?

About

Some SchemaTypes to get you started with @protagonists/coerce

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published