node-uuid

Node.js套件中,幫忙產生類似'02a2ce90-1432-11e1-8558-0b488e4fc115'這樣字串的工具,提供兩種產生方式:1.時間序列方式產出,2.亂數產出。

Github repository

https://github.com/broofa/node-uuid

Installation

npm install node-uuid

Sample Usage

最簡單的建立方式:

var uuid = require('node-uuid');

var v1 = uuid.v1();

console.log(v1);

可以針對建立的過程添加一些參數,讓亂數...更亂一些...

var uuid = require('node-uuid');

/**
 * 設定產生uuid的亂數變數
 * 相關資訊請參考:RFC4122 v1 
 */
var v1 = uuid.v1({
  node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
  clockseq: 0x1234,
  msecs: new Date().getTime(),
  nsecs: 5678
}); 

console.log(v1);

results matching ""

    No results matching ""