npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sugarcoated/fondant-model

v1.0.5

Published

Model data without the hassle.

Downloads

4

Readme

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.

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); }