Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution to implement url-safe strings (#347) #514

Closed
wants to merge 1 commit into from

Conversation

Mindslayer001
Copy link

Description:

This pull request introduces an approach to generate URL-safe strings, as discussed in Issue #347. It implements a new --url-safe (or -u) flag for the nanoid CLI, enabling users to generate IDs that are safe to use in URLs by avoiding problematic characters, such as underscores at the end of strings.

Key Changes:

  • New URL-Safe Alphabet: A custom alphabet is now used for generating URL-safe IDs. It excludes characters like underscores and other potentially problematic characters in URLs.
  • CLI Update: The --url-safe flag has been added to the command-line interface, allowing users to specify that the generated ID should be URL-safe.
  • Enhanced customAlphabet Function: The customAlphabet function has been updated to accept a url_safe parameter, making it easy for users to generate URL-safe IDs when needed.

Motivation:

This approach addresses issues related to trailing underscores and other characters that can cause problems in URLs, such as rendering issues or broken links in Markdown and web applications. By enabling the generation of URL-safe IDs, the solution enhances compatibility and reliability when working with URLs.

Key Note:

This is not yet considered a complete solution, but rather an approach to how this can be implemented. Feedback is welcome for further improvement.

@ai
Copy link
Owner

ai commented Jan 1, 2025

Sorry, I don’t plan to change alphabet. I think #347 can be better solved by adding / to the end of URL.

@ai ai closed this Jan 1, 2025
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.

2 participants