Registry / testing / sql-validator

sql-validator

JSON →
library2.0.2jsnpmunverified

A lightweight JavaScript object validator supporting data type checks (isNumeric, isEmail, etc.), value/length ranges, and custom validation functions. Version 2.0.2 targets Node.js and browsers, is not actively maintained (last release 2016), and offers a simple synchronous API. It reuses validator.js for data type checking and requires manual mandatory field handling. Differentiators include minimal dependencies and straightforward integration for basic object validation.

npm install sql-validator
INSTALL
IMPORT
SIG · SQL-VALIDATOR
S
sql-validator
testingjavascriptv2.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (Validator class)
import Validator from 'sql-validator'
const Validator = require('sql-validator')
Package ships CommonJS; ESM import works in bundlers but requires default interop.
Validator constructor
new Validator(mandatoryMap)
Validator(mandatoryMap) (missing new)
Always instantiate with 'new' to avoid TypeError.
Validator.prototype.isValid
validatorInstance.isValid(data, validationMap, mode)
Validator.isValid(data, validationMap, mode) (static call)
isValid is an instance method; call on a Validator object.

Demonstrates basic usage: import, create validator with mandatory map, define validation rules, and validate data.

import Validator from 'sql-validator'; const mandatoryMap = { create: ['id', 'name'], update: ['id'] }; const validator = new Validator(mandatoryMap); const data = { id: 1, name: 'Alice', age: '30' }; const validationMap = { id: { dataType: 'isNumeric' }, name: { dataType: 'isAlphanumeric', lengthBetween: { min: 2, max: 50 } }, age: { dataType: 'isNumeric' } }; const result = validator.isValid(data, validationMap, 'create'); console.log(result); // Output: { valid: true } or { valid: false, error: 'Validation Failure.', invalid_key: 'age' }
Debug
Known issues
deprecatedPackage not updated since 2016; depends on old version of validator.js with known issues.
fix
Consider migrating to class-validator or joi for active maintenance.
affects: >=1.0.0
gotchaThe mandatory map fields are checked for presence but not type; missing mandatory fields cause isValid to return invalid.
fix
Ensure mandatory fields exist in data even if optional; adjust mandatoryMap accordingly.
affects: >=1.0.0
breakingIn v2.0.0, the API changed from chaining validation methods to object-based map format. Old chaining API (e.g., .dataType().lengthBetween()) still works but may be removed.
fix
Use map format for future-proof code; chaining is currently supported but deprecated.
affects: >=2.0.0
gotchaCustom validators must be added via addValidations before isValid call; they are not global.
fix
Call validator.addValidations(customValidators) before validation.
affects: >=1.0.0
deprecatedThe package does not support async validation; all validations are synchronous.
fix
Wrap validation in try/catch for error handling; no async support planned.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Validator is not a constructor
Importing default incorrectly or omitting 'new' when using CJS require.
fix
Use 'const Validator = require('sql-validator').default' or 'import Validator from 'sql-validator'; then 'new Validator(...)'.
Cannot read property 'isValid' of undefined
Calling isValid on the class instead of an instance.
fix
Ensure you have instantiated with 'new Validator(mandatoryMap)' and call instance.isValid(...).
Validation Failure.
Data validation failed; check invalid_key for the specific failing field.
fix
Inspect the value of the invalid key and adjust data or validation rules accordingly.
addValidations is not a function
Calling addValidations on validator class instead of instance.
fix
Call instance.addValidations(...) after creation.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
validatorrequiredUsed for data type validations (e.g., isNumeric, isEmail) via chriso/validator
Agent activity
9 hits · last 30 days
node
8
Resources
sql-validator — npm install sql-validator · libregistry