diff --git a/.gitignore b/.gitignore index dbacc54..e26c031 100644 --- a/.gitignore +++ b/.gitignore @@ -1,32 +1,35 @@ -# See https://help.github.com/ignore-files/ for more about ignoring files. - -# dependencies -node_modules - -# builds -build -dist -.rpt2_cache - -# misc -.DS_Store -.env -.env.local -.env.development.local -.env.test.local -.env.production.local - -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# Optional eslint cache -.eslintcache - -coverage - -storybook-static -.terraform -terraform - +# See https://help.github.com/ignore-files/ for more about ignoring files. + +# dependencies +node_modules + +# builds +build +dist +.rpt2_cache + +# misc +.DS_Store +.env +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Optional eslint cache +.eslintcache + +coverage + +storybook-static +.terraform +terraform + +# Ignore vs folder +.vs + .npmrc \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 53cd1a5..99dc9ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- `isValidGuid` unwanted behaviour which was returning false for Guid sequentially generated by following Microsoft EntityFramework +- maxGuid (`ffffffff-ffff-ffff-ffff-ffffffffffff`) is now recognized as valid Guid + ## [1.3.0] - 2025-04-10 ### Changed diff --git a/src/lib/guid.spec.ts b/src/lib/guid.spec.ts index d6a48b1..0c7dd9b 100644 --- a/src/lib/guid.spec.ts +++ b/src/lib/guid.spec.ts @@ -19,11 +19,11 @@ describe("guid tests", () => { [" ", false], ["507956c7-30b3-4401-9800-e5e7f8f3276X", false], ["507956c7-30b3-4401-9800-e5e7f8f32761", true], + ["f094d99a-347e-4fe5-eea2-08dbc5deb2a0", true], [newGuid(), true], [emptyGuid, true], ["3B467B14-CD99-4199-8E35-82B3C37182BA", true], - // MAX not recognized as guid > https://github.com/uuidjs/uuid/pull/714 - ["ffffffff-ffff-ffff-ffff-ffffffffffff", false], + ["ffffffff-ffff-ffff-ffff-ffffffffffff", true], ])("isValidGuid", (value, expected) => { expect(isValidGuid(value)).toBe(expected); }); diff --git a/src/lib/guid.ts b/src/lib/guid.ts index 630e350..0577f1f 100644 --- a/src/lib/guid.ts +++ b/src/lib/guid.ts @@ -9,12 +9,13 @@ export function newGuid() { } /** - * Check whether a string it is a valid Guid (version 4 UUID) + * Check whether a string it is a valid Guid * @param str The string to test whether it is a valid Guid * @returns A value indicating whether the string is a valid Guid */ export function isValidGuid(str: string) { - return uuid.validate(str); + const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; + return typeof str === "string" && regex.test(str); } /**