New: Introducing PHP and Composer Support.Read the Announcement →
Socket
Book a DemoInstallSign in
Socket

@0x4447/pretzel

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0x4447/pretzel

🥨 Recursive JSON data validation.

Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
9
-78.57%
Maintainers
1
Weekly downloads
 
Created
Source

🥨 Pretzel

Pretzel is a recursive JSON data validation, created out of frustration since there are no npm modules that can recursively validate a JSON object with multiple nested values objects.

We are aware of Validate.js, but as the author explains, the support for complete object is very basic. We did consider proposing a PR to the project, but the source code turned out to be to hard to rezone about, and thus Pretzel was born.

The goal of this tools is not only to handle nested JSON files like this:

{
	first_name: 'David',
	last_name: 'Gatti',
	age: 99,
	address: {
		street: 'Wonder Land',
		nr: 55,
		state: 'TX',
		country: 'United States'
	}
}

With rules structured this way:

{
	first_name: {
		type: 'string'
	},
	last_name: {
		regexp: '[a-zA-Z]'
	},
	age: {
		type: 'number'
	},
	address: {
		street: {
			type: 'string'
		},
		nr: {
			type: 'number'
		},
		state: {
			includes: ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY']
		},
		country: {
			includes: ['United States', 'Canada']
		}
	}
}

We also wanted to make sure the source code is a simple to understand. If you check the index.js file you'll see that we mean. We hope that his way you can learn something or modify the code to suits your needs.

How to Install

] npm install @0x4447/pretzel

How to Test

] npm run test

How to Require

let pretzel = require('pretzel');

How to Use

//
//	RULES
//
let rules = {
	name: {
		type: "string"
	}
};

//
//	DATA
//
let data = {
	name: '0x4447'
};

//
//	1.	Execute on the function.
//
let result = pretzel(data, rules);

//
//	2.	Check if the array that we got back has something in it.
//
if(result.length)
{
	console.info(result);
}

Rules

Bellow you can find a list of all the rules support by the module at this time.

Bigger then

{
	biggerThen: 5
}

Comparison

{
	comparison: 1
}

Includes

{
	includes: [9, '0x4447']
}

Regular Expression

{
	regexp: '[aAzZ.-]'
}

Smaller then

{
	smallerThen: 5
}

Type

{
	type: "string || number || object || array"
}

The End

If you enjoyed this project, please consider giving it a 🌟. And check out our 0x4447 GitHub account, where we have additional resources that you might find useful or interesting.

Sponsor 🎊

This project is brought to you by 0x4447 LLC, a software company specializing in build custom solutions on top of AWS. Find out more by following this link: https://0x4447.com or, say hello@0x4447.email.

Keywords

0x4447

FAQs

Package last updated on 19 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts