Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@florianb/rec

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@florianb/rec

Primitive model toolset delivered as base class for your models.

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

rec

Minimal ECMAScript-module facilitating model-framework to support a straight-forward workflow without magic.

Features:

  • Leaves JS class- and objectfunctionality as it is
  • Allows PlainObject instantiation as class
  • Validates class at instantiation using (cached) AJV-validators
Install
npm i --save @florianb/rec

Usage

import Base from '@florianb/rec'

class FellowShipOfTheRing extends Base {
	static get schema() {
		return {
			properties: {
				boromir: {
					type: 'integer'
				}
			}
		}
	}
}

const sourceObject = {boromir: false}

let fellowship = FellowShipOfTheRing.newFrom(sourceObject)
// TypeError: Schema validation for FellowShipOfTheRing failed at: .boromir: should be integer

fellowship = FellowShipOfTheRing.newFrom({boromir: 0})
// success! 

Instantiate a class from a plain object using the static method newFrom(). If the schema-property is defined, its value is used as JSONSchema and the plain object is validated against it. If the validation fails a TypeError is raised.

Base API

static newFrom(Object source) -> Object

Returns a new instance of the class having the source merged in. If the schema property is defined, the source wil be validated before being merged.

  • returns: Object - instantiated class with merged in properties from source
  • throws: TypeError - if schema is set and validation fails

get static schema() -> Object

Overrride to provide a JSONSchema for the class. If set the schema will be used to validate any new instantiation of the Class.

  • returns: Object - JSONSchema object according to the schema-version 7

FAQs

Package last updated on 25 Nov 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc