Skip to content

Commit

Permalink
✨ add UUID's v3 function
Browse files Browse the repository at this point in the history
  • Loading branch information
VitorLuizC committed Jun 2, 2020
1 parent d1e2f81 commit d648a58
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ components **template** and script, like the example below.
class="button"
@click="uuid = $uuid.v1()"
>Generate V1</button>
<button
class="button"
@click="uuid = $uuid.v3()"
>Generate V3</button>
<button
class="button"
@click="uuid = $uuid.v4()"
Expand All @@ -57,6 +61,7 @@ components **template** and script, like the example below.
NAMESPACE,
uuid: uuid.v1(),
v1: this.$uuid.v1(),
v3: this.$uuid.v3(),
v4: this.$uuid.v4(),
v5: this.$uuid.v5("Name 2", NAMESPACE)
};
Expand Down
9 changes: 5 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import Vue from "vue";
import { v1, v4, v5 } from "uuid";
import { v1, v3, v4, v5 } from "uuid";

export interface UUID {
v1: typeof v1;
v3: typeof v3;
v4: typeof v4;
v5: typeof v5;
}

declare module "vue/types/vue" {
interface VueConstructor {
/**
* An object with uuid's v1, v4 and v5 functions.
* An object with uuid's v1, v3, v4 and v5 functions.
*/
$uuid: UUID;
}
}

/**
* An object with uuid's v1, v4 and v5 functions.
* An object with uuid's v1, v3, v4 and v5 functions.
*/
export const uuid: UUID;

/**
* Installs UUID on Vue instance. It creates a property on Vue instance to
* expose an object with uuid's v1, v4 and v5 functions.
* expose an object with uuid's v1, v3, v4 and v5 functions.
* @example ```js
* import Vue from 'vue';
* import VueUUID from 'vue-uuid';
Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { v1, v4, v5 } from "uuid";
import { v1, v3, v4, v5 } from "uuid";

/**
* @typedef {Object} UUID
* @property {typeof v1} v1
* @property {typeof v3} v3
* @property {typeof v4} v4
* @property {typeof v5} v5
*/

/**
* An object with uuid's v1, v4 and v5 functions.
* An object with uuid's v1, v3, v4 and v5 functions.
* @type {UUID}
*/
export const uuid = { v1, v4, v5 };
export const uuid = { v1, v3, v4, v5 };

/**
* Installs UUID on Vue instance. It creates a property on Vue instance to
* expose an object with uuid's v1, v4 and v5 functions.
* expose an object with uuid's v1, v3, v4 and v5 functions.
* @example ```js
* import Vue from 'vue';
* import VueUUID from 'vue-uuid';
Expand Down
11 changes: 7 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import test from "ava";
import { v1, v3, v4, v5 } from "uuid";

import install from "./";

const generateVue = () => {
Expand All @@ -19,12 +21,13 @@ test("Exposes uuid as Vue's property $uuid", (context) => {
context.true(typeof Vue.prototype.$uuid === "object");
});

test("Exposed $uuid has v1, v4 & v5", (context) => {
test("Exposed $uuid's methods v1, v3, v4 & v5 are UUID functions", (context) => {
const Vue = generateVue();

Vue.use(install);

context.true(typeof Vue.prototype.$uuid.v1 === "function");
context.true(typeof Vue.prototype.$uuid.v4 === "function");
context.true(typeof Vue.prototype.$uuid.v5 === "function");
context.is(Vue.prototype.$uuid.v1, v1);
context.is(Vue.prototype.$uuid.v3, v3);
context.is(Vue.prototype.$uuid.v4, v4);
context.is(Vue.prototype.$uuid.v5, v5);
});

0 comments on commit d648a58

Please sign in to comment.