https://github.com/talyssonoc/structure
A simple schema/attributes library built on top of modern JavaScript
https://github.com/talyssonoc/structure
coercion domain-entity javascript model schema validation
Last synced: 19 days ago
JSON representation
A simple schema/attributes library built on top of modern JavaScript
- Host: GitHub
- URL: https://github.com/talyssonoc/structure
- Owner: talyssonoc
- License: mit
- Created: 2016-10-13T07:15:19.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T01:56:07.000Z (over 2 years ago)
- Last Synced: 2024-10-30T02:35:54.471Z (6 months ago)
- Topics: coercion, domain-entity, javascript, model, schema, validation
- Language: JavaScript
- Homepage: https://structure.js.org/
- Size: 2.15 MB
- Stars: 301
- Watchers: 13
- Forks: 20
- Open Issues: 34
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: contributing.md
- License: license.md
Awesome Lists containing this project
README
## A simple schema/attributes library built on top of modern JavaScript
Structure provides a simple interface which allows you to add attributes to your classes based on a schema, with validations and type coercion.
## Packages
- [Structure](packages/structure)
- [jest-structure](packages/jest-structure)## [Documentation](https://structure.js.org/)
## Example Structure usage
For each attribute on your schema, a getter and a setter will be created into the given class. It'll also auto-assign those attributes passed to the constructor.
```js
const { attributes } = require('structure');const User = attributes({
name: String,
age: {
type: Number,
default: 18,
},
birthday: Date,
})(
class User {
greet() {
return `Hello ${this.name}`;
}
}
);const user = new User({
name: 'John Foo',
});user.name; // 'John Foo'
user.greet(); // 'Hello John Foo'
```## [Contributing](contributing.md)
## [LICENSE](license.md)