Code Monkey home page Code Monkey logo

objection-slugify's People

Contributors

abelsoares avatar calvinl avatar jas avatar jrbarnard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

objection-slugify's Issues

Allow custom suffix for unique slugs

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.

Implement plugin as class mixin

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.

Better performance for unique slug checking

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.

Allow setting internal slugify options

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.