Coder Social home page Coder Social logo

timmikeladze / space-slug Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 340 KB

๐ŸŒ Generate unique slugs like `wonderful-jabba` or `hyperspace-4812` using a customizable api with zero dependencies.

License: MIT License

JavaScript 8.30% Shell 0.67% TypeScript 91.03%
random random-slug random-words slug slug-generator slugs username-generator unique-slug random-word random-word-generator

space-slug's Introduction

๐ŸŒ space-slug

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();
// Returns: joyful-illusion-30

๐Ÿ“ก Install

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.

๐Ÿš€ Getting Started

const { spaceSlug, color, digits, noun } from 'space-slug';

const slug = spaceSlug([color(), noun(2), digits(3)], {
  separator: '_'
});
// Returns: blue_celestial_labyrinth_718

๐Ÿ“š Custom dictionaries and locales

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',
});
/// Returns: jabba-ezra-39

๐Ÿ—ƒ๏ธ Tracking used slugs

const { uniqueSpaceSlug, color, digits } from 'space-slug';

const slug = await uniqueSpaceSlug([
  color(1),
  digits(4),
], {
  usedSlugs: ['orange-3918']
});
// Returns: a slug that is not orange-3918

โœ… Verifying that a slug is a unique

const { uniqueSpaceSlug } from 'space-slug';

await uniqueSpaceSlug([], {
  maxAttempts: 10, // default is 10 attempts before throwing an error
  isUnique: async (slug) => {
    // check database to see if slug is unique
    return true;
  }
});
// Returns: a slug that you have verified is unique

๐Ÿฆ„ Making a slug unique

await uniqueSpaceSlug(['jabba'], {
  isUnique: async (slug) => {
    // a db lookup to see if slug is unique
    return false;
  },
  makeUnique: async (slug) => {
    // somehow make the slug unique
    return slug + '-hutt';
  }
});

โœจ Transforming a slug

const { spaceSlug } from 'space-slug';

await spaceSlug([], {
  transform: (x) => x.toUpperCase()
});
// Returns: QUAINT-HORIZON-1293

โœ๏ธ Using hard-coded values

const { spaceSlug, color, digits } from 'space-slug';

