uuid-mongodb
Advanced tools
Comparing version 2.1.4 to 2.2.0
@@ -77,3 +77,3 @@ /* | ||
function stringify(buffer) { | ||
function stringify(buffer, delimiter) { | ||
return [ | ||
@@ -85,3 +85,3 @@ buffer.toString('hex', 0, 4), | ||
buffer.toString('hex', 10, 16), | ||
].join('-'); | ||
].join(delimiter); | ||
} | ||
@@ -91,6 +91,14 @@ | ||
// add to string method | ||
mu.toString = function() { | ||
return stringify(this.buffer); | ||
// formatting parameter (optional) follows the behavior of Microsoft's UUID string function: https://docs.microsoft.com/en-us/dotnet/api/system.guid.tostring | ||
mu.toString = function(format) { | ||
let delimiter = '-'; | ||
let prefix = ''; | ||
let suffix = ''; | ||
if (format === 'N') delimiter = ''; | ||
if (format === 'B') { prefix = '{'; suffix = '}'; } | ||
if (format === 'P') { prefix = '('; suffix = ')'; } | ||
return prefix + stringify(this.buffer, delimiter) + suffix; | ||
}.bind(mu); | ||
return mu; | ||
} |
{ | ||
"name": "uuid-mongodb", | ||
"version": "2.1.4", | ||
"version": "2.2.0", | ||
"description": "Generates and parses MongoDB BSON UUIDs. Plays nicely with others including the MongoDB native driver and Mongoose.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -41,2 +41,21 @@ # uuid-mongodb | ||
## Formatting | ||
UUIDs may be formatted using the following options: | ||
N | 32 digits:00000000000000000000000000000000 | ||
-- | -- | ||
D | 32 digits separated by hyphens:00000000-0000-0000-0000-000000000000 | ||
B | 32 digits separated by hyphens, enclosed in braces:{00000000-0000-0000-0000-000000000000} | ||
P | 32 digits separated by hyphens, enclosed in parentheses:(00000000-0000-0000-0000-000000000000) | ||
**example:** | ||
```javascript | ||
const mUUID4 = MUUID.v4(); | ||
mUUID1.toString(); // equivalent to `D` separated by hyphens | ||
mUUID1.toString('P'); // enclosed in parens, separated by hypens | ||
mUUID1.toString('B'); // enclosed in braces, separated by hyphens | ||
mUUID1.toString('N'); // 32 digits | ||
``` | ||
## Examples | ||
@@ -43,0 +62,0 @@ |
11450
103
167