Skip to content

Commit d191cb6

Browse files
authored
Merge pull request #18 from jchook/17-case-insensitive-test
Case-insensitive test()
2 parents 6e96a2c + 8d8a02f commit d191cb6

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": true
6+
}

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ time.
66
## 1.3.1 <small>- Jun 19, 2020</small>
77

88
- Fixes issue with iOS 9 ([#15](https://github.com/jchook/uuid-random/issues/15))
9+
- Fixes issue with `test()` case-sensitivity ([#17](https://github.com/jchook/uuid-random/issues/17))
10+
- Improves tests
911
- Improves benchmarks
1012

1113

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// Test for uuid
3232
uuid.test = function(uuid) {
3333
if (typeof uuid === 'string') {
34-
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(uuid);
34+
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(uuid);
3535
}
3636
return false;
3737
};

test.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,32 @@ var uuid = require('./index');
33

44
// Check format
55
var i;
6-
for (i = 0; i<10000; i++) {
7-
assert(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(uuid()));
6+
for (i = 0; i < 10000; i++) {
7+
assert(uuid.test(uuid()));
8+
}
9+
10+
// Check the test function on known-[in]valid UUIDs
11+
const healthyUuids = ['6514db12-0a68-4108-a8c9-3ddc6f489a26'];
12+
const invalidUuids = [
13+
'920b70bf-168a-458d-c1ac-50e488e5976f',
14+
'633ca20d-1e9e-7b81-b725-82a595ce3515',
15+
'knuth',
16+
undefined,
17+
null,
18+
[],
19+
42,
20+
];
21+
for (const healthyUuid of healthyUuids) {
22+
assert(uuid.test(healthyUuid) === true);
23+
assert(uuid.test(healthyUuid.toUpperCase()) === true);
24+
}
25+
for (const invalidUuid of invalidUuids) {
26+
assert(uuid.test(invalidUuid) === false);
827
}
928

1029
// Clear the buffer and change the randomBytes function to return 0s
1130
uuid.clearBuffer();
12-
uuid.randomBytes = function(length) {
13-
return (new Array(length)).fill(0, 0, length);
31+
uuid.randomBytes = function (length) {
32+
return new Array(length).fill(0, 0, length);
1433
};
1534
assert(uuid() === '00000000-0000-4000-8000-000000000000');

0 commit comments

Comments
 (0)