combine / objection-slugify Goto Github PK
View Code? Open in Web Editor NEWSlugged models for Objection.js
Slugged models for Objection.js
First of all, thanks for this plugin, right what i was looking for!
I see that the plugin does not follow the objection.js
suggestion of implementation as class mixin.
The problem is that with the current implementation we can to do this:
const slugged = Slugify(Model, options);
class Foobar extends Slugged {
...
Which is ok, but it becames hard to mixin other plugins, having to do something like this:
const slugged = model => Slugify(model, options);
class Foobar extends slugged(otherPlugin(Model)) {
...
Would you consider a simple PR to change this plugin to follow this recommendations? I have already test it locally and it's an easy fix.
As of now, generating a unique slug means checking the slug against the database each time and then incrementing the count, checking again, and so on, until an unused slug is found. For slugs with a high count, this can mean checking against the database many times.
One method is to parse the suffix's count and increment once from there. However, this would not work with a custom generator (if #3 is implemented). Another way is to suffix with a UUID. A third way would be to allow both as default strategies for unique slugging, but this could have repercussions if the strategy is changed sometime during the lifetime of the application.
Right now, the default implementation is to append a -${n}
to the slug string. It would be nice to be able to customize this, perhaps allowing a custom function to generate the suffix, e.g. with SecureRandom
or some other method.
E.g, if we want to set the remove regex as per the docs here, we can't currently.
Proposed syntax:
const slugify = slugifyPlugin({
sourceField: 'title',
slugField: 'slug',
slugifyOptions: {
remove: /[*+~.()'"!:@]/g,
},
});
I'm happy to do a PR for this if you guys want?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.