speakingurl
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -1,20 +0,42 @@ | ||
var makeUrl = require('../lib/'), | ||
url, string; | ||
var makeSlug = require('../lib'), | ||
slug; | ||
string = "Möchtest du eine schöne URL?"; | ||
slug = makeSlug("Das ist ein schöner Titel, der keine Wünsche offen läßt!"); | ||
console.log(slug); | ||
// Output: "moechtest-du-eine-schoene-url" | ||
url = makeUrl(string); | ||
slug = makeSlug("Première neige repéré!!"); | ||
console.log(slug); | ||
// Output: "premiere-neige-repere" | ||
console.log(url); | ||
// optionally allow RFC3986 conform url path, default base64 /A-Za-z0-9_-/ | ||
slug = makeSlug("Allow *RFC396* characters like 'that'?", {rfc3986: true} ); | ||
console.log(slug); | ||
// Output: "allow-*rfc396*-characters-like-'that'" | ||
string = "Première neige repéré!!"; | ||
url = makeUrl(string); | ||
// if you choose a separator which is'nt a Base64 (/A-Za-z0-9_-/) character => rfc3986 == true | ||
slug = makeSlug("Choosing 'separator' to non Base64 char, rfc3986 chars are allowed at all", {separator: '*'} ); | ||
console.log(slug); | ||
// Output: "choosing*'separator'*to*non*base64*char,*rfc3986*chars*are*allowed*at*all" | ||
console.log(url); | ||
// optionally use a different separator character | ||
slug = makeSlug("Would you like another seaprator?", {separator: '_'} ); | ||
console.log(slug); | ||
// Output: "would_you_like_another_character" | ||
string = "---This Is A___”Test!!!!"; | ||
url = makeUrl(string); | ||
// optionally maintain case | ||
slug = makeSlug("Don't convert UPPERCASE chars", {maintainCase: true}); | ||
console.log(slug); | ||
// Output: "Do-not-convert-UPPERCASE-chars" | ||
console.log(url); | ||
// optionally trim to max length while not breaking any words | ||
slug = makeSlug("Trim sentence ... to fit in length", {smartTrim: 16}); | ||
console.log(slug); | ||
// Output: "trim-sentence-to" | ||
// optionally allow RFC3986 conform url path with smart trim | ||
slug = makeSlug("Allow *RFC3986* characters like 'that'?", {rfc3986: true, smartTrim: 20} ); | ||
console.log(slug); | ||
// Output: "allow-*rfc396*" | ||
// |
@@ -1,1 +0,1 @@ | ||
module.exports = require('./lib'); | ||
module.exports = require('./speakingurl'); |
@@ -1,66 +0,1 @@ | ||
'use strict'; | ||
var alphabet = { | ||
a: /[\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250]/ig, | ||
aa: /[\uA733]/ig, | ||
ae: /[\u00E6\u01FD\u01E3\u00E4]/ig, | ||
ao: /[\uA735]/ig, | ||
au: /[\uA737]/ig, | ||
av: /[\uA739\uA73B]/ig, | ||
ay: /[\uA73D]/ig, | ||
b: /[\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253]/ig, | ||
c: /[\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184]/ig, | ||
d: /[\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A]/ig, | ||
dz: /[\u01F3\u01C6]/ig, | ||
e: /[\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD]/ig, | ||
f: /[\u0066\u24D5\uFF46\u1E1F\u0192\uA77C]/ig, | ||
g: /[\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F]/ig, | ||
h: /[\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265]/ig, | ||
hv: /[\u0195]/ig, | ||
i: /[\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131]/ig, | ||
j: /[\u006A\u24D9\uFF4A\u0135\u01F0\u0249]/ig, | ||
k: /[\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3]/ig, | ||
l: /[\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747]/ig, | ||
lj: /[\u01C9]/ig, | ||
m: /[\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F]/ig, | ||
n: /[\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5]/ig, | ||
nj: /[\u01CC]/ig, | ||
o: /[\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275]/ig, | ||
oi: /[\u01A3]/ig, | ||
ou: /[\u0223]/ig, | ||
oo: /[\uA74F]/ig, | ||
oe: /[\u00F6]/ig, | ||
p: /[\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755]/ig, | ||
q: /[\u0071\u24E0\uFF51\u024B\uA757\uA759]/ig, | ||
r: /[\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783]/ig, | ||
s: /[\u0073\u24E2\uFF53\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B]/ig, | ||
ss: /[\u00DF]/ig, | ||
t: /[\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787]/ig, | ||
tz: /[\uA729]/ig, | ||
u: /[\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289]/ig, | ||
ue: /[\u00FC]/ig, | ||
v: /[\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C]/ig, | ||
vy: /[\uA761]/ig, | ||
w: /[\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73]/ig, | ||
x: /[\u0078\u24E7\uFF58\u1E8B\u1E8D]/ig, | ||
y: /[\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF]/ig, | ||
z: /[\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763]/ig, | ||
'': /[\u0300\u0301\u0302\u0303\u0308]/ig, | ||
'-': /[^a-z0-9]+/ig | ||
}; | ||
var speakingUrl = function (str) { | ||
for (var letter in alphabet) { | ||
str = str.replace(alphabet[letter], letter); | ||
} | ||
// trim | ||
str = str.replace(/(^-|-$)+/g, ''); | ||
return str; | ||
}; | ||
module.exports = exports = speakingUrl; | ||
module.exports = require('../speakingurl'); |
{ | ||
"name": "speakingurl", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Generate of so called 'static' or 'nice-looking' or 'SpeakingURL' or 'slug' from a string.", | ||
"keywords": [ | ||
"speakingUrl", | ||
"speakingurl", | ||
"speaking Url", | ||
"nice Url", | ||
"static url", | ||
"nice looking URL", | ||
"slug"], | ||
"slug", | ||
"seo", | ||
"url", | ||
"speakingurl", | ||
"nice url", | ||
"static url", | ||
"nice looking url" | ||
], | ||
"author": { | ||
@@ -18,3 +19,3 @@ "name": "Sascha Droste", | ||
}, | ||
"main": "index.js", | ||
"main": "speakingurl", | ||
"dependencies": {}, | ||
@@ -26,3 +27,3 @@ "devDependencies": { | ||
"scripts": { | ||
"test": "mocha -R spec" | ||
"test": "mocha" | ||
}, | ||
@@ -37,5 +38,6 @@ "repository": { | ||
"licenses": [{ | ||
"type": "BSD", | ||
"url": "https://raw.github.com/pid/speakingurl/master/LICENCE" | ||
}], | ||
"type": "MIT", | ||
"url": "https://raw.github.com/pid/speakingurl/master/LICENCE" | ||
} | ||
], | ||
"engines": { | ||
@@ -42,0 +44,0 @@ "node": ">=0.8.0" |
@@ -1,45 +0,77 @@ | ||
[![Build Status](https://travis-ci.org/pid/speakingurl.png)](https://travis-ci.org/pid/speakingurl) [![NPM version](https://badge.fury.io/js/speakingurl.png)](http://badge.fury.io/js/speakingurl) | ||
# Speaking URL | ||
# Speaking URL [![NPM version](https://badge.fury.io/js/speakingurl.png)](http://badge.fury.io/js/speakingurl) | ||
Generate of so called "static" or "nice-looking" or "SpeakingURL" or "slug" from a string. | ||
Works in browser and on node-server | ||
## Contribution | ||
The current state is definitely not complete - we need you to improve it! | ||
#### Notes | ||
In v0.1.x converting symbols is disabled, should be added in v0.2.x (see [Issues](https://github.com/pid/speakingurl/issues)) | ||
This is an early version, please check for your needs and give feedback to improve it. | ||
started with the transformation table taken from https://github.com/dypsilon/js-replace-diacritics (AMD) | ||
## Installation | ||
$ npm install speakingurl | ||
```bash | ||
$ npm install speakingurl | ||
``` | ||
## Usage | ||
### makeSlug(input, [options]); | ||
```input```: string to convert | ||
```options```: config object (see below) | ||
## Running tests | ||
* ```separator``` default: '-' | ||
* char that replace the whitespaces | ||
* ```maintainCase``` default: false | ||
* true => maintain case chars | ||
* false => convert all chars to lower case | ||
* ```rfc3986``` default: false | ||
* true => allow chars allowed by ~RFC3986 for url path | ||
* false => only Base64 chars allowed(/A-Za-z0-9-_/) | ||
* ```smartTrim``` default: 0 | ||
* 0 == don't trim length | ||
* >0 == trim to max length while not breaking any words | ||
[![Build Status](https://travis-ci.org/pid/speakingurl.png)](https://travis-ci.org/pid/speakingurl) | ||
notes: if you set ```onlyBase64``` and ```rfc3986``` to ```true```, ```onlyBase64``` is prioritized | ||
```bash | ||
$ npm test | ||
``` | ||
## Examples | ||
```javascript | ||
var makeSlug = require('speakingurl'), | ||
slug; | ||
## Usage | ||
slug = makeSlug("Das ist ein schöner Titel, der keine Wünsche offen läßt ! "); | ||
console.log(slug); | ||
// Output: "das-ist-ein-schoener-titel-der-keine-wuensche-offen-laesst" | ||
```js | ||
slug = makeSlug("Première neige repéré!!"); | ||
console.log(slug); | ||
// Output: "premiere-neige-repere" | ||
var makeSlug = require('speakingurl'), | ||
url, string; | ||
// optionally use a different separator character | ||
slug = makeSlug("Would you like another character?", {separator: '_'} ); | ||
console.log(slug); | ||
// Output: "want_another_separator" | ||
string = "Möchtest du eine schöne URL?"; | ||
slug = makeSlug(string); | ||
console.log(slug); // Output: moechtest-du-eine-schoene-url | ||
// optionally maintain case | ||
slug = makeSlug("Do not convert UPPERCASE chars", {maintainCase: true}); | ||
console.log(slug); | ||
// Output: "Do-not-convert-UPPERCASE-chars" | ||
// optionally trim to max length while not breaking any words | ||
slug = makeSlug("Trim sentence ... to fit in length", {smartTrim: 16}); | ||
console.log(slug); | ||
// Output: "trim-sentence-to" | ||
string = "Première neige repéré!!"; | ||
slug = makeSlug(string); | ||
console.log(slug); // Output: premiere-neige-repere | ||
// optionally allow RFC3986 conform url path, default base64 /A-Za-z0-9_-/ | ||
slug = makeSlug("Allow *RFC396* characters like 'that'?", {rfc3986: true} ); | ||
console.log(slug); | ||
// Output: "allow-*rfc396*-characters-like-'that'" | ||
``` | ||
## Running tests | ||
[![Build Status](https://travis-ci.org/pid/speakingurl.png)](https://travis-ci.org/pid/speakingurl) | ||
```shell | ||
$ npm test | ||
``` | ||
## Credits | ||
- @simov https://github.com/simov/slugify | ||
- @henrikjoreteg https://github.com/henrikjoreteg/slugger | ||
- @Aaronontheweb https://github.com/Aaronontheweb/node-slugs | ||
## License | ||
@@ -46,0 +78,0 @@ [BSD](https://raw.github.com/pid/speakingurl/master/LICENCE) |
@@ -1,56 +0,73 @@ | ||
var makeUrl = require('../lib/'); | ||
require('should'); | ||
var getSlug = require('../lib'); | ||
describe('make a speaking Url', function () { | ||
describe('getSlug misc', 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'); | ||
}); | ||
describe('testing string without transformation neccacary', function () { | ||
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 RFC3986 characters allowed', function () { | ||
getSlug('Foo, Bar Baz', {separator: '_', rfc3986: true}).should.eql('foo,_bar_baz'); | ||
getSlug('Foo- Bar Baz', {separator: '_', rfc3986: true}).should.eql('foo-_bar_baz'); | ||
getSlug('Foo] Bar Baz', {separator: '_', rfc3986: true}).should.eql('foo_bar_baz'); | ||
}); | ||
var url = makeUrl("this-is-a-test"); | ||
it('should separate with configured character, with smart trim', function () { | ||
getSlug('Foobarbaz, Bar Baz', {separator: '_', smartTrim: 12}).should.eql('foobarbaz'); | ||
getSlug('Foobarbaz, Bar Baz', {separator: '_', smartTrim: 15}).should.eql('foobarbaz_bar'); | ||
getSlug(' Foobarbaz, Bar Baz', {separator: '_', smartTrim: 15}).should.eql('foobarbaz_bar'); | ||
getSlug(' Foobarbaz, Bar Baz', {separator: '_', smartTrim: 15}).should.eql('foobarbaz_bar'); | ||
}); | ||
it('should be a string with 14 chars', function () { | ||
url.should.be.a('string'); | ||
url.should.have.length(14); | ||
url.should.match(/[a-z0-9-]/); | ||
url.should.be.equal('this-is-a-test'); | ||
}); | ||
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'); | ||
}); | ||
describe('testing uppercase string', function () { | ||
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 RFC3986 characters allowed', function () { | ||
getSlug('Foo, Bar Baz', {maintainCase: true, rfc3986: true}).should.eql('Foo,-Bar-Baz'); | ||
getSlug('Foo- Bar Baz', {maintainCase: true, rfc3986: true}).should.eql('Foo-Bar-Baz'); | ||
getSlug('Foo] Bar Baz', {maintainCase: true, rfc3986: true}).should.eql('Foo-Bar-Baz'); | ||
}); | ||
var url = makeUrl("__---This_Is_A_Test!!"); | ||
it('should be a string with 14 chars', function () { | ||
url.should.be.a('string'); | ||
url.should.have.length(14); | ||
url.should.match(/[a-z0-9-]/); | ||
url.should.be.equal('this-is-a-test'); | ||
}); | ||
it('should maintain case characters, with smart trim', function () { | ||
getSlug('Foobarbaz, Bar Baz', {maintainCase: true, smartTrim: 12}).should.eql('Foobarbaz'); | ||
getSlug('Foobarbaz, Bar Baz', {maintainCase: true, smartTrim: 15}).should.eql('Foobarbaz-Bar'); | ||
getSlug(' Foobarbaz, Bar Baz', {maintainCase: true, smartTrim: 15}).should.eql('Foobarbaz-Bar'); | ||
getSlug(' Foobarbaz, Bar Baz', {maintainCase: true, smartTrim: 15}).should.eql('Foobarbaz-Bar'); | ||
}); | ||
describe('testing string with special characters', function () { | ||
var url = makeUrl("Check for special chars!\"§$%&/()=?`´*+'_-:.;.'"); | ||
it('should be a string with 23 chars', function () { | ||
url.should.be.a('string'); | ||
url.should.have.length(23); | ||
url.should.match(/[a-z0-9-]/); | ||
url.should.be.equal('check-for-special-chars'); | ||
}); | ||
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'); | ||
}); | ||
describe('testing unicode string', function () { | ||
}); | ||
var url = makeUrl("Première neige ”repéré”!!"); | ||
it('should be a string with 21 chars', function () { | ||
url.should.be.a('string'); | ||
url.should.have.length(21); | ||
url.should.be.equal('premiere-neige-repere'); | ||
}); | ||
}); | ||
}); | ||
// { | ||
// separator: '-', | ||
// maintainCase: false, | ||
// onlyBase64: true, // => RFC 3986 == false | ||
// rfc3986: false, // set 'onlyBase64' or 'rfc3986', onlyBase64 is prioritized | ||
// smartTrim: 0 // 0 == don't trim, otherwise trim to max length, | ||
// consider word boundaries | ||
// } |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
29208
19
327
92
1