有时需要在前端生成UUID,可以在jsp中引用内容如下的文件UUID.js。
使用时直接用new生成即可
var uuidId = new UUID();
UUID.js
/*
*
* uuid.js - Version 0.3 JavaScript Class to create a UUID like identifier
*
* Copyright (C) 2006-2008, Erik Giberti (AF-Design), All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* The latest version of this file can be downloaded from
* http://www.af-design.com/resources/javascript_uuid.php
*
* HISTORY: 6/5/06 - Initial Release 5/22/08 - Updated code to run faster,
* removed randrange(min,max) in favor of a simpler rand(max) function. Reduced
* overhead by using getTime() method of date class (suggestion by James Hall).
* 9/5/08 - Fixed a bug with rand(max) and additional efficiencies pointed out
* by Robert Kieffer http://broofa.com/
*
* KNOWN ISSUES: - Still no way to get MAC address in JavaScript - Research into
* other versions of UUID show promising possibilities (more research needed) -
* Documentation needs improvement
*
*/
// On creation of a UUID object, set it's initial value
function UUID() {
this.id = this.createUUID();
}
// When asked what this Object is, lie and return it's value
UUID.prototype.valueOf = function() {
return this.id;
}
UUID.prototype.toString = function() {
return this.id;
}
//
// INSTANCE SPECIFIC METHODS
//
UUID.prototype.createUUID = function() {
//
// Loose interpretation of the specification DCE 1.1: Remote Procedure Call
// described at
// http://www.opengroup.org/onlinepubs/009629399/apdxa.htm#tagtcjh_37
// since JavaScript doesn't allow access to internal systems, the last 48
// bits
// of the node section is made up using a series of random numbers (6 octets
// long).
//
var dg = new Date(1582, 10, 15, 0, 0, 0, 0);
var dc = new Date();
var t = dc.getTime() - dg.getTime();
var tl = UUID.getIntegerBits(t, 0, 31);
var tm = UUID.getIntegerBits(t, 32, 47);
var thv = UUID.getIntegerBits(t, 48, 59) + '1'; // version 1, security version is 2
var csar = UUID.getIntegerBits(UUID.rand(4095), 0, 7);
var csl = UUID.getIntegerBits(UUID.rand(4095), 0, 7);
// since detection of anything about the machine/browser is far to buggy,
// include some more random numbers here
// if NIC or an IP can be obtained reliably, that should be put in
// here instead.
var n = UUID.getIntegerBits(UUID.rand(8191), 0, 7)
+ UUID.getIntegerBits(UUID.rand(8191), 8, 15)
+ UUID.getIntegerBits(UUID.rand(8191), 0, 7)
+ UUID.getIntegerBits(UUID.rand(8191), 8, 15)
+ UUID.getIntegerBits(UUID.rand(8191), 0, 15); // this last number is two octets long
return tl + tm + thv + csar + csl + n;
}
//
// GENERAL METHODS (Not instance specific)
//
// Pull out only certain bits from a very large integer, used to get the time
// code information for the first part of a UUID. Will return zero's if there
// aren't enough bits to shift where it needs to.
UUID.getIntegerBits = function(val, start, end) {
var base16 = UUID.returnBase(val, 16);
var quadArray = new Array();
var quadString = '';
var i = 0;
for (i = 0; i < base16.length; i++) {
quadArray.push(base16.substring(i, i + 1));
}
for (i = Math.floor(start / 4); i <= Math.floor(end / 4); i++) {
if (!quadArray[i] || quadArray[i] == '')
quadString += '0';
else
quadString += quadArray[i];
}
return quadString;
}
// Replaced from the original function to leverage the built in methods in
// JavaScript. Thanks to Robert Kieffer for pointing this one out
UUID.returnBase = function(number, base) {
return (number).toString(base).toUpperCase();
}
// pick a random number within a range of numbers
// int b rand(int a); where 0 <= b <= a
UUID.rand = function(max) {
return Math.floor(Math.random() * (max + 1));
}
// end of UUID class file
分享到:
相关推荐
简单快速javascript生成UUID
javascript生成uuid的js库文件
这个函数用最短的代码生成了非常有效的uuid,非常巧妙。短小精悍,一个字符都不多。Returns a random v4 UUID of the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx, where each x is replaced with a random ...
javascript 随机生成36为的UUID值
主要介绍了两行Javascript代码生成UUID的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
UUID.js, 用于JavaScript的符合RFC的UUID生成器 电子邮件名称UUID.js - 适用于JavaScript的兼容UUID生成器概要<!-- HTML5 -->[removed][removed]&
node-uuid, 在JavaScript中,生成符合RFC的uuid uuid 简单。快速生成 RFC4122 uuid 。功能:支持版本 1,4和 5 uuid跨平台使用加密的强随机数 api ( 可用时)零相关性,小容量( 。但不是这个小的 )快速入门- CommonJS...
java生成UUID通用唯一识别码.docx
Zazu UUID生成器Zazu插件可生成UUID。 只需键入uuid并选择结果即可复制新生成的UUID!致谢
这是一个纯 JavaScript 和无依赖库,用于生成 DCE 1.1、ISO/IEC 11578:1996 和 IETF RFC-4122 兼容的通用唯一标识符 (UUID)。 它支持版本 1(基于时间和节点)、版本 3(基于名称,MD5)、版本 4(基于随机数)和...
有序 UUID v4 - COMB(组合时间-GUID) ordered-uuid-v4是一个 JavaScript 包,可以生成一个 COMB(combined time-GUID),基本上是一个有序的 UUID。 COMB/有序 UUID 包含: 48 位时间戳:自 1970 年 1 月 1 日 00:...
UUID.js-JavaScript的RFC兼容UUID生成器 概要 <!-- HTML5 --> < script src =" src/uuid.js " > </ script > < script > var uuid = UUID . generate ( ) ; </ script > // Node.js...
用于在Web浏览器中生成抗碰撞UUID的简单实用程序 使用NPM安装 npm install uuid-js 使用Yarn进行安装 yarn add uuid-js 用法示例 import uuid from "web-uuid-js" ; const Uuid = uuid ( ) ; 运行单元测试 yarn...
输入项name (可选)使用它可以基于输入生成UUID。namespace (可选)设置UUID命名空间。产出uuid 生成的UUID。用法示例 jobs : test : runs-on : ubuntu-latest name : Test UUID action steps : - name : Set UUID...
Vue UUID 将UUID添加到Vue实例。安装安装非常容易,您只需要使用NPM或Yarn安装即可。 npm i vue-uuid Vue的use方法将把技巧添加到Vue中。 import Vue from "vue" ;import UUID from "vue-uuid" ;Vue . use ( UUID ) ...
工作流程在v1和v4中生成UUID 安装 $ npm install --global alfred-uuid 需要付费的升级使用和 。 用法 在Alfred中,输入uid , ⏎ 按⏎复制一个uuid。 有关的 uuid-用于生成软件包 执照 麻省理工学院:copyright:
用于创建 UUID 完整-支持RFC4122版本1、3、4和5 UUID 跨平台-支持... CommonJS, 和 节点8、10、12、14 Chrome,Safari,Firefox,Edge,IE 11浏览器 Webpack和rollup.js模块捆绑器 安全-加密强度高的随机值 ...
'-uuid UUID v4 生成器和验证器(符合 RFC4122) 名称用户名版本0.1.1 尺寸1 KB / > 1 KB (gzipped) 环境浏览器,Node.js安装通过 npm install lil-uuid 通过bower install lil-uuid 通过component install lil-js/...
爵士音乐节插件,用于在适当的位置生成UUID。用法就像其他任何插件一样,将插件提供给jazzon.use方法。 let jazzon = require ( 'jazzon' ) ;let uuid = require ( 'jazzon-uuid' ) ;let json = { id : "@{ uuid }"}...
程序包的原始包装,用于使用Base64编码生成UUID v4。 原因是使用可打印字符获得通用且简短的UUID表示形式,无需特殊的UUID类型即可在JSON和数据库中有效使用它。 它仅产生22个字符,而不是带有分隔符的规范的36个...