What is @types/speakingurl?
@types/speakingurl is a TypeScript type definition package for the 'speakingurl' library, which is used to generate slugs from strings. Slugs are URL-friendly strings typically used in web development for creating readable and SEO-friendly URLs.
What are @types/speakingurl's main functionalities?
Basic Slug Generation
This feature allows you to generate a basic slug from a given string. The generated slug is URL-friendly and typically used in web development for creating readable URLs.
const speakingurl = require('speakingurl');
const slug = speakingurl('Hello World!');
console.log(slug); // Output: 'hello-world'
Custom Separator
This feature allows you to customize the separator used in the generated slug. By default, the separator is a hyphen ('-'), but you can change it to any character you prefer.
const speakingurl = require('speakingurl');
const slug = speakingurl('Hello World!', { separator: '_' });
console.log(slug); // Output: 'hello_world'
Transliteration
This feature supports transliteration, which converts non-Latin characters to their Latin equivalents. This is useful for generating slugs from strings in various languages.
const speakingurl = require('speakingurl');
const slug = speakingurl('你好世界');
console.log(slug); // Output: 'ni-hao-shi-jie'
Custom Replacements
This feature allows you to define custom replacements for specific words or characters in the input string. This can be useful for handling special cases or ensuring consistency in the generated slugs.
const speakingurl = require('speakingurl');
const slug = speakingurl('Hello World!', { custom: { 'Hello': 'Hi' } });
console.log(slug); // Output: 'hi-world'
Other packages similar to @types/speakingurl
slugify
The 'slugify' package is another popular library for generating URL-friendly slugs from strings. It offers similar functionality to 'speakingurl', including support for custom separators and transliteration. However, 'slugify' is known for its simplicity and ease of use.
limax
The 'limax' package is a library for generating slugs with a focus on handling various languages and special characters. It provides more advanced options for transliteration and custom replacements compared to 'speakingurl'. 'limax' is suitable for applications that require robust handling of multilingual input.
slug
The 'slug' package is a lightweight library for creating slugs from strings. It offers basic features such as custom separators and transliteration. While it may not have as many advanced options as 'speakingurl', it is a good choice for simple slug generation tasks.
Installation
npm install --save @types/speakingurl
Summary
This package contains type definitions for speakingurl (http://pid.github.io/speakingurl/).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/speakingurl.
interface Dictionary<T> {
[x: string]: T;
}
interface SpeakingURLOptions {
separator?: string | undefined;
lang?: string|boolean | undefined;
symbols?: boolean | undefined;
maintainCase?: boolean | undefined;
titleCase?: string[]|boolean | undefined;
truncate?: number | undefined;
uric?: boolean | undefined;
uricNoSlash?: boolean | undefined;
mark?: boolean | undefined;
custom?: string[]|Dictionary<string> | undefined;
}
declare function getSlug(input: string, options?: SpeakingURLOptions|string): string;
declare namespace getSlug {
function createSlug(options: SpeakingURLOptions): (input: string) => string;
}
export = getSlug;
Additional Details
- Last updated: Tue, 06 Jul 2021 16:35:09 GMT
- Dependencies: none
- Global values: none
Credits
These definitions were written by Zlatko Andonovski.