larvitutils
Advanced tools
Comparing version 1.0.1 to 1.0.2
11
index.js
@@ -21,3 +21,3 @@ 'use strict'; | ||
function escapeRegExp(str) { | ||
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); | ||
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1'); | ||
} | ||
@@ -35,8 +35,10 @@ | ||
// If a buffer, get the string representation | ||
if (Buffer.isBuffer(uuidStr)) | ||
if (Buffer.isBuffer(uuidStr)) { | ||
uuidStr = uuidStr.toString('hex'); | ||
} | ||
// Now uuidStr MUST be a string | ||
if (typeof uuidStr !== 'string') | ||
if (typeof uuidStr !== 'string') { | ||
return false; | ||
} | ||
@@ -47,4 +49,5 @@ // Remove all but hex characters | ||
// All uuid strings have exactly 32 hex characters! | ||
if (uuidStr.length !== 32) | ||
if (uuidStr.length !== 32) { | ||
return false; | ||
} | ||
@@ -51,0 +54,0 @@ // Add dashes in the right places |
{ | ||
"name": "larvitutils", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Misc utils", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -60,1 +60,16 @@ [![Build Status](https://travis-ci.org/larvit/larvitutils.svg)](https://travis-ci.org/larvit/larvitutils) [![Dependencies](https://david-dm.org/larvit/larvitutils.svg)](https://david-dm.org/larvit/larvitutils.svg) | ||
``` | ||
## Validate an uuid string | ||
```javascript | ||
const utils = require('larvitutils'), | ||
validUuid = 'f9684592-b245-42fa-88c6-9f16b9236ac3', | ||
invalidUuid1 = false, | ||
invalidUuid2 = 'foobar', | ||
invalidUuid3 = {'höhö': 'oveboll'}; | ||
utils.formatUuid(validUuid); // true | ||
utils.formatUuid(invalidUuid1); // false | ||
utils.formatUuid(invalidUuid2); // false | ||
utils.formatUuid(invalidUuid3); // false | ||
``` |
@@ -10,3 +10,3 @@ 'use strict'; | ||
assert(uuid === 'f9684592-b245-42fa-88c6-9f16b9236ac3', 'Uuid is wrong, expected "f9684592-b245-42fa-88c6-9f16b9236ac3", but got "' + uuid + '"'); | ||
assert.deepEqual(uuid, 'f9684592-b245-42fa-88c6-9f16b9236ac3'); | ||
@@ -20,3 +20,3 @@ done(); | ||
assert(formatted === '0e7e26b7-f180-4d65-9512-80b776a7509e', 'Uuid is wrong, expected "0e7e26b7-f180-4d65-9512-80b776a7509e" but got "' + formatted + '"'); | ||
assert.deepEqual(formatted, '0e7e26b7-f180-4d65-9512-80b776a7509e'); | ||
done(); | ||
@@ -29,3 +29,3 @@ }); | ||
assert(formatted === '62be934b-24c2-4944-981c-40d4163e3bc9', 'Uuid is wrong, expected "62be934b-24c2-4944-981c-40d4163e3bc9" but got "' + formatted + '"'); | ||
assert.deepEqual(formatted, '62be934b-24c2-4944-981c-40d4163e3bc9'); | ||
done(); | ||
@@ -39,5 +39,5 @@ }); | ||
assert(blaj === false, 'Expected false but got "' + blaj + '"'); | ||
assert(toShortHex === false, 'Expected false but got "' + toShortHex + '"'); | ||
assert(toLongHex === false, 'Expected false but got "' + toLongHex + '"'); | ||
assert.deepEqual(blaj, false); | ||
assert.deepEqual(toShortHex, false); | ||
assert.deepEqual(toLongHex, false); | ||
@@ -50,6 +50,16 @@ done(); | ||
assert(formatted === '80d7b01d-e5d8-43a4-b5f1-e2703506860a', 'Expected "80d7b01d-e5d8-43a4-b5f1-e2703506860a" but got "' + formatted + '"'); | ||
assert.deepEqual(formatted, '80d7b01d-e5d8-43a4-b5f1-e2703506860a'); | ||
done(); | ||
}); | ||
it('Should fail on anything but a string', function(done) { | ||
const test1 = utils.formatUuid([3, 4]), | ||
test2 = utils.formatUuid({'höhö': 'fippel'}); | ||
assert.deepEqual(test1, false); | ||
assert.deepEqual(test2, false); | ||
done(); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11543
180
75