vue-is-defined 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ <p align="center">
2
+ <img src="logo.svg" alt="vue-is-defined" width="180" />
3
+ </p>
4
+
5
+ <h1 align="center">vue-is-defined</h1>
6
+
7
+ <p align="center">A Vue 3 composition API type guard utility that checks if a ref's value is defined (not null or undefined), with proper TypeScript type narrowing for safe property access.</p>
8
+
9
+ <p align="center">
10
+ <a href="https://www.npmjs.com/package/vue-is-defined"><img src="https://img.shields.io/npm/v/vue-is-defined.svg" alt="npm version" /></a>
11
+ <a href="https://www.npmjs.com/package/vue-is-defined"><img src="https://img.shields.io/npm/dm/vue-is-defined.svg" alt="npm downloads" /></a>
12
+ <a href="https://github.com/vuefrag/vue-is-defined/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/vue-is-defined.svg" alt="license" /></a>
13
+ </p>
14
+
15
+ > Extracted from [VueUse](https://vueuse.org/) for standalone use.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install vue-is-defined
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```ts
26
+ import { isDefined } from 'vue-is-defined';
27
+ ```
28
+
29
+ Non-nullish checking type guard for Ref.
30
+
31
+ ```ts
32
+ import { isDefined } from 'vue-is-defined'
33
+
34
+ const example = ref(Math.random() ? 'example' : undefined) // Ref<string | undefined>
35
+
36
+ if (isDefined(example))
37
+ example // Ref<string>
38
+ ```
39
+
40
+ ## License
41
+
42
+ MIT
package/banner.svg ADDED
@@ -0,0 +1,52 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 640" width="1280" height="640">
2
+ <defs>
3
+ <linearGradient id="banner-bg" x1="0%" y1="0%" x2="100%" y2="100%">
4
+ <stop offset="0%" style="stop-color:#2c3e50;stop-opacity:1" />
5
+ <stop offset="100%" style="stop-color:#1a252f;stop-opacity:1" />
6
+ </linearGradient>
7
+ </defs>
8
+
9
+ <!-- Background -->
10
+ <rect width="1280" height="640" fill="url(#banner-bg)"/>
11
+
12
+ <!-- Decorative elements -->
13
+ <circle cx="1200" cy="100" r="300" fill="#3498db" opacity="0.05"/>
14
+ <circle cx="80" cy="540" r="200" fill="#3498db" opacity="0.05"/>
15
+
16
+ <!-- Top accent bar -->
17
+ <rect x="0" y="0" width="1280" height="8" fill="#3498db"/>
18
+
19
+ <!-- VueFrag badge -->
20
+ <g transform="translate(80, 80)">
21
+ <rect width="140" height="50" rx="8" fill="#3498db"/>
22
+ <text x="70" y="33" text-anchor="middle" font-family="system-ui, -apple-system, sans-serif" font-size="22" font-weight="700" fill="white">VueFrag</text>
23
+ </g>
24
+
25
+ <!-- Package name -->
26
+ <text x="80" y="280" font-family="system-ui, -apple-system, sans-serif" font-size="72" font-weight="700" fill="white">vue-is-defined</text>
27
+
28
+ <!-- Description -->
29
+ <text x="80" y="360" font-family="system-ui, -apple-system, sans-serif" font-size="32" fill="#94a3b8">Vue 3 type guard checking if ref value is not null/undefined</text>
30
+
31
+ <!-- Install command -->
32
+ <g transform="translate(80, 420)">
33
+ <rect width="500" height="60" rx="8" fill="#0f172a"/>
34
+ <text x="20" y="40" font-family="ui-monospace, monospace" font-size="24" fill="#94a3b8">npm install</text>
35
+ <text x="200" y="40" font-family="ui-monospace, monospace" font-size="24" fill="#3498db">vue-is-defined</text>
36
+ </g>
37
+
38
+ <!-- Category badge -->
39
+ <g transform="translate(80, 520)">
40
+ <rect width="158" height="40" rx="20" fill="#3498db" opacity="0.2"/>
41
+ <text x="79" y="27" text-anchor="middle" font-family="system-ui, -apple-system, sans-serif" font-size="18" fill="#3498db">Utilities</text>
42
+ </g>
43
+
44
+ <!-- Vue logo hint -->
45
+ <g transform="translate(1080, 480)">
46
+ <polygon points="100,20 140,100 60,100" fill="#3498db" opacity="0.3"/>
47
+ <polygon points="100,40 125,90 75,90" fill="#3498db" opacity="0.5"/>
48
+ </g>
49
+
50
+ <!-- Bottom text -->
51
+ <text x="1200" y="600" text-anchor="end" font-family="system-ui, -apple-system, sans-serif" font-size="18" fill="#64748b">Standalone VueUse function</text>
52
+ </svg>
package/dist/index.cjs ADDED
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const vue = require('vue');
4
+
5
+ function isDefined(v) {
6
+ return vue.unref(v) != null;
7
+ }
8
+
9
+ exports.isDefined = isDefined;
@@ -0,0 +1,9 @@
1
+ import { ComputedRef, Ref } from 'vue';
2
+
3
+ type IsDefinedReturn = boolean;
4
+ declare function isDefined<T>(v: ComputedRef<T>): v is ComputedRef<Exclude<T, null | undefined>>;
5
+ declare function isDefined<T>(v: Ref<T>): v is Ref<Exclude<T, null | undefined>>;
6
+ declare function isDefined<T>(v: T): v is Exclude<T, null | undefined>;
7
+
8
+ export { isDefined };
9
+ export type { IsDefinedReturn };
@@ -0,0 +1,9 @@
1
+ import { ComputedRef, Ref } from 'vue';
2
+
3
+ type IsDefinedReturn = boolean;
4
+ declare function isDefined<T>(v: ComputedRef<T>): v is ComputedRef<Exclude<T, null | undefined>>;
5
+ declare function isDefined<T>(v: Ref<T>): v is Ref<Exclude<T, null | undefined>>;
6
+ declare function isDefined<T>(v: T): v is Exclude<T, null | undefined>;
7
+
8
+ export { isDefined };
9
+ export type { IsDefinedReturn };
@@ -0,0 +1,9 @@
1
+ import { ComputedRef, Ref } from 'vue';
2
+
3
+ type IsDefinedReturn = boolean;
4
+ declare function isDefined<T>(v: ComputedRef<T>): v is ComputedRef<Exclude<T, null | undefined>>;
5
+ declare function isDefined<T>(v: Ref<T>): v is Ref<Exclude<T, null | undefined>>;
6
+ declare function isDefined<T>(v: T): v is Exclude<T, null | undefined>;
7
+
8
+ export { isDefined };
9
+ export type { IsDefinedReturn };
package/dist/index.mjs ADDED
@@ -0,0 +1,7 @@
1
+ import { unref } from 'vue';
2
+
3
+ function isDefined(v) {
4
+ return unref(v) != null;
5
+ }
6
+
7
+ export { isDefined };
package/logo.svg ADDED
@@ -0,0 +1,34 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96" width="256" height="256">
2
+ <defs>
3
+ <linearGradient id="bg-grad" x1="0%" y1="0%" x2="100%" y2="100%">
4
+ <stop offset="0%" style="stop-color:#2c3e50;stop-opacity:1" />
5
+ <stop offset="100%" style="stop-color:#1a252f;stop-opacity:1" />
6
+ </linearGradient>
7
+ </defs>
8
+
9
+ <!-- Background -->
10
+ <rect width="96" height="96" rx="16" fill="url(#bg-grad)"/>
11
+
12
+ <!-- Decorative corner accent -->
13
+ <path d="M96 0v20c0-11.046-8.954-20-20-20H96z" fill="#3498db" opacity="0.12"/>
14
+
15
+ <!-- Vue badge -->
16
+ <g transform="translate(8, 8)">
17
+ <rect width="18" height="9" rx="2" fill="#3498db"/>
18
+ <text x="9" y="6.8" text-anchor="middle" font-family="system-ui, -apple-system, sans-serif" font-size="4.5" font-weight="700" fill="white">VUE</text>
19
+ </g>
20
+
21
+ <!-- Category icon -->
22
+ <g>
23
+ <path d="M42 20l-8 8 8 8" fill="none" stroke="#3498db" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M54 20l8 8-8 8" fill="none" stroke="#3498db" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/><line x1="51" y1="18" x2="45" y2="38" stroke="#3498db" stroke-width="2" stroke-linecap="round"/>
24
+ </g>
25
+
26
+ <!-- Function name - textLength ensures it fits within bounds -->
27
+ <text x="48" y="57" text-anchor="middle" font-family="system-ui, -apple-system, sans-serif" font-size="10" font-weight="600" fill="white" textLength="60" lengthAdjust="spacingAndGlyphs">Is Defined</text>
28
+
29
+ <!-- Category label -->
30
+ <text x="48" y="72" text-anchor="middle" font-family="system-ui, -apple-system, sans-serif" font-size="7" fill="#3498db" opacity="0.85">Utilities</text>
31
+
32
+ <!-- Bottom accent line -->
33
+ <rect x="28" y="82" width="40" height="2" rx="1" fill="#3498db" opacity="0.5"/>
34
+ </svg>
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "vue-is-defined",
3
+ "version": "1.0.0",
4
+ "description": "Vue 3 type guard checking if ref value is not null/undefined",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.cjs",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "logo.svg",
18
+ "banner.svg"
19
+ ],
20
+ "scripts": {
21
+ "build": "unbuild",
22
+ "prepublishOnly": "npm run build"
23
+ },
24
+ "keywords": [
25
+ "vue",
26
+ "vue3",
27
+ "vue-3",
28
+ "composable",
29
+ "composition-api",
30
+ "vueuse",
31
+ "utility",
32
+ "helper",
33
+ "utils",
34
+ "defined",
35
+ "nullish",
36
+ "type-guard",
37
+ "typescript",
38
+ "check",
39
+ "null",
40
+ "undefined",
41
+ "isDefined"
42
+ ],
43
+ "author": "VueFrag",
44
+ "license": "MIT",
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/vuefrag/vue-is-defined.git"
48
+ },
49
+ "bugs": {
50
+ "url": "https://github.com/vuefrag/vue-is-defined/issues"
51
+ },
52
+ "homepage": "https://github.com/vuefrag/vue-is-defined#readme",
53
+ "peerDependencies": {
54
+ "vue": ">=3.0.0"
55
+ },
56
+ "devDependencies": {
57
+ "unbuild": "^2.0.0",
58
+ "typescript": "^5.0.0",
59
+ "vue": "^3.4.0"
60
+ }
61
+ }