Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

form-schema

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

form-schema - npm Package Compare versions

Comparing version 0.1.2 to 1.0.0

scripts/colors

3

package.json
{
"name": "form-schema",
"version": "0.1.2",
"version": "1.0.0",
"description": "A form validation tool that traverses the data according to the schema and calls the validators.",
"main": "lib/index.js",
"webpack": "src/index.js",
"scripts": {

@@ -7,0 +8,0 @@ "browser": "scripts/browser",

@@ -293,9 +293,14 @@ import chai from 'chai';

describe('validators', () => {
it('should supply field data and entire form data', () => {
it('should supply field data and its ancestors to the validator', () => {
const data = {
id: 'id1',
name: 'ABC',
nested: {
random: '123',
},
arr: [3, 4, 5],
};
const testValidator = (fieldData, dataRoot) => {
dataRoot.should.equal(data);
const rootFieldsValidator = (fieldData, ancestors) => {
ancestors.should.have.length(1);
ancestors[0].should.equal(data);
return {

@@ -305,5 +310,25 @@ isValid: true,

};
const nestedFieldValidator = (fieldData, ancestors) => {
ancestors.should.have.length(2);
ancestors[0].should.equal(data.nested);
ancestors[1].should.equal(data);
return {
isValid: true,
};
};
const arrFieldValidator = (fieldData, ancestors) => {
ancestors.should.have.length(2);
ancestors[0].should.equal(data.arr);
ancestors[1].should.equal(data);
return {
isValid: true,
};
};
const schema = {
id: field(testValidator).isRequired(),
name: field(testValidator).isRequired(),
id: field(rootFieldsValidator).isRequired(),
name: field(rootFieldsValidator).isRequired(),
nested: {
random: field(nestedFieldValidator),
},
arr: [field(arrFieldValidator)],
};

@@ -310,0 +335,0 @@ const { isValid } = validate(data, schema);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc