universal-app-opener 0.1.2 → 0.2.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/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +55 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
type Platform = 'youtube' | 'linkedin' | 'instagram' | 'unknown';
|
|
1
2
|
interface DeepLinkResult {
|
|
2
3
|
webUrl: string;
|
|
3
4
|
ios: string | null;
|
|
4
5
|
android: string | null;
|
|
5
|
-
platform:
|
|
6
|
+
platform: Platform;
|
|
6
7
|
}
|
|
8
|
+
interface DeepLinkHandler {
|
|
9
|
+
match(url: string): RegExpMatchArray | null;
|
|
10
|
+
build(url: string, match: RegExpMatchArray): DeepLinkResult;
|
|
11
|
+
}
|
|
12
|
+
|
|
7
13
|
declare function generateDeepLink(url: string): DeepLinkResult;
|
|
8
14
|
declare function detectOS(): 'ios' | 'android' | 'desktop';
|
|
9
15
|
interface OpenLinkOptions {
|
|
@@ -13,4 +19,4 @@ interface OpenLinkOptions {
|
|
|
13
19
|
}
|
|
14
20
|
declare function openLink(url: string, options?: OpenLinkOptions): void;
|
|
15
21
|
|
|
16
|
-
export { type DeepLinkResult, type OpenLinkOptions, detectOS, generateDeepLink, openLink };
|
|
22
|
+
export { type DeepLinkHandler, type DeepLinkResult, type OpenLinkOptions, type Platform, detectOS, generateDeepLink, openLink };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
type Platform = 'youtube' | 'linkedin' | 'instagram' | 'unknown';
|
|
1
2
|
interface DeepLinkResult {
|
|
2
3
|
webUrl: string;
|
|
3
4
|
ios: string | null;
|
|
4
5
|
android: string | null;
|
|
5
|
-
platform:
|
|
6
|
+
platform: Platform;
|
|
6
7
|
}
|
|
8
|
+
interface DeepLinkHandler {
|
|
9
|
+
match(url: string): RegExpMatchArray | null;
|
|
10
|
+
build(url: string, match: RegExpMatchArray): DeepLinkResult;
|
|
11
|
+
}
|
|
12
|
+
|
|
7
13
|
declare function generateDeepLink(url: string): DeepLinkResult;
|
|
8
14
|
declare function detectOS(): 'ios' | 'android' | 'desktop';
|
|
9
15
|
interface OpenLinkOptions {
|
|
@@ -13,4 +19,4 @@ interface OpenLinkOptions {
|
|
|
13
19
|
}
|
|
14
20
|
declare function openLink(url: string, options?: OpenLinkOptions): void;
|
|
15
21
|
|
|
16
|
-
export { type DeepLinkResult, type OpenLinkOptions, detectOS, generateDeepLink, openLink };
|
|
22
|
+
export { type DeepLinkHandler, type DeepLinkResult, type OpenLinkOptions, type Platform, detectOS, generateDeepLink, openLink };
|
package/dist/index.js
CHANGED
|
@@ -25,22 +25,12 @@ __export(index_exports, {
|
|
|
25
25
|
openLink: () => openLink
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
return {
|
|
35
|
-
webUrl,
|
|
36
|
-
ios: `vnd.youtube://watch?v=${videoId}`,
|
|
37
|
-
android: `intent://watch?v=${videoId}#Intent;scheme=vnd.youtube;package=com.google.android.youtube;end`,
|
|
38
|
-
platform: "youtube"
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const linkedinMatch = webUrl.match(/linkedin\.com\/in\/([^/?]+)/);
|
|
42
|
-
if (linkedinMatch) {
|
|
43
|
-
const profileId = linkedinMatch[1];
|
|
28
|
+
|
|
29
|
+
// src/platforms/linkedin.ts
|
|
30
|
+
var linkedinHandler = {
|
|
31
|
+
match: (url) => url.match(/linkedin\.com\/in\/([^/?]+)/),
|
|
32
|
+
build: (webUrl, match) => {
|
|
33
|
+
const profileId = match[1];
|
|
44
34
|
return {
|
|
45
35
|
webUrl,
|
|
46
36
|
ios: `linkedin://in/${profileId}`,
|
|
@@ -48,6 +38,10 @@ function generateDeepLink(url) {
|
|
|
48
38
|
platform: "linkedin"
|
|
49
39
|
};
|
|
50
40
|
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/platforms/unknown.ts
|
|
44
|
+
function unknownHandler(webUrl) {
|
|
51
45
|
return {
|
|
52
46
|
webUrl,
|
|
53
47
|
ios: null,
|
|
@@ -55,6 +49,51 @@ function generateDeepLink(url) {
|
|
|
55
49
|
platform: "unknown"
|
|
56
50
|
};
|
|
57
51
|
}
|
|
52
|
+
|
|
53
|
+
// src/platforms/youtube.ts
|
|
54
|
+
var youtubeHandler = {
|
|
55
|
+
match: (url) => url.match(/youtube\.com\/watch\?v=([^&]+)/) ?? url.match(/youtu\.be\/([^?]+)/),
|
|
56
|
+
build: (webUrl, match) => {
|
|
57
|
+
const videoId = match[1];
|
|
58
|
+
return {
|
|
59
|
+
webUrl,
|
|
60
|
+
ios: `vnd.youtube://watch?v=${videoId}`,
|
|
61
|
+
android: `intent://watch?v=${videoId}#Intent;scheme=vnd.youtube;package=com.google.android.youtube;end`,
|
|
62
|
+
platform: "youtube"
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/platforms/instagram.ts
|
|
68
|
+
var instagramHandler = {
|
|
69
|
+
match: (url) => url.match(/instagram\.com\/([^/?]+)/),
|
|
70
|
+
build: (webUrl, match) => {
|
|
71
|
+
const username = match[1];
|
|
72
|
+
return {
|
|
73
|
+
webUrl,
|
|
74
|
+
ios: `instagram://user?username=${username}`,
|
|
75
|
+
android: `intent://user?username=${username}#Intent;scheme=instagram;package=com.instagram.android;end`,
|
|
76
|
+
platform: "instagram"
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/index.ts
|
|
82
|
+
var handlers = [
|
|
83
|
+
youtubeHandler,
|
|
84
|
+
linkedinHandler,
|
|
85
|
+
instagramHandler
|
|
86
|
+
];
|
|
87
|
+
function generateDeepLink(url) {
|
|
88
|
+
const webUrl = url.trim();
|
|
89
|
+
for (const handler of handlers) {
|
|
90
|
+
const match = handler.match(webUrl);
|
|
91
|
+
if (match) {
|
|
92
|
+
return handler.build(webUrl, match);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return unknownHandler(webUrl);
|
|
96
|
+
}
|
|
58
97
|
function detectOS() {
|
|
59
98
|
if (typeof window === "undefined") {
|
|
60
99
|
return "desktop";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/platforms/linkedin.ts","../src/platforms/unknown.ts","../src/platforms/youtube.ts","../src/platforms/instagram.ts"],"sourcesContent":["import { instagramHandler, linkedinHandler, unknownHandler, youtubeHandler } from \"./platforms\";\nimport { DeepLinkResult } from \"./types\";\n\nexport * from './types';\n\nconst handlers = [\n youtubeHandler,\n linkedinHandler,\n instagramHandler\n];\nexport function generateDeepLink(url: string): DeepLinkResult {\n const webUrl = url.trim();\n\n for (const handler of handlers) {\n const match = handler.match(webUrl);\n if (match) {\n return handler.build(webUrl, match);\n }\n }\n\n return unknownHandler(webUrl);\n}\n\nexport function detectOS(): 'ios' | 'android' | 'desktop' {\n if (typeof window === 'undefined') {\n return 'desktop';\n }\n\n const userAgent = window.navigator.userAgent.toLowerCase();\n\n if (/iphone|ipad|ipod/.test(userAgent)) {\n return 'ios';\n }\n\n if (/android/.test(userAgent)) {\n return 'android';\n }\n\n return 'desktop';\n}\n\nexport interface OpenLinkOptions {\n fallbackToWeb?: boolean;\n fallbackDelay?: number;\n openInNewTab?: boolean;\n}\n\nexport function openLink(url: string, options: OpenLinkOptions = {}): void {\n const {\n fallbackToWeb = true,\n fallbackDelay = 2500,\n openInNewTab = false\n } = options;\n\n const os = detectOS();\n const result = generateDeepLink(url);\n\n let deepLink: string | null = null;\n\n if (os === 'ios' && result.ios) {\n deepLink = result.ios;\n } else if (os === 'android' && result.android) {\n deepLink = result.android;\n }\n\n if (deepLink && (os === 'ios' || os === 'android')) {\n window.location.href = deepLink;\n\n if (fallbackToWeb) {\n setTimeout(() => {\n if (openInNewTab) {\n window.open(result.webUrl, '_blank');\n } else {\n window.location.href = result.webUrl;\n }\n }, fallbackDelay);\n }\n } else {\n if (openInNewTab) {\n window.open(result.webUrl, '_blank');\n } else {\n window.location.href = result.webUrl;\n }\n }\n}\n\n","import { DeepLinkHandler } from '../types';\n\nexport const linkedinHandler: DeepLinkHandler = {\n match: (url) => url.match(/linkedin\\.com\\/in\\/([^/?]+)/),\n\n build: (webUrl, match) => {\n const profileId = match[1];\n\n return {\n webUrl,\n ios: `linkedin://in/${profileId}`,\n android: `intent://in/${profileId}#Intent;scheme=linkedin;package=com.linkedin.android;end`,\n platform: 'linkedin',\n };\n },\n};\n","import { DeepLinkResult } from '../types';\n\nexport function unknownHandler(webUrl: string): DeepLinkResult {\n return {\n webUrl,\n ios: null,\n android: null,\n platform: 'unknown',\n };\n}\n","import { DeepLinkHandler } from '../types';\n\nexport const youtubeHandler: DeepLinkHandler = {\n match: (url) =>\n url.match(/youtube\\.com\\/watch\\?v=([^&]+)/) ??\n url.match(/youtu\\.be\\/([^?]+)/),\n\n build: (webUrl, match) => {\n const videoId = match[1];\n\n return {\n webUrl,\n ios: `vnd.youtube://watch?v=${videoId}`,\n android: `intent://watch?v=${videoId}#Intent;scheme=vnd.youtube;package=com.google.android.youtube;end`,\n platform: 'youtube',\n };\n },\n};\n","import { DeepLinkHandler } from '../types';\n\nexport const instagramHandler: DeepLinkHandler = {\n match: (url) =>\n url.match(/instagram\\.com\\/([^/?]+)/),\n\n build: (webUrl, match) => {\n const username = match[1];\n\n return {\n webUrl,\n ios: `instagram://user?username=${username}`,\n android: `intent://user?username=${username}#Intent;scheme=instagram;package=com.instagram.android;end`,\n platform: 'instagram',\n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
|
-
|
|
6
|
-
if (youtubeWatchMatch || youtubeShortMatch) {
|
|
7
|
-
const videoId = youtubeWatchMatch ? youtubeWatchMatch[1] : youtubeShortMatch[1];
|
|
8
|
-
return {
|
|
9
|
-
webUrl,
|
|
10
|
-
ios: `vnd.youtube://watch?v=${videoId}`,
|
|
11
|
-
android: `intent://watch?v=${videoId}#Intent;scheme=vnd.youtube;package=com.google.android.youtube;end`,
|
|
12
|
-
platform: "youtube"
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
const linkedinMatch = webUrl.match(/linkedin\.com\/in\/([^/?]+)/);
|
|
16
|
-
if (linkedinMatch) {
|
|
17
|
-
const profileId = linkedinMatch[1];
|
|
1
|
+
// src/platforms/linkedin.ts
|
|
2
|
+
var linkedinHandler = {
|
|
3
|
+
match: (url) => url.match(/linkedin\.com\/in\/([^/?]+)/),
|
|
4
|
+
build: (webUrl, match) => {
|
|
5
|
+
const profileId = match[1];
|
|
18
6
|
return {
|
|
19
7
|
webUrl,
|
|
20
8
|
ios: `linkedin://in/${profileId}`,
|
|
@@ -22,6 +10,10 @@ function generateDeepLink(url) {
|
|
|
22
10
|
platform: "linkedin"
|
|
23
11
|
};
|
|
24
12
|
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// src/platforms/unknown.ts
|
|
16
|
+
function unknownHandler(webUrl) {
|
|
25
17
|
return {
|
|
26
18
|
webUrl,
|
|
27
19
|
ios: null,
|
|
@@ -29,6 +21,51 @@ function generateDeepLink(url) {
|
|
|
29
21
|
platform: "unknown"
|
|
30
22
|
};
|
|
31
23
|
}
|
|
24
|
+
|
|
25
|
+
// src/platforms/youtube.ts
|
|
26
|
+
var youtubeHandler = {
|
|
27
|
+
match: (url) => url.match(/youtube\.com\/watch\?v=([^&]+)/) ?? url.match(/youtu\.be\/([^?]+)/),
|
|
28
|
+
build: (webUrl, match) => {
|
|
29
|
+
const videoId = match[1];
|
|
30
|
+
return {
|
|
31
|
+
webUrl,
|
|
32
|
+
ios: `vnd.youtube://watch?v=${videoId}`,
|
|
33
|
+
android: `intent://watch?v=${videoId}#Intent;scheme=vnd.youtube;package=com.google.android.youtube;end`,
|
|
34
|
+
platform: "youtube"
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/platforms/instagram.ts
|
|
40
|
+
var instagramHandler = {
|
|
41
|
+
match: (url) => url.match(/instagram\.com\/([^/?]+)/),
|
|
42
|
+
build: (webUrl, match) => {
|
|
43
|
+
const username = match[1];
|
|
44
|
+
return {
|
|
45
|
+
webUrl,
|
|
46
|
+
ios: `instagram://user?username=${username}`,
|
|
47
|
+
android: `intent://user?username=${username}#Intent;scheme=instagram;package=com.instagram.android;end`,
|
|
48
|
+
platform: "instagram"
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/index.ts
|
|
54
|
+
var handlers = [
|
|
55
|
+
youtubeHandler,
|
|
56
|
+
linkedinHandler,
|
|
57
|
+
instagramHandler
|
|
58
|
+
];
|
|
59
|
+
function generateDeepLink(url) {
|
|
60
|
+
const webUrl = url.trim();
|
|
61
|
+
for (const handler of handlers) {
|
|
62
|
+
const match = handler.match(webUrl);
|
|
63
|
+
if (match) {
|
|
64
|
+
return handler.build(webUrl, match);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return unknownHandler(webUrl);
|
|
68
|
+
}
|
|
32
69
|
function detectOS() {
|
|
33
70
|
if (typeof window === "undefined") {
|
|
34
71
|
return "desktop";
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/platforms/linkedin.ts","../src/platforms/unknown.ts","../src/platforms/youtube.ts","../src/platforms/instagram.ts","../src/index.ts"],"sourcesContent":["import { DeepLinkHandler } from '../types';\n\nexport const linkedinHandler: DeepLinkHandler = {\n match: (url) => url.match(/linkedin\\.com\\/in\\/([^/?]+)/),\n\n build: (webUrl, match) => {\n const profileId = match[1];\n\n return {\n webUrl,\n ios: `linkedin://in/${profileId}`,\n android: `intent://in/${profileId}#Intent;scheme=linkedin;package=com.linkedin.android;end`,\n platform: 'linkedin',\n };\n },\n};\n","import { DeepLinkResult } from '../types';\n\nexport function unknownHandler(webUrl: string): DeepLinkResult {\n return {\n webUrl,\n ios: null,\n android: null,\n platform: 'unknown',\n };\n}\n","import { DeepLinkHandler } from '../types';\n\nexport const youtubeHandler: DeepLinkHandler = {\n match: (url) =>\n url.match(/youtube\\.com\\/watch\\?v=([^&]+)/) ??\n url.match(/youtu\\.be\\/([^?]+)/),\n\n build: (webUrl, match) => {\n const videoId = match[1];\n\n return {\n webUrl,\n ios: `vnd.youtube://watch?v=${videoId}`,\n android: `intent://watch?v=${videoId}#Intent;scheme=vnd.youtube;package=com.google.android.youtube;end`,\n platform: 'youtube',\n };\n },\n};\n","import { DeepLinkHandler } from '../types';\n\nexport const instagramHandler: DeepLinkHandler = {\n match: (url) =>\n url.match(/instagram\\.com\\/([^/?]+)/),\n\n build: (webUrl, match) => {\n const username = match[1];\n\n return {\n webUrl,\n ios: `instagram://user?username=${username}`,\n android: `intent://user?username=${username}#Intent;scheme=instagram;package=com.instagram.android;end`,\n platform: 'instagram',\n };\n },\n};\n","import { instagramHandler, linkedinHandler, unknownHandler, youtubeHandler } from \"./platforms\";\nimport { DeepLinkResult } from \"./types\";\n\nexport * from './types';\n\nconst handlers = [\n youtubeHandler,\n linkedinHandler,\n instagramHandler\n];\nexport function generateDeepLink(url: string): DeepLinkResult {\n const webUrl = url.trim();\n\n for (const handler of handlers) {\n const match = handler.match(webUrl);\n if (match) {\n return handler.build(webUrl, match);\n }\n }\n\n return unknownHandler(webUrl);\n}\n\nexport function detectOS(): 'ios' | 'android' | 'desktop' {\n if (typeof window === 'undefined') {\n return 'desktop';\n }\n\n const userAgent = window.navigator.userAgent.toLowerCase();\n\n if (/iphone|ipad|ipod/.test(userAgent)) {\n return 'ios';\n }\n\n if (/android/.test(userAgent)) {\n return 'android';\n }\n\n return 'desktop';\n}\n\nexport interface OpenLinkOptions {\n fallbackToWeb?: boolean;\n fallbackDelay?: number;\n openInNewTab?: boolean;\n}\n\nexport function openLink(url: string, options: OpenLinkOptions = {}): void {\n const {\n fallbackToWeb = true,\n fallbackDelay = 2500,\n openInNewTab = false\n } = options;\n\n const os = detectOS();\n const result = generateDeepLink(url);\n\n let deepLink: string | null = null;\n\n if (os === 'ios' && result.ios) {\n deepLink = result.ios;\n } else if (os === 'android' && result.android) {\n deepLink = result.android;\n }\n\n if (deepLink && (os === 'ios' || os === 'android')) {\n window.location.href = deepLink;\n\n if (fallbackToWeb) {\n setTimeout(() => {\n if (openInNewTab) {\n window.open(result.webUrl, '_blank');\n } else {\n window.location.href = result.webUrl;\n }\n }, fallbackDelay);\n }\n } else {\n if (openInNewTab) {\n window.open(result.webUrl, '_blank');\n } else {\n window.location.href = result.webUrl;\n }\n }\n}\n\n"],"mappings":";AAEO,IAAM,kBAAmC;AAAA,EAC9C,OAAO,CAAC,QAAQ,IAAI,MAAM,6BAA6B;AAAA,EAEvD,OAAO,CAAC,QAAQ,UAAU;AACxB,UAAM,YAAY,MAAM,CAAC;AAEzB,WAAO;AAAA,MACL;AAAA,MACA,KAAK,iBAAiB,SAAS;AAAA,MAC/B,SAAS,eAAe,SAAS;AAAA,MACjC,UAAU;AAAA,IACZ;AAAA,EACF;AACF;;;ACbO,SAAS,eAAe,QAAgC;AAC7D,SAAO;AAAA,IACL;AAAA,IACA,KAAK;AAAA,IACL,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AACF;;;ACPO,IAAM,iBAAkC;AAAA,EAC7C,OAAO,CAAC,QACN,IAAI,MAAM,gCAAgC,KAC1C,IAAI,MAAM,oBAAoB;AAAA,EAEhC,OAAO,CAAC,QAAQ,UAAU;AACxB,UAAM,UAAU,MAAM,CAAC;AAEvB,WAAO;AAAA,MACL;AAAA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