Skip to content

Commit 4c40026

Browse files
committed
✨ add support to Vue 3
1 parent 4e6d3b0 commit 4c40026

File tree

11 files changed

+551
-94
lines changed

11 files changed

+551
-94
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ npm i vue-uuid
1515
Vue's `use` method will do the trick adding to Vue.
1616

1717
```js
18-
import Vue from "vue";
19-
import UUID from "vue-uuid";
18+
import { createApp } from "vue";
19+
import withUUID from "vue-uuid";
2020

21-
Vue.use(UUID);
21+
const app = withUUID(
22+
createApp({
23+
// ...
24+
}),
25+
);
2226
```
2327

2428
## Usage

dist/index.esm.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { v1, v3, v4, v5 } from 'uuid';
22

3+
// @ts-check
34
/**
45
* @typedef {Object} UUID
56
* @property {typeof v1} v1
@@ -20,25 +21,39 @@ var uuid = {
2021
v5: v5
2122
};
2223
/**
23-
* Installs UUID on Vue instance. It creates a property on Vue instance to
24-
* expose an object with uuid's v1, v3, v4 and v5 functions.
24+
* @typedef {import('vue').App<HostElement>} App
25+
* @template HostElement
26+
*/
27+
28+
/**
29+
* Defines '$uuid' property globally, to be accessed in any component instance
30+
* inside the application. The '$uuid' is an object with uuid's v1, v3, v4 and
31+
* v5 functions.
32+
*
2533
* @example ```js
2634
* import Vue from 'vue';
27-
* import VueUUID from 'vue-uuid';
35+
* import withUUID from 'vue-uuid';
2836
*
29-
* Vue.use(VueUUID);
37+
* const app = withUUID(
38+
* createApp({
39+
* // ...
40+
* }),
41+
* );
3042
*
31-
* new Vue({
32-
* mounted () {
33-
* console.log(this.$uuid.v1());
43+
* app.component('c-button', {
44+
* created() {
45+
* this.id = this.$uuid.v4();
3446
* }
3547
* });
3648
* ```
37-
* @param {import('vue').default} Vue Vue constructor.
49+
* @param {App<HostElement>} app
50+
* @returns {App<HostElement>}
51+
* @template HostElement
3852
*/
3953

40-
function install(Vue) {
41-
Vue.prototype.$uuid = uuid;
54+
function withUUID(app) {
55+
app.config.globalProperties["$uuid"] = uuid;
56+
return app;
4257
}
4358

44-
export { install as default, uuid };
59+
export { withUUID as default, uuid };

dist/index.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
44

55
var uuid$1 = require('uuid');
66

7+
// @ts-check
78
/**
89
* @typedef {Object} UUID
910
* @property {typeof v1} v1
@@ -24,26 +25,40 @@ var uuid = {
2425
v5: uuid$1.v5
2526
};
2627
/**
27-
* Installs UUID on Vue instance. It creates a property on Vue instance to
28-
* expose an object with uuid's v1, v3, v4 and v5 functions.
28+
* @typedef {import('vue').App<HostElement>} App
29+
* @template HostElement
30+
*/
31+
32+
/**
33+
* Defines '$uuid' property globally, to be accessed in any component instance
34+
* inside the application. The '$uuid' is an object with uuid's v1, v3, v4 and
35+
* v5 functions.
36+
*
2937
* @example ```js
3038
* import Vue from 'vue';
31-
* import VueUUID from 'vue-uuid';
39+
* import withUUID from 'vue-uuid';
3240
*
33-
* Vue.use(VueUUID);
41+
* const app = withUUID(
42+
* createApp({
43+
* // ...
44+
* }),
45+
* );
3446
*
35-
* new Vue({
36-
* mounted () {
37-
* console.log(this.$uuid.v1());
47+
* app.component('c-button', {
48+
* created() {
49+
* this.id = this.$uuid.v4();
3850
* }
3951
* });
4052
* ```
41-
* @param {import('vue').default} Vue Vue constructor.
53+
* @param {App<HostElement>} app
54+
* @returns {App<HostElement>}
55+
* @template HostElement
4256
*/
4357

44-
function install(Vue) {
45-
Vue.prototype.$uuid = uuid;
58+
function withUUID(app) {
59+
app.config.globalProperties["$uuid"] = uuid;
60+
return app;
4661
}
4762

48-
exports["default"] = install;
63+
exports["default"] = withUUID;
4964
exports.uuid = uuid;

dist/index.umd.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.VueUUID = {}, global.uuid$1));
55
})(this, (function (exports, uuid$1) { 'use strict';
66

7+
// @ts-check
78
/**
89
* @typedef {Object} UUID
910
* @property {typeof v1} v1
@@ -24,28 +25,42 @@
2425
v5: uuid$1.v5
2526
};
2627
/**
27-
* Installs UUID on Vue instance. It creates a property on Vue instance to
28-
* expose an object with uuid's v1, v3, v4 and v5 functions.
28+
* @typedef {import('vue').App<HostElement>} App
29+
* @template HostElement
30+
*/
31+
32+
/**
33+
* Defines '$uuid' property globally, to be accessed in any component instance
34+
* inside the application. The '$uuid' is an object with uuid's v1, v3, v4 and
35+
* v5 functions.
36+
*
2937
* @example ```js
3038
* import Vue from 'vue';
31-
* import VueUUID from 'vue-uuid';
39+
* import withUUID from 'vue-uuid';
3240
*
33-
* Vue.use(VueUUID);
41+
* const app = withUUID(
42+
* createApp({
43+
* // ...
44+
* }),
45+
* );
3446
*
35-
* new Vue({
36-
* mounted () {
37-
* console.log(this.$uuid.v1());
47+
* app.component('c-button', {
48+
* created() {
49+
* this.id = this.$uuid.v4();
3850
* }
3951
* });
4052
* ```
41-
* @param {import('vue').default} Vue Vue constructor.
53+
* @param {App<HostElement>} app
54+
* @returns {App<HostElement>}
55+
* @template HostElement
4256
*/
4357

44-
function install(Vue) {
45-
Vue.prototype.$uuid = uuid;
58+
function withUUID(app) {
59+
app.config.globalProperties["$uuid"] = uuid;
60+
return app;
4661
}
4762

48-
exports["default"] = install;
63+
exports["default"] = withUUID;
4964
exports.uuid = uuid;
5065

5166
Object.defineProperty(exports, '__esModule', { value: true });

dist/index.umd.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.umd.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.d.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Vue from "vue";
2-
import { v1, v3, v4, v5 } from "uuid";
1+
import type { App } from "vue";
2+
import type { v1, v3, v4, v5 } from "uuid";
33

44
export interface UUID {
55
v1: typeof v1;
@@ -8,8 +8,8 @@ export interface UUID {
88
v5: typeof v5;
99
}
1010

11-
declare module "vue/types/vue" {
12-
interface VueConstructor {
11+
declare module "@vue/runtime-core" {
12+
export interface ComponentCustomProperties {
1313
/**
1414
* An object with uuid's v1, v3, v4 and v5 functions.
1515
*/
@@ -23,20 +23,26 @@ declare module "vue/types/vue" {
2323
export const uuid: UUID;
2424

2525
/**
26-
* Installs UUID on Vue instance. It creates a property on Vue instance to
27-
* expose an object with uuid's v1, v3, v4 and v5 functions.
28-
* @example ```js
26+
* Defines '$uuid' property globally, to be accessed in any component instance
27+
* inside the application. The '$uuid' is an object with uuid's v1, v3, v4 and
28+
* v5 functions.
29+
*
30+
* @example
2931
* import Vue from 'vue';
30-
* import VueUUID from 'vue-uuid';
32+
* import withUUID from 'vue-uuid';
3133
*
32-
* Vue.use(VueUUID);
34+
* const app = withUUID(
35+
* createApp({
36+
* // ...
37+
* }),
38+
* );
3339
*
34-
* new Vue({
35-
* mounted () {
36-
* console.log(this.$uuid.v1());
40+
* app.component('c-button', {
41+
* created() {
42+
* this.id = this.$uuid.v4();
3743
* }
3844
* });
39-
* ```
40-
* @param Vue - Vue constructor.
4145
*/
42-
export default function install(Vue: Vue): void;
46+
export default function withUUID<HostElement = any>(
47+
app: App<HostElement>
48+
): App<HostElement>;

index.mjs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-check
2+
13
import { v1, v3, v4, v5 } from "uuid";
24

35
/**
@@ -15,22 +17,35 @@ import { v1, v3, v4, v5 } from "uuid";
1517
export const uuid = { v1, v3, v4, v5 };
1618

1719
/**
18-
* Installs UUID on Vue instance. It creates a property on Vue instance to
19-
* expose an object with uuid's v1, v3, v4 and v5 functions.
20-
* @example ```js
20+
* @typedef {import('vue').App<HostElement>} App
21+
* @template HostElement
22+
*/
23+
24+
/**
25+
* Defines '$uuid' property globally, to be accessed in any component instance
26+
* inside the application. The '$uuid' is an object with uuid's v1, v3, v4 and
27+
* v5 functions.
28+
*
29+
* @example
2130
* import Vue from 'vue';
22-
* import VueUUID from 'vue-uuid';
31+
* import withUUID from 'vue-uuid';
2332
*
24-
* Vue.use(VueUUID);
33+
* const app = withUUID(
34+
* createApp({
35+
* // ...
36+
* }),
37+
* );
2538
*
26-
* new Vue({
27-
* mounted () {
28-
* console.log(this.$uuid.v1());
39+
* app.component('c-button', {
40+
* created() {
41+
* this.id = this.$uuid.v4();
2942
* }
3043
* });
31-
* ```
32-
* @param {import('vue').default} Vue Vue constructor.
44+
* @param {App<HostElement>} app
45+
* @returns {App<HostElement>}
46+
* @template HostElement
3347
*/
34-
export default function install(Vue) {
35-
Vue.prototype.$uuid = uuid;
48+
export default function withUUID(app) {
49+
app.config.globalProperties["$uuid"] = uuid;
50+
return app;
3651
}

0 commit comments

Comments
 (0)