
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
#chck
Inspired by JSON Filter by Matt McKegg
Check that objects match a specification. Written specifically for use in Lambda function event handler guard clauses as described in Serverless: Patterns of Modern Application Design Using Microservices
$ npm install chck
We find chck especially useful for refactoring boolean expressions in guard clauses so that they're obvious and maintainable.
var chck = require('chck');
exports.handler = function(order, context) {
if(chck(order, {
UserId: {$present: true},
FeedbackHistory: {$present: false}
})) {
feedback.lookup(order.UserId, function(err, history) {
// attach history to message...
var chck = require('chck')
Checks a source object according to a spec object and returns true or false depending on whether it matches. Every attribute in spec must be satisfied or the check fails.
Matching attributes in spec is not required, but if there is a match, it must pass.
Slight variation in that every attribute present in source must be included in spec.
Deep comparison. All attributes must be exactly the same and $conditionals are ignored. Useful for detecting changed objects.
The spec parameter is an object with keys and values constituting instructions for either accepting or rejecting the source object. For example, if you want to require that the attribute type equals person then your spec would be {type: 'person'}.
The following conditional attributes are available:
Specify that the value of an attribute must not be null or false (i.e. 'truthy').
{
name: {$present: true}
}
Specify that the value of an attribute can be anything.
{
description: {$any: true}
}
For matching against an array. The array must contain all of the values specified.
{
tags: {$contains: ['cat', 'animal']}
}
For matching against an array. The array cannot contain any of the values specified.
{
permissions: {$excludes: ['admin', 'mod']}
}
The value can only be one of the ones specified.
{
gender: {$only: ['male', 'female', 'unspecified']}
}
The value can be anything except one of the ones specified.
{
browser: {$not: ['IE', 'Firefox']}
}
Allows a filter to branch into multiple filters when at least one must match.
{
$matchAny: [
{ type: "Post"
state: {$only: ['draft', 'published']}
},
{ type: "Comment"
state: {$only: ['pending', 'approved', 'spam']}
}
]
}
Syntax sugar for specifying many $any filters at the same time.
{
$optional: ['description', 'color', 'age']
}
Is equivalent to:
{
description: {$any: true},
color: {$any: true},
age: {$any: true}
}
FAQs
Check that an object's attributes match a specification
We found that chck 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.