mongoose-url-slugs
Advanced tools
Comparing version 0.1.0 to 0.1.1
12
index.js
@@ -43,6 +43,8 @@ var extend = require('extend'); | ||
if (!options.index_unique) return cb(null, true, slug); | ||
var doc = this; | ||
var model = doc.constructor; | ||
var q = {}; | ||
q[options.field] = new RegExp('^' + slug); | ||
var doc = this, | ||
model = doc.constructor, | ||
slugLimited = (options.maxLength && slug.length == options.maxLength)? true : false, | ||
q = {}; | ||
q[options.field] = new RegExp('^' + (slugLimited? slug.substr(0, slug.length - 2) : slug)); | ||
q._id = {$ne: doc._id}; | ||
@@ -59,3 +61,3 @@ var fields = {}; | ||
if (docSlug != slug) { | ||
count = docSlug.match(new RegExp(slug + options.separator + '([0-9]+)$')); | ||
count = docSlug.match(new RegExp((slugLimited? slug.substr(0, slug.length - 2) : slug) + options.separator + '([0-9]+)$')); | ||
count = ((count instanceof Array)? parseInt(count[1], 10) : 0) + 1; | ||
@@ -62,0 +64,0 @@ } |
@@ -9,3 +9,3 @@ { | ||
"description": "Create URL compatiable slugs on mongoose models, ensuring uniqueness.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"keywords": [ | ||
@@ -12,0 +12,0 @@ "mongoose slugs", |
@@ -56,5 +56,5 @@ [![Build Status](https://travis-ci.org/mindblaze/mongoose-url-slugs.png?branch=master)](https://travis-ci.org/mindblaze/mongoose-url-slugs) | ||
## Defaults and Configurables | ||
## Default options | ||
* **field** (Default: 'slug') - field to use for slug building/ | ||
* **field** (Default: 'slug') - Slug field to use for storage. | ||
* **addField** (Default: True) - Add slug field to mongoose schema. | ||
@@ -75,2 +75,3 @@ * **separator** (Default: '-') - Separator to use for invalid characters. | ||
## History | ||
* v0.1.1 (2014-12-09) -- Fixed an issue due to maxLength. | ||
* v0.1.0 (2014-11-28) -- Added index_sparse, maxLength options. | ||
@@ -77,0 +78,0 @@ * v0.0.10 (2014-10-14) -- Dependencies updated. |
Sorry, the diff of this file is not supported yet
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
10240
98
105