bookshelf-slug
v1.0.1
Published
Bookshelfjs plugin to generate unique slugs
Downloads
4
Maintainers
Readme
bookshelf-slug
Automatically generate slugs for your models
Requirements
- Bookshelfjs 1.x
- Nodejs 10.x, 12.x
Install
npm install bookshelf-slug
Setup
let knex = require('knex')(require('./knexfile.js'))
let bookshelf = require('bookshelf')(knex)
// Add the plugin
bookshelf.plugin(require('bookshelf-slug'))
// Enable it on your models
let User = bookshelf.Model.extend({
tableName: 'user',
// setup 1 default column is 'slug'
slug: ['firstName', 'lastName', 'nickName'] ,
// or setup 2 override default column
slug: {
column: 'uniqueField',
items: ['firstName', 'lastName', 'nickName']
}
})
Example
User.forge({
firstName: 'Theodore',
lastName: 'Douglas',
nickName: 'theo'
})
.save()
.then(model => {
console.log(model.get('slug')) // theodore-douglas-theo
})