forked from Rikhart/loopback-slug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.md~
More file actions
54 lines (41 loc) · 1.68 KB
/
README.md~
File metadata and controls
54 lines (41 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# loopback-slug
url friendly generator for loopback.io framework.
[](http://travis-ci.org/rikhart/loopback-slug)
## Installation
This module is installed via npm:
``` bash
$ npm install loopback-slug
or
$ npm install git://github.com/rikhart/loopback-slug.git
```
## Example Usage
Edit the /common/models/name_of_your_models.js and add a hook method.
Use the hook "beforeSave" method to add the functionality, pass the Model,newdata,and the configoptions.
## Configoptions:(json object)
* **separator** (Default: '-') - Separator to use for characters.
* **slug** (Default: 'slug') - Parts that are uploaded simultaneously.
* **fields** (Default: 'title') - Array that will use to form the slug.
``` js
var loopbackslug=require("loopback-slug");
module.exports = function (Category) {
Category.observe('before save', function (ctx, next) { //!!important
loopbackslug.middleware(Category, ctx, {
fields: ['name'],
slug: "slug"
}, function (err) {
if (err) return next(err);
else next(null);
});
});
};
```
## License
Apache-2.0 © [Dick Van Ocampo Davila]()
[npm-image]: https://badge.fury.io/js/loopback-slug.svg
[npm-url]: https://npmjs.org/package/loopback-slug
[travis-image]: https://travis-ci.org/rikhart/loopback-slug.svg?branch=master
[travis-url]: https://travis-ci.org/rikhart/loopback-slug
[daviddm-image]: https://david-dm.org/rikhart/loopback-slug.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/rikhart/loopback-slug
[coveralls-image]: https://coveralls.io/repos/rikhart/loopback-slug/badge.svg
[coveralls-url]: https://coveralls.io/r/rikhart/loopback-slug