https://github.com/codeekage/schema
Firebase User Defined Schema
https://github.com/codeekage/schema
Last synced: about 1 year ago
JSON representation
Firebase User Defined Schema
- Host: GitHub
- URL: https://github.com/codeekage/schema
- Owner: codeekage
- License: mit
- Created: 2019-07-09T14:09:36.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-16T18:11:26.000Z (over 6 years ago)
- Last Synced: 2025-02-17T07:46:45.267Z (about 1 year ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# @codeekage/schema
Schema is an open source `0` dependency package inspired by the schemaless nature of Firebase. Schema helps you add "schema" definitions to a schemaless database you'd prefer to have schemas, like Firebase. Schema also comes with Typescript Lang support.
Schema is pretty easy to use, and to get started with.
## Installation
```shell
npm i @codeekage/schema
```
## Usage
```js
import { schema } from '@codeekage/schema'
const UserSchema = schema({
firstname: {
type: "string",
required: true,
value: "Joe"
},
lastname: {
type: "string",
required: true,
value: "Doe"
},
email: {
type: "string",
value: "joedoe@example.com",
required: true
},
phone_number: {
type: "string",
required: true,
value: "555-555-555"
},
id_number: {
type: "number",
required: true,
value: 0123456789
}
});
```
Schema returns an object like so:
```js
{
firstname : "Joe",
lastname : "Doe",
email : "joedoe@example.com",
phone_number: "555-555-555",
id_number: 0123456789
}
```
and returns `TypeError` if the supplied value does not match the `type` defined for a `field`. If a `field` is defined with
`required: false` the `type` for the `field` is also ignored, but if `true` the `field` type is enforced.