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.
validate.io
Advanced tools
Readme
Validation utilities.
The primary motivation for this module is to validate input arguments provided to publicly exposed methods. Other utilities exist but are either limited, more verbose (use method chaining), used as if asynchronous (callbacks), or part of some larger utility library (e.g., underscore).
$ npm install validate.io
var validate = require( 'validate.io' );
The validate
module is comprised of several smaller modules. If you want to roll your own validate
, follow the links and import the individual modules. For method documentation, see each respective module.
var validate = require( 'validate.io' );
function is( bool, value, msg ) {
if ( validate.isRegexp( value ) ) {
value = value.toString();
}
else if ( validate.isFunction( value ) ) {
value = value.constructor.name;
}
else {
value = JSON.stringify( value );
}
console.log( '%s is %s%s', value, ( bool ) ? '' : 'not ', msg );
}
var methods,
bool,
vals,
fcn,
msg,
v,
N, M,
i, j;
vals = [
'beep',
5,
Math.PI,
-0,
true,
null,
undefined,
[],
{},
function foo(){},
/.*/,
new Date(),
-1,
JSON.parse
];
methods = [
[ validate.isStringPrimitive, 'a string' ],
[ validate.isNegativeZero, 'negative zero' ],
[ validate.isPositiveInteger, 'a positive integer' ],
[ validate.isPositive, 'a positive number' ],
[ validate.isNegativeInteger, 'a negative integer' ],
[ validate.isNull, 'null' ],
[ validate.isUndefined, 'undefined' ],
[ validate.isBoolean, 'a boolean' ],
[ validate.isNativeFunction, 'a native function' ],
[ validate.isFunction, 'a function' ],
[ validate.isArray, 'an array' ],
[ validate.isStrictDate, 'a date object' ],
[ validate.isRegexp, 'a regular expression' ],
[ validate.isObject, 'an object' ]
];
N = vals.length;
M = methods.length;
for ( i = 0; i < N; i++ ) {
v = vals[ i ];
for ( j = 0; j < M; j++ ) {
fcn = methods[ j ][ 0 ];
msg = methods[ j ][ 1 ];
bool = fcn( v );
if ( bool ) {
is( bool, v, msg );
break;
} else {
is( bool, v, msg );
}
}
}
To run the example code from the top-level application directory,
$ node ./examples/index.js
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
Copyright © 2014-2015. The Validate.io Authors.
FAQs
Validation utilities.
The npm package validate.io receives a total of 4 weekly downloads. As such, validate.io popularity was classified as not popular.
We found that validate.io 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.