npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

weare-mongoose-slug

v0.3.1

Published

Consist of a mongoose plugin that generate unique slugs with incrementation.

Downloads

5

Readme

weare-mongoose-slug

Consist of a plugins that can generate unique slugs with an increment (exemple: mycoolslug-2). It can also be used to generate unique fields (dosen't have to be an actual slug, can be a string of any kind).

This module support Mixed fields with objects containings slugs (like multilingual objects).

Installation

$ npm install weare-mongoose-slug

Usage

#!javascript
var mongooseSlug = require('weare-mongoose-slug');

Exemples

:sparkles: Simple

This will populate the slug field with a slugified version of the title field.

It will also add incrementation if an identical slug already exist in database.

#!javascript
var mongooseSlug = require('weare-mongoose-slug');

var MySchema = new Schema({
  title: String,
  slug: String // can be created now but it will be created by the plugin if it doesn't exist
});

// add slug plugin
MySchema.plugin(mongooseSlug.plugin, {
  fieldFrom: 'title'
});

:scream: Complex

You can also independently use internal components to make your own complex slugs :

#!javascript
var mongooseSlug = require('weare-mongoose-slug');

var MySchema = new Schema({
  title: String,
  titleOfDoom: String
});

// add slug fields + generates them on save
MySchema.plugin(mongooseSlug.plugins.slug, {
  fieldFrom: 'title',
  fieldTo: 'strangeFieldNameForASlug',
  options: {} // options passed to slug module
});

MySchema.plugin(mongooseSlug.plugins.slug, {
  fieldFrom: 'titleOfDoom',
  fieldTo: 'anOtherSlugBecauseOfReasons'
});

// add auto increment when slug is not unique
MySchema.plugin(mongooseSlug.plugins.autoIncrement, {
  fields: ['strangeFieldNameForASlug','anOtherSlugBecauseOfReasons']
});

Changes log

0.3.*

  • add handling for dotted paths (like slug.fr, slug.en, etc.)
  • strict passing of mongoose document instance in many functions instead of simple object (generateSlug helper and more)
  • clean obselete code

0.2.*

  • remove the model option used in autoincrement plugin, therefore the plugin does not need to be added after the model is compiled
  • autocreate the fieldTo path in the schema if undefined
  • add emptyOnly for slug plugin

0.1.* - The module was born

The code was partially taken from evenko-yuleat and some things have changed while transfering it into a module :

  • the method handleSlug in routes helpers has been modified to be used with a document instead of a req object
  • fix string slug support
  • the increment separator now consist of a format in which we inject the value
  • fix support for indendent increment on slug object with multiple properties