npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mas-piano-validator

v2.0.0

Published

This repository contains the core library to validate the piano files used in the Monika After Story DDLC Mod.

Downloads

28

Readme

MAS Piano Songs Validator

Build Status XO code style Maintainability

This repository contains the core library to validate the piano files used in the DDLC Mod "Monika After Story".

The Credits file clearly states who is the author of every song example you can find in this repository.

You can find the corresponding CLI application here.

Introduction

In MAS you can play the piano to Monika and, depending on how the songs are described, she reacts to the song played.

The mod recognizes all piano songs by parsing JSON formatted files.

This library allows you to validate the structure of the songs you are working on.

This project does not aim to check for the actual correctness of the song you are authoring.

Installation

Note: to use this library, you have to have installed Node.js and a console you can run commands into. The minimum required version of Node.js is: 8 - codename "Carbon".

In your console, run the following command:

$ npm install mas-piano-validator

You can also use yarn (like we do in this project):

$ yarn add mas-piano-validator

Usage

The library exports a single function you can use to validate your object.

It is critical that you pass in an already parsed JSON object. This may change in the future, but for the moment the library expects you to parse the JSON.

Simple example

const validate = require('mas-piano-validator');

const validMASPiano = {
    "name": "Song name",
    "verse_list": [0],
    "pnm_list": [
        {
            "text": "One",
            "style": "monika_credits_text",
            "notes": [
                "D5",
                "C5SH",
                "B4",
                "F4SH"
            ]
        },
        {
            "text": "Two",
            "style": "monika_credits_text",
            "notes": [
                "D5",
                "A4",
                "D5",
                "A4"
            ]
        }
    ]
};

const result = validate(validMASPiano);

console.log(result.ok); // true
console.log(result.errors); // []

Example with multiple input (all API)

const validate = require('mas-piano-validator');

const validMASPiano = {
	"name": "Song name",
	"verse_list": [0],
	"pnm_list": [
		{
			"text": "One",
			"style": "monika_credits_text",
			"notes": [
				"D5",
				"C5SH",
				"B4",
				"F4SH"
			]
		},
		{
			"text": "Two",
			"style": "monika_credits_text",
			"notes": [
				"D5",
				"A4",
				"D5",
				"A4"
			]
		}
	]
};

const container = new validate.ValidationInputContainer();
container.add(validMASPiano, 'test1').add(validMASPiano, 'test2');

const results = validate.all(container);
console.log(results.ok); // true
console.log(results.summary); // All files are valid Monika After Story piano songs.

Parse existing file

const fs = require('fs');
const {promisify} = require('util');

const validate = require('mas-piano-validator'); 

// We are going to use the promisified version of the fs.readFile function 
const readFile = promisify(fs.readFile);

const someFilePath = '...';

async function main() {
    const fileContent = await readFile(someFilePath, {encoding: 'utf8'});
    // Optional object, useful when you want to keep track of validation results
    const meta = {
        src: someFilePath
    };
    // Here you should handle the error in case the file is not a valid JSON file
    try {
        console.log(validate(fileContent, meta).ok); // true or false depending on the file...
    }
}

For other usage examples you can take a look at:

Accessing the schema file

If you want you can access the JSON Schema document used in this library for JSON validation.

The simplest way of accessing it is using require:

const pianoSchema = require('mas-piano-validator/schema/piano.schema.json')

Related