Skip to content

NodeJS module to export and validate a GameBook in JSON file

License

Notifications You must be signed in to change notification settings

alexbernardi360/gamebook-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 😊

About

NodeJS module to export and validate a GameBook in JSON file

Resources

License

Stars

Watchers

Forks