Get a unique string that looks like this wonderful-jabba or this hyperspace-4812.
Generate unique slugs, usernames, numbers, custom words, and more using an intuitive api with zero dependencies.
const { spaceSlug } from 'space-slug';
const slug = spaceSlug();
npm install space-slug
yarn add space-slug
pnpm add space-slug
Hello there! Follow me @linesofcode or visit linesofcode.dev for more cool projects like this one.
const { spaceSlug, adjective, color, digits, noun } from 'space-slug';
const slug = spaceSlug([color(), adjective(), noun(1), digits(3)], {
separator: '_'
});
const { spaceSlug, word, SpaceSlugDictionary } from 'space-slug';
const dictionary: SpaceSlugDictionary = {
en: {
starwars: ['jabba', 'ezra'],
},
};
const slug = spaceSlug([word('starwars')(2), digits(2)], {
dictionary,
locale: 'en',
});
const { uniqueSpaceSlug, color, digits } from 'space-slug';
const slug = await uniqueSpaceSlug([
color(1),
digits(4),
], {
usedSlugs: ['orange-3918']
});
const { uniqueSpaceSlug } from 'space-slug';
await uniqueSpaceSlug([], {
maxAttempts: 10,
isUnique: async (slug) => {
return true;
}
});
await uniqueSpaceSlug(['jabba'], {
isUnique: async (slug) => {
return false;
},
makeUnique: async (slug) => {
return slug + '-hutt';
}
});
const { spaceSlug } from 'space-slug';
await spaceSlug([], {
transform: (x) => x.toUpperCase()
});
const { spaceSlug, color, digits } from 'space-slug';
spaceSlug([
'jabba',
digits(),
];
spaceSlug([
color(),
['jabba', 'hutt'],
digits(),
];
| Function |
Type |
word |
(type: string) => (count?: number or undefined, _words?: string[] or undefined) => (options: SpaceSlugOptions) => Set<string> |
| Function |
Type |
digits |
(count?: number or undefined, noConsecutive?: boolean or undefined) => (options: SpaceSlugOptions) => string |
| Function |
Type |
cleanString |
(inputString: string, separator: string) => string |
| Function |
Type |
uniqueSpaceSlug |
(spaceSlugFn: SpaceSlugInput[], options?: SpaceSlugOptions and UniqueSpaceSlugOptions) => Promise<string> |
| Function |
Type |
spaceSlug |
(spaceSlugInputs?: SpaceSlugInput[] or undefined, options?: SpaceSlugOptions) => string |
| Constant |
Type |
spaceSlugDefaultDictionary |
SpaceSlugDictionary |
| Constant |
Type |
spaceSlugDefaultOptions |
Partial<SpaceSlugOptions> |
| Constant |
Type |
noun |
(count?: number or undefined, _words?: string[] or undefined) => (options: SpaceSlugOptions) => Set<string> |
| Constant |
Type |
adjective |
(count?: number or undefined, _words?: string[] or undefined) => (options: SpaceSlugOptions) => Set<string> |
| Constant |
Type |
color |
(count?: number or undefined, _words?: string[] or undefined) => (options: SpaceSlugOptions) => Set<string> |
| Constant |
Type |
season |
(count?: number or undefined, _words?: string[] or undefined) => (options: SpaceSlugOptions) => Set<string> |
| Constant |
Type |
emoji |
(count?: number or undefined, _words?: string[] or undefined) => (options: SpaceSlugOptions) => Set<string> |
| Constant |
Type |
verb |
(count?: number or undefined, _words?: string[] or undefined) => (options: SpaceSlugOptions) => Set<string> |
| Constant |
Type |
animal |
(count?: number or undefined, _words?: string[] or undefined) => (options: SpaceSlugOptions) => Set<string> |
| Constant |
Type |
cosmos |
(count?: number or undefined, _words?: string[] or undefined) => (options: SpaceSlugOptions) => Set<string> |