Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Utility functions for using Joi without using Joi.
Joiless lives on npm, so just install it via the command line and you're good to go.
$ npm install --save joi joiless
You need to install joi
itself as this module does not include it as a production dependency (so you can use your own joi
version). If you try a version which has an issue caused by the module, please file an issue.
I love Joi's validation, and I love Hapi, so I use Joi all the time. Unfortunately I hate Joi's chaining, so I wrote Joiless to assist. Basically, it's Joi using JSON.
Here's an example (both of these are identical, and are in fact a test case in this repo):
const Joi = require('joi');
const Joiless = require('joiless');
// Joi version
let joiSpec = Joi
.date()
.description('The date (in milliseconds) that this crash last appeared')
.timestamp('javascript')
.default(Date.now, 'Current timestamp generation');
// Joiless version
let joilessSpec = Joiless.spec('date', {
description: 'The date (in milliseconds) that this crash last appeared',
timestamp: 'javascript',
default: [ Date.now, 'Current timestamp generation' ]
});
The translation is simple; the key is the function called on the Joi chain, and the value is the value passed into the Joi chain call.
[ [ <your_array> ] ]
.undefined
as the value, or you can use the after
hook (whichever you prefer):const Joiless = require('joiless');
// via undefined
Joiless.spec('string', {
after: function (spec) {
spec.strip();
spec.insensitive();
}
});
// via after
Joiless.spec('string', {
strip: undefined,
insensitive: undefined
})
If you make a complex schema, you can use attach
to hook the child keys onto the parent.
For example, in the snippet below you can reference Record.Username
to pull back the username spec. This is done using get
, it doesn't store the value twice.
const Joiless = require('joiless');
// define the spec
const Record = Joiless.spec({
type: 'object',
description: 'A database model',
keys: {
username: Joiless.spec({
type: 'string',
description: 'The username for this record',
required: true
})
}
});
// attach the children
Joiless.attach(Record);
Sometimes you wish to define a base schema, and then extend it to override some of the parent stuff. Naturally, the spec
API doesn't fit here, so I added an extend
in v1.1
.
Extension is easy, you just pass the schema to extend as first arg, and your spec overrides in the second argument.
const Joi = require('joi');
const Joiless = require('joiless');
// define the base spec
let base = Joiless.spec('object', {
keys: {
a: Joiless.spec('number'),
b: Joiless.spec('string')
}
});
// define our extension
let extended = Joiless.extend(base, {
keys: {
a: Joiless.spec('string')
}
});
// run validation
Joi.validate({ a: 'hello' }, base); // fails
Joi.validate({ a: 'hello' }, extended); // passes
FAQs
Utility functions for using Joi without using Joi
The npm package joiless receives a total of 6 weekly downloads. As such, joiless popularity was classified as not popular.
We found that joiless 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.