Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
object-checker
Advanced tools
Readme
Notice: the package is updated to
v1.0.0
and APIs are changed:
API | before v1.0.0 | after v1.0.0 |
---|---|---|
isValid() | Check the object and throw Exceptions when invalid | Renamed to verify() |
checkObject() | Check the object and return check result. | Renamed to check() |
isValidObject() | Check the object and return true /false for result | Renamed to isValid() |
bodyCheckMiddleware | Middleware for express | Renamed to expressBodyCheckMiddleware |
errorHandler | Handler for middleware | Renamed to expressErrorHandler |
A tool for checking object. And also provide a middleware for express.
router.js
in Express as an API document.var objectChecker = require('object-checker');
var checker = objectChecker.createObjectChecker()
var obj = {
users: [
{
name:"a@a.com",
additional:{
age : 20,
height: 180,
score : [80, 90, 100]
}
},
{
name:"123@b.com"
},
{
name:"123@a.com",
additional: {
age : 100,
height:200,
score : [60, 70, 80, 90]
}
}
]
};
var opt = {
users: {
$maxLength: 5,
$: {
name: {
$isEmail : true,
$minLength: 6,
$maxLength: 10
},
additional: {
$isOptional: true,
age: {
$minValue: 20,
$maxValue: 100
},
height: {
$minValue: 100,
$maxValue: 200
},
score: {
$minLength: 3,
$: {
$minValue: 60,
$maxValue: 100
}
}
}
}
}
};
console.log(checker.check(obj, opt));
// router.js
var express = require('express');
var expressBodyCheckMiddleware = require('object-checker').expressBodyCheckMiddleware;
var router = express.Router();
var opt = {
username: {
$isEmail: true
},
password: {
$minLength: 6,
$maxLength: 20
}
};
router.post('/users', expressBodyCheckMiddleware(opt), handlerFunction);
module.exports = router;
// router.js
var express = require('express');
var expressBodyCheckMiddleware = require('object-checker').expressBodyCheckMiddleware;
var validator = require('validator'); // 3rd-part validator module
var router = express.Router();
var opt = {
username: {
$assertTrue: validator.isEmail // 3rd-part validator function(value){...}
},
password: {
$minLength: 6,
$maxLength: 20
}
};
router.post('/users', expressBodyCheckMiddleware(opt), handlerFunction);
module.exports = router;
var objectChecker = require('../object-checker');
var checker = objectChecker.createObjectChecker({
customDirectives: {
$doNotCheck: null,
$inRange: function(value, option) { return option.min < value && value < option.max;}
},
messageTemplate: {
invalid : "Value of Field `{{fieldName}}` is not valid. Got `{{fieldValue}}`, but require {{checkerName}} = {{checkerOption}}",
missing : "Missing {{fieldName}}",
unexpected: "Not support {{fieldName}}"
}
};
checker.verify(yourObject);
var objectChecker = require('../object-checker');
objectChecker.messageTemplate = {
invalid : "Value of Field `{{fieldName}}` is not valid. Got `{{fieldValue}}`, but require {{checkerName}} = {{checkerOption}}",
missing : "Missing {{fieldName}}",
unexpected: "Not support {{fieldName}}"
};
var objectChecker = require('../object-checker');
objectChecker.expressErrorHandler = function(err, req, res, next) {
console.log(err);
var template = {
"invalid" : "invalid request",
"missing" : "missing parameter",
"unexpected": "found unexpected parameter"
};
res.send({
err: 400,
msg: objectChecker.createErrorMessage(err, template);
});
};
undefined
. (When defaultRequired
=== true)$isOptional
undefined
. (When defaultRequired
=== true)$isRequired
null
.assertFunction
assertFunction(value)
should return true
.assertFunction
assertFunction(value)
should return false
.''
.$isPositiveIntegerOrZero
0
.$isNegativeIntegerOrZero
0
.option
option
.option
option
.option
option
option
option
option1
, option2
, ...]
option1
, option2
, ...]
option
.option
.option
option
.RegExp
.
RegExp
.RegExp
.
RegExp
.npm install object-checker
cd node_modules/object-checker
npm test
FAQs
A tool for checking object. (also provide a middleware for express)
The npm package object-checker receives a total of 1 weekly downloads. As such, object-checker popularity was classified as not popular.
We found that object-checker 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.