
Security News
High Salaries No Longer Enough to Attract Top Cybersecurity Talent
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
awesomize
Advanced tools
Totally Awesome Validation/Sanitization/Normalization for your app.
npm install awesomize
Awesomize
First, require the module.
const Awesomize = require 'awesomize'
Then, build your awesomizer function.
// Example inputs
const vals = {
foo: 'foo'
, bar: 'bar'
};
// Your validator spec
const spec = Awesomize({}, (v) => {
return {
foo: {
validate: [ v.required ]
}
, bar: {
validate: [ v.required ]
}
}
});
This will return a function that you pass your object of values to, which then in turn returns a promise.
The function given to the Awesomizer will map to the values in the object that it is given. Each validate key is a list, and multiple validation functions can be provided. Each will be run on the associated values. If a key is not explicitly required, then it is optional.
In addition to simple validation, Awesomize allows you to add sanitization and normalization. Sanitization occurs before checking validation, and normalization occurs after. Here we'll use Ramda for some example functions.
const _ = require 'ramda'
const spec = Awesomize({}, (v) => {
return {
foo: {
// Sanitize -> validate -> normalize
sanitize: [ _.toLower ]
, validate: [ v.required ]
, normalize: [ _.toUpper ]
}
}
})
Awesomize.dataOrError
Awesomize.dataOrError
works similarly to Awesomize
, but allows you to pass an error function before the validation function. With this function, in the event that any of the validation fails, it throws the provided error function.
const spec = Awesomize.dataOrError(errorFn)({}, (v) => {
return {
// validators
...
}
});
read
When included along-side validation, read
allows you to form more complex information for the validator to check. the functions in read
have access to the entire object passed to the Awesomize function.
const _ = require 'ramda'
// gets the value at req.bar.baz and adds 1 to it.
const addOneToPath = _.compose(
_.inc
, _.path(['bar', 'baz'])
);
const isTwo = (val) => { val === 2 };
const spec = Awesomize({}, (v) => {
return {
foo: {
read: [ addOneToPath ]
, validate: [ isTwo ]
}
}
});
The following validation functions are built-in:
// required
v.required
// not equal to (x)
v.notEqual(x)
// is array
v.isArray
// is function
v.isFunction
// is a list of (checkFn)
// Takes a function that returns a boolean and an optional message
v.listOf({(a) -> bool}, msg)
Awesomize.Result.hasError
on a result set to see if any of them failed validation.null
on successful validation, or a string on failed validation.FAQs
Totally Awesome Validation/Sanitization/Normalization for your app.
The npm package awesomize receives a total of 2 weekly downloads. As such, awesomize popularity was classified as not popular.
We found that awesomize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 10 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
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.