Catalog npm
Back to packageRELEASE DETAILS

1.0.6

npm

@0x4447/pretzel

🥨 Recursive JSON data validation.

0x4447clijsonnodejsrecursiverecursive validationvalidation
Published26 Apr 2019
Direct dependencies2
Transitive dependenciesNot calculated

README

Current package documentation

🥨 Pretzel

We created our Pretzel recursive JSON data validation after realizing that there were no npm modules that could 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 too hard to rezone about. Thus, Pretzel was born.

The goal of this tool is not just to handle nested JSON files like this...

{
	"company_name": "0x4447",
	"address": {
		"street": "42 Life",
		"state": "TX",
		"code": 123456,
		"country": "United States",
		"contact": {
			"email": "hello@0x4447.email",
			"phone_nr": "+1 (555) 555-6666"
		}
	},
	"employs": {
		"ceo": {
			"individual": {
				"first_name": "David",
				"last_name": "Gatti"
			},
			"assistant": {
				"first_name": "Very",
				"last_name": "Helpful"
			}
		}
	}
}

...with rules structured this way:

{
	company_name: {
		type: 'string'
	},
	address: {
		street: {
			type: 'string'
		},
		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']
		},
		code: {
			type: 'number'
		},
		country: {
			includes: ['United States', 'Canada']
		},
		contact: {
			email: {
				type: 'string'
			},
			phone_nr: {
				type: 'string'
			}
		}
	},
	employs: {
		ceo: {
			individual: {
				first_name: {
					type: 'string'
				},
				last_name: {
					type: 'string'
				}
			},
			assistant: {
				first_name: {
					type: 'string'
				},
				last_name: {
					type: 'string'
				}
			}
		}
	}
}

We also wanted to make the source code as simple to understand as possible. If you check the index.js file, you'll see what we mean. Use it, modify it, learn from it.

How to Install

] npm install @0x4447/pretzel

How to Test

] npm run test

How to Require

let pretzel = require('pretzel');

How to Use


let pretzel = require('pretzel');

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

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

//
//	Bad DATA
//
let bad_data = {
	name: 123321
};

//
//	1.	Execute validation.
//
let good = pretzel(good_data, rules);
let bad = pretzel(bad_data, rules);

//
//	2.	Check the validation result.
//
console.info(good);
console.info(bad);

Rules

Below is a list of all the rules the module supports at this time.

Bigger than

{
	biggerThan: 5
}

Smaller than

{
	smallerThan: 5
}

Comparison

{
	comparison: 1
}

Includes

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

Regular Expression

{
	regexp: '[aAzZ.-]'
}

Types

{
	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.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 2

Native requirements
2 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
chai
Environment
{
  "local_name": "chai",
  "alias": false,
  "peer_metadata": null
}
^4.2.0runtime
mocha
Environment
{
  "local_name": "mocha",
  "alias": false,
  "peer_metadata": null
}
^6.1.4runtime

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-icXiWuzZ+IfGzUprCDSkLbFSRnMnx7YkuiGT3pjjxKCAhp5Yev8Z113/GlwwR6z9+jlNWf/5u5NGwC0jsI5DEA==",
  "shasum": "fbd2cb87bd85c147ad8b99501de12191774fdaac",
  "tarball": "https://registry.npmjs.org/@0x4447/pretzel/-/pretzel-1.0.6.tgz",
  "fileCount": 4,
  "unpackedSize": 9589,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcwzjICRA9TVsSAnZWagAAwBsP/0LEEvszqo3A4viBRwZg\nvQMVZ2ZvnYa0LDInliHHuBZ/ZrCtkQzc9+uSZuTLYSZj95/st4kQff/XQYxy\n6dyRrOH+3qhVQ/L1iCGN9pjeRjUAOxjFukNMGaJNjOXhFDdMiL86E9EcJiQO\nz/jYBq5C4QyFPlLB2fWy+AFghiHYZ6kbweGzCEok/ioWXIw8I+KBYXmDA0EG\nZs52EM4a2d56Ae8aWRuHPAVofouR0ssLIV7envqYRokEd/w3br0etgwg4OjR\nZwqXc+K/p9GQWUXbkEJm1oBEx5z4IsvY7WBSXPJgbVPPbwz1tYjFFveDWGRT\nIER5BgoO7OkXsB3JfkYQqzHPNWoLo1uiyOZX3pbPQBDmksBeUaXrov4mEybm\nxMmoLwdUIQ0wNs9CzkJ2iSIZjM/qCIXcJPH5fhu5235dJNy66epgkaZUdqeM\nFTW1BBCdul7/lyk1A0zaAeoFHPyS1DulacfwuKB2dHmIU5dtTCq+yB1x4X6O\nGq2d4D5vPv/5UBXZyn/njcPAh5NmHwfnyX825r8nSY2JJLuYhi3zZPBxDiQZ\nKLef0IAGgbdWWC7uTo25mDAQuWAz2Tj3XRWe1orwwMXAfMgdizL7x7iwAal/\nOU1dDzeDgir8Dto2+d9pLIyu+LK5Lv99UTzZil7MOUG9aoihzw/NSjoQGXzn\nTwPs\r\n=0C6Y\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEQCIFBjWgjsczu0TKuQi8fYCtQ2J/onGr+kPLv457UPZvC2AiB6GX2A864jAU8HNSWRERhBm814BjraLBmMN5ZDkoDB0Q=="
    }
  ]
}

Repository

PENDING
0x4447/0x4447-cli-node-pretzel

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:37 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:3b82f53dd0130c64d4fcef13e0e0595d531ee168f2ee2943df4c092bb69f669a

Other collected versions

1.0.726 Apr1.0.522 Apr1.0.420 Apr1.0.320 Apr1.0.219 Apr1.0.119 AprView all collected versions →