
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
unique-slug
Advanced tools
Generate a unique character string suitible for use in files and URLs.
The unique-slug npm package is a simple utility for generating unique, random slugs that can be used for file names, URLs, unique identifiers, etc. It uses a combination of the current timestamp and a random string to ensure uniqueness.
Generate a unique slug
This feature generates a unique slug that can be used where a unique string is needed, such as for a unique filename or URL component.
const uniqueSlug = require('unique-slug');
const slug = uniqueSlug();
console.log(slug);
Generate a unique slug with a prefix
This feature allows for the generation of a unique slug with a specified prefix, which can be useful for categorizing or identifying the type of resource the slug represents.
const uniqueSlug = require('unique-slug');
const prefix = 'img_';
const slugWithPrefix = uniqueSlug(prefix);
console.log(slugWithPrefix);
Shortid is a package that generates short, non-sequential, URL-friendly unique ids. Unlike unique-slug, which combines a timestamp with a random string, shortid generates shorter identifiers that are easier to read and type. It's often used for URL shorteners or anywhere a shorter identifier is beneficial.
UUID is a package that generates RFC-compliant UUIDs (Universally Unique Identifiers). It provides different versions of UUIDs, such as v1 (timestamp-based) and v4 (random). While unique-slug generates a unique string based on timestamp and randomness, UUID provides a standardized format for unique identifiers, which can be important for interoperability and when a universally accepted unique identifier format is required.
NanoID is a tiny, secure URL-friendly unique string ID generator. It is similar to unique-slug in that it generates unique strings, but it offers a customizable alphabet and size, allowing for a wider range of possible IDs and control over the length of the generated ID. NanoID claims to be a more secure and compact alternative to UUID.
Generate a unique character string suitible for use in files and URLs.
var uniqueSlug = require('unique-slug')
var randomSlug = uniqueSlug()
var fileSlug = uniqueSlug('/etc/passwd')
If str is passed in then the return value will be its murmur hash in hex.
If str is not passed in, it will be 4 randomly generated bytes converted into 8 hexadecimal characters.
5.0.0 (2024-09-24)
unique-slug
now supports node ^18.17.0 || >=20.5.0
1881f90
#97 run template-oss-apply (@hashtagchris)0a6131f
#96 enable auto publish (#96) (@reggi)06d88e6
#94 bump @npmcli/eslint-config from 4.0.5 to 5.0.0 (@dependabot[bot])14f6a93
#84 bump @npmcli/template-oss to 4.22.0 (@lukekarrys)a3a1fa5
#36 bump @npmcli/eslint-config from 3.1.0 to 4.0.0 (@dependabot[bot])dd40a9a
#95 postinstall for dependabot template-oss PR (@hashtagchris)3082ca1
#95 bump @npmcli/template-oss from 4.23.1 to 4.23.3 (@dependabot[bot])FAQs
Generate a unique character string suitible for use in files and URLs.
The npm package unique-slug receives a total of 17,200,557 weekly downloads. As such, unique-slug popularity was classified as popular.
We found that unique-slug demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
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.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.