You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

aslug

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aslug

A lossless slug that preserves uniqueness

0.5.2
latest
Source
npmnpm
Version published
Weekly downloads
1
-80%
Maintainers
0
Weekly downloads
 
Created
Source

aslug

Version Types License

A lossless slug that preserves uniqueness.

Install

npm install aslug

Features

An example use case for aslug would be a set of ids that have to be made safe for some character set, while maintaining readability and ensuring they won't conflict with other valid ids. Hence, aslug:

  • Produces a readable, lossless, encoding.
  • Includes a decoder to recover the original string.
  • Allows the character set to be modified via options.

Usage

new Slug(alphabet?: string | null, options?: Slug.Options)

The Slug class optionally takes an alphabet string and an options object.

  • alphabet defaults to: '0123456789ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-'
  • options fields include:
    • A separator to be used between the readable string and the payload. Defaults to '.'.
    • A map function to determine the strategy to use when replacing characters with a string within alphabet -otherwise an empty string. It can be used to remove diacritics, leave empty, or any other alternative. Defaults to replacing characters for their ASCII equivalent, if in alphabet.

Simple example

import { Slug } from 'aslug';

const slug = new Slug();

slug.encode('string w/ special chars'); // string-w-special-chars.EjhdB6y8T2PsDU0e6zUv
slug.decode('string-w-special-chars.EjhdB6y8T2PsDU0e6zUv'); // string w/ special chars

Keywords

slug

FAQs

Package last updated on 29 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts