
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
sql-validator
Advanced tools
A simple and light validator for Javascript Objects.
Install the library with npm install sql-validator
Supports 4 type of validations:
dataType - (Supports most of Validation of chriso's Validator ) - isNumeric, isAlpha, isAlphanumeric, isBase84, isAscii, isBoolean, isDecimal, isEmail, isIp, isInt, isJson, isNull, isMongoid, isUrl etc. -
isOneOf - checks if input is one of actual value
lengthBetween - checks if length of string is between two values (min & max)
valueBetween - checks if a number is between two values (min & max).
And along with these 4 validations one can add own custom validations. See below for Example Code.
var Validator = require('./');
// create & update are mode
var mandatoryMap = {
create: ['id', 'string1', 'status', 'date', 'value'],
update: ['id']
};
var addressValidator = new Validator(mandatoryMap);
// data to be validated
var address = {
id: 17282,
country: 'INDIA',
status: 1,
created_at: new Date()
}
// there are two way to create validation map
// 1)
var validationMap1 = {
date : addressValidator.check('should be a valid date').dataType('isDate'),
age : addressValidator.check().dataType('isNumeric').custom(even),
string1 : addressValidator.check('length should be between 3 & 30').dataType('isAlphanumeric').lengthBetween({'min': 3, 'max': 30})
};
// 2)
var validationMap2 = {
id: {
dataType: 'isNumeric'
},
country: {
'dataType': 'isAlphanumeric',
'lengthBetween': {
'min': 3,
'max': 255
},
},
status: {
'dataType': 'isBoolean',
'isOneOf': [0, 1]
},
created_at: {
'dataType': 'isDate'
}
};
var result1 = addressValidator.isValid(address, validationMap1, 'update');
var result2 = addressValidator.isValid(address, validationMap2, 'update');
if valid
{ valid: true }
if invalid
{ valid: false, error: 'Validation Failure.', invalid_key: 'key' }
var even = function() {
return function(actual) {
return actual % 2 === 0 ? true : false;
};
};
var evenValidator = {
even: even
};
addressValidator.addValidations(evenValidator);
For more usage examples, take a look at example.js.
Copyright (c) 2016 Ramjeet Saran
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
SQL Data Validator
The npm package sql-validator receives a total of 213 weekly downloads. As such, sql-validator popularity was classified as not popular.
We found that sql-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.