https://github.com/wmfs/json-schema-to-cardscript
https://github.com/wmfs/json-schema-to-cardscript
cardscript tymly
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/wmfs/json-schema-to-cardscript
- Owner: wmfs
- License: mit
- Created: 2019-01-18T08:40:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-02-16T00:39:04.000Z (3 months ago)
- Last Synced: 2025-04-19T20:25:36.783Z (about 1 month ago)
- Topics: cardscript, tymly
- Language: JavaScript
- Size: 200 KB
- Stars: 1
- Watchers: 6
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# json-schema-to-cardscript
[](https://tymly.io/)
[](https://circleci.com/gh/wmfs/json-schema-to-cardscript)
[](https://www.npmjs.com/package/@wmfs/json-schema-to-cardscript)
[](https://codecov.io/gh/wmfs/json-schema-to-cardscript)
[](https://www.codefactor.io/repository/github/wmfs/json-schema-to-cardscript)
[](https://dependabot.com/)
[](http://commitizen.github.io/cz-cli/)
[](https://standardjs.com)
[](https://github.com/wmfs/tymly/blob/master/packages/concrete-paths/LICENSE)> Scaffold Cardscript from a JSON-Schema schema
## Install
```bash
$ npm install json-schema-to-cardscript --save
``````javascript
const jsonSchemaToCardscript = require('json-schema-to-cardscript')// Given this sort of JSON Schema...
const cardscript = jsonSchemaToCardscript(
{
"$schema": "http://json-schema.org/draft-06/schema#",
"title": "Pizza",
"description": "A model for storing details of a pizza (recipe, price etc.)",
"type": "object",
"properties": {
"code": {
"title": "Unique code of the pizza",
"examples": [
"CHEESE_TOMATO"
],
"type": "string",
"minLength": 3,
"maxLength": 15
},
"label": {
"title": "Customer-facing label",
"examples": [
"Cheese & Tomato"
],
"type": "string"
},
"popularitySeq": {
"title": "Integer value to order lists by",
"type": "integer",
"minimum": 1
},
"imageUri": {
"title": "URI to an enticing photo of the pizza",
"examples": [
"https://tinyurl.com/y8r5bbu5"
],
"type": "string",
"format": "uri"
},
"vegetarian": {
"title": "Is the pizza suitable for vegetarians?",
"default": false,
"type": "boolean"
},
"allergens": {
"title": "List of allergens present in pizza",
"examples": [
[
"Gluten",
"Wheat",
"Milk"
]
],
"type": "array",
"uniqueItems": true,
"items": {
"type": "string"
}
},
"availabilityEnd": {
"title": "Date when pizza is no longer available.",
"examples": [
"2019-12-31"
],
"type": "string",
"format": "date-time"
},
"reviews": {
"title": "Favourable customer reviews",
"type": "array",
"items": {
"type": "object",
"properties": {
"username": {
"title": "Who wrote the review",
"examples": [
"joebloggs4"
],
"type": "string"
},
"review": {
"title": "Something nice to say",
"examples": [
"Lovely stuff!"
],
"type": "string"
},
"rating": {
"title": "Star rating (0=Awful 5=Great)",
"default": 5,
"examples": [
5
],
"type": "integer",
"minimum": 0,
"maximum": 5
}
},
"required": [
"username",
"review",
"rating"
]
}
}
},
"required": [
"code",
"label",
"popularitySeq",
"imageUri",
"vegetarian"
]
},
// And some options
{
purpose: 'editing'
}
)// -----------------------------------------------
// Expect a half-decent stab at some Cardscript...
// -----------------------------------------------```
```bash
$ npm test
```## License
[MIT](https://github.com/wmfs/cardscript/blob/master/LICENSE)