Gathering detailed insights and metrics for @tenda.digital/mongoose-slug-generator
Gathering detailed insights and metrics for @tenda.digital/mongoose-slug-generator
Gathering detailed insights and metrics for @tenda.digital/mongoose-slug-generator
Gathering detailed insights and metrics for @tenda.digital/mongoose-slug-generator
npm install @tenda.digital/mongoose-slug-generator
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
30 Stars
25 Commits
16 Forks
2 Watchers
1 Branches
6 Contributors
Updated on May 26, 2024
Latest Version
1.2.1
Package Id
@tenda.digital/mongoose-slug-generator@1.2.1
Unpacked Size
28.39 kB
Size
5.40 kB
File Count
8
NPM Version
5.6.0
Node Version
8.11.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Mongoose plugin for creating slugs based on mongoose schema fields. For example you can create a slug based on a document's title and author's name: my-post-title-kevin-roosevelt, or unique slugs based on just the title: my-post-title-Nyiy4wW9l.
The best way to install it is using npm
1npm install @tenda.digital/mongoose-slug-generator --save
1var slug = require('@tenda.digital/mongoose-slug-generator');
1var mongoose = require('mongoose'); 2mongoose.plugin(slug);
This plugin is based on the idea of using the mongoose schema as the way to check the use of slug fields.
The plugin checks and updates automatically the slug field with the correct slug.
If you only want to create the slug based on a simple field.
1var mongoose = require('mongoose'), 2 slug = require('@tenda.digital/mongoose-slug-generator'), 3 mongoose.plugin(slug), 4 Schema = mongoose.Schema, 5 schema = new Schema({ 6 title: String, 7 slug: { type: String, slug: "title" } 8});
You can add as many slug fields as you wish
1var mongoose = require('mongoose'), 2 slug = require('@tenda.digital/mongoose-slug-generator'), 3 mongoose.plugin(slug), 4 Schema = mongoose.Schema, 5 schema = new Schema({ 6 title: String, 7 subtitle: String, 8 slug: { type: String, slug: "title" }, 9 slug2: { type: String, slug: "title" }, 10 slug3: { type: String, slug: "subtitle" } 11});
If you want, you can use more than one field in order to create a new slug field.
1var mongoose = require('mongoose'), 2 slug = require('@tenda.digital/mongoose-slug-generator'), 3 mongoose.plugin(slug), 4 Schema = mongoose.Schema, 5 schema = new Schema({ 6 title: String, 7 subtitle: String, 8 slug: { type: String, slug: ["title", "subtitle"] } 9});
To create a unique slug field, you must only add add the unique: true parameter in the path (also, this way the default mongo unique index gets created)
1var mongoose = require('mongoose'), 2 slug = require('@tenda.digital/mongoose-slug-generator'), 3 mongoose.plugin(slug), 4 Schema = mongoose.Schema, 5 schema = new Schema({ 6 title: String, 7 subtitle: String, 8 slug: { type: String, slug: ["title", "subtitle"], unique: true } 9});
If unique is set, the plugin searches in the mongo database, and if the slug already exists in the collection, it appends to the slug a separator (default: "-") and a random string (generated with the shortid module).
example random
1mongoose.model('Resource').create({ 2 title: 'Am I wrong, fallin\' in love with you!', 3 subtitle: "tell me am I wrong, well, fallin' in love with you" 4}) // slug -> 'am-i-wrong-fallin-in-love-with-you' 5 6mongoose.model('Resource').create({ 7 title: 'Am I wrong, fallin\' in love with you!', 8 subtitle: "tell me am I wrong, well, fallin' in love with you" 9}) // slug -> 'am-i-wrong-fallin-in-love-with-you-Nyiy4wW9l' 10 11mongoose.model('Resource').create({ 12 title: 'Am I wrong, fallin\' in love with you!', 13 subtitle: "tell me am I wrong, well, fallin' in love with you" 14}) // slug -> 'am-i-wrong-fallin-in-love-with-you-NJeskEPb5e'
Alternatively you can modify this behaviour and instead of appending a random string, an incremental counter will be used. For that to happen, you must use the parameter slug_padding_size specifying the total length of the counter:
example counter
1var mongoose = require('mongoose'), 2 slug = require('@tenda.digital/mongoose-slug-generator'), 3 mongoose.plugin(slug), 4 Schema = mongoose.Schema, 5 schema = new Schema({ 6 title: String, 7 subtitle: String, 8 slug: { type: String, slug: ["title", "subtitle"], slug_padding_size: 4, unique: true } 9}); 10 11mongoose.model('Resource').create({ 12 title: 'Am I wrong, fallin\' in love with you!', 13 subtitle: "tell me am I wrong, well, fallin' in love with you" 14}) // slug -> 'am-i-wrong-fallin-in-love-with-you' 15 16mongoose.model('Resource').create({ 17 title: 'Am I wrong, fallin\' in love with you!', 18 subtitle: "tell me am I wrong, well, fallin' in love with you" 19}) // slug -> 'am-i-wrong-fallin-in-love-with-you-0001' 20 21mongoose.model('Resource').create({ 22 title: 'Am I wrong, fallin\' in love with you!', 23 subtitle: "tell me am I wrong, well, fallin' in love with you" 24}) // slug -> 'am-i-wrong-fallin-in-love-with-you-0002'
You can change any options adding to the plugin
1var mongoose = require('mongoose'), 2 slug = require('@tenda.digital/mongoose-slug-generator'), 3 options = { 4 separator: "-", 5 lang: "en", 6 truncate: 120 7 }, 8 mongoose.plugin(slug, options), 9 Schema = mongoose.Schema, 10 schema = new Schema({ 11 title: String, 12 subtitle: String, 13 slug: { type: String, slug: ["title", "subtitle"], unique: true } 14});
You can find more options in the speakingURL's npm page
This plugin is proudly supported by Kubide
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 4/18 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More