2.4.1 • Published 3 years ago

gamebook-api v2.4.1

Weekly downloads
9
License
MIT
Repository
github
Last release
3 years ago

GameBook API

NPM

NPM npm

Node.js module to export and validate a GameBook in JSON format.

Features

  • Convert a GameBook in SQLite3 format (LGC3) in JSON format according to the scheme.
  • Export the GameBook to a .json file.
  • Get a JSON object from a .json file.
  • Validate a GameBook in JSON format according to the scheme.

JSON schema for GameBooks

gamebook.schema.json

Installation

$ npm install gamebook-api

Usage

const Parser = require('gamebook-api').Parser;
const validate = require('gamebook-api').validate;
const readJSON = require('gamebook-api').readJSON;

// Instantiate the Parser class
const parser = new Parser('your/path/gamebook.db');

Example

const Parser = require('gamebook-api').Parser;
const validate = require('gamebook-api').validate;
const readJSON = require('gamebook-api').readJSON;

function convert(inputPath, outputPath) {
  // Instantiate the Parser class
  const parser = new Parser(inputPath);

  // Exporting the object to file
  parser.exportToFile(outputPath)
    .then((msg) => console.log(msg))
    .catch((error) => console.log(error));
}

function validateFile(filePath) {
  try {
    let instance = readJSON(filePath);
    let result = validate(instance);
  } catch (error) {
    return undefined;
    console.log(error);
  }
  if (result.valid) console.log('No error: JSON validated.');
  else {
    console.log('Error: JSON not validated.');
    console.log(result.errors);
  }

  return result;
}

Get a SQLite database GameBook

Contributing

$ git clone https://github.com/alexbernardi360/GameBook-parser.git
$ npm install

Make a pull request with your changes \ Contributions, features request or any other kind of help are very welcome 😊

2.4.1

3 years ago

2.4.0

3 years ago

2.3.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago