Skip to content

feat(common): add nanoid-based ID generators#22

Merged
brunozoric merged 2 commits into
mainfrom
bruno/feat/generate-id
Jun 8, 2026
Merged

feat(common): add nanoid-based ID generators#22
brunozoric merged 2 commits into
mainfrom
bruno/feat/generate-id

Conversation

@brunozoric

Copy link
Copy Markdown
Contributor

Summary

  • Adds nanoid-based ID generators to @webiny/stdlib (common slice), ported from webiny-js-v6/packages/utils/src/generateId.ts
  • Six generators: generateId, generateAlphaNumericId, generateAlphaNumericLowerCaseId, generateAlphaId, generateAlphaLowerCaseId, generateAlphaUpperCaseId
  • All accept an optional size parameter (default 21 characters)
  • New dependencies: nanoid (v5), nanoid-dictionary (v5)

Usage

import {
    generateId,
    generateAlphaNumericId,
    generateAlphaNumericLowerCaseId,
    generateAlphaId,
    generateAlphaLowerCaseId,
    generateAlphaUpperCaseId
} from "@webiny/stdlib";

generateId();            // URL-safe: "V1StGXR8_Z5jdHi6B-myT"
generateId(10);          // custom size: "V1StGXR8_Z"
generateAlphaNumericId();         // A-Z a-z 0-9
generateAlphaNumericLowerCaseId(); // a-z 0-9
generateAlphaId();                // A-Z a-z
generateAlphaLowerCaseId();       // a-z
generateAlphaUpperCaseId();       // A-Z

What changed

File Change
src/common/utils/generateId/generateId.ts Implementation (copied from v6)
src/common/utils/generateId/index.ts Barrel export
src/common/utils/generateId/README.md Feature docs with API table and usage examples
src/common/index.ts Re-exports all six generators from @webiny/stdlib
__tests__/generateId.test.ts 23 tests covering default size, custom size, character set validation, uniqueness
AGENTS.md Added generateId to @webiny/stdlib package contents
README.md Added row to Common features table
src/common/utils/README.md Added row to utils index
package.json / yarn.lock Added nanoid + nanoid-dictionary

Test plan

  • 401 tests passing (378 baseline + 23 new), zero failures
  • Full pre-commit chain clean (yarn && yarn adio && yarn format:fix && yarn lint:fix && yarn typecheck && yarn build && yarn test:coverage)
  • No regressions in existing tests
  • Coverage: 96.52% statements, 93.44% branches

Ports the generateId utility from webiny-js-v6, providing configurable
ID generation with various alphabet/case combinations via nanoid v5.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@brunozoric brunozoric self-assigned this Jun 8, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@brunozoric brunozoric merged commit 5924242 into main Jun 8, 2026
16 checks passed
@brunozoric brunozoric deleted the bruno/feat/generate-id branch June 8, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant