Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a (painfully minimal) web playground #350

Merged
merged 1 commit into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
CODE_OF_CONDUCT.md
benchmark/
coverage/
index.html
test/
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@ If you are using TypeScript you can install the accompanying types
npm install --save-dev @types/slug
```

## Differences between `slug` and `slugify` packages

Here are some key differences between this package and [`slugify`](https://github.com/simov/slugify).

- **Defaults:** `slug` has the `lower` option enabled by default, lowercasing all slugs
(`'On SALE'` becomes `'on-sale'`).
`slugify` has the `lower` option disabled by default (`'On SALE'` becomes `'On-SALE'`).
- **Symbols:** `slug` removes unrecognized symbols (`'$100'` becomes `'100'`, `'<5'` becomes `'5'`, etc.).
`slugify` maps them to words (`'$100'` becomes `'dollar100'`, `'<5'` becomes `'less5'`, etc.).
- **Empty Output:** `slug` will return a short, predictable hash (`' '` becomes `'icag'` and `'🎉'` becomes `'8joiq'`).
`slugify` will return an empty string (`' '` and `'🎉'` become `''`).
- **Stability:** `slug` is planning [a new release](https://github.com/Trott/slug/blob/beta/CHANGELOG.md) that will drop support for CommonJS
and only support ESM modules.
`slugify` will continue to support CommonJS and is likely to remain stable for the foreseeable future.

## Example

```javascript
Expand Down Expand Up @@ -124,3 +109,23 @@ slug.defaults.modes['pretty'] = {
fallback: true
};
```

## Differences between `slug` and `slugify` packages

Here are some key differences between this package and [`slugify`](https://github.com/simov/slugify).

- **Defaults:** `slug` has the `lower` option enabled by default, lowercasing all slugs
(`'On SALE'` becomes `'on-sale'`).
`slugify` has the `lower` option disabled by default (`'On SALE'` becomes `'On-SALE'`).
- **Symbols:** `slug` removes unrecognized symbols (`'$100'` becomes `'100'`, `'<5'` becomes `'5'`, etc.).
`slugify` maps them to words (`'$100'` becomes `'dollar100'`, `'<5'` becomes `'less5'`, etc.).
- **Empty Output:** `slug` will return a short, predictable hash (`' '` becomes `'icag'` and `'🎉'` becomes `'8joiq'`).
`slugify` will return an empty string (`' '` and `'🎉'` become `''`).
- **Stability:** `slug` is planning [a new release](https://github.com/Trott/slug/blob/beta/CHANGELOG.md) that will drop support for CommonJS
and only support ESM modules.
`slugify` will continue to support CommonJS and is likely to remain stable for the foreseeable future.

## Playground

A (painfully minimal) web playground is available at https://trott.github.io/slug/. It doesn't allow you to specify options, so it's utility is
minimal. Pull requests welcome to add the ability to specify options.
22 changes: 22 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>slug playground</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<form>
<input type="text" id="slug" />
<input type="submit" value="Slug it" onclick="slugIt(); return false;"></input>
</form>
<p>Result: <span id="slugOutput"></span></p>
<script src="./slug.js"></script>
<script>
function slugIt() {
const output = slug(document.getElementById("slug").value);
document.getElementById("slugOutput").innerHTML = output;
}
</script>
</body>
</html>