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.
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 64 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
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.