Giter VIP home page Giter VIP logo

uuid.js's Introduction

UUID.js

The RFC-compliant UUID generator for JavaScript.

See RFC 4122 http://www.ietf.org/rfc/rfc4122.txt.

Features

Generates RFC 4122 compliant UUIDs.

Version 4 UUIDs (UUIDs from random numbers) and version 1 UUIDs (time-based UUIDs) are available.

UUID object allows a variety of access to the UUID including access to the UUID fields.

Low timestamp resolution of JavaScript is compensated by random numbers.

Usage Examples

Load src/uuid.js to get full functionality. If you only need UUID.generate() method, dist/uuid.core.js satisfies your needs.

// the simplest way to get an UUID (as a hexadecimal string)
document.writeln(UUID.generate());  // "0db9a5fa-f532-4736-89d6-8819c7f3ac7b"


// create a version 4 (random-numbers-based) UUID object
var objV4 = UUID.genV4();

// create a version 1 (time-based) UUID object
var objV1 = UUID.genV1();

// create an UUID object from a hexadecimal string
var uuid = UUID.parse("a0e0f130-8c21-11df-92d9-95795a3bcd40");


// UUID object as a string
document.writeln(uuid.toString());  // "a0e0f130-8c21-11df-92d9-95795a3bcd40"
document.writeln(uuid.hexString);   // "a0e0f130-8c21-11df-92d9-95795a3bcd40"
document.writeln(uuid.bitString);   // "101000001110000 ... 1100110101000000"
document.writeln(uuid.urn);         // "urn:uuid:a0e0f130-8c21-11df-92d9-95795a3bcd40"

// compare UUID objects
document.writeln(objV4.equals(objV1));  // false

// show version numbers
document.writeln(objV4.version);  // 4
document.writeln(objV1.version);  // 1

// get UUID field values in 3 different formats by 2 different accessors
document.writeln(uuid.intFields.timeLow);               // 2699096368
document.writeln(uuid.bitFields.timeMid);               // "1000110000100001"
document.writeln(uuid.hexFields.timeHiAndVersion);      // "11df"
document.writeln(uuid.intFields.clockSeqHiAndReserved); // 146
document.writeln(uuid.bitFields.clockSeqLow);           // "11011001"
document.writeln(uuid.hexFields.node);                  // "95795a3bcd40"

document.writeln(uuid.intFields[0]);                    // 2699096368
document.writeln(uuid.bitFields[1]);                    // "1000110000100001"
document.writeln(uuid.hexFields[2]);                    // "11df"
document.writeln(uuid.intFields[3]);                    // 146
document.writeln(uuid.bitFields[4]);                    // "11011001"
document.writeln(uuid.hexFields[5]);                    // "95795a3bcd40"

License

This library is licensed under the MIT license.

Copyright (c) 2010-2012 LiosK.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

uuid.js's People

Contributors

liosk avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.