getSlug 

Converts a string into a URL-friendly slug. The input is trimmed, split into words on whitespace and any existing -/_ characters, and joined back together with the chosen separator. Letters are kept, while non-Latin letters, digits and special characters are gated by the options below.
The behavior is intentionally simple and predictable:
- The result is lowercased by default (or uppercased when
uppercaseis set). - Only whitespace and
-/_act as word boundaries. Other dropped characters (such as@or.) simply disappear, so the characters around them merge into a single word. - Non-Latin letters (for example Korean) are kept as-is by default because modern browsers can display them in a URL. Set
includeNonLatintofalseto keep only ASCII letters. - Digits are included by default; special characters are excluded by default. When
includeSpecialis enabled, each special character is percent-encoded (for example&becomes%26). - When
baseUrlis provided and the slug is not empty, the slug is appended to it to form a full URL. A trailing slash on the base URL is normalized away. - An empty input (or one that produces no slug) returns an empty string, even when a
baseUrlis set.
Parameters
| Name | Type | Required | Default |
|---|---|---|---|
text | string | ● | – |
options![]() named | object | – | – |

named parameters are passed as named parameters in Dart and keyword arguments in Python.
options| Name | Type | Required | Default |
|---|---|---|---|
separator | string | – | '-' |
| The word separator. | |||
includeNumbers | boolean | – | true |
| Keep digits. | |||
includeSpecial | boolean | – | false |
| Percent-encode and keep special characters. | |||
uppercase | boolean | – | false |
| Output in uppercase instead of lowercase. | |||
includeNonLatin | boolean | – | true |
| Keep non-Latin letters such as Korean. | |||
baseUrl | string | – | '' |
| When set, prepend this base URL to build a full URL. | |||
Returns
string
Examples
javascript
getSlug('Hello World'); // Returns 'hello-world'
getSlug('안녕 하세요 반갑습니다'); // Returns '안녕-하세요-반갑습니다'
getSlug('Product #123 (2024)'); // Returns 'product-123-2024'
getSlug('Hello World', { separator: '_', uppercase: true }); // Returns 'HELLO_WORLD'
getSlug('Café & Restaurant', { includeSpecial: true }); // Returns 'café-%26-restaurant'
getSlug('Hello 안녕', { includeNonLatin: false }); // Returns 'hello'
getSlug('Hello World', { baseUrl: 'https://example.com/blog' }); // Returns 'https://example.com/blog/hello-world'dart
getSlug('Hello World'); // Returns 'hello-world'
getSlug('안녕 하세요 반갑습니다'); // Returns '안녕-하세요-반갑습니다'
getSlug('Product #123 (2024)'); // Returns 'product-123-2024'
getSlug('Hello World', separator: '_', uppercase: true); // Returns 'HELLO_WORLD'
getSlug('Café & Restaurant', includeSpecial: true); // Returns 'café-%26-restaurant'
getSlug('Hello 안녕', includeNonLatin: false); // Returns 'hello'
getSlug('Hello World', baseUrl: 'https://example.com/blog'); // Returns 'https://example.com/blog/hello-world'python
getSlug('Hello World') # Returns 'hello-world'
getSlug('안녕 하세요 반갑습니다') # Returns '안녕-하세요-반갑습니다'
getSlug('Product #123 (2024)') # Returns 'product-123-2024'
getSlug('Hello World', separator='_', uppercase=True) # Returns 'HELLO_WORLD'
getSlug('Café & Restaurant', includeSpecial=True) # Returns 'café-%26-restaurant'
getSlug('Hello 안녕', includeNonLatin=False) # Returns 'hello'
getSlug('Hello World', baseUrl='https://example.com/blog') # Returns 'https://example.com/blog/hello-world'