Generate a slug – transliteration with a lot of options
Usage no npm install needed!
<script type="module">
import speakingurl from 'https://cdn.skypack.dev/speakingurl';
</script>
README
SpeakingURL
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!
NPM Badge
Installation
npm
npm install speakingurl --save
yarn
yarn add speakingurl --dev
Bower
bower install --save speakingurl
Component
component install pid/speakingurl
Ruby on Rails
# Add to Gemfile
gem 'speakingurl-rails'
Download Package
copy the file speakingurl.min.js to your script directory
object -> custom map for translation, overwrites all i.e. { '&': '#', '*': ' star ' }
array -> add chars to allowed charMap (see example)
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.
options: {object|string} config object or separator string (see above)
Create your own specially configured function.
var options = {
maintainCase: true,
separator: '_'
};
var mySlug = require('speakingurl').createSlug(options);
// in browser:
// var mySlug = createSlug(options);
var slug = mySlug("Schöner Titel läßt grüßen!? Bel été !");
console.log(slug); // Output: Schoener_Titel_laesst_gruessen_Bel_ete
Create your own specially configured function with title-case feature.
var options = {
titleCase: [
"a","an","and","as","at","but",
"by","en","for","if","in","nor",
"of","on","or","per","the","to","vs"
]
};
var mySlug = require('speakingurl').createSlug(options);
// in browser:
// var mySlug = createSlug(options);
var slug = mySlug('welcome to the jungle');
console.log(slug); // Output: Welcome-to-the-Jungle
# fork pid/speakingurl on Github
$ git clone git@github.com:<YOUR_USER>/speakingurl.git
$ cd speakingurl
$ npm install
# add your stuff
# add tests
# add example for new feature
# add release info to CHANGELOG.md
# add description/example to README.md
$ gulp
$ commit files (speakingurl.min.js,...)
# if everything works fine, commit, push to your repository
# create pull request
Copyright (c) 2013-2017 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:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
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.