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

cuid2::is_cuid2 for validiting a cuid2 string #9

Closed
alelopezperez opened this issue Jun 27, 2023 · 1 comment
Closed

cuid2::is_cuid2 for validiting a cuid2 string #9

alelopezperez opened this issue Jun 27, 2023 · 1 comment

Comments

@alelopezperez
Copy link
Contributor

alelopezperez commented Jun 27, 2023

Hi, I noticed that cuid::is_cuid is now deprecated since it follows non cuid2 standards. I checked the original isCuid2 from paralleldrive implementation and transcribed to a similar function from the deprecrated cuid::is_cuid

Original JS Implementation

link to original JS implementation

const isCuid = (id, { minLength = 2, maxLength = bigLength } = {}) => {
  const length = id.length;
  const regex = /^[0-9a-z]+$/;

  try {
    if (
      typeof id === "string" &&
      length >= minLength &&
      length <= maxLength &&
      regex.test(id)
    )
      return true;
  } finally {
  }

  return false;
};

The requirements are as follows

  • length from 2 to 32 (in the code we have a BIG_LENGTH so any changes will reflect on the function.
  • it only contains lowecase a to z and 0 to 9

Added Requirements by me

  • starts with an lowercase ascii letter ( a to z)
@mplanchard
Copy link
Owner

Sorry for the slow response on this. Just recently finished up moving across the country, so things have been hectic!

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

No branches or pull requests

2 participants