Skip to content
This repository was archived by the owner on Oct 13, 2026. It is now read-only.

Commit 8723d07

Browse files
jefrydcopi0
authored andcommitted
feat: add types (#323)
Co-Authored-By: pooya parsa <pyapar@gmail.com> # feat(types): add boolean options for pwa options interface # feat(types): add typescript declaration # chore: add types field and include types dir on publish # chore: add nuxt types and workbox sw types
1 parent 8419e48 commit 8723d07

7 files changed

Lines changed: 690 additions & 5 deletions

File tree

‎package.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
"license": "MIT",
77
"main": "lib/module.js",
88
"files": [
9-
"lib"
9+
"lib",
10+
"types"
1011
],
12+
"types": "./types/index.d.ts",
1113
"scripts": {
1214
"dev": "nuxt test/fixture",
1315
"lint": "eslint --ext .js,.vue .",
@@ -23,8 +25,10 @@
2325
"workbox-cdn": "^5.1.3"
2426
},
2527
"devDependencies": {
28+
"@nuxt/types": "^2.14.1",
2629
"@nuxtjs/eslint-config": "latest",
2730
"@nuxtjs/module-test-utils": "latest",
31+
"@types/workbox-sw": "^4.3.1",
2832
"axios": "latest",
2933
"babel-eslint": "latest",
3034
"codecov": "latest",

‎types/icon.d.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
export type iOSType = 'ipad' | 'ipadpro9' | 'ipadpro9' | 'ipadpro10' | 'ipadpro12' | 'iphonese' | 'iphone6' | 'iphoneplus' | 'iphonex' | 'iphonexr' | 'iphonexsmax'
3+
export type iOSSize = [number, number, iOSType]
4+
5+
export interface IconOptions {
6+
/**
7+
* Default: `[srcDir]/[staticDir]/icon.png`
8+
*/
9+
source: string,
10+
/**
11+
* Default: `icon.png`
12+
*/
13+
fileName: string,
14+
/**
15+
* Array of sizes to be generated (Square).
16+
* Default: `[64, 120, 144, 152, 192, 384, 512]`
17+
*/
18+
sizes: number[],
19+
20+
/**
21+
* Default:
22+
* ```javascript
23+
* [
24+
* [1536, 2048, 'ipad'], // Ipad
25+
* [1536, 2048, 'ipadpro9'], // Ipad Pro 9.7"
26+
* [1668, 2224, 'ipadpro10'], // Ipad Pro 10.5"
27+
* [2048, 2732, 'ipadpro12'], // Ipad Pro 12.9"
28+
* [640, 1136, 'iphonese'], // Iphone SE
29+
* [50, 1334, 'iphone6'], // Iphone 6
30+
* [1080, 1920, 'iphoneplus'], // Iphone Plus
31+
* [1125, 2436, 'iphonex'], // Iphone X
32+
* [828, 1792, 'iphonexr'], // Iphone XR
33+
* [1242, 2688, 'iphonexsmax'] // Iphone XS Max
34+
* ]
35+
* ```
36+
*/
37+
iosSizes: iOSSize[],
38+
/**
39+
* Default: `icons`
40+
*/
41+
targetDir: string,
42+
/**
43+
* Make icons accessible through `ctx` or Vue instances.
44+
*
45+
* Default: `true`
46+
*/
47+
plugin: boolean,
48+
/**
49+
* Name of property for accessible icons.
50+
*
51+
* Default: `$icon`
52+
*/
53+
pluginName: string,
54+
/**
55+
* Array or string of icon purpose.
56+
*
57+
* Default: `['any', 'maskable']`
58+
*/
59+
purpose: string[] | string,
60+
/**
61+
* Cache dir for generated icons
62+
*
63+
* Default: `{rootDir}/node_modules/.cache/icon`
64+
*/
65+
cacheDir: string
66+
}

‎types/index.d.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
import { IconOptions } from './icon'
3+
import { MetaOptions } from './meta'
4+
import { ManifestOptions } from './manifest'
5+
import { WorkboxOptions } from './workbox'
6+
7+
8+
declare module '@nuxt/types/config/index' {
9+
interface NuxtOptions {
10+
pwa: {
11+
icon: IconOptions | boolean,
12+
meta: MetaOptions | boolean,
13+
manifest: ManifestOptions | boolean,
14+
workbox: WorkboxOptions | boolean
15+
}
16+
icon: IconOptions | boolean
17+
meta: MetaOptions | boolean
18+
manifest: ManifestOptions | boolean
19+
workbox: WorkboxOptions | boolean
20+
}
21+
}

‎types/manifest.d.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
export interface ManifestOptions {
2+
/**
3+
* Default: _npm_package_name_
4+
*/
5+
name: string,
6+
/**
7+
* Default: _npm_package_name_
8+
*/
9+
short_name: string,
10+
/**
11+
* Default: _npm_package_description_
12+
*/
13+
description: string,
14+
/**
15+
*
16+
*/
17+
icons: Record<string, any>[],
18+
/**
19+
* Default: `routerBase + '?standalone=true'`
20+
*/
21+
start_url: string,
22+
/**
23+
* Default: `standalone`
24+
*/
25+
display: string,
26+
/**
27+
* Default: `#ffffff`
28+
*/
29+
background_color: string,
30+
/**
31+
* Default: `this.options.loading.color`
32+
*/
33+
theme_color: string,
34+
/**
35+
* Default: `ltr`
36+
*/
37+
dir: 'ltr' | 'rtl',
38+
/**
39+
* Default: `en`
40+
*/
41+
lang: string,
42+
/**
43+
* Default: `false`
44+
*/
45+
useWebmanifestExtension: boolean,
46+
/**
47+
* Default: A combination of `routerBase` and `options.build.publicPath`
48+
*/
49+
publicPath: string
50+
}

‎types/meta.d.ts‎

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
export type OgImageObject = {
2+
path: string,
3+
width: number,
4+
height: number,
5+
type: string
6+
}
7+
8+
export interface MetaOptions {
9+
/**
10+
* Default: `utf-8`
11+
*/
12+
charset: string,
13+
/**
14+
* Default: `width=device-width, initial-scale=1`
15+
*
16+
* Meta: `viewport`
17+
*/
18+
viewport: string,
19+
/**
20+
* Default: `true`
21+
*
22+
* Meta: `mobile-web-app-capable`
23+
*/
24+
mobileApp: boolean,
25+
/**
26+
* Default: `false`
27+
*
28+
* Meta: `apple-mobile-web-app-capable`
29+
*/
30+
mobileAppIOS: boolean,
31+
/**
32+
* Default: `default`
33+
*/
34+
appleStatusBarStyle: string,
35+
/**
36+
* Default: `true` (to use options.icons)
37+
*
38+
* Meta: `shortcut icon` + `apple-touch-icon`
39+
*/
40+
favicon: boolean,
41+
/**
42+
* Default: _npm_package_name_
43+
*
44+
* Meta: `title`
45+
*/
46+
name: string,
47+
/**
48+
* Default: _npm_package_author_name_
49+
*
50+
* Meta: `author`
51+
*/
52+
author: string,
53+
/**
54+
* Default: _npm_package_description_
55+
*
56+
* Meta: `description`
57+
*/
58+
description: string,
59+
/**
60+
* Default: `options.loading.color`
61+
*
62+
* Meta: `description`
63+
*/
64+
theme_color: string,
65+
/**
66+
* Default: `en`
67+
*
68+
* Meta: `lang`
69+
*/
70+
lang: string,
71+
/**
72+
* Default: `website`
73+
*
74+
* Meta: `og:type`
75+
*/
76+
ogType: string,
77+
/**
78+
* Default: _npm_package_name_
79+
*
80+
* Meta: `og:site_name`
81+
*/
82+
ogSiteName: string,
83+
/**
84+
* Default: _npm_package_name_
85+
*
86+
* Meta: `og:title`
87+
*/
88+
ogTitle: string,
89+
/**
90+
* Default: _npm_package_description_
91+
*
92+
* Meta: `og:description`
93+
*/
94+
ogDescription: string,
95+
/**
96+
* Default: `undefined`
97+
*
98+
* Meta: `N/A`
99+
*/
100+
ogHost: string | undefined,
101+
/**
102+
* Default: `true`
103+
*
104+
* Meta: `og:image` and sub-tags
105+
*/
106+
ogImage: boolean | string | OgImageObject,
107+
/**
108+
* Default: ogHost (if defined)
109+
*
110+
* Meta: `og:url`
111+
*/
112+
ogUrl: string | undefined,
113+
/**
114+
* Default: `undefined`
115+
*
116+
* Meta: `twitter:card`
117+
*/
118+
twitterCard: string | undefined,
119+
/**
120+
* Default: `undefined`
121+
*
122+
* Meta: `twitter:site`
123+
*/
124+
twitterSite: string | undefined,
125+
/**
126+
* Default: `undefined`
127+
*
128+
* Meta: `twitter:creator`
129+
*/
130+
twitterCreator: string | undefined,
131+
/**
132+
* Default: `false`
133+
*/
134+
nativeUI: boolean
135+
}

0 commit comments

Comments
 (0)