npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sluggo

v1.0.0

Published

High-speed, unicode-aware, browser-friendly slug generator

Downloads

4,084

Readme

sluggo

sluggo is a slug generator that:

  • Understands Unicode
  • Runs fast (much, much faster than a RegExp solution)
  • Replaces all runs of punctuation (in any language), control characters, whitespace, etc. with single dashes, with no leading or trailing dashes
  • Allows you to let one punctuation character through if you wish, such as a slash for pathnames
  • Allows you to change the separator character
  • Is small enough to include in your browser javascript (<10K), even with the Unicode data

Installation

npm install sluggo

Usage

var sluggo = require('sluggo');

var s = sluggo('@ monkey\'s are elab؉؉orate fools##');
console.log(s);

Outputs:

monkey-s-are-elab-orate-fools

Options

separator

Change the string separator by passing a string (usually one character) to separator.

const sluggo = require('sluggo');

const s = sluggo('monkey\'s are elaborate fools', {
  separator: ','
});
console.log(s);

Outputs:

monkey,s,are,elaborate,fools

allow

Set a single-character string to allow in returned strings. Otherwise all punctuation characters are replaced by the separator.

const sluggo = require('sluggo');

const s = sluggo('@ monkey\'s are elab؉؉orate fools##', {
  allow: '؉'
});
console.log(s);

Outputs:

monkey-s-are-elab؉؉orate-fools

In the Browser

You just want sluggo.js. Add that file to your frontend javascript world.

Now you can call the sluggo() function anywhere.

You do NOT need generator.js, which we will use when the next version of Unicode comes out to update this module.

About ApostropheCMS

sluggo was created at P'unk Avenue for use in ApostropheCMS, an open-source content management system built on Node.js. If you like sanitize-html you should definitely check out Apostrophe.

Support

Feel free to open issues on Github.

Changelog

1.0.0 - 2023-05-03

  • Accepts an array of exceptions in the allow options property while still accepting a string. Declared stable.

0.3.1 - 2021-04-23

  • Accepts the empty string as a legitimate value for def, as was always intended, rather than forcing none in that situation. If def is not set at all none is still the fallback default.

0.3.0 - 2020-01-27

  • Updates package.json with new metadata
  • Updates README.

0.2.0

Whoops, the classic apostrophe slugify method accepted allow, not allowed. We just released this today, so I've switched to allow in sluggo as well. However I did bump to 0.2.0 to remain faithful to the semver standard.

0.1.2

Converts to lowercase properly.

0.1.1

Packaged correctly to work in either node or the browser.

0.1.0

Initial release.