Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
speakingurl
Advanced tools
Generate of so called 'static' or 'Clean URL' or 'Pretty URL' or 'nice-looking URL' or 'Speaking URL' or 'user-friendly URL' or 'SEO-friendly URL' or 'slug' from a string.
The 'speakingurl' npm package is used to generate slugs from strings. It is particularly useful for creating URL-friendly strings from titles or other text inputs. The package supports multiple languages and offers various customization options.
Basic Slug Generation
This feature allows you to convert a string into a URL-friendly slug. Special characters are removed, and spaces are replaced with hyphens.
const getSlug = require('speakingurl');
const slug = getSlug('Hello World!');
console.log(slug); // Output: 'hello-world'
Custom Separator
You can customize the separator used in the slug. In this example, an underscore is used instead of the default hyphen.
const getSlug = require('speakingurl');
const slug = getSlug('Hello World!', { separator: '_' });
console.log(slug); // Output: 'hello_world'
Language Support
The package supports multiple languages, allowing you to generate slugs that are appropriate for different linguistic contexts.
const getSlug = require('speakingurl');
const slug = getSlug('你好,世界', { lang: 'zh' });
console.log(slug); // Output: 'ni-hao-shi-jie'
Custom Transliteration
You can define custom transliterations for specific characters, giving you more control over the slug generation process.
const getSlug = require('speakingurl');
const slug = getSlug('Hello World!', { custom: { 'H': 'h', 'W': 'w' } });
console.log(slug); // Output: 'hello-world'
'slugify' is another popular package for generating URL-friendly slugs. It offers similar functionality to 'speakingurl' but is often considered simpler and more lightweight. It also supports custom replacements and different character sets.
'limax' is a slug generator that focuses on Unicode support and transliteration. It is highly configurable and supports a wide range of languages, making it a strong alternative to 'speakingurl' for internationalization needs.
'url-slug' is a package designed to create slugs from strings with a focus on simplicity and ease of use. It provides basic slug generation features and is a good choice for straightforward use cases.
Generate of so called "static" or "Clean URL" or "Pretty URL" or "nice-looking URL" or "Speaking URL" or "user-friendly URL" or "SEO-friendly URL" or "slug" from a string.
This module aims to transliteration the input string.
For use in browser and server - no dependencies!
server-side:
$ npm install speakingurl --save
client-side:
$ # http://bower.io/
$ bower install speakingurl
or
$ # http://component.io/
$ component install pid/speakingurl
or
$ # http://jamjs.org/
$ jam install speakingurl
or
copy the file speakingurl.min.js to your script directory
or use the CDN from Cloudflare
use //cdnjs.cloudflare.com/ajax/libs/speakingurl/0.2.21/speakingurl.min.js
input
: {string} to convert; options
: {object|string} config object or separator string (see below)
separator
{string} default: '-'
lang
{string} default: 'en'
maintainCase
{boolean} default: false
uric
{boolean} default: false
uricNoSlash
{boolean} default: false
mark
{boolean} default: false
custom
{object} default: {}
truncate
{number} default: 0
options
{string} separatornotes: 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.
var getSlug = require('speakingurl');
var slug;
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !");
console.log(slug); // Output: schoener-titel-laesst-gruessen-bel-ete
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", "*");
console.log(slug); // Output: schoener*titel*laesst*gruessen*bel*ete
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", {separator: "_"});
console.log(slug); // Output: schoener_titel_laesst_gruessen_bel_ete
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", {uric: true});
console.log(slug); // Output: schoener-titel-laesst-gruessen?-bel-ete
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", {uricNoSlash: true});
console.log(slug); // Output: schoener-titel-laesst-gruessen?-bel-ete
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", {mark: true});
console.log(slug); // Output: schoener-titel-laesst-gruessen!-bel-ete-!
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", {truncate: 20});
console.log(slug); // Output: schoener-titel
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", {maintainCase: true});
console.log(slug); // Output: Schoener-Titel-laesst-gruessen-Bel-ete
slug = getSlug("Äpfel & Birnen!", {lang: 'de'});
console.log(slug); // Output: aepfel-und-birnen
slug = getSlug("Apple & Pear!", {lang: 'en'}); // lang: "en" is default, just to clarify
console.log(slug); // Output: apple-and-pear
slug = getSlug('Foo & Bar * Baz', {custom: {'&': ' doo '}, uric:true } );
console.log(slug); // Output: foo-doo-bar-baz
slug = getSlug('Foo ♥ Bar');
console.log(slug); // Output: foo-love-bar
slug = getSlug('Foo & Bar | (Baz) * Doo', {custom:{'*': "Boo"},mark:true});
console.log(slug); // Output: foo-and-bar-or-(baz)-boo-doo
slug = getSlug('NEXUS4 only $299');
console.log(slug); // Output: nexus-4-only-usd299
slug = getSlug('NEXUS4 only €299', {maintainCase: true});
console.log(slug); // Output: NEXUS-4-only-EUR299
In browser:
<script src="components/speakingurl/speakingurl.min.js"></script>
<script>
var slug = getSlug('NEXUS4 only €299', {maintainCase: true});
console.log(slug); // Output: NEXUS-4-only-EUR299
</script>
options
: {object|string} config object or separator string (see above)
Create your own specially configured function.
var slug;
var options = {
maintainCase: true,
separator: '_'
};
var mySlug = require('speakingurl').createSlug(options);
slug = mySlug("Schöner Titel läßt grüßen!? Bel été !");
console.log(slug); // Output: Schoener_Titel_laesst_gruessen_Bel_ete
In browser:
<script src="components/speakingurl/speakingurl.min.js"></script>
<script>
var options = {
maintainCase: true,
separator: '_'
};
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
</script>
$ npm test
The BSD 3-Clause License (BSD3)
Copyright (c) 2013 Sascha Droste sascha.droste@gmail.com 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.
FAQs
Generate a slug – transliteration with a lot of options
The npm package speakingurl receives a total of 953,552 weekly downloads. As such, speakingurl popularity was classified as popular.
We found that speakingurl demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.