WXL
3 天以前 9bce51f651aad297ef9eb6df832bfdaf1de05d84
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* global describe,it */
 
var getSlug = require('../lib/speakingurl');
 
describe('getSlug defaults', function () {
    'use strict';
 
    it('should replace whitespaces with separator', function (done) {
 
        getSlug('foo bar baz')
            .should.eql('foo-bar-baz');
 
        done();
    });
 
    it('should remove trailing space if any', function (done) {
 
        getSlug(' foo bar baz ')
            .should.eql('foo-bar-baz');
 
        done();
    });
 
    it('should remove multiple whitespaces', function (done) {
 
        getSlug(' foo bar  baz   FOO    BAR      BAZ      ')
            .should.eql('foo-bar-baz-foo-bar-baz');
 
        done();
    });
 
    it('should remove multiple separators at start and end', function (done) {
 
        getSlug('-foo- bar -baz-')
            .should.eql('foo-bar-baz');
        getSlug('--foo- bar -baz---')
            .should.eql('foo-bar-baz');
        getSlug('---foo- bar -baz---')
            .should.eql('foo-bar-baz');
 
        done();
    });
 
    it('should remove multple separators', function (done) {
 
        getSlug('foo- bar -baz')
            .should.eql('foo-bar-baz');
 
        done();
    });
 
    it('should remove non-base64 characters', function (done) {
 
        var nonBase64 = ['[', ']', ',', '*', '+', '~', '.', '(', ')', '\'', '"', '!', ':', '@'];
 
        for (var i = 0; i < nonBase64.length; i++) {
            getSlug("foo " + nonBase64[i] + " bar baz")
                .should.eql("foo-bar-baz");
        }
 
        done();
    });
 
    it('should remove trailing separator', function (done) {
 
        getSlug('C\'est un beau titre qui ne laisse rien à désirer  ! ')
            .should.eql(
                'c-est-un-beau-titre-qui-ne-laisse-rien-a-desirer');
 
        done();
    });
 
    it('should handle whitespace after symbol', function (done) {
 
        getSlug('∆299')
            .should.eql('delta-299');
        getSlug('∆world')
            .should.eql('delta-world');
        getSlug('∆-299')
            .should.eql('delta-299');
        getSlug('∆-world')
            .should.eql('delta-world');
 
        getSlug('(∆)299')
            .should.eql('delta-299');
        getSlug('(∆)299', {
                mark: true
            })
            .should.eql('(delta)299');
 
        getSlug('∆299')
            .should.eql('delta-299');
        getSlug('∆world')
            .should.eql('delta-world');
 
        getSlug('Hello∆299')
            .should.eql('hello-delta-299');
        getSlug('299∆Hello')
            .should.eql('299-delta-hello');
 
        done();
    });
 
    it('should not fail if symbol at the end', function (done) {
 
        getSlug('test &')
            .should.eql('test-and');
        getSlug('test & ')
            .should.eql('test-and');
        getSlug('test &', '_')
            .should.eql('test_and');
        getSlug('test ♥')
            .should.eql('test-love');
        getSlug('test ♥ ')
            .should.eql('test-love');
        getSlug('test ♥  ')
            .should.eql('test-love');
 
        done();
 
    });
 
});