Comparing version 0.1.2 to 1.0.0
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var uuid = _interopDefault(require('uuid')); | ||
var v1 = _interopDefault(require('uuid/v1')); | ||
var v4 = _interopDefault(require('uuid/v4')); | ||
var v5 = _interopDefault(require('uuid/v5')); | ||
var uuid = { v1: v1, v4: v4, v5: v5 }; | ||
var install = function (Vue) { | ||
@@ -11,2 +17,3 @@ Vue.prototype.$uuid = uuid; | ||
module.exports = install; | ||
exports.uuid = uuid; | ||
exports['default'] = install; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('crypto')) : | ||
typeof define === 'function' && define.amd ? define(['crypto'], factory) : | ||
(global.vueUuid = factory(global.crypto)); | ||
}(this, (function (crypto) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('crypto')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'crypto'], factory) : | ||
(factory((global.vueUuid = {}),global.crypto)); | ||
}(this, (function (exports,crypto) { 'use strict'; | ||
@@ -170,14 +170,139 @@ crypto = crypto && crypto.hasOwnProperty('default') ? crypto['default'] : crypto; | ||
var uuid = v4_1; | ||
uuid.v1 = v1_1; | ||
uuid.v4 = v4_1; | ||
// Adapted from Chris Veness' SHA1 code at | ||
// http://www.movable-type.co.uk/scripts/sha1.html | ||
'use strict'; | ||
var uuid_1 = uuid; | ||
function f(s, x, y, z) { | ||
switch (s) { | ||
case 0: return (x & y) ^ (~x & z); | ||
case 1: return x ^ y ^ z; | ||
case 2: return (x & y) ^ (x & z) ^ (y & z); | ||
case 3: return x ^ y ^ z; | ||
} | ||
} | ||
function ROTL(x, n) { | ||
return (x << n) | (x>>> (32 - n)); | ||
} | ||
function sha1(bytes) { | ||
var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6]; | ||
var H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]; | ||
if (typeof(bytes) == 'string') { | ||
var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape | ||
bytes = new Array(msg.length); | ||
for (var i = 0; i < msg.length; i++) { bytes[i] = msg.charCodeAt(i); } | ||
} | ||
bytes.push(0x80); | ||
var l = bytes.length/4 + 2; | ||
var N = Math.ceil(l/16); | ||
var M = new Array(N); | ||
for (var i=0; i<N; i++) { | ||
M[i] = new Array(16); | ||
for (var j=0; j<16; j++) { | ||
M[i][j] = | ||
bytes[i * 64 + j * 4] << 24 | | ||
bytes[i * 64 + j * 4 + 1] << 16 | | ||
bytes[i * 64 + j * 4 + 2] << 8 | | ||
bytes[i * 64 + j * 4 + 3]; | ||
} | ||
} | ||
M[N - 1][14] = ((bytes.length - 1) * 8) / | ||
Math.pow(2, 32); M[N - 1][14] = Math.floor(M[N - 1][14]); | ||
M[N - 1][15] = ((bytes.length - 1) * 8) & 0xffffffff; | ||
for (var i=0; i<N; i++) { | ||
var W = new Array(80); | ||
for (var t=0; t<16; t++) { W[t] = M[i][t]; } | ||
for (var t=16; t<80; t++) { | ||
W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1); | ||
} | ||
var a = H[0], b = H[1], c = H[2], d = H[3], e = H[4]; | ||
for (var t=0; t<80; t++) { | ||
var s = Math.floor(t/20); | ||
var T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0; | ||
e = d; | ||
d = c; | ||
c = ROTL(b, 30) >>> 0; | ||
b = a; | ||
a = T; | ||
} | ||
H[0] = (H[0] + a) >>> 0; | ||
H[1] = (H[1] + b) >>> 0; | ||
H[2] = (H[2] + c) >>> 0; | ||
H[3] = (H[3] + d) >>> 0; | ||
H[4] = (H[4] + e) >>> 0; | ||
} | ||
return [ | ||
H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, | ||
H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, | ||
H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, | ||
H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, | ||
H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff | ||
]; | ||
} | ||
var sha1Browser = sha1; | ||
function uuidToBytes(uuid) { | ||
// Note: We assume we're being passed a valid uuid string | ||
var bytes = []; | ||
uuid.replace(/[a-fA-F0-9]{2}/g, function(hex) { | ||
bytes.push(parseInt(hex, 16)); | ||
}); | ||
return bytes; | ||
} | ||
function stringToBytes(str) { | ||
str = unescape(encodeURIComponent(str)); // UTF8 escape | ||
var bytes = new Array(str.length); | ||
for (var i = 0; i < str.length; i++) { | ||
bytes[i] = str.charCodeAt(i); | ||
} | ||
return bytes; | ||
} | ||
function v5(name, namespace, buf, offset) { | ||
if (typeof(name) == 'string') { name = stringToBytes(name); } | ||
if (typeof(namespace) == 'string') { namespace = uuidToBytes(namespace); } | ||
if (!Array.isArray(name)) { throw TypeError('name must be an array of bytes'); } | ||
if (!Array.isArray(namespace) || namespace.length != 16) { throw TypeError('namespace must be uuid string or an Array of 16 byte values'); } | ||
// Per 4.3 | ||
var bytes = sha1Browser(namespace.concat(name)); | ||
bytes[6] = (bytes[6] & 0x0f) | 0x50; | ||
bytes[8] = (bytes[8] & 0x3f) | 0x80; | ||
return buf || bytesToUuid_1(bytes); | ||
} | ||
// Pre-defined namespaces, per Appendix C | ||
v5.DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'; | ||
v5.URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8'; | ||
var v5_1 = v5; | ||
var uuid = { v1: v1_1, v4: v4_1, v5: v5_1 }; | ||
var install = function (Vue) { | ||
Vue.prototype.$uuid = uuid_1; | ||
Vue.prototype.$uuid = uuid; | ||
}; | ||
return install; | ||
exports.uuid = uuid; | ||
exports['default'] = install; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r(require("crypto")):"function"==typeof define&&define.amd?define(["crypto"],r):e.vueUuid=r(e.crypto)}(this,function(e){"use strict";for(var r=(e=e&&e.hasOwnProperty("default")?e.default:e).randomBytes,n=function(){return r(16)},t=[],o=0;o<256;++o)t[o]=(o+256).toString(16).substr(1);var u=function(e,r){var n=r||0,o=t;return o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]},i=n(),c=[1|i[0],i[1],i[2],i[3],i[4],i[5]],s=16383&(i[6]<<8|i[7]),a=0,f=0,d=function(e,r,t){var o=r&&t||0;"string"==typeof e&&(r="binary"==e?new Array(16):null,e=null);var i=(e=e||{}).random||(e.rng||n)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,r)for(var c=0;c<16;++c)r[o+c]=i[c];return r||u(i)},v=d;v.v1=function(e,r,n){var t=r&&n||0,o=r||[],i=void 0!==(e=e||{}).clockseq?e.clockseq:s,d=void 0!==e.msecs?e.msecs:(new Date).getTime(),v=void 0!==e.nsecs?e.nsecs:f+1,p=d-a+(v-f)/1e4;if(p<0&&void 0===e.clockseq&&(i=i+1&16383),(p<0||d>a)&&void 0===e.nsecs&&(v=0),v>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");a=d,f=v,s=i;var y=(1e4*(268435455&(d+=122192928e5))+v)%4294967296;o[t++]=y>>>24&255,o[t++]=y>>>16&255,o[t++]=y>>>8&255,o[t++]=255&y;var l=d/4294967296*1e4&268435455;o[t++]=l>>>8&255,o[t++]=255&l,o[t++]=l>>>24&15|16,o[t++]=l>>>16&255,o[t++]=i>>>8|128,o[t++]=255&i;for(var m=e.node||c,w=0;w<6;++w)o[t+w]=m[w];return r||u(o)},v.v4=d;var p=v;return function(e){e.prototype.$uuid=p}}); | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("crypto")):"function"==typeof define&&define.amd?define(["exports","crypto"],e):e(r.vueUuid={},r.crypto)}(this,function(r,e){"use strict";function n(r,e,n,t){switch(r){case 0:return e&n^~e&t;case 1:return e^n^t;case 2:return e&n^e&t^n&t;case 3:return e^n^t}}function t(r,e){return r<<e|r>>>32-e}function o(r,e,n,t){if("string"==typeof r&&(r=function(r){r=unescape(encodeURIComponent(r));for(var e=new Array(r.length),n=0;n<r.length;n++)e[n]=r.charCodeAt(n);return e}(r)),"string"==typeof e&&(e=function(r){var e=[];return r.replace(/[a-fA-F0-9]{2}/g,function(r){e.push(parseInt(r,16))}),e}(e)),!Array.isArray(r))throw TypeError("name must be an array of bytes");if(!Array.isArray(e)||16!=e.length)throw TypeError("namespace must be uuid string or an Array of 16 byte values");var o=g(e.concat(r));return o[6]=15&o[6]|80,o[8]=63&o[8]|128,n||i(o)}for(var a=(e=e&&e.hasOwnProperty("default")?e.default:e).randomBytes,u=function(){return a(16)},c=[],f=0;f<256;++f)c[f]=(f+256).toString(16).substr(1);var i=function(r,e){var n=e||0,t=c;return t[r[n++]]+t[r[n++]]+t[r[n++]]+t[r[n++]]+"-"+t[r[n++]]+t[r[n++]]+"-"+t[r[n++]]+t[r[n++]]+"-"+t[r[n++]]+t[r[n++]]+"-"+t[r[n++]]+t[r[n++]]+t[r[n++]]+t[r[n++]]+t[r[n++]]+t[r[n++]]},s=u(),d=[1|s[0],s[1],s[2],s[3],s[4],s[5]],v=16383&(s[6]<<8|s[7]),y=0,p=0,l=function(r,e,n){var t=e&&n||0,o=e||[],a=void 0!==(r=r||{}).clockseq?r.clockseq:v,u=void 0!==r.msecs?r.msecs:(new Date).getTime(),c=void 0!==r.nsecs?r.nsecs:p+1,f=u-y+(c-p)/1e4;if(f<0&&void 0===r.clockseq&&(a=a+1&16383),(f<0||u>y)&&void 0===r.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");y=u,p=c,v=a;var s=(1e4*(268435455&(u+=122192928e5))+c)%4294967296;o[t++]=s>>>24&255,o[t++]=s>>>16&255,o[t++]=s>>>8&255,o[t++]=255&s;var l=u/4294967296*1e4&268435455;o[t++]=l>>>8&255,o[t++]=255&l,o[t++]=l>>>24&15|16,o[t++]=l>>>16&255,o[t++]=a>>>8|128,o[t++]=255&a;for(var h=r.node||d,g=0;g<6;++g)o[t+g]=h[g];return e||i(o)},h=function(r,e,n){var t=e&&n||0;"string"==typeof r&&(e="binary"==r?new Array(16):null,r=null);var o=(r=r||{}).random||(r.rng||u)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,e)for(var a=0;a<16;++a)e[t+a]=o[a];return e||i(o)},g=function(r){var e=[1518500249,1859775393,2400959708,3395469782],o=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof r){var a=unescape(encodeURIComponent(r));for(r=new Array(a.length),i=0;i<a.length;i++)r[i]=a.charCodeAt(i)}r.push(128);for(var u=r.length/4+2,c=Math.ceil(u/16),f=new Array(c),i=0;i<c;i++){f[i]=new Array(16);for(var s=0;s<16;s++)f[i][s]=r[64*i+4*s]<<24|r[64*i+4*s+1]<<16|r[64*i+4*s+2]<<8|r[64*i+4*s+3]}for(f[c-1][14]=8*(r.length-1)/Math.pow(2,32),f[c-1][14]=Math.floor(f[c-1][14]),f[c-1][15]=8*(r.length-1)&4294967295,i=0;i<c;i++){for(var d=new Array(80),v=0;v<16;v++)d[v]=f[i][v];for(v=16;v<80;v++)d[v]=t(d[v-3]^d[v-8]^d[v-14]^d[v-16],1);for(var y=o[0],p=o[1],l=o[2],h=o[3],g=o[4],v=0;v<80;v++){var b=Math.floor(v/20),m=t(y,5)+n(b,p,l,h)+g+e[b]+d[v]>>>0;g=h,h=l,l=t(p,30)>>>0,p=y,y=m}o[0]=o[0]+y>>>0,o[1]=o[1]+p>>>0,o[2]=o[2]+l>>>0,o[3]=o[3]+h>>>0,o[4]=o[4]+g>>>0}return[o[0]>>24&255,o[0]>>16&255,o[0]>>8&255,255&o[0],o[1]>>24&255,o[1]>>16&255,o[1]>>8&255,255&o[1],o[2]>>24&255,o[2]>>16&255,o[2]>>8&255,255&o[2],o[3]>>24&255,o[3]>>16&255,o[3]>>8&255,255&o[3],o[4]>>24&255,o[4]>>16&255,o[4]>>8&255,255&o[4]]};o.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",o.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8";var b={v1:l,v4:h,v5:o};r.uuid=b,r.default=function(r){r.prototype.$uuid=b},Object.defineProperty(r,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=vue-uuid.min.js.map |
@@ -1,3 +0,7 @@ | ||
import uuid from 'uuid' | ||
import v1 from 'uuid/v1' | ||
import v4 from 'uuid/v4' | ||
import v5 from 'uuid/v5' | ||
export const uuid = { v1, v4, v5 } | ||
const install = (Vue) => { | ||
@@ -4,0 +8,0 @@ Vue.prototype.$uuid = uuid |
{ | ||
"name": "vue-uuid", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"description": "Add UUID to Vue instance.", | ||
"main": "dist/vue-uuid.common.js", | ||
"module": "dist/vue-uuid.es.js", | ||
"scripts": { | ||
"test": "standard", | ||
"build": "bili ./index.js -o dist --format cjs --format umd --compress umd", | ||
"test": "standard && ava", | ||
"build": "bili ./index.js -o dist --format cjs --format es --format umd --compress umd", | ||
"prepare": "npm run test && npm run build" | ||
@@ -27,2 +28,3 @@ }, | ||
"devDependencies": { | ||
"ava": "^0.23.0", | ||
"bili": "^0.18.2", | ||
@@ -29,0 +31,0 @@ "standard": "^10.0.3" |
@@ -5,4 +5,12 @@ # Vue UUID | ||
## Installation | ||
| [![JavaScript Style Guide][2]][3] | [![Build Status][0]][1] | | ||
|---|---| | ||
[0]: https://travis-ci.org/VitorLuizC/vue-uuid.svg?branch=master | ||
[1]: https://travis-ci.org/VitorLuizC/vue-uuid | ||
[2]: https://img.shields.io/badge/code_style-standard-brightgreen.svg | ||
[3]: https://standardjs.com | ||
## Install | ||
Installation is very easy, you just need to install using NPM or Yarn. | ||
@@ -28,3 +36,3 @@ | ||
```vue | ||
```html | ||
<template> | ||
@@ -41,2 +49,6 @@ <div class="uuid-panel"> | ||
>Generate V4</button> | ||
<button | ||
class="button" | ||
@click="uuid = $uuid.v5()" | ||
>Generate V5</button> | ||
</div> | ||
@@ -46,6 +58,12 @@ </template> | ||
<script> | ||
import { uuid } from 'vue-uuid' // uuid object is also exported to things | ||
// outside Vue instance. | ||
export default { | ||
data () { | ||
return { | ||
uuid: this.$uuid() // is equals to this.$uuid.v4() | ||
uuid: uuid.v1(), | ||
v1: this.$uuid.v1(), | ||
v4: this.$uuid.v4(), | ||
v5: this.$uuid.v5() | ||
} | ||
@@ -52,0 +70,0 @@ } |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
16499
54998
12
304
1
70
3