mplanchard / cuid-rust

Rust implemention of CUID unique IDs
https://crates.io/crates/cuid
MIT License
91 stars 15 forks source link

cuid2::is_cuid2 for validiting a cuid2 string #9

Closed alelopezperez closed 1 year ago

alelopezperez commented 1 year ago

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

Added Requirements by me

mplanchard commented 1 year ago

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