### Mix Dependency Installation Source: https://github.com/jayjun/slugify/blob/master/README.md Shows how to add the slugify package to your Elixir project's dependencies. ```elixir def deps do [ {:slugify, "~> 1.3"} ] end ``` -------------------------------- ### Custom Separator Example Source: https://github.com/jayjun/slugify/blob/master/README.md Replaces default hyphens with a specified character, like a period. ```elixir Slug.slugify("John Doe", separator: ?.) "john.doe" ``` -------------------------------- ### Transliterate Bengali Script Source: https://context7.com/jayjun/slugify/llms.txt This example demonstrates transliterating Bengali script into Latin characters using Slugify. ```elixir # Bengali script Slug.slugify("ওহে বিশ্ব") # => "ohe-bishb" ``` -------------------------------- ### Transliterate Tamil Script Source: https://context7.com/jayjun/slugify/llms.txt This example shows how Slugify transliterates Tamil script into Latin characters. ```elixir # Tamil script Slug.slugify("வணக்கம், உலகம்") # => "vnnkkm-ulkm" ``` -------------------------------- ### Transliterate Amharic (Ethiopic) Source: https://context7.com/jayjun/slugify/llms.txt This example shows transliteration of Amharic text in the Ethiopic script into Latin characters. ```elixir # Amharic (Ethiopic script) Slug.slugify("ሰላም ልዑል") # => "salaame-leule" ``` -------------------------------- ### Combine Ignore with Lowercase Option Source: https://context7.com/jayjun/slugify/llms.txt The `ignore` option can be combined with other options like `lowercase`. This example ignores an exclamation mark and keeps the original casing. ```elixir Slug.slugify("Hello, World!", ignore: "!", lowercase: false) # => "Hello-World!" ``` -------------------------------- ### Ignore Specific Chinese Characters Source: https://context7.com/jayjun/slugify/llms.txt Use the `ignore` option to specify characters that should not be transliterated. This example shows ignoring specific Chinese characters. ```elixir Slug.slugify("你好,世界", ignore: "好界") # => "ni-好-shi-界" ``` -------------------------------- ### Basic Slugification Source: https://github.com/jayjun/slugify/blob/master/README.md Use for simple string to slug conversion. Handles Unicode transliteration and punctuation stripping. ```elixir Slug.slugify("Hello, World!") "hello-world" ``` ```elixir Slug.slugify("你好,世界") "nihaoshijie" ``` -------------------------------- ### Configure custom separators Source: https://context7.com/jayjun/slugify/llms.txt Use the :separator option to define how words are joined. Leading, trailing, and repeated separators are automatically trimmed. ```elixir # Use underscore as separator (codepoint) Slug.slugify("Hello, World!", separator: ?_) # => "hello_world" # Use custom string as separator Slug.slugify("Wide open spaces", separator: "%20") # => "wide%20open%20spaces" # Use dot as separator Slug.slugify("John Doe", separator: ?.) # => "john.doe" # No separator - concatenate all words Slug.slugify("Madam, I'm Adam", separator: "") # => "madamimadam" # Existing separators in input are normalized Slug.slugify("--Hello--World--") # => "hello-world" Slug.slugify("__HELLO__WORLD__", separator: ?_) # => "hello_world" ``` -------------------------------- ### Generate slugs with Slug.slugify/2 Source: https://context7.com/jayjun/slugify/llms.txt Convert strings into URL-friendly slugs. Returns nil if the input cannot be transliterated. ```elixir # Basic usage - converts to lowercase with hyphen separators Slug.slugify("Hello, World!") # => "hello-world" # Handles multiple whitespaces and special characters Slug.slugify(" Hello, World! ") # => "hello-world" # Chinese characters are transliterated to pinyin Slug.slugify("你好,世界") # => "ni-hao-shi-jie" # Japanese hiragana Slug.slugify("こんにちは") # => "konnitiha" # Korean characters Slug.slugify("안녕하세요, 세계") # => "annyeonghaseyo-segye" # Russian Cyrillic Slug.slugify("Привет мир") # => "privet-mir" # Greek letters Slug.slugify("Γεια σας, τον κόσμο") # => "geia-sas-ton-kosmo" # Arabic script Slug.slugify("مرحبا بالعالم") # => "mrhb-blaalm" # Vietnamese with diacritics Slug.slugify("Chào thế giới") # => "chao-the-gioi" # Returns nil for non-translatable input (emoji only) Slug.slugify("🙅‍") # => nil # Check for nil when a valid slug is required case Slug.slugify(user_input) do nil -> {:error, "Cannot create slug from input"} slug -> {:ok, slug} end ``` -------------------------------- ### Handling Unslugifiable Characters Source: https://github.com/jayjun/slugify/blob/master/README.md Demonstrates that characters without a transliteration will result in nil. Check for nil if a valid slug is crucial. ```elixir # Remember to check for nil if a valid slug is important! Slug.slugify("🙅‍") nil ``` -------------------------------- ### Transliterate Hebrew Script Source: https://context7.com/jayjun/slugify/llms.txt Demonstrates transliteration of Hebrew script into Latin characters. ```elixir # Hebrew script Slug.slugify("שלום, עולם") # => "shlvm-vlm" ``` -------------------------------- ### Customizing Separator and Case Source: https://github.com/jayjun/slugify/blob/master/README.md Allows modification of the separator character and forces lowercase output. ```elixir Slug.slugify("Wikipedia case", separator: ?_, lowercase: false) "Wikipedia_case" ``` -------------------------------- ### Stripping Leading/Trailing Whitespace Source: https://github.com/jayjun/slugify/blob/master/README.md Shows how the default separator handles extra whitespace. ```elixir Slug.slugify(" How are you? ") "how-are-you" ``` -------------------------------- ### Control slug casing Source: https://context7.com/jayjun/slugify/llms.txt Use the :lowercase option to toggle between forced lowercase and preserving original capitalization. ```elixir # Default behavior - lowercase Slug.slugify("StUdLy CaPs") # => "studly-caps" # Preserve original capitalization Slug.slugify("StUdLy CaPs", lowercase: false) # => "StUdLy-CaPs" # Useful for Wikipedia-style URLs Slug.slugify("Wikipedia case", separator: ?_, lowercase: false) # => "Wikipedia_case" # Preserve case with no separator Slug.slugify("CamelCaseExample", separator: "", lowercase: false) # => "CamelCaseExample" ``` -------------------------------- ### Slug.slugify/2 Source: https://context7.com/jayjun/slugify/llms.txt The primary function for converting strings into URL-friendly slugs with support for various configuration options. ```APIDOC ## Slug.slugify(input, options) ### Description Converts a string into a URL-friendly slug. Returns the slug string on success or nil if the input cannot be converted. ### Parameters #### Arguments - **input** (String) - Required - The string to be converted. - **options** (Keyword List) - Optional - Configuration options for the slug generation. #### Options - **separator** (String/Integer) - Optional - The character or string used to replace whitespace. Defaults to '-'. - **lowercase** (Boolean) - Optional - Whether to force the output to lowercase. Defaults to true. - **truncate** (Integer) - Optional - Limits the slug length to the specified number of characters, trimmed to the nearest word boundary. - **ignore** (String/List) - Optional - Specific characters or list of strings to preserve from transliteration. ### Request Example Slug.slugify("Hello, World!", separator: ?_, lowercase: false) ### Response - **Result** (String/nil) - The generated slug or nil if conversion fails. ``` -------------------------------- ### Transliterate Khmer Script Source: https://context7.com/jayjun/slugify/llms.txt Demonstrates transliteration of Khmer script into Latin characters. ```elixir # Khmer script Slug.slugify("សួស្តី​ពិភពលោក") # => "suastii-bibhblook" ``` -------------------------------- ### Transliterate Hindi (Devanagari) Source: https://context7.com/jayjun/slugify/llms.txt Slugify supports transliteration for Hindi using the Devanagari script into Latin characters. ```elixir # Hindi (Devanagari script) Slug.slugify("नमस्ते दुनिया") # => "nmste-duniyaa" ``` -------------------------------- ### Transliterate Lao Script Source: https://context7.com/jayjun/slugify/llms.txt Slugify supports transliteration for Lao script into Latin characters. ```elixir # Lao script Slug.slugify("ສະ​ບາຍ​ດີ​ຊາວ​ໂລກ") # => "sa-baany-dii-saaw-olk" ``` -------------------------------- ### Empty Separator Source: https://github.com/jayjun/slugify/blob/master/README.md Removes all separators by passing an empty string. ```elixir Slug.slugify("Madam, I'm Adam", separator: "") "madamimadam" ``` -------------------------------- ### Transliterate Armenian Script Source: https://context7.com/jayjun/slugify/llms.txt Slugify handles transliteration for Armenian script, converting it to Latin characters. ```elixir # Armenian script Slug.slugify("Բdelays աdelays") # => "barew-ashkharh" ``` -------------------------------- ### Transliterate Gujarati Script Source: https://context7.com/jayjun/slugify/llms.txt Slugify supports transliteration for Gujarati script into Latin characters. ```elixir # Gujarati script Slug.slugify("હેલો, વિશ્વ") # => "helo-vishv" ``` -------------------------------- ### Transliterate Burmese Script Source: https://context7.com/jayjun/slugify/llms.txt Slugify transliterates Burmese script into Latin characters. ```elixir # Burmese script Slug.slugify("မင်္ဂလာပါကမ္ဘာလောက") # => "mngglaapkmbhaaleaak" ``` -------------------------------- ### Preserving Case Source: https://github.com/jayjun/slugify/blob/master/README.md Disables automatic lowercasing by setting `lowercase: false`. ```elixir Slug.slugify("StUdLy CaPs", lowercase: false) "StUdLy-CaPs" ``` -------------------------------- ### Truncate slug length Source: https://context7.com/jayjun/slugify/llms.txt Use the :truncate option to limit the length of the slug, ensuring it stops at a word boundary. ```elixir # Truncate to 7 characters - stops at word boundary Slug.slugify("Call Me Maybe", truncate: 7) # => "call-me" # Truncate to 10 characters - still stops at "call-me" (7 chars) # because "call-me-ma" (10) would break "maybe" Slug.slugify("Call Me Maybe", truncate: 10) # => "call-me" # Full slug when under limit Slug.slugify("It's a small world", truncate: 20) # => "its-a-small-world" # Truncate with exact boundary match Slug.slugify("It's a small world", truncate: 5) # => "its-a" # Returns nil if truncate is too short for any word Slug.slugify("It's a small world", truncate: 2) # => nil # Zero or negative truncate returns nil Slug.slugify("Hello World", truncate: 0) # => nil ``` -------------------------------- ### Transliterate Punjabi (Gurmukhi) Source: https://context7.com/jayjun/slugify/llms.txt Slugify transliterates Punjabi text written in the Gurmukhi script into Latin characters. ```elixir # Punjabi (Gurmukhi script) Slug.slugify("ਸਤਿ ਸ੍ਰੀ ਅਕਾਲ ਦੁਨਿਆ") # => "sti-srii-akaal-duniaa" ``` -------------------------------- ### Preserve Only Comma Source: https://context7.com/jayjun/slugify/llms.txt When only specific punctuation needs to be preserved, provide a single character string to the `ignore` option. ```elixir Slug.slugify("test,is a.test", ignore: ",") # => "test,is-a-test" ``` -------------------------------- ### Transliterate Thai Script Source: https://context7.com/jayjun/slugify/llms.txt Slugify can transliterate Thai script into Latin characters, preserving the phonetic representation. ```elixir # Thai script Slug.slugify("สวัสดีชาวโลก") # => "swasdiichaawolk" ``` -------------------------------- ### Truncating Slugs Source: https://github.com/jayjun/slugify/blob/master/README.md Limits slug length, trimming to the nearest word boundary defined by separators. ```elixir Slug.slugify("Call Me Maybe", truncate: 7) "call-me" ``` ```elixir Slug.slugify("Call Me Maybe", truncate: 10) "call-me" ``` -------------------------------- ### Ignore specific characters Source: https://context7.com/jayjun/slugify/llms.txt Use the :ignore option to prevent specific characters from being transliterated. ```elixir # Ignore specific Chinese characters (as list) Slug.slugify("你好,世界", ignore: ["你", "好"]) # => "你好-shi-jie" ``` -------------------------------- ### Ignoring Specific Characters Source: https://github.com/jayjun/slugify/blob/master/README.md Prevents transformation of specified characters by passing them in the `ignore` option. ```elixir Slug.slugify("你好,世界", ignore: "你好") "你好shijie" ``` ```elixir Slug.slugify("你好,世界", ignore: ["你", "好"]) "你好shijie" ``` -------------------------------- ### Preserve Punctuation Marks Source: https://context7.com/jayjun/slugify/llms.txt The `ignore` option can also preserve punctuation marks. Provide a list of punctuation characters to keep them in the slug. ```elixir Slug.slugify("test,is a.test", ignore: [",", "."]) # => "test,is-a.test" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.