1.6.2 • Published 8 months ago

@secture/validator v1.6.2

Weekly downloads
14
License
ISC
Repository
github
Last release
8 months ago

@secture/validator

A schema validator for JavaScript and TypeScript that validates object structures against defined rules.

Installation

npm install @secture/validator
# or
yarn add @secture/validator

Basic Usage

import Validator from '@secture/validator';

const validator = new Validator();

// Simple validation
const data = {
  name: 'John Doe',
  age: 30,
  email: 'john@example.com'
};

const rules = {
  name: 'string',
  age: 'number',
  email: 'string'
};

// Returns array of errors, empty if valid
const errors = validator.validate(rules, data);

// Or use assert to throw on invalid data
try {
  validator.assert(rules, data);
  // Data is valid
} catch (e) {
  // Handle validation errors
}

Features

  • Validate nested objects and arrays
  • Custom type validators
  • Optional fields with field? or field|undefined syntax
  • Multiple type validation with string|number|null syntax
  • Wildcards for flexible validation
  • Data sanitization
  • Written in TypeScript with type definitions
1.6.2

8 months ago

1.5.0

1 year ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago