
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.
nsure is a JS class that allows deep testing/sanitation, modification chains and model generation of objects.
[nsure] is a nodejs class that allows deep testing, modification chains and model generation of objects
The goal here was to have a simple, yet highly flexible cheking system for variables
This project is still in very early development, hence anything is subject to change!
npm install nsure
this is a series of checks and modifications to make sure (nsure ;) ) that a string is a valid email
var nsure = require('nsure');
var nsureRules_user_email = {
defaultTo: function() {
return 'defaultEmail@itsatony.com';
},
checks: [ 'type', 'stringMaxLength', 'replace_trim', 'email' ],
type: {
expected: 'string',
onFail: [ 'returnError' ],
error: {
code: 'email.format',
msg: '[email] needs to be valid, >6 chars and <80 chars.'
}
},
stringMaxLength: {
max: 80,
onFail: [ 'returnError' ],
error: {
code: 'email.format',
msg: '[email] needs to be valid, >6 chars and <80 chars.'
}
},
replace_trim: {
query: /^[\s]+|[\s]+$/g,
replacement: ''
},
email: {
onFail: [ 'returnError' ],
error: {
code: 'email.format',
msg: '[email] needs to be valid, >6 chars and <80 chars.'
}
}
};
var emailCheck = new nsure(nsureRules_user_email);
emailCheck('bla @blub');
var helpDemoRuleSet = {
'attributesToCheck': {
'gender': Nsure.helpers.inListNsure(['m', 'f']),
'height': Nsure.helpers.numberNsure(100, 290, 180),
'tld': Nsure.helpers.stringNsure(4, '.com'),
'url': Nsure.helpers.urlNsure(400, 'http://google.com'),
'email': Nsure.helpers.emailNsure(),
'protocols': Nsure.helpers.arrayOfNsure(['string', ['http', 'ftp', 'https' ], ['http'])
},
onUnruledAttributes: [ 'deleteAttribute' ],
onError: 'returnErrorMsg'
};
var testObject = {
};
var testEnsure = new Nsure(helpDemoRuleSet);
console.log(testObject);
console.log('single attribute check ---');
var result = testEnsure.check(testObject, [ 'gender' ]);
console.log(result);
console.log('full attribute check ---');
var result = testEnsure.check(testObject);
console.log(result);
console.log('---MODEL---');
console.log(testEnsure.model);
console.log('---=====---');
Here a complex object is defined, then a ruleset is defined and a nsure generated for it. the object is passed through and the result is modified appropriately. Also, whenever a nsure is instanced using a ruleset, it will generate a model based on that set of rules, which is available via .model
var rules = {
attributesToCheck: {
level: {
checks: ['type', 'numberRange'],
type: {
expected: 'number',
onFail: [ 'toInt' ],
fallback: function(input, options, fullInput, fullRules) { console.log('Error detected in "level"! "level" must be a number!'); return fullInput.level; }
},
numberRange: {
min: 1,
max: 13,
onFail: [ 'toBorder' ]
}
},
a: {
checks: [ 'type', 'numberRange' ],
type: {
expected: 'number',
onFail: [ 'toInt' ],
fallback: 0
},
numberRange: {
min: 2,
max: 1000,
onFail: [ 'toBorder' ]
}
},
b: {
checks: [ 'type', 'stringMaxLength' ],
type: {
expected: 'string',
onFail: [ 'toFallback' ],
fallback: ''
},
stringMaxLength: {
max: 8,
onFail: [ 'cut' ]
}
},
d: {
checks: [ 'mongoId' ],
mongoId: {
onFail: [ 'toFallback' ],
fallback: new ObjectID()
}
},
f: {
checks: [ 'regEx' ],
regEx: {
method: 'test',
//method: 'execute',
//executeReturn: 0,
expression: '^[0-9a-fA-F]{24}$',
flags: 'gi',
onFail: [ 'returnError' ],
error: {
code: 'test.f',
msg: '[f] should be a String of 24 chars.'
}
}
},
timestamp: {
checks: [ 'type' ],
type: {
expected: 'number',
onFail: [ 'toInt' ],
toInt: {
onFail: [ 'returnError' ],
error: {
code: 'timestamp',
msg: 'timestamp must be a number.'
}
},
fallback: function(val) {
var error = new aError('timestamp', 'timestamp must be a number.', val);
return error;
}
}
},
o: {
checks: [ 'type', 'subNsure' ],
type: {
expected: 'object',
onFail: [ 'returnError' ],
error: {
code: 'noObject',
msg: 'o must be a object.'
}
},
subNsure: {
attributesToCheck: {
o_a: {
checks: [ 'type' ],
type: {
expected: 'number',
onFail: [ 'returnError' ],
error: {
code: 'noNumber',
msg: 'o.o_a must be a number.'
}
}
},
o_c: {
checks: [ 'type', 'subNsure' ],
type: {
expected: 'object',
onFail: [ 'returnError' ],
error: {
code: 'noObject',
msg: 'o.o_c must be a object.'
}
},
subNsure: {
attributesToCheck: {
o_c_1: {
checks: [ 'type' ],
type: {
expected: 'number',
onFail: [ 'returnError' ],
error: {
code: 'noNumber',
msg: 'o.o_c.o_c_1 must be a number.'
}
}
}
}
}
}
},
onUnruledAttributes: [ 'deleteAttribute' ],
onError: 'returnErrorMsg'
}
}
},
onUnruledAttributes: [ 'deleteAttribute' ],
onError: 'returnErrorMsg'
};
var testEnsure = new nsureField(rules);
console.log(testObject);
var result = testEnsure.check(testObject);
console.log(result);
console.log('---MODEL---');
console.log(testEnsure.model);
console.log('---=====---'); */
-
var a = 1;
- get everything
var a = 1;
v 0.2.27
Toni Wagner
free
FAQs
nsure is a JS class that allows deep testing/sanitation, modification chains and model generation of objects.
We found that nsure 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.