With this package you can easily turn a property from an ObjectionJS model into a sluggable. This package is based on slugify.
ObjectionJS is an ORM for Node.js that aims to stay out of your way and make it as easy as possible to use the full power of SQL and the underlying database engine while still making the common stuff easy and enjoyable.
$ npm i -S objectionjs-slugify
You only need put @Sluggable([...propsName]) above the property that will store the slug, indicating which properties to use to generate it.
// This options are from slugify package, see more on the official documentation.
const SlugBaseConfig: ISlugConfig = {
replacement: "-",
remove: undefined,
lower: true,
strict: true,
locale: "v1",
edit: true,
};
class Person extends Model {
static tableName = "persons";
id!: number;
firstname: string;
lastname: string;
@Sluggable(["firstname", "lastname"], SlugBaseConfig)
slug?: string;
}
objectionjs-slugify is an MIT-licensed open source project. If you want to contribute something, you can generate a pull request and I will be reviewing it :)
Objection-slugify - LICENSE