New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@sugarcoated/fondant-model

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sugarcoated/fondant-model

Model data without the hassle.

latest
Source
npmnpm
Version
1.0.5
Version published
Maintainers
1
Created
Source

We all model data, but we have nothing to cling on to for managing the data within that model. It is just an object that is returned from an API, or a database. Converting plain objects to types or updating the contents of a typed model without losing reference is strenuous, which is where Model comes in. Extending this class will inherit important methods for cloning, assigning, casting and so on.

  • View the source at src/Globals/Model.js
  • View the test fie at test/Globals/testModel.js
  • View the NPM package at @sugarcoated/fondant-dictionary

API Reference

new Model()

Creates a Model instance.

class Book extends Model { constructor (bookName) { super ();

  this.bookName = bookName;
}

}

.difference(comparison)

Checks the difference against the instance and the Object passed.

  • comparison is expected as an Object, representing a set ofm properties to compare against.

    myModel.difference(myObject);

.assign(values)

Assigns values from an Object to the properties on an instance.

  • values is expected as an Object, representing a casted or uncasted version of the instance with differing values to assign to the instance.

    myModel.assign(itClone);

.prune([item])

Prunes foreign* properties (not prefixed with the name of the model) from an instance, or a passed Object.

  • item is an optional parameter, expected as an Object. When no item is passed, pruning applies to the instance called upon.

    itBook.prune();

.clone()

Creates a direct copy of the modeled Object. On this base class, this will simply return a plain Object. When extending the Model class, an override can be written to cast this as seen fit.

  const myClone = myModel.clone();

.cast(item, [model])

Casts a plain Object to an instance of Model, or passed in. An override can be written for this method to pass in the Class itself, and return the super method's result anyway.

  • item is expected as an Object, representing an uncasted identical version of the model.

  • model is an optional parameter, expected as a Class that extends Model.

    static cast (castItem) { return super.cast(castItem, User); }

Keywords

Model

FAQs

Package last updated on 25 Aug 2018

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