Gathering detailed insights and metrics for mongoose-slug-generator
Gathering detailed insights and metrics for mongoose-slug-generator
npm install mongoose-slug-generator
Typescript
Module System
Min. Node Version
Node Version
NPM Version
75.3
Supply Chain
100
Quality
79.1
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
430,517
Last Day
300
Last Week
1,333
Last Month
7,325
Last Year
89,318
30 Stars
25 Commits
16 Forks
3 Watching
1 Branches
6 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.4
Package Id
mongoose-slug-generator@1.0.4
Size
10.63 kB
NPM Version
2.11.3
Node Version
0.12.7
Cumulative downloads
Total Downloads
Last day
-4.8%
300
Compared to previous day
Last week
-35.1%
1,333
Compared to previous week
Last month
-8.3%
7,325
Compared to previous month
Last year
-16.6%
89,318
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 mongoose-slug-generator --save
1var slug = require('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('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('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('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('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('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('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-02-03
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