From 0b38c25af233ef0439f85f810f62c9469fd7834d Mon Sep 17 00:00:00 2001 From: James Drew Date: Mon, 22 Dec 2014 22:32:03 +0000 Subject: [PATCH] Added function to generate UUID --- lib/random.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/random.js b/lib/random.js index a4bc18585..830926537 100644 --- a/lib/random.js +++ b/lib/random.js @@ -51,6 +51,16 @@ var random = { var key = faker.random.array_element(array); return field === "key" ? key : object[key]; + }, + + uuid : function () { + var RFC4122_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'; + var replacePlaceholders = function (placeholder) { + var random = Math.random()*16|0; + var value = placeholder == 'x' ? random : (random &0x3 | 0x8); + return value.toString(16); + }; + return RFC4122_TEMPLATE.replace(/[xy]/g, replacePlaceholders); } };