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

composite-data

v0.1.14

Published

A library of data in a composite pattern to be used for validation

Downloads

2

Readme

logo

npm version npm Build Status GitHub issues GitHub stars

composite-data is a library that stores data in a composite pattern to be used for cross project validation. Implement a front-end application and a server-side application and be able to use the exact same validation processes in both. The library also allows data to be grouped into object to allow for collections of data to be validated simultaneously. Use this library with data storage and singleton's to create robust form components or use it client side to create comprehensive models that are guaranteed to be inflated easily with client side data and verification processes.

Installation

yarn

yarn add composite-data

npm

npm install composite-data --save

How To Use This Library

There are two types of objects that can be instantiated, DataLeafs and DataComposites, as well as two interfaces, IObserver and IObservable. Each of these are covered below.

DataLeaf

The DataLeaf is the purest form of information, it sits at the bottom level of the composite, and holds a single object. DataLeaf Also uses a template for the value that it contains, this type for the value is defined by T. Also it is important to note that each dataLeaf extends the IObservable Interface

getValue(): T

This will return the current value for the data object. So if it is a string then it will return the string for the leaf. If there is no value it will return undefined.

getComponent(): DataLeaf<T>

This will return the object itself, over very useful for iteration of multiple different dataLeaves.

set(value: T | any, force?: boolean): boolean | Promise<boolean>

To change the value held by the leaf, use this method. value is the data you want to replace and the function will always return true or false based on if the value passed validation. In some cases where an api call is needed to validate or a promise/callback is involved in the validation, then a promise that returns a boolean will be returned.

updateObservers(): void

This will update all observers of the current value held.

addObserver(observer: IObserver): void

Adds another observer to current instance of the DataLeaf.

DataComposite

The DataObserver is a collection of other IData (other DataComposites or DataLeaves) and are organized via a structure define the template variable P which is of type IDataMap

getValue(): object

This will return a JSON object of all the children of this data composite. An example of Name is below

const firstName: FirstName = new FirstName("Christopher");
const middleName: MiddleName = new MiddleName("Vinson");
const lastName: LastName = new LastName("Powroznik");
const fullNameMap: IFullNameMap = {
    firstName,
    lastName,
    middleName,
};
const fullName: FullName = new FullName(fullNameMap);
const fullNameValue: object = fullName.getValue();

console.log(fullNameValue);
{
    "firstName": "Christopher",
    "middleName": "Vinson",
    "lastName": "Powroznik",
}

getComponent(): P

this will return a IDataMap object specified by the template variable P

const firstName: FirstName = new FirstName("Christopher");
const middleName: MiddleName = new MiddleName("Vinson");
const lastName: LastName = new LastName("Powroznik");
const fullNameMap: IFullNameMap = {
    firstName,
    lastName,
    middleName,
};
const fullName: FullName = new FullName(fullNameMap);
const fullNameComponent: IFullNameMap = fullName.getComponent();

// fullNameComponent will be deep equal fullNameMap

set(dataMap: P, force?: boolean): boolean | Promise<boolean>

Allows a complete reset of the entire dataMap. It is not advised to use this often as it is better practice to edit each dataLeaf, but this method is more efficient if it necessary to replace every DataLeaf.

const firstName: FirstName = new FirstName("Christopher");
const middleName: MiddleName = new MiddleName("Vinson");
const lastName: LastName = new LastName("Powroznik");
const fullNameMap: IFullNameMap = {
    firstName,
    lastName,
    middleName,
};
const fullName: FullName = new FullName();
fullName.set(fullNameMap);

isValid(value?: P): boolean | Promise<boolean>

updateSelf(newValue?: any): void

public updateObservers(): void

This will update all observers of this data type of the current value held.

public addObserver(observer: IObserver): void

Adds another observer to current instance of the DataComposite.

IObserver

IObservable

Creating Custom Data

Custom DataLeaf

Custom Composite

Extending Current Data

Design Patterns

The library uses two designs patterns extensively, which are the composite-pattern and observer-pattern. These two design patterns are critical to the development and implementation of this library. In this library these two patterns are implemented loosely to the image below.

model diagram