Coder Social home page Coder Social logo

danieldietrich / slugify Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 590 KB

Turns strings into user-friendly and search engine-friendly URL slugs.

License: MIT License

JavaScript 24.28% TypeScript 75.72%
slugify slug url uri ascii latin-1 roman unicode typescript

slugify's Introduction

npm versionvulnerabilitiesminzipped size   buildcoverage   Platform   Sponsordonatelicense   Follow

slugify

Turns strings into user-friendly and search engine-friendly URL slugs.

Slugify uses a dictionary to translate certain glyphs to the alphabet a-z A-Z 0-9. Beside whitespace, the characters !#$%&()*+,-./:;=?@[\]_|~ are considered as space. All other characters are removed, especially single ' and double " quotes. Finally, the words are joined, by default with hyphen '-'.

A highlight of this solution is the readability of slugs. Only words and a single separator type are used.

Installation

npm i @danieldietrich/slugify

Usage

The module supports ES6 import and CommonJS require style.

import slugify from '@danieldietrich/slugify';

// I-love-it
slugify('I ♥ it!');

// I_love_it
slugify('I ♥ it!', '_');

// cafebab3-gmail-com
slugify('[email protected]');

// dos-and-donts
slugify("Do's and Don'ts").toLowerCase();

Copyright © 2020 by Daniel Dietrich. Released under the MIT license.

slugify's People

Contributors

danieldietrich avatar dependabot-preview[bot] avatar dependabot[bot] avatar github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

slugify's Issues

Design decision required: consider adding an alphabet option

The purpose of slugify is to provide human readable urls consisting of words.

One could argue that that urls contain non-alphabet chars, like

https://npmjs.com/~danieldietrich
https://www.npmjs.com/package/@danieldietrich/slugify

But ~danieldietrich and @danieldietrich are fixed names. We are not allowed to change any character!

The same applies to email addresses in urls, like

https://my-domain.com/[email protected]/

The purpose of slugify is to provide stable, human readable urls that contain only words of alphabet characters.

Therefore I will close this issue.

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.