Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
bookshelf-mask
Advanced tools
This Bookshelf.js plugin enables you to define masks on your models and serialize to JSON based on its fields using the json-mask API.
Install the package via npm:
$ npm install --save bookshelf-mask
Require and register the bookshelf-mask plugin:
var bookshelf = require('bookshelf')(knex);
var mask = require('bookshelf-mask');
bookshelf.plugin(mask);
Define masks on your models with masks
class property:
var Author = bookshelf.Model.extend({
posts: {
return this.hasMany(Post);
},
tableName: 'Author'
}, {
masks: {
custom: 'id,name'
}
});
If you're using ES6 class syntax, define masks
as static property:
class Author extends bookshelf.Model {
get tableName() {
return 'Author';
}
posts() {
return this.hasMany(Post);
}
static masks = {
custom: 'id,name'
}
}
Use the mask
method to serialize the registered masks or pass the fields directly:
Author
.forge({ name: 'foo' })
.fetch({ withRelated: 'posts' })
.then(function(model) {
console.log(model.mask('custom'));
// => { id: 1, name: 'foo' }
console.log(model.mask('name,posts(title,body)'));
// => { name: 'foo', posts: [{ title: 'biz', body: 'baz' }, { title: 'qux', body: 'qix' }]}
});
The mask
method can be applied to collections and the same options accepted in toJSON
can also be provided.
Contributions are welcome and greatly appreciated, so feel free to fork this repository and submit pull requests.
$ npm test
bookshelf-mask enforces linting using ESLint with the Seegno-flavored ESLint config. We recommend you to install an eslint plugin in your editor of choice, although you can run the linter anytime with:
$ eslint src test
Please follow these advices to simplify the pull request workflow:
2.0.1 (2016-10-26)
Merged pull requests:
FAQs
Mask Bookshelf.js models with json-mask
The npm package bookshelf-mask receives a total of 61 weekly downloads. As such, bookshelf-mask popularity was classified as not popular.
We found that bookshelf-mask 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
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.