speakingurl
Advanced tools
Comparing version 0.2.4 to 0.2.5
{ | ||
"name": "speakingurl", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Generate of so called 'static' or 'nice-looking' or 'slug' or 'SpeakingURL' from a string.", | ||
"main": "speakingurl.min.js", | ||
"license": "BSD", | ||
"homepage": "https://github.com/pid/speakingurl", | ||
"bugs": "https://github.com/pid/speakingurl/issues", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/pid/speakingurl.git" | ||
}, | ||
"licenses": [{ | ||
"type": "BSD", | ||
"url": "https://raw.github.com/pid/speakingurl/master/LICENCE" | ||
} | ||
], | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"components" | ||
"**/.*", | ||
"node_modules", | ||
"components" | ||
] | ||
} |
@@ -60,6 +60,6 @@ var getSlug = require('../lib'), | ||
slug = getSlug('Foo & Bar | Baz * Doo', {custom:{'*': "Boo"},mark:true}); | ||
slug = getSlug('Foo & Bar | (Baz) * Doo', {custom:{'*': "Boo"},mark:true}); | ||
console.log(slug); | ||
console.log("\n"); | ||
// Output: foo-and-bar-or-baz-boo-doo | ||
// Output: foo-and-bar-or-(baz)-boo-doo | ||
@@ -66,0 +66,0 @@ |
module.exports = function (grunt) { | ||
// Project configuration. | ||
grunt.initConfig({ | ||
pkg: grunt.file.readJSON('package.json'), | ||
uglify: { | ||
options: { | ||
banner: '/*! <%= pkg.name %> v<%= pkg.version %> (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %> <%= pkg.homepage %> */\n' | ||
}, | ||
build: { | ||
src: '<%= buildSourceFile %>', | ||
dest: '<%= pkg.name %>.min.js' | ||
} | ||
}, | ||
jshint: { | ||
src: ['Gruntfile.js', '<%= sourceFiles %>', 'i<$= testFiles'] | ||
}, | ||
watch: { | ||
files: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js', 'package.json'], | ||
tasks: ['jshint', 'mocha', 'uglify'] | ||
}, | ||
// Project configuration. | ||
grunt.initConfig({ | ||
pkg: grunt.file.readJSON('package.json'), | ||
uglify: { | ||
options: { | ||
banner: '/*! <%= pkg.name %> v<%= pkg.version %> (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %> <%= pkg.homepage %> */\n' | ||
}, | ||
build: { | ||
src: '<%= buildSourceFile %>', | ||
dest: '<%= pkg.name %>.min.js' | ||
} | ||
}, | ||
jshint: { | ||
src: ['Gruntfile.js', '<%= sourceFiles %>', '<%= testFiles %>'] | ||
}, | ||
watch: { | ||
files: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js', 'package.json'], | ||
tasks: ['jshint', 'mocha', 'uglify'] | ||
}, | ||
// files | ||
buildSourceFile: 'lib/index.js', | ||
sourceFiles: 'lib/**/*.js', | ||
testFiles: 'test/**/*.js' | ||
}); | ||
// files | ||
buildSourceFile: 'lib/index.js', | ||
sourceFiles: 'lib/**/*.js', | ||
testFiles: 'test/**/*.js' | ||
}); | ||
grunt.registerTask('mocha', 'run mocha', function () { | ||
var done = this.async(); | ||
require('child_process') | ||
.exec('mocha', function (err, stdout) { | ||
grunt.log.write(stdout); | ||
done(err); | ||
}); | ||
grunt.registerTask('mocha', 'run mocha', function () { | ||
var done = this.async(); | ||
require('child_process') | ||
.exec('mocha', function (err, stdout) { | ||
grunt.log.write(stdout); | ||
done(err); | ||
}); | ||
}); | ||
grunt.event.on('watch', function (action, filepath) { | ||
grunt.log.writeln(filepath + ' has ' + action); | ||
}); | ||
grunt.event.on('watch', function (action, filepath) { | ||
grunt.log.writeln(filepath + ' has ' + action); | ||
}); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
// Default task(s). | ||
grunt.registerTask('default', ['uglify', 'jshint']); | ||
// Default task(s). | ||
grunt.registerTask('default', ['uglify', 'jshint']); | ||
}; |
@@ -1,1 +0,1 @@ | ||
module.exports = require('lib/'); | ||
module.exports = require('./lib/'); |
{ | ||
"name": "speakingurl", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Generate of so called 'static' or 'nice-looking' or 'SpeakingURL' or 'slug' from a string.", | ||
"homepage": "https://github.com/pid/speakingurl", | ||
"keywords": [ | ||
"slug", | ||
"seo", | ||
"url", | ||
"speakingurl", | ||
"nice url", | ||
"static url" | ||
"slug", | ||
"seo", | ||
"url", | ||
"speakingurl", | ||
"nice url", | ||
"static url" | ||
], | ||
@@ -27,4 +27,16 @@ "author": { | ||
"grunt-contrib-jshint": "~0.5.4", | ||
"grunt-contrib-watch": "~0.4.4" | ||
"grunt-contrib-watch": "~0.4.4", | ||
"tape": "~1.0.2" | ||
}, | ||
"testling": { | ||
"harness": "mocha", | ||
"files": "test/*.js", | ||
"browsers": { | ||
"ie": [ 6, 7, 8, 9, 10 ], | ||
"firefox": [ 19 ], | ||
"chrome": [ 25 ], | ||
"safari": [ 5.1, 6.0 ], | ||
"opera": [ 10, 12 ] | ||
} | ||
}, | ||
"scripts": { | ||
@@ -40,4 +52,3 @@ "test": "mocha" | ||
}, | ||
"licenses": [ | ||
{ | ||
"licenses": [{ | ||
"type": "MIT", | ||
@@ -50,2 +61,2 @@ "url": "https://raw.github.com/pid/speakingurl/master/LICENCE" | ||
} | ||
} | ||
} |
@@ -96,5 +96,5 @@ # Speaking URL [![NPM version](https://badge.fury.io/js/speakingurl.png)](http://badge.fury.io/js/speakingurl) | ||
slug = getSlug('Foo & Bar | Baz * Doo', {custom:{'*': "Boo"},mark:true}); | ||
slug = getSlug('Foo & Bar | (Baz) * Doo', {custom:{'*': "Boo"},mark:true}); | ||
console.log(slug); | ||
// Output: foo-and-bar-or-baz-boo-doo | ||
// Output: foo-and-bar-or-(baz)-boo-doo | ||
@@ -106,2 +106,3 @@ | ||
[![Build Status](https://travis-ci.org/pid/speakingurl.png)](https://travis-ci.org/pid/speakingurl) | ||
```shell | ||
@@ -108,0 +109,0 @@ $ npm test |
@@ -0,34 +1,53 @@ | ||
var should = require('should'); | ||
var getSlug = require('../lib'); | ||
describe('getSlug defaults', function () { | ||
it('should replace whitespaces with separator', function () { | ||
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 () { | ||
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 () { | ||
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 () { | ||
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 () { | ||
it('should remove multple separators', function (done) { | ||
getSlug('foo- bar -baz') | ||
.should.eql('foo-bar-baz'); | ||
done(); | ||
}); | ||
it('should remove non-base64 characters', function () { | ||
it('should remove non-base64 characters', function (done) { | ||
var nonBase64 = ['[', ']', ',', '*', '+', '~', '.', '(', ')', '\'', '"', '!', ':', '@']; | ||
@@ -39,9 +58,13 @@ for (var i = 0; i < nonBase64.length; i++) { | ||
} | ||
done(); | ||
}); | ||
it('should remove trailing separator', function () { | ||
it('should remove trailing separator', function (done) { | ||
getSlug('C\'est un beau titre qui ne laisse rien à désirer ! ') | ||
.should.eql('cest-un-beau-titre-qui-ne-laisse-rien-a-desirer'); | ||
done(); | ||
}); | ||
}); |
@@ -1,11 +0,20 @@ | ||
// test-maintaincase.js | ||
var should = require('should'); | ||
var getSlug = require('../lib'); | ||
describe('getSlug maintainCase', function () { | ||
it('should maintain case characters', function () { | ||
getSlug('Foo, Bar Baz', {maintainCase: true}).should.eql('Foo-Bar-Baz'); | ||
getSlug('Foo- Bar Baz', {maintainCase: true}).should.eql('Foo-Bar-Baz'); | ||
getSlug('Foo] Bar Baz', {maintainCase: true}).should.eql('Foo-Bar-Baz'); | ||
it('should maintain case characters', function (done) { | ||
getSlug('Foo, Bar Baz', { | ||
maintainCase: true | ||
}) | ||
.should.eql('Foo-Bar-Baz'); | ||
getSlug('Foo- Bar Baz', { | ||
maintainCase: true | ||
}) | ||
.should.eql('Foo-Bar-Baz'); | ||
getSlug('Foo] Bar Baz', { | ||
maintainCase: true | ||
}) | ||
.should.eql('Foo-Bar-Baz'); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -1,3 +0,2 @@ | ||
// test-rfc3986.js | ||
var should = require('should'); | ||
var getSlug = require('../lib'); | ||
@@ -7,3 +6,4 @@ | ||
it('"uric" characters allowed', function () { | ||
it('"uric" characters allowed', function (done) { | ||
var chars = [';', '?', ':', '@', '&', '=', '+', ',', '/']; | ||
@@ -16,5 +16,8 @@ for (var i = 0; i < chars.length; i++) { | ||
} | ||
done(); | ||
}); | ||
it('"uricNoSlash" characters allowed', function () { | ||
it('"uricNoSlash" characters allowed', function (done) { | ||
var chars = [';', '?', ':', '@', '&', '=', '+', ',']; | ||
@@ -27,5 +30,8 @@ for (var i = 0; i < chars.length; i++) { | ||
} | ||
done(); | ||
}); | ||
it('"mark" characters allowed', function () { | ||
it('"mark" characters allowed', function (done) { | ||
var chars = ['.', '!', '~', '*', '\'', '(', ')']; | ||
@@ -38,5 +44,8 @@ for (var i = 0; i < chars.length; i++) { | ||
} | ||
done(); | ||
}); | ||
it('"uric" characters allowed, separator ";"', function () { | ||
it('"uric" characters allowed, separator ";"', function (done) { | ||
var chars = ['?', ':', '@', '&', '=', '+', ',', '/']; | ||
@@ -50,13 +59,19 @@ for (var i = 0; i < chars.length; i++) { | ||
} | ||
done(); | ||
}); | ||
it('"uric" characters allowed, separator ";" included in input string', function () { | ||
getSlug("foo ; bar baz", { | ||
uric: true, | ||
separator: ';' | ||
}) | ||
.should.eql("foo;bar;baz"); | ||
it('"uric" characters allowed, separator ";" included in input string', function (done) { | ||
getSlug("foo ; bar baz", { | ||
uric: true, | ||
separator: ';' | ||
}) | ||
.should.eql("foo;bar;baz"); | ||
done(); | ||
}); | ||
it('"uricNoSlash" characters allowed, separator ";"', function () { | ||
it('"uricNoSlash" characters allowed, separator ";"', function (done) { | ||
var chars = ['?', ':', '@', '&', '=', '+', ',']; | ||
@@ -70,13 +85,19 @@ for (var i = 0; i < chars.length; i++) { | ||
} | ||
done(); | ||
}); | ||
it('"uricNoSlash" characters allowed, separator ";" included in input string', function () { | ||
getSlug("foo ; bar baz", { | ||
uric: true, | ||
separator: ';' | ||
}) | ||
.should.eql("foo;bar;baz"); | ||
it('"uricNoSlash" characters allowed, separator ";" included in input string', function (done) { | ||
getSlug("foo ; bar baz", { | ||
uric: true, | ||
separator: ';' | ||
}) | ||
.should.eql("foo;bar;baz"); | ||
done(); | ||
}); | ||
it('"mark" characters allowed, separator "."', function () { | ||
it('"mark" characters allowed, separator "."', function (done) { | ||
var chars = ['!', '~', '*', '\'', '(', ')']; | ||
@@ -90,11 +111,16 @@ for (var i = 0; i < chars.length; i++) { | ||
} | ||
done(); | ||
}); | ||
it('"mark" characters allowed, separator "." included in input string', function () { | ||
getSlug("foo . bar baz", { | ||
it('"mark" characters allowed, separator "." included in input string', function (done) { | ||
getSlug("foo . bar baz", { | ||
uric: true, | ||
separator: '.' | ||
}) | ||
.should.eql("foo.bar.baz"); | ||
.should.eql("foo.bar.baz"); | ||
done(); | ||
}); | ||
}); |
@@ -0,1 +1,2 @@ | ||
var should = require('should'); | ||
var getSlug = require('../lib'); | ||
@@ -5,38 +6,115 @@ | ||
it('should separate with non-whitespace', function () { | ||
getSlug('Foo Bar Baz', {separator: '-'}).should.eql('foo-bar-baz'); | ||
getSlug('Foo Bar Baz', {separator: '*'}).should.eql('foo*bar*baz'); | ||
getSlug('Foo Bar Baz', {separator: '_'}).should.eql('foo_bar_baz'); | ||
it('should separate with non-whitespace', function (done) { | ||
getSlug('Foo Bar Baz', { | ||
separator: '-' | ||
}) | ||
.should.eql('foo-bar-baz'); | ||
getSlug('Foo Bar Baz', { | ||
separator: '*' | ||
}) | ||
.should.eql('foo*bar*baz'); | ||
getSlug('Foo Bar Baz', { | ||
separator: '_' | ||
}) | ||
.should.eql('foo_bar_baz'); | ||
done(); | ||
}); | ||
it('should separate with non-whitespace, with trailing spaces', function () { | ||
getSlug(' Foo Bar Baz ', {separator: '-'}).should.eql('foo-bar-baz'); | ||
getSlug(' Foo Bar Baz ', {separator: '*'}).should.eql('foo*bar*baz'); | ||
getSlug(' Foo Bar Baz ', {separator: '_'}).should.eql('foo_bar_baz'); | ||
it('should separate with non-whitespace, with trailing spaces', function (done) { | ||
getSlug(' Foo Bar Baz ', { | ||
separator: '-' | ||
}) | ||
.should.eql('foo-bar-baz'); | ||
getSlug(' Foo Bar Baz ', { | ||
separator: '*' | ||
}) | ||
.should.eql('foo*bar*baz'); | ||
getSlug(' Foo Bar Baz ', { | ||
separator: '_' | ||
}) | ||
.should.eql('foo_bar_baz'); | ||
done(); | ||
}); | ||
it('should separate with trailing separator "-"', function () { | ||
getSlug('-Foo Bar Baz-', {separator: '-'}).should.eql('foo-bar-baz'); | ||
getSlug('--Foo Bar Baz---', {separator: '-'}).should.eql('foo-bar-baz'); | ||
getSlug('---Foo Bar Baz---', {separator: '-'}).should.eql('foo-bar-baz'); | ||
it('should separate with trailing separator "-"', function (done) { | ||
getSlug('-Foo Bar Baz-', { | ||
separator: '-' | ||
}) | ||
.should.eql('foo-bar-baz'); | ||
getSlug('--Foo Bar Baz---', { | ||
separator: '-' | ||
}) | ||
.should.eql('foo-bar-baz'); | ||
getSlug('---Foo Bar Baz---', { | ||
separator: '-' | ||
}) | ||
.should.eql('foo-bar-baz'); | ||
done(); | ||
}); | ||
it('should separate with trailing separator "*"', function () { | ||
getSlug('*Foo Bar Baz*', {separator: '*'}).should.eql('foo*bar*baz'); | ||
getSlug('**Foo Bar Baz**', {separator: '*'}).should.eql('foo*bar*baz'); | ||
getSlug('***Foo Bar Baz***', {separator: '*'}).should.eql('foo*bar*baz'); | ||
it('should separate with trailing separator "*"', function (done) { | ||
getSlug('*Foo Bar Baz*', { | ||
separator: '*' | ||
}) | ||
.should.eql('foo*bar*baz'); | ||
getSlug('**Foo Bar Baz**', { | ||
separator: '*' | ||
}) | ||
.should.eql('foo*bar*baz'); | ||
getSlug('***Foo Bar Baz***', { | ||
separator: '*' | ||
}) | ||
.should.eql('foo*bar*baz'); | ||
done(); | ||
}); | ||
it('should separate with trailing separator "_"', function () { | ||
getSlug('_Foo Bar Baz_', {separator: '_'}).should.eql('foo_bar_baz'); | ||
getSlug('__Foo Bar Baz__', {separator: '_'}).should.eql('foo_bar_baz'); | ||
getSlug('___Foo Bar Baz___', {separator: '_'}).should.eql('foo_bar_baz'); | ||
it('should separate with trailing separator "_"', function (done) { | ||
getSlug('_Foo Bar Baz_', { | ||
separator: '_' | ||
}) | ||
.should.eql('foo_bar_baz'); | ||
getSlug('__Foo Bar Baz__', { | ||
separator: '_' | ||
}) | ||
.should.eql('foo_bar_baz'); | ||
getSlug('___Foo Bar Baz___', { | ||
separator: '_' | ||
}) | ||
.should.eql('foo_bar_baz'); | ||
done(); | ||
}); | ||
it('should remove trailing separator "*"', function () { | ||
getSlug(' C\'est un beau titre qui ne laisse rien à désirer !', {separator: '*'}) | ||
it('should remove trailing separator "*"', function (done) { | ||
getSlug(' C\'est un beau titre qui ne laisse rien à désirer !', { | ||
separator: '*' | ||
}) | ||
.should.eql('cest*un*beau*titre*qui*ne*laisse*rien*a*desirer'); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -0,1 +1,2 @@ | ||
var should = require('should'); | ||
var getSlug = require('../lib'); | ||
@@ -5,9 +6,26 @@ | ||
it('should maintain case characters, with smart trim', function () { | ||
getSlug('Foobarbaz, Bar Baz', {truncate: 12}).should.eql('foobarbaz'); | ||
getSlug('Foobarbaz, Bar Baz', {truncate: 15}).should.eql('foobarbaz-bar'); | ||
getSlug(' Foobarbaz, Bar Baz', {truncate: 15}).should.eql('foobarbaz-bar'); | ||
getSlug(' Foobarbaz, Bar Baz', {truncate: 15}).should.eql('foobarbaz-bar'); | ||
it('should maintain case characters, with smart trim', function (done) { | ||
getSlug('Foobarbaz, Bar Baz', { | ||
truncate: 12 | ||
}) | ||
.should.eql('foobarbaz'); | ||
getSlug('Foobarbaz, Bar Baz', { | ||
truncate: 15 | ||
}) | ||
.should.eql('foobarbaz-bar'); | ||
getSlug(' Foobarbaz, Bar Baz', { | ||
truncate: 15 | ||
}) | ||
.should.eql('foobarbaz-bar'); | ||
getSlug(' Foobarbaz, Bar Baz', { | ||
truncate: 15 | ||
}) | ||
.should.eql('foobarbaz-bar'); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -0,50 +1,184 @@ | ||
var should = require('should'); | ||
var getSlug = require('../lib'); | ||
describe('getSlug config combinations', function () { | ||
it('should separate with configured character, with non-Base64 separator', function () { | ||
getSlug('Foo, Bar Baz', {separator: '*', maintainCase: false}).should.eql('foo*bar*baz'); | ||
getSlug('Foo- Bar Baz', {separator: '*', maintainCase: false}).should.eql('foo-*bar*baz'); | ||
getSlug('Foo] Bar Baz', {separator: '*', maintainCase: false}).should.eql('foo*bar*baz'); | ||
it('should separate with configured character, with non-Base64 separator', function (done) { | ||
getSlug('Foo, Bar Baz', { | ||
separator: '*', | ||
maintainCase: false | ||
}) | ||
.should.eql('foo*bar*baz'); | ||
getSlug('Foo- Bar Baz', { | ||
separator: '*', | ||
maintainCase: false | ||
}) | ||
.should.eql('foo-*bar*baz'); | ||
getSlug('Foo] Bar Baz', { | ||
separator: '*', | ||
maintainCase: false | ||
}) | ||
.should.eql('foo*bar*baz'); | ||
done(); | ||
}); | ||
it('should separate with configured character, with only Base64 characters allowed', function () { | ||
getSlug('Foo, Bar Baz', {separator: '_', onlyBase64: true}).should.eql('foo_bar_baz'); | ||
getSlug('Foo- Bar Baz', {separator: '_', onlyBase64: true}).should.eql('foo-_bar_baz'); | ||
getSlug('Foo] Bar Baz', {separator: '_', onlyBase64: true}).should.eql('foo_bar_baz'); | ||
it('should separate with configured character, with only Base64 characters allowed', function (done) { | ||
getSlug('Foo, Bar Baz', { | ||
separator: '_', | ||
onlyBase64: true | ||
}) | ||
.should.eql('foo_bar_baz'); | ||
getSlug('Foo- Bar Baz', { | ||
separator: '_', | ||
onlyBase64: true | ||
}) | ||
.should.eql('foo-_bar_baz'); | ||
getSlug('Foo] Bar Baz', { | ||
separator: '_', | ||
onlyBase64: true | ||
}) | ||
.should.eql('foo_bar_baz'); | ||
done(); | ||
}); | ||
it('should separate with configured character, with smart trim', function () { | ||
getSlug('Foobarbaz, Bar Baz', {separator: '_', truncate: 12}).should.eql('foobarbaz'); | ||
getSlug('Foobarbaz, Bar Baz', {separator: '_', truncate: 15}).should.eql('foobarbaz_bar'); | ||
getSlug(' Foobarbaz, Bar Baz', {separator: '_', truncate: 15}).should.eql('foobarbaz_bar'); | ||
getSlug(' Foobarbaz, Bar Baz', {separator: '_', truncate: 15}).should.eql('foobarbaz_bar'); | ||
it('should separate with configured character, with smart trim', function (done) { | ||
getSlug('Foobarbaz, Bar Baz', { | ||
separator: '_', | ||
truncate: 12 | ||
}) | ||
.should.eql('foobarbaz'); | ||
getSlug('Foobarbaz, Bar Baz', { | ||
separator: '_', | ||
truncate: 15 | ||
}) | ||
.should.eql('foobarbaz_bar'); | ||
getSlug(' Foobarbaz, Bar Baz', { | ||
separator: '_', | ||
truncate: 15 | ||
}) | ||
.should.eql('foobarbaz_bar'); | ||
getSlug(' Foobarbaz, Bar Baz', { | ||
separator: '_', | ||
truncate: 15 | ||
}) | ||
.should.eql('foobarbaz_bar'); | ||
done(); | ||
}); | ||
it('should maintain case characters, with non-Base64 separator', function () { | ||
getSlug('Foo, Bar Baz', {maintainCase: true, separator: '*'}).should.eql('Foo*Bar*Baz'); | ||
getSlug('Foo- Bar Baz', {maintainCase: true, separator: '*'}).should.eql('Foo-*Bar*Baz'); | ||
getSlug('Foo] Bar Baz', {maintainCase: true, separator: '*'}).should.eql('Foo*Bar*Baz'); | ||
it('should maintain case characters, with non-Base64 separator', function (done) { | ||
getSlug('Foo, Bar Baz', { | ||
maintainCase: true, | ||
separator: '*' | ||
}) | ||
.should.eql('Foo*Bar*Baz'); | ||
getSlug('Foo- Bar Baz', { | ||
maintainCase: true, | ||
separator: '*' | ||
}) | ||
.should.eql('Foo-*Bar*Baz'); | ||
getSlug('Foo] Bar Baz', { | ||
maintainCase: true, | ||
separator: '*' | ||
}) | ||
.should.eql('Foo*Bar*Baz'); | ||
done(); | ||
}); | ||
it('should maintain case characters, with only Base64 characters allowed', function () { | ||
getSlug('Foo, Bar Baz', {maintainCase: true, onlyBase64: true}).should.eql('Foo-Bar-Baz'); | ||
getSlug('Foo- Bar Baz', {maintainCase: true, onlyBase64: true}).should.eql('Foo-Bar-Baz'); | ||
getSlug('Foo] Bar Baz', {maintainCase: true, onlyBase64: true}).should.eql('Foo-Bar-Baz'); | ||
it('should maintain case characters, with only Base64 characters allowed', function (done) { | ||
getSlug('Foo, Bar Baz', { | ||
maintainCase: true, | ||
onlyBase64: true | ||
}) | ||
.should.eql('Foo-Bar-Baz'); | ||
getSlug('Foo- Bar Baz', { | ||
maintainCase: true, | ||
onlyBase64: true | ||
}) | ||
.should.eql('Foo-Bar-Baz'); | ||
getSlug('Foo] Bar Baz', { | ||
maintainCase: true, | ||
onlyBase64: true | ||
}) | ||
.should.eql('Foo-Bar-Baz'); | ||
done(); | ||
}); | ||
it('should maintain case characters, with smart trim', function () { | ||
getSlug('Foobarbaz, Bar Baz', {maintainCase: true, truncate: 12}).should.eql('Foobarbaz'); | ||
getSlug('Foobarbaz, Bar Baz', {maintainCase: true, truncate: 15}).should.eql('Foobarbaz-Bar'); | ||
getSlug(' Foobarbaz, Bar Baz', {maintainCase: true, truncate: 15}).should.eql('Foobarbaz-Bar'); | ||
getSlug(' Foobarbaz, Bar Baz', {maintainCase: true, truncate: 15}).should.eql('Foobarbaz-Bar'); | ||
it('should maintain case characters, with smart trim', function (done) { | ||
getSlug('Foobarbaz, Bar Baz', { | ||
maintainCase: true, | ||
truncate: 12 | ||
}) | ||
.should.eql('Foobarbaz'); | ||
getSlug('Foobarbaz, Bar Baz', { | ||
maintainCase: true, | ||
truncate: 15 | ||
}) | ||
.should.eql('Foobarbaz-Bar'); | ||
getSlug(' Foobarbaz, Bar Baz', { | ||
maintainCase: true, | ||
truncate: 15 | ||
}) | ||
.should.eql('Foobarbaz-Bar'); | ||
getSlug(' Foobarbaz, Bar Baz', { | ||
maintainCase: true, | ||
truncate: 15 | ||
}) | ||
.should.eql('Foobarbaz-Bar'); | ||
done(); | ||
}); | ||
it('should prefer Base64 characters only', function () { | ||
getSlug('Foo, Bar Baz', {rfc3986: true, onlyBase64: true}).should.eql('foo-bar-baz'); | ||
getSlug('Foo- Bar Baz', {rfc3986: true, onlyBase64: true}).should.eql('foo-bar-baz'); | ||
getSlug('Foo] Bar Baz', {rfc3986: true, onlyBase64: true}).should.eql('foo-bar-baz'); | ||
getSlug('Foo* Bar Baz', {rfc3986: true, onlyBase64: true}).should.eql('foo-bar-baz'); | ||
it('should prefer Base64 characters only', function (done) { | ||
getSlug('Foo, Bar Baz', { | ||
rfc3986: true, | ||
onlyBase64: true | ||
}) | ||
.should.eql('foo-bar-baz'); | ||
getSlug('Foo- Bar Baz', { | ||
rfc3986: true, | ||
onlyBase64: true | ||
}) | ||
.should.eql('foo-bar-baz'); | ||
getSlug('Foo] Bar Baz', { | ||
rfc3986: true, | ||
onlyBase64: true | ||
}) | ||
.should.eql('foo-bar-baz'); | ||
getSlug('Foo* Bar Baz', { | ||
rfc3986: true, | ||
onlyBase64: true | ||
}) | ||
.should.eql('foo-bar-baz'); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -0,58 +1,217 @@ | ||
var should = require('should'); | ||
var getSlug = require('../lib'); | ||
describe('getSlug symbols', function () { | ||
it('should convert symbols', function () { | ||
getSlug('Foo & Bar | Baz').should.eql('foo-and-bar-or-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'en'}).should.eql('foo-and-bar-or-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'de'}).should.eql('foo-und-bar-oder-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'fr'}).should.eql('foo-et-bar-ou-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'es'}).should.eql('foo-y-bar-u-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'ru'}).should.eql('foo-i-bar-ili-baz'); | ||
it('should convert symbols', function (done) { | ||
getSlug('Foo & Bar | Baz') | ||
.should.eql('foo-and-bar-or-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'en' | ||
}) | ||
.should.eql('foo-and-bar-or-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'de' | ||
}) | ||
.should.eql('foo-und-bar-oder-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'fr' | ||
}) | ||
.should.eql('foo-et-bar-ou-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'es' | ||
}) | ||
.should.eql('foo-y-bar-u-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'ru' | ||
}) | ||
.should.eql('foo-i-bar-ili-baz'); | ||
done(); | ||
}); | ||
it('should not convert symbols with uric flag true', function () { | ||
getSlug('Foo & Bar | Baz', {uric: true}).should.eql('foo-&-bar-or-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'en', uric: true}).should.eql('foo-&-bar-or-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'de', uric: true}).should.eql('foo-&-bar-oder-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'fr', uric: true}).should.eql('foo-&-bar-ou-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'es', uric: true}).should.eql('foo-&-bar-u-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'ru', uric: true}).should.eql('foo-&-bar-ili-baz'); | ||
it('should not convert symbols with uric flag true', function (done) { | ||
getSlug('Foo & Bar | Baz', { | ||
uric: true | ||
}) | ||
.should.eql('foo-&-bar-or-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'en', | ||
uric: true | ||
}) | ||
.should.eql('foo-&-bar-or-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'de', | ||
uric: true | ||
}) | ||
.should.eql('foo-&-bar-oder-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'fr', | ||
uric: true | ||
}) | ||
.should.eql('foo-&-bar-ou-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'es', | ||
uric: true | ||
}) | ||
.should.eql('foo-&-bar-u-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'ru', | ||
uric: true | ||
}) | ||
.should.eql('foo-&-bar-ili-baz'); | ||
done(); | ||
}); | ||
it('should not convert symbols with uricNoSlash flag true', function () { | ||
getSlug('Foo & Bar | Baz', {uricNoSlash: true}).should.eql('foo-&-bar-or-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'en', uricNoSlash: true}).should.eql('foo-&-bar-or-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'de', uricNoSlash: true}).should.eql('foo-&-bar-oder-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'fr', uricNoSlash: true}).should.eql('foo-&-bar-ou-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'es', uricNoSlash: true}).should.eql('foo-&-bar-u-baz'); | ||
getSlug('Foo & Bar | Baz', {lang: 'ru', uricNoSlash: true}).should.eql('foo-&-bar-ili-baz'); | ||
it('should not convert symbols with uricNoSlash flag true', function (done) { | ||
getSlug('Foo & Bar | Baz', { | ||
uricNoSlash: true | ||
}) | ||
.should.eql('foo-&-bar-or-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'en', | ||
uricNoSlash: true | ||
}) | ||
.should.eql('foo-&-bar-or-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'de', | ||
uricNoSlash: true | ||
}) | ||
.should.eql('foo-&-bar-oder-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'fr', | ||
uricNoSlash: true | ||
}) | ||
.should.eql('foo-&-bar-ou-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'es', | ||
uricNoSlash: true | ||
}) | ||
.should.eql('foo-&-bar-u-baz'); | ||
getSlug('Foo & Bar | Baz', { | ||
lang: 'ru', | ||
uricNoSlash: true | ||
}) | ||
.should.eql('foo-&-bar-ili-baz'); | ||
done(); | ||
}); | ||
it('should not convert symbols with mark flag true', function () { | ||
getSlug('Foo (Bar) . Baz', {mark: true}).should.eql('foo-(bar)-.-baz'); | ||
getSlug('Foo (Bar) . Baz', {lang: 'en', mark: true}).should.eql('foo-(bar)-.-baz'); | ||
getSlug('Foo (Bar) . Baz', {lang: 'de', mark: true}).should.eql('foo-(bar)-.-baz'); | ||
getSlug('Foo (Bar) . Baz', {lang: 'fr', mark: true}).should.eql('foo-(bar)-.-baz'); | ||
getSlug('Foo (Bar) . Baz', {lang: 'es', mark: true}).should.eql('foo-(bar)-.-baz'); | ||
getSlug('Foo (Bar) . Baz', {lang: 'ru', mark: true}).should.eql('foo-(bar)-.-baz'); | ||
}); | ||
it('should not convert symbols with mark flag true', function (done) { | ||
it('should convert symbols with flags true', function () { | ||
getSlug('Foo (♥) ; Baz=Bar', {lang: 'en', uric: true, uricNoSlash: true, mark: true}).should.eql('foo-(love)-;-baz=bar'); | ||
getSlug('Foo (♥) ; Baz=Bar', {lang: 'de', uric: true, uricNoSlash: true, mark: true}).should.eql('foo-(liebe)-;-baz=bar'); | ||
getSlug('Foo (♥) ; Baz=Bar', {lang: 'fr', uric: true, uricNoSlash: true, mark: true}).should.eql('foo-(amour)-;-baz=bar'); | ||
getSlug('Foo (♥) ; Baz=Bar', {lang: 'es', uric: true, uricNoSlash: true, mark: true}).should.eql('foo-(amor)-;-baz=bar'); | ||
getSlug('Foo (♥) ; Baz=Bar', {lang: 'ru', uric: true, uricNoSlash: true, mark: true}).should.eql('foo-(lubov)-;-baz=bar'); | ||
}); | ||
getSlug('Foo (Bar) . Baz', { | ||
mark: true | ||
}) | ||
.should.eql('foo-(bar)-.-baz'); | ||
it('should replace symbols (de)', function () { | ||
getSlug('Äpfel & Birnen', {lang: 'de'}).should.eql('aepfel-und-birnen'); | ||
getSlug('ÄÖÜäöüß', {lang: 'de', maintainCase: true}).should.eql('AeOeUeaeoeuess'); | ||
}); | ||
getSlug('Foo (Bar) . Baz', { | ||
lang: 'en', | ||
mark: true | ||
}) | ||
.should.eql('foo-(bar)-.-baz'); | ||
it('should ignore not available language param', function () { | ||
getSlug('Äpfel & Birnen', {lang: 'xx'}).should.eql('aepfel-and-birnen'); | ||
}); | ||
getSlug('Foo (Bar) . Baz', { | ||
lang: 'de', | ||
mark: true | ||
}) | ||
.should.eql('foo-(bar)-.-baz'); | ||
getSlug('Foo (Bar) . Baz', { | ||
lang: 'fr', | ||
mark: true | ||
}) | ||
.should.eql('foo-(bar)-.-baz'); | ||
getSlug('Foo (Bar) . Baz', { | ||
lang: 'es', | ||
mark: true | ||
}) | ||
.should.eql('foo-(bar)-.-baz'); | ||
getSlug('Foo (Bar) . Baz', { | ||
lang: 'ru', | ||
mark: true | ||
}) | ||
.should.eql('foo-(bar)-.-baz'); | ||
done(); | ||
}); | ||
it('should convert symbols with flags true', function (done) { | ||
getSlug('Foo (♥) ; Baz=Bar', { | ||
lang: 'en', | ||
uric: true, | ||
uricNoSlash: true, | ||
mark: true | ||
}) | ||
.should.eql('foo-(love)-;-baz=bar'); | ||
getSlug('Foo (♥) ; Baz=Bar', { | ||
lang: 'de', | ||
uric: true, | ||
uricNoSlash: true, | ||
mark: true | ||
}) | ||
.should.eql('foo-(liebe)-;-baz=bar'); | ||
getSlug('Foo (♥) ; Baz=Bar', { | ||
lang: 'fr', | ||
uric: true, | ||
uricNoSlash: true, | ||
mark: true | ||
}) | ||
.should.eql('foo-(amour)-;-baz=bar'); | ||
getSlug('Foo (♥) ; Baz=Bar', { | ||
lang: 'es', | ||
uric: true, | ||
uricNoSlash: true, | ||
mark: true | ||
}) | ||
.should.eql('foo-(amor)-;-baz=bar'); | ||
getSlug('Foo (♥) ; Baz=Bar', { | ||
lang: 'ru', | ||
uric: true, | ||
uricNoSlash: true, | ||
mark: true | ||
}) | ||
.should.eql('foo-(lubov)-;-baz=bar'); | ||
done(); | ||
}); | ||
it('should replace symbols (de)', function (done) { | ||
getSlug('Äpfel & Birnen', { | ||
lang: 'de' | ||
}) | ||
.should.eql('aepfel-und-birnen'); | ||
getSlug('ÄÖÜäöüß', { | ||
lang: 'de', | ||
maintainCase: true | ||
}) | ||
.should.eql('AeOeUeaeoeuess'); | ||
done(); | ||
}); | ||
it('should ignore not available language param', function (done) { | ||
getSlug('Äpfel & Birnen', { | ||
lang: 'xx' | ||
}) | ||
.should.eql('aepfel-and-birnen'); | ||
done(); | ||
}); | ||
}); |
@@ -0,1 +1,2 @@ | ||
var should = require('should'); | ||
var getSlug = require('../lib'); | ||
@@ -5,9 +6,22 @@ | ||
it('should maintain case characters, with smart truncate', function () { | ||
getSlug('Foobarbaz, Bar Baz', {truncate: 12}).should.eql('foobarbaz'); | ||
getSlug('Foobarbaz, Bar Baz', {truncate: 15}).should.eql('foobarbaz-bar'); | ||
getSlug(' Foobarbaz, Bar Baz', {truncate: 15}).should.eql('foobarbaz-bar'); | ||
getSlug(' Foobarbaz, Bar Baz', {truncate: 15}).should.eql('foobarbaz-bar'); | ||
it('should maintain case characters, with smart truncate', function (done) { | ||
getSlug('Foobarbaz, Bar Baz', { | ||
truncate: 12 | ||
}) | ||
.should.eql('foobarbaz'); | ||
getSlug('Foobarbaz, Bar Baz', { | ||
truncate: 15 | ||
}) | ||
.should.eql('foobarbaz-bar'); | ||
getSlug(' Foobarbaz, Bar Baz', { | ||
truncate: 15 | ||
}) | ||
.should.eql('foobarbaz-bar'); | ||
getSlug(' Foobarbaz, Bar Baz', { | ||
truncate: 15 | ||
}) | ||
.should.eql('foobarbaz-bar'); | ||
done(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
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
49543
23
1211
133
7