Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
A parameter verify tools.
$ npm install parameter --save
validate(rule, value)
- validate the value
conforms to rule
. return an array of errors if break rule.validate.addRule(type, check)
- add custom rules.
type
- rule type, required and must be string type.check
- check handler. can be a function
or a RegExp
.var validate = require('parameter');
var data = {
name: 'foo',
age: 24,
gender: 'male'
};
var rule = {
name: 'string',
age: 'int',
gender: ['male', 'female', 'unknown']
};
var errors = validate(data, rule);
required
- if required
is set to false, this property can be empty. default to true
.type
- The type of property, every type has it's own rule for the validate.If type is int
, there has tow addition rules:
max
- The maximum of the value, value
must <= max
.min
- The minimum of the value, value
must >= min
.Alias to int
.
If type is number
, there has tow addition rules:
max
- The maximum of the value, value
must <= max
.min
- The minimum of the value, value
must >= min
.The date
type want to match YYYY-MM-DD
type date string.
The dateTime
type want to match YYYY-MM-DD HH:mm:ss
type date string.
Alias to dateTime
.
The id
type want to match /^\d+$/
type date string.
Match boolean
type value.
Alias to boolean
If type is string
, there has four addition rules:
allowEmpty
(alias to empty
) - allow empty string, default to false.format
- A RegExp
to check string's format.max
- The maximum length of the string.min
- The minimum length of the string.The email
type want to match RFC 5322 email address.
allowEmpty
- allow empty string, default is false.The password
type want to match /^$/
type string.
compare
- Compare field to check equal, default null, not check.max
- The maximum length of the password.min
- The minimum length of the password, default is 6.If type is enum
, it requires an addition rule:
values
- An array of data, value
must be one on them. this rule is required.If type is object
, there has one addition rule:
rule
- An object that validate the properties ot the object.If type is array
, there has tow addition rule:
itemType
- The type of every item in this array.rule
- An object that validate the items of the array. Only work with itemType
.'int'
=> {type: 'int', required: true}
'integer'
=> {type: 'integer', required: true}
'number'
=> {type: 'number', required: true}
'date'
=> {type: 'date', required: true}
'dateTime'
=> {type: 'dateTime', required: true}
'id'
=> {type: 'id', required: true}
'boolean'
=> {type: 'boolean', required: true}
'bool'
=> {type: 'bool', required: true}
'string'
=> {type: 'string', required: true, allowEmpty: false}
'email'
=> {type: 'email', required: true, allowEmpty: false, format: EMAIL_RE}
'password'
=> {type: 'password', required: true, allowEmpty: false, format: PASSWORD_RE, min: 6}
'object'
=> {type: 'object', required: true}
'array'
=> {type: 'array', required: true}
[1, 2]
=> {type: 'enum', values: [1, 2]}
/\d+/
=> {type: 'string', required: true, allowEmpty: false, format: /\d+/}
## `errors` examples
### `code: missing_field`
```js
{
code: 'missing_field',
field: 'name',
message: 'name required'
}
code: invalid
{
code: 'invalid',
field: 'age',
message: 'age should be an integer'
}
FAQs
A parameter verify tools.
The npm package parameter receives a total of 737 weekly downloads. As such, parameter popularity was classified as not popular.
We found that parameter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.