-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathslugify.js
More file actions
54 lines (41 loc) · 927 Bytes
/
slugify.js
File metadata and controls
54 lines (41 loc) · 927 Bytes
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
/*
* imacss
*
* Copyright(c) 2014 - 2015 André König <andre.koenig@posteo.de>
* MIT Licensed
*
*/
/**
* @author André König <andre.koenig@posteo.de>
*
*/
'use strict';
var stream = require('stream');
var path = require('path');
var util = require('util');
var slug = require('slug');
/**
* The stream which will create a slug based on the
* image name. A slug is a short, normalized name.
*
* @param {object} options Stream options.
*
*/
function Slugify (options) {
options = options || {};
options.objectMode = true;
stream.Transform.call(this, options);
}
util.inherits(Slugify, stream.Transform);
/**
* The transformation process.
*
*/
Slugify.prototype._transform = function _transform (image, enc, cb) {
image.slug = slug(path.basename(image.name, path.extname(image.name)));
this.push(image);
cb();
};
module.exports = function () {
return new Slugify();
};