@snickbit/model
v1.2.1
Published
Simple object modeling library
Downloads
80
Readme
@snickbit/model
Simple object modeling library based on object-path
Installation
yarn add @snickbit/model
npm add @snickbit/model
Basic Usage
import {Model} from '@snickbit/model';
// const { Model } = require('@snickbit/model');
// Use lowercase import for use as a function instead.
// import { model } from '@snickbit/model';
const data = {
name: 'John Doe',
age: 30,
address: {
street: '123 Main St',
city: 'Anytown',
state: 'CA',
zip: '12345',
},
}
const person = new Model(data);
// or as a function
// const person = model(data)
console.log(person.get('name')); // John Doe
console.log(person.get('address.street')); // 123 Main St
console.log(person.get('address.city')); // Anytown
console.log(person.get()); // { name: 'John Doe', age: 30, address: { street: '123 Main St', city: 'Anytown', state: 'CA', zip: '12345' } }
person.set('name', 'Jane Doe');
console.log(person.get('name')); // Jane Doe
console.log(person.pull('age')); // 30
console.log(person.has('age')); // false
Documentation
API Docs
CHANGELOG
License
Copyright (c) 2022 - Nicholas Lowe aka Snickbit