Skip to content

Commit 4a567e1

Browse files
authored
Fix IsValidGuid (#67)
1 parent def1d2f commit 4a567e1

4 files changed

Lines changed: 44 additions & 35 deletions

File tree

.gitignore

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
1-
# See https://help.github.com/ignore-files/ for more about ignoring files.
2-
3-
# dependencies
4-
node_modules
5-
6-
# builds
7-
build
8-
dist
9-
.rpt2_cache
10-
11-
# misc
12-
.DS_Store
13-
.env
14-
.env.local
15-
.env.development.local
16-
.env.test.local
17-
.env.production.local
18-
19-
npm-debug.log*
20-
yarn-debug.log*
21-
yarn-error.log*
22-
23-
# Optional eslint cache
24-
.eslintcache
25-
26-
coverage
27-
28-
storybook-static
29-
.terraform
30-
terraform
31-
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
6+
# builds
7+
build
8+
dist
9+
.rpt2_cache
10+
11+
# misc
12+
.DS_Store
13+
.env
14+
.env.local
15+
.env.development.local
16+
.env.test.local
17+
.env.production.local
18+
19+
npm-debug.log*
20+
yarn-debug.log*
21+
yarn-error.log*
22+
23+
# Optional eslint cache
24+
.eslintcache
25+
26+
coverage
27+
28+
storybook-static
29+
.terraform
30+
terraform
31+
32+
# Ignore vs folder
33+
.vs
34+
3235
.npmrc

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- `isValidGuid` unwanted behaviour which was returning false for Guid sequentially generated by following Microsoft EntityFramework
13+
- maxGuid (`ffffffff-ffff-ffff-ffff-ffffffffffff`) is now recognized as valid Guid
14+
1015
## [1.3.0] - 2025-04-10
1116

1217
### Changed

src/lib/guid.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ describe("guid tests", () => {
1919
[" ", false],
2020
["507956c7-30b3-4401-9800-e5e7f8f3276X", false],
2121
["507956c7-30b3-4401-9800-e5e7f8f32761", true],
22+
["f094d99a-347e-4fe5-eea2-08dbc5deb2a0", true],
2223
[newGuid(), true],
2324
[emptyGuid, true],
2425
["3B467B14-CD99-4199-8E35-82B3C37182BA", true],
25-
// MAX not recognized as guid > https://github.com/uuidjs/uuid/pull/714
26-
["ffffffff-ffff-ffff-ffff-ffffffffffff", false],
26+
["ffffffff-ffff-ffff-ffff-ffffffffffff", true],
2727
])("isValidGuid", (value, expected) => {
2828
expect(isValidGuid(value)).toBe(expected);
2929
});

src/lib/guid.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ export function newGuid() {
99
}
1010

1111
/**
12-
* Check whether a string it is a valid Guid (version 4 UUID)
12+
* Check whether a string it is a valid Guid
1313
* @param str The string to test whether it is a valid Guid
1414
* @returns A value indicating whether the string is a valid Guid
1515
*/
1616
export function isValidGuid(str: string) {
17-
return uuid.validate(str);
17+
const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
18+
return typeof str === "string" && regex.test(str);
1819
}
1920

2021
/**

0 commit comments

Comments
 (0)