1.4.0 • Published 4 years ago
justintime50-slugify v1.4.0
Slugify
Slugify a string. Perfect for URLs!
Install
npm i justintime50-slugify
NOTE: This project requires jQuery for an HTML implementation.
Usage
Website
See Slugify in action here: https://justintime50.github.io/slugify.
Javascript Example
Pass in text and slug the result in console.
const slugify = require("justintime50-slugify");
console.log(slugify("Here is my FIRST -- Slug!", { lowercase: true }));
//=> 'here-is-my-first-slug'
Options
lowercase
: true/false (default: false)
HTML Form Example
Transform a blog title into a slug to easily create our article URL.
<label for="title">Title</label>
<input type="text" class="title" name="title">
<label for="slug">Slug (URL)</label>
<input type="text" class="slug" name="slug">
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="path/to/slugify/index.js"></script>
<script>
// We slugify whatever is typed into the "title" field into the "slug" field in real time.
slugifyField(".title", ".slug");
</script>
Development
# Lint the project
npx eslint index.js
# Test the project
npm run test
Attributions
Based on snippets from mathewbyrne and sindresorhus.