spaceSlug([
  'jabba',
  digits(),
];
// Returns: jabba-1293

spaceSlug([
  color(),
  ['jabba', 'hutt'],
  digits(),
];
// Returns: red-jabba-hutt-3979

๐Ÿงฐ Functions

โš™๏ธ word

Function Type
word (type: string) => (count?: number, _words?: string[]) => (options: SpaceSlugOptions) => Set<string>

โš™๏ธ digits

Function Type
digits (count?: number, noConsecutive?: boolean) => (options: SpaceSlugOptions) => string

โš™๏ธ cleanString

Function Type
cleanString (inputString: string, separator: string) => string

โš™๏ธ uniqueSpaceSlug

Function Type
uniqueSpaceSlug (spaceSlugFn: SpaceSlugInput[], options?: SpaceSlugOptions and UniqueSpaceSlugOptions) => Promise<string>

โš™๏ธ spaceSlug

Function Type
spaceSlug (spaceSlugInputs?: SpaceSlugInput[], options?: SpaceSlugOptions) => string

๐Ÿ”ง Constants

โš™๏ธ spaceSlugDefaultDictionary

Constant Type
spaceSlugDefaultDictionary SpaceSlugDictionary

โš™๏ธ spaceSlugDefaultOptions

Constant Type
spaceSlugDefaultOptions Partial<SpaceSlugOptions>

โš™๏ธ noun

Constant Type
noun (count?: number, _words?: string[]) => (options: SpaceSlugOptions) => Set<string>

โš™๏ธ adjective

Constant Type
adjective (count?: number, _words?: string[]) => (options: SpaceSlugOptions) => Set<string>

โš™๏ธ color

Constant Type
color (count?: number, _words?: string[]) => (options: SpaceSlugOptions) => Set<string>

โš™๏ธ season

Constant Type
season (count?: number, _words?: string[]) => (options: SpaceSlugOptions) => Set<string>

โš™๏ธ emoji

Constant Type
emoji (count?: number, _words?: string[]) => (options: SpaceSlugOptions) => Set<string>

โš™๏ธ verb

Constant Type
verb (count?: number, _words?: string[]) => (options: SpaceSlugOptions) => Set<string>

โš™๏ธ animal

Constant Type
animal (count?: number, _words?: string[]) => (options: SpaceSlugOptions) => Set<string>

โš™๏ธ cosmos

Constant Type
cosmos (count?: number, _words?: string[]) => (options: SpaceSlugOptions) => Set<string>

space-slug's People

Contributors

renovate[bot] avatar timmikeladze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

space-slug's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency eslint-plugin-unused-imports to v4

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

  • chore(deps): update all non-major dependencies (@babel/core, @babel/preset-env, @babel/preset-react, @babel/preset-typescript, @commitlint/cli, @commitlint/config-conventional, @storybook/addon-essentials, @storybook/addon-interactions, @storybook/addon-links, @storybook/blocks, @storybook/react, @storybook/react-webpack5, @testing-library/jest-dom, @testing-library/react, @types/node, @types/react, @types/react-dom, @types/react-test-renderer, @typescript-eslint/eslint-plugin, @typescript-eslint/parser, @vitejs/plugin-react, @vitest/coverage-v8, eslint-plugin-react-hooks, eslint-plugin-unused-imports, lint-staged, parse-url, react, react-dom, react-test-renderer, release-it, semver, storybook, tsdoc-markdown, typescript, vitest, yaml)
  • chore(deps): update dependency @testing-library/react to v15
  • chore(deps): update storybook monorepo to v8 (major) (@storybook/addon-essentials, @storybook/addon-interactions, @storybook/addon-links, @storybook/blocks, @storybook/react, @storybook/react-webpack5, storybook)
  • Click on this checkbox to rebase all open PRs at once

Detected dependencies

github-actions
.github/workflows/main.yml
  • actions/checkout v4
  • actions/setup-node v4
npm
package.json
  • @babel/core 7.24.0
  • @babel/preset-env 7.24.0
  • @babel/preset-react 7.23.3
  • @babel/preset-typescript 7.23.3
  • @commitlint/cli 19.2.0
  • @commitlint/config-conventional 19.1.0
  • @ryansonshine/commitizen 4.2.8
  • @ryansonshine/cz-conventional-changelog 3.3.4
  • @storybook/addon-essentials 7.6.17
  • @storybook/addon-interactions 7.6.17
  • @storybook/addon-links 7.6.17
  • @storybook/blocks 7.6.17
  • @storybook/react 7.6.17
  • @storybook/react-webpack5 7.6.17
  • @storybook/storybook-deployer 2.8.16
  • @storybook/testing-library 0.2.2
  • @testing-library/jest-dom ^6.4.2
  • @testing-library/react ^14.2.1
  • @types/node 20.11.28
  • @types/react 18.2.67
  • @types/react-dom 18.2.22
  • @types/react-test-renderer 18.0.7
  • @typescript-eslint/eslint-plugin 7.2.0
  • @typescript-eslint/parser 7.2.0
  • @vitejs/plugin-react ^4.2.1
  • @vitest/coverage-v8 ^1.3.0
  • babel-loader 9.1.3
  • concurrently 8.2.2
  • eslint 8.57.0
  • eslint-config-airbnb 19.0.4
  • eslint-config-prettier 9.1.0
  • eslint-plugin-import 2.29.1
  • eslint-plugin-jsx-a11y 6.8.0
  • eslint-plugin-prefer-arrow 1.2.3
  • eslint-plugin-prettier 5.1.3
  • eslint-plugin-react 7.34.1
  • eslint-plugin-react-hooks 4.6.0
  • eslint-plugin-sort-class-members ^1.20.0
  • eslint-plugin-storybook 0.8.0
  • eslint-plugin-typescript-sort-keys 3.2.0
  • eslint-plugin-unused-imports 3.1.0
  • husky 9.0.11
  • jsdom ^24.0.0
  • lint-staged 15.2.2
  • prettier 3.2.5
  • prop-types 15.8.1
  • react 18.2.0
  • react-dom 18.2.0
  • react-test-renderer 18.2.0
  • release-it 17.1.1
  • storybook 7.6.17
  • tsdoc-markdown ^0.4.0
  • tsup 8.0.2
  • typescript 5.4.2
  • vitest ^1.3.0
  • yalc 1.0.0-pre.53
  • node >=14.0.0
  • glob-parent >=5.1.2
  • parse-url >=8.1.0
  • semver >=7.5.2
  • trim >=0.0.3
  • trim-newlines >=3.0.1
  • yaml >=2.2.2

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.