Skip to content
This repository has been archived by the owner on Apr 7, 2019. It is now read-only.
/ yajjsl Public archive

Yet Another javascript json schema library

Notifications You must be signed in to change notification settings

metric-space/yajjsl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yet Another Javascript Json Schema Library (...hehe)

rickandmorty

Yet another piece of code that tries to validate json based on types, this is NOT BASED ON THE JSON SCHEMA STANDARD which I find too verbose for my likes but that's just me. YET REJOICE BECAUSE THE OUTPUT IS MONADIC !!!!

Goals of this Library

  1. To provide type validation for entities inside a json object
  2. To provide checkif-empty/undefined validation for entities inside a json object
  3. The output of this will be the first error encountered (Wrapped in a Left) or the whole object (wrapped in a Right) aka monadic (Either Monad)

Install

npm install yajjsl

Development Goals

  1. Use Applictive-functors/Monads and it's related operations to make for readable code
  2. Use Ramda.js for other other operations
  3. Test library thoroughly

Example

const schema1 = {
        "weapon": "String",
        "pokemon": Tuple("Array", "String"),
        "pokeball": {
            "material": "String",
            "cost": "Number"
        },
	"characters": Tuple("Array", {"name": "String"})

    };

const incorrect1 = {
        "pokemon": [1, 2],
        "pokeball": {
            "material": ["Egg Nut", "Brown Nut"],
            "cost": 100
        },
	"characters": [{ "name": "Red Foreman"}, 
		       { "name": "I am Fez" }]

    };

validate(incorrect1, schema1);

// output -> Left(Tuple("weapon", undefined)) 
// tuples are based on fantasy-land-tuples

Left Output

 // note I use Tuple and Tuple2 interchangebly

 Left(Tuple("key", undefined))   // -> "key" field is undefined 
 Left(Tuple("key", false))       // -> "key" has failed schema-based-validation
 Left(Tuple("key", "empty"))     // -> "key" has an empty element ({} or [])
 Left(Tuple("Schema","invalid")) // -> schema given is invalid
 

What this is not

  1. An uber fast library

P.S

  1. This also features schema checking for validity based on some preset rules
  2. The output is based off fantasy-land compliant stuff so you should be able to use the monadic output in any monadic/ applicative-functorish chains as long as the monads/applicative-functors belong to any fantasy-land compliant library

License

MIT License

Build Status