https://github.com/zillow/manikin-model
A JS library for defining clear, reliable, flexible, and enforceable data models.
https://github.com/zillow/manikin-model
Last synced: 6 months ago
JSON representation
A JS library for defining clear, reliable, flexible, and enforceable data models.
- Host: GitHub
- URL: https://github.com/zillow/manikin-model
- Owner: zillow
- License: apache-2.0
- Created: 2019-01-29T16:27:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-07-14T20:39:35.000Z (almost 5 years ago)
- Last Synced: 2025-02-09T16:17:13.316Z (over 1 year ago)
- Language: JavaScript
- Size: 198 KB
- Stars: 1
- Watchers: 9
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.com/zillow/manikin-model)
[](https://www.npmjs.com/package/manikin-model)
# Manikin Model
Manikin provides a basis for defining models/schema for JavaScript concepts.
## Docs
- [API](src/api.md)
## Installation
`npm install manikin-model --save`
## Overview
Example of a basic model:
```javascript
import { createModel } from "manikin-model";
/**
* A model that represents a company.
*
* @class CompanyModel
*/
const CompanyModel = createModel("CompanyModel", {
/**
* The name of the company.
*
* @type {String}
* @default ''
*/
companyName: "",
/**
* The url for the company.
*
* @type {String}
* @default null
*/
url: null
});
export default CompanyModel;
```
Creating an instance of the model:
```javascript
import CompanyModel from "./path/to/CompanyModel";
let microsoft = new CompanyModel({
companyName: "Microsoft"
});
// Get a value
console.log(microsoft.get("companyName")); // 'Microsoft'
// Set a value and get it after it has been changed
console.log(microsoft.get("url")); // null
microsoft = microsoft.set("url", "http://microsoft.com");
console.log(microsoft.get("url")); // 'http://microsoft.com'
// Get and set multiple properties at a time
console.log(microsoft.getProperties("companyName", "url")); // { companyName: 'Microsoft', url: 'http://microsoft.com'}
microsoft = microsoft.setProperties({
companyName: "Google",
url: "http://google.com"
});
console.log(microsoft.getProperties("companyName", "url")); // { companyName: 'Google', url: 'http://google.com'}
```
## Testing
This project uses Jest for testing. Relevant tests will be run on precommit, and all tests will be run on Jenkins once your changes are pushed.
- Run tests relevant to your changes `npm test`
- Run all test via `npm test -- --watchAll`.
- Run all tests without watch by running `npm test -- --no-watch`.
- Run tests for a specific file by running `npm test -- MyFile.js`.
- Run tests based on the test name by running `npm test -- -t 'test pattern'`.
- Run test with coverage by running `npm test -- --coverage`.
Because this is a utility that could be used in many ways, a high level of testing coverage will be maintained on this project.
## Linting
This project uses eslint and prettier to format JavaScript.