mongoose-sluggable
Advanced tools
Comparing version 0.7.2 to 0.7.4
@@ -45,2 +45,4 @@ var generateSlug = require('slug'); | ||
value = array.join(separator); | ||
} else if(Object.prototype.toString.call(source) == '[object Function]') { | ||
value = source(this, separator); | ||
} else { | ||
@@ -47,0 +49,0 @@ throw new Error('Source can be an array or a string'); |
{ | ||
"name": "mongoose-sluggable", | ||
"version": "0.7.2", | ||
"version": "0.7.4", | ||
"description": "Mongoose slug plugin", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -45,3 +45,3 @@ # mongoose-sluggable | ||
| **unique** | Should slug be unique for this collection? *Default "false"*. | | ||
| **source** | Name of fields that will be used to create slug. You can pass string or array of strings? *Default "title"*. | | ||
| **source** | Name of fields that will be used to create slug. You can pass string, an array of strings or a function? *Default "title"*. | | ||
| **separator** | Separator used to replace all non a-z and 0-9 characters. *Default "-"*. | | ||
@@ -84,2 +84,21 @@ | **updatable** | If set to *"false"*, not empty slug will not be changed by the plugin. *Default "true"*. | | ||
Now document with name "Dariusz" and surname "Półtorak" will be translated to "dariusz-poltorak". And another document like that will receive "dariusz-poltorak-2". | ||
Example for source as function: | ||
``` | ||
var slugSource = function(doc, seperator){ | ||
if(doc.role = 'COMPANY') { | ||
return String(doc.title || '').trim(); | ||
} | ||
else { | ||
return String(doc.firstName + seperator + doc.lastName || '').trim(); | ||
} | ||
}; | ||
schema.plugin(sluggable, { | ||
"field": "username", | ||
"source": slugSource, | ||
"unique": true, | ||
"updatable": false | ||
}); | ||
``` | ||
Now document with name "Dariusz" and surname "Półtorak" will be translated to "dariusz-poltorak". And another document like that will receive "dariusz-poltorak-2". |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8879
91
103