0.0.6 • Published 2 months ago
@matcher9131/mjson v0.0.6
日本語のREADMEはこちら
MJson
A schema of Mahjong record based on JSON
Features
- Record whole game of Mahjong with easy description
- Use JSON Typedef (jtd)
- Validate data by validators like jtd, ajv and so on
- Generate native types in your programming language
- Extend schema easily if you need
Installation
npm install -D @matcher9131/mjson
or
yarn add -dev @matcher9131/mjson
Usage
Typescript: Import types
You can use MJson as typed variant by importing type.
import { MJson } from "@matcher9131/mjson";
import data from "./foo.json"; // Import MJson file you like
const mJson = data as MJson;
console.log(mJson.players[0].name);
Validation
Example: Validate MJson by jtd on Node.js
import { validate } from "jtd";
import schema from "@matcher9131/mjson/jsonTypedef" assert { type: "json" };
import data from "./foo.json" assert { type: "json" }; // Import MJson file you like
const errors = validate(schema, data);
console.log(`Number of errors: ${errors.length}`);
Documentation
Type definition (Sorry, available only in Japanese currently)