Name: speakingurl
Owner: Wire Swiss GmbH
Description: Generate a slug ? transliteration with a lot of options
Forked from: pid/speakingurl
Created: 2016-10-31 16:39:02.0
Updated: 2017-10-19 08:38:35.0
Pushed: 2016-11-02 13:55:15.0
Homepage: http://pid.github.io/speakingurl/
Size: 1190
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
====================================================================================================================================================================================================================================================================================================================================================
Generate a slug with a lot of options; create a so-called Semantic URL or 'Clean URL' or 'Pretty URL' or 'nice-looking URL' or 'Speaking URL' or 'user-friendly URL' or 'SEO-friendly URL' from a string. This module aims to transliterate the input string.
For use in browser and server - no dependencies!
install speakingurl --save
r install --save speakingurl
onent install pid/speakingurl
install speakingurl
d to Gemfile
'speakingurl-rails'
copy the file speakingurl.min.js to your script directory
available versions:
available versions:
input
: {string} to convert
options
{object|string} config object or separator string (see below)
options
{object}
separator
{string} default: '-'lang
{string} default: 'en' // ISO 639-1 Codessymbols
{boolean} default: truemaintainCase
{boolean} default: falsetitleCase
{boolean|array} default: falsetruncate
{number} default: 0uric
{boolean} default: falseuricNoSlash
{boolean} default: falsemark
{boolean} default: falsecustom
{object|array} default: {}options
{string} separator
notes: default only Base64 chars are allowed (/A-Za-z0-9_-/), setting uric
, uricNoSlash
or/and mark
to true
will add the specified chars to the list of allowed characters. The separator-character is always allowed.
getSlug = require('speakingurl');
ipt src="bower_components/speakingurl/speakingurl.min.js"></script>
d to application.js
require speakingurl
slug;
= getSlug("Schöner Titel läßt grüßen!? Bel été !");
ole.log(slug); // Output: schoener-titel-laesst-gruessen-bel-ete
= getSlug("Schöner Titel läßt grüßen!? Bel été !", '*');
ole.log(slug); // Output: schoener*titel*laesst*gruessen*bel*ete
= getSlug("Schöner Titel läßt grüßen!? Bel été !", {
separator: '_'
});
ole.log(slug); // Output: schoener_titel_laesst_gruessen_bel_ete
= getSlug("Schöner Titel läßt grüßen!? Bel été !", {
uric: true
});
ole.log(slug); // Output: schoener-titel-laesst-gruessen?-bel-ete
= getSlug("Schöner Titel läßt grüßen!? Bel été !", {
uricNoSlash: true
});
ole.log(slug); // Output: schoener-titel-laesst-gruessen?-bel-ete
= getSlug("Schöner Titel läßt grüßen!? Bel été !", {
mark: true
});
ole.log(slug); // Output: schoener-titel-laesst-gruessen!-bel-ete-!
= getSlug("Schöner Titel läßt grüßen!? Bel été !", {
truncate: 20
});
ole.log(slug); // Output: schoener-titel
= getSlug("Schöner Titel läßt grüßen!? Bel été !", {
maintainCase: true
});
ole.log(slug); // Output: Schoener-Titel-laesst-gruessen-Bel-ete
= getSlug("Äpfel & Birnen!", {
lang: 'de'
});
ole.log(slug); // Output: aepfel-und-birnen
= getSlug("?????? ????", {
lang: 'my'
});
ole.log(slug); // Output: myanma-thadak
= getSlug('???????? ?? ???? ?????', {
lang: 'dv'
});
ole.log(slug); // Output: miadhakee hd reethi dvhkv
= getSlug("Apple & Pear!", {
lang: 'en' // lang: "en" is default, just to clarify
});
ole.log(slug); // Output: apple-and-pear
= getSlug('Foo & Bar * Baz', {
custom: {
'&': ' doo '
},
uric:true
});
ole.log(slug); // Output: foo-doo-bar-baz
= getSlug('Foo ? Bar');
ole.log(slug); // Output: foo-love-bar
= getSlug('Foo & Bar | (Baz) * Doo', {
custom: {
'*': 'Boo'
},
mark:true
});
ole.log(slug); // Output: foo-and-bar-or-(baz)-boo-doo
= getSlug('Foo and Bar or Baz', {
custom: {
'and': 'und',
'or': ''
}
});
ole.log(slug); // Output: foo-und-bar-baz
= getSlug('[Knöpfe]', {
custom: [
'[',
']'
]
});
ole.log(slug); // Output: [knoepfe]
= getSlug('NEXUS4 only $299');
ole.log(slug); // Output: nexus-4-only-usd299
= getSlug('NEXUS4 only ?299', {
maintainCase: true
});
ole.log(slug); // Output: NEXUS-4-only-EUR299
= getSlug('Don\'t drink and drive', {
titleCase: true
});
ole.log(slug); // Output: Don-t-Drink-And-Drive
= getSlug('Don\'t drink and drive', {
titleCase: ['and']
});
ole.log(slug); // Output: Don-t-Drink-and-Drive
= getSlug('Foo & Bar ? Foo < Bar', {
lang: false
});
ole.log(slug); // Output: foo-bar-foo-bar
= getSlug('Foo & Bar ? Foo < Bar', {
symbols: false
});
ole.log(slug); // Output: foo-bar-foo-bar
= getSlug('ä?ä', {
lang: 'tr',
symbols: false
});
ole.log(slug); // Output: a
options
: {object|string} config object or separator string (see above)
Create your own specially configured function.
options = {
maintainCase: true,
separator: '_'
};
mySlug = require('speakingurl').createSlug(options);
n browser:
ar mySlug = createSlug(options);
slug = mySlug("Schöner Titel läßt grüßen!? Bel été !");
ole.log(slug); // Output: Schoener_Titel_laesst_gruessen_Bel_ete
Create your own specially configured function with title-case feature.
options = {
titleCase: [
"a","an","and","as","at","but",
"by","en","for","if","in","nor",
"of","on","or","per","the","to","vs"
]
};
mySlug = require('speakingurl').createSlug(options);
n browser:
ar mySlug = createSlug(options);
slug = mySlug('welcome to the jungle');
ole.log(slug); // Output: Welcome-to-the-Jungle
see CHANGELOG.md
test
rk pid/speakingurl on Github
t clone git@github.com:<YOUR_USER>/speakingurl.git
speakingurl
m install
d your stuff
d tests
d example for new feature
d release info to CHANGELOG.md
d description/example to README.md
lp
mmit files (speakingurl.min.js,...)
everything works fine, commit, push to your repository
eate pull request
lp bumpup --patch # --minor # --major
lp
lp release
lp
m build speakingurl-rails.gemspec
m push speakingurl-rails-x.x.x.gem
The BSD 3-Clause License (BSD3)
Copyright (c) 2013-2016 Sascha Droste pid@posteo.net All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.