Giter Club home page Giter Club logo

slugify's Introduction

Slugify 🔤

Swift Version Swift Version Vapor Version Circle CI codebeat badge codecov Readme Score GitHub license

📦 Installation

This package is independent of Vapor and can be used for all Swift projects up til version 4.2

Update your Package.swift file.

.package(url: "https://github.com/nodes-vapor/slugify", from: "2.0.0")

Getting started 🚀

import Slugify
print("My test URL æøå".slugify())

The above code will print: my-test-url-aeoa

🏆 Credits

This package is developed and maintained by the Vapor team at Nodes. The package owner for this project is John.

📄 License

This package is open-sourced software licensed under the MIT license

slugify's People

Contributors

brettrtoomey avatar casperhr avatar heidipuk avatar joscdk avatar steffendsommer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slugify's Issues

Optimization

If that cocoa function works on Linux it should be fine for now.

I think the comparisons will want to work with byte types as they're faster to iterate over and maybe use a hashed collection to do the comparisons as they'll be a lot faster than iterating over that giant data structure for each byte

The `replaceChars` function is extremely brittle

The dictionary that contains a mapping of strings to an array of strings is extremely brittle. It should be re-written as a switch statement. Creating a switch statement also adds compile time checking that is lacking from this implementation.

// This throws errors because the original mapping has collisions.

       switch char {
        case "°", "", "۰": return "0"
        case "¹", "", "۱": return "1"
        case "²", "", "۲": return "2"
        case "³", "", "۳": return "3"
        case "", "", "۴", "٤": return "4"
        case "", "", "۵", "٥": return "5"
        case "", "", "۶", "٦": return "6"
        case "", "", "۷": return "7"
        case "", "", "۸": return "8"
        case "", "", "۹": return "9"
        case "à", "á", "", "ã", "", "ă", "", "", "", "", "", "â", "", "", "", "", "", "ā", "ą", "å", "α", "ά", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "ά", "", "", "", "", "", "", "", "а", "أ", "", "", "", "ǻ", "ǎ", "ª", "", "", "ا": return "a"
        case "б", "β", "Ъ", "Ь", "ب", "", "": return "b"
        case "ç", "ć", "č", "ĉ", "ċ": return "c"
        case "ď", "ð", "đ", "ƌ", "ȡ", "ɖ", "ɗ", "", "", "", "д", "δ", "د", "ض", "", "", "": return "d"
        case "é", "è", "", "", "", "ê", "ế", "", "", "", "", "ë", "ē", "ę", "ě", "ĕ", "ė", "ε", "έ", "", "", "", "", "", "", "", "έ", "е", "ё", "э", "є", "ə", "", "", "", "", "", "إ", "ئ": return "e"
        case "ф", "φ", "ف", "ƒ", "": return "f"
        case "ĝ", "ğ", "ġ", "ģ", "г", "ґ", "γ", "", "", "گ": return "g"
        case "ĥ", "ħ", "η", "ή", "ح", "ه", "", "", "": return "h"
        case "í", "ì", "", "ĩ", "", "î", "ï", "ī", "ĭ", "į", "ı", "ι", "ί", "ϊ", "ΐ", "", "", "", "", "", "", "", "", "", "ί", "", "", "", "ΐ", "", "", "і", "ї", "и", "", "", "", "ည်", "ǐ", "", "": return "i"
        case "ĵ", "ј", "Ј", "", "ج": return "j"
        case "ķ", "ĸ", "к", "κ", "Ķ", "ق", "ك", "က", "", "", "ک": return "k"
        case "ł", "ľ", "ĺ", "ļ", "ŀ", "л", "λ", "ل", "", "": return "l"
        case "м", "μ", "م", "", "": return "m"
        case "ñ", "ń", "ň", "ņ", "ʼn", "ŋ", "ν", "н", "ن", "", "": return "n"
        case "ó", "ò", "", "õ", "", "ô", "", "", "", "", "", "ơ", "", "", "", "", "", "ø", "ō", "ő", "ŏ", "ο", "", "", "", "", "", "", "", "ό", "о", "و", "θ", "ို", "ǒ", "ǿ", "º", "", "": return "o"
        case "п", "π", "", "", "پ": return "p"
        case "": return "q"
        case "ŕ", "ř", "ŗ", "р", "ρ", "ر", "": return "r"
        case "ś", "š", "ş", "с", "σ", "ș", "ς", "س", "ص", "", "ſ", "": return "s"
        case "ť", "ţ", "т", "τ", "ț", "ت", "ط", "", "", "ŧ", "", "": return "t"
        case "ú", "ù", "", "ũ", "", "ư", "", "", "", "", "", "û", "ū", "ů", "ű", "ŭ", "ų", "µ", "у", "", "", "", "ǔ", "ǖ", "ǘ", "ǚ", "ǜ", "", "": return "u"
        case "в", "", "ϐ": return "v"
        case "ŵ", "ω", "ώ", "", "": return "w"
        case "χ", "ξ": return "x"
        case "ý", "", "", "", "", "ÿ", "ŷ", "й", "ы", "υ", "ϋ", "ύ", "ΰ", "ي", "": return "y"
        case "ź", "ž", "ż", "з", "ζ", "ز", "", "": return "z"
        case "ع", "", "آ": return "aa"
        case "ä", "æ", "ǽ": return "ae"
        case "": return "ai"
        case "@": return "at"
        case "ч", "", "", "چ": return "ch"
        case "ђ", "đ": return "dj"
        case "џ", "": return "dz"
        case "": return "ei"
        case "غ", "": return "gh"
        case "": return "ii"
        case "ij": return "ij"
        case "х", "خ", "": return "kh"
        case "љ": return "lj"
        case "њ": return "nj"
        case "ö", "œ", "ؤ": return "oe"
        case "": return "oi"
        case "ψ": return "ps"
        case "ш", "", "ش": return "sh"
        case "ß": return "ss"
        case "ŝ": return "sx"
        case "þ", "ϑ", "ث", "ذ", "ظ": return "th"
        case "ц", "", "": return "ts"
        case "ü": return "ue"
        case "": return "uu"
        case "я": return "ya"
        case "ю": return "yu"
        case "ж", "", "ژ": return "zh"
        case "©": return "(c"
        case "Á", "À", "", "Ã", "", "Ă", "", "", "", "", "", "Â", "", "", "", "", "", "Å", "Ā", "Ą", "Α", "Ά", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Ά", "", "А", "Ǻ", "Ǎ": return "A"
        case "Б", "Β", "": return "B"
        case "Ç", "Ć", "Č", "Ĉ", "Ċ": return "C"
        case "Ď", "Ð", "Đ", "Ɖ", "Ɗ", "Ƌ", "", "", "Д", "Δ": return "D"
        case "É", "È", "", "", "", "Ê", "", "", "", "", "", "Ë", "Ē", "Ę", "Ě", "Ĕ", "Ė", "Ε", "Έ", "", "", "", "", "", "", "Έ", "", "Е", "Ё", "Э", "Є", "Ə": return "E"
        case "Ф", "Φ": return "F"
        case "Ğ", "Ġ", "Ģ", "Г", "Ґ", "Γ": return "G"
        case "Η", "Ή", "Ħ": return "H"
        case "Í", "Ì", "", "Ĩ", "", "Î", "Ï", "Ī", "Ĭ", "Į", "İ", "Ι", "Ί", "Ϊ", "", "", "", "", "", "", "Ἷ", "", "", "", "Ί", "И", "І", "Ї", "Ǐ", "ϒ": return "I"
        case "К", "Κ": return "K"
        case "Ĺ", "Ł", "Л", "Λ", "Ļ", "Ľ", "Ŀ", "": return "L"
        case "М", "Μ": return "M"
        case "Ń", "Ñ", "Ň", "Ņ", "Ŋ", "Н", "Ν": return "N"
        case "Ó", "Ò", "", "Õ", "", "Ô", "", "", "", "", "", "Ơ", "", "", "", "", "", "Ø", "Ō", "Ő", "Ŏ", "Ο", "Ό", "", "", "", "", "", "", "", "Ό", "О", "Θ", "Ө", "Ǒ", "Ǿ": return "O"
        case "П", "Π": return "P"
        case "Ř", "Ŕ", "Р", "Ρ", "Ŗ": return "R"
        case "Ş", "Ŝ", "Ș", "Š", "Ś", "С", "Σ": return "S"
        case "Ť", "Ţ", "Ŧ", "Ț", "Т", "Τ": return "T"
        case "Ú", "Ù", "", "Ũ", "", "Ư", "", "", "", "", "", "Û", "Ū", "Ů", "Ű", "Ŭ", "Ų", "У", "Ǔ", "Ǖ", "Ǘ", "Ǚ", "Ǜ": return "U"
        case "В": return "V"
        case "Ω", "Ώ", "Ŵ": return "W"
        case "Χ", "Ξ": return "X"
        case "Ý", "", "", "", "", "Ÿ", "", "", "", "Ύ", "Ы", "Й", "Υ", "Ϋ", "Ŷ": return "Y"
        case "Ź", "Ž", "Ż", "З", "Ζ": return "Z"
        case "Ä", "Æ", "Ǽ": return "AE"
        case "Ч": return "CH"
        case "Ђ": return "DJ"
        case "Џ": return "DZ"
        case "Ĝ": return "GX"
        case "Ĥ": return "HX"
        case "IJ": return "IJ"
        case "Ĵ": return "JX"
        case "Х": return "KH"
        case "Љ": return "LJ"
        case "Њ": return "NJ"
        case "Ö", "Œ": return "OE"
        case "Ψ": return "PS"
        case "Ш": return "SH"
        case "": return "SS"
        case "Þ": return "TH"
        case "Ц": return "TS"
        case "Ü": return "UE"
        case "Я": return "YA"
        case "Ю": return "YU"
        case "Ж": return "ZH"
        case " ": return "-"
        default: return char
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.