universal-app-opener 0.1.1 → 0.1.2
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 +43 -53
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +37 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,86 +18,76 @@ yarn add universal-app-opener
|
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
21
|
-
###
|
|
21
|
+
### One-Click Open (Recommended)
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
import { generateDeepLink, detectOS } from 'universal-app-opener';
|
|
23
|
+
The simplest way to open a link - automatically detects platform and opens the appropriate app or web URL:
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
```typescript
|
|
26
|
+
import { openLink } from 'universal-app-opener';
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
// {
|
|
31
|
-
// webUrl: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
|
32
|
-
// ios: 'vnd.youtube://watch?v=dQw4w9WgXcQ',
|
|
33
|
-
// android: 'intent://watch?v=dQw4w9WgXcQ#Intent;scheme=vnd.youtube;package=com.google.android.youtube;end',
|
|
34
|
-
// platform: 'youtube'
|
|
35
|
-
// }
|
|
28
|
+
openLink('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
|
|
36
29
|
```
|
|
37
30
|
|
|
38
|
-
|
|
31
|
+
**With options:**
|
|
39
32
|
|
|
40
33
|
```typescript
|
|
41
|
-
import {
|
|
34
|
+
import { openLink } from 'universal-app-opener';
|
|
42
35
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
window.location.href = result.ios;
|
|
49
|
-
} else if (os === 'android' && result.android) {
|
|
50
|
-
window.location.href = result.android;
|
|
51
|
-
} else {
|
|
52
|
-
window.open(result.webUrl, '_blank');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
openLink('https://www.linkedin.com/in/iamsaban/');
|
|
36
|
+
openLink('https://www.linkedin.com/in/iamsaban/', {
|
|
37
|
+
fallbackToWeb: true, // Fallback to web if app not installed (default: true)
|
|
38
|
+
fallbackDelay: 2500, // Delay before fallback in ms (default: 2500)
|
|
39
|
+
openInNewTab: false // Open web URL in new tab (default: false)
|
|
40
|
+
});
|
|
57
41
|
```
|
|
58
42
|
|
|
59
|
-
###
|
|
43
|
+
### Advanced Usage
|
|
44
|
+
|
|
45
|
+
If you need more control, you can use the lower-level APIs:
|
|
60
46
|
|
|
61
47
|
```typescript
|
|
62
48
|
import { generateDeepLink, detectOS } from 'universal-app-opener';
|
|
63
49
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
deepLink = result.android;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (deepLink) {
|
|
77
|
-
window.location.href = deepLink;
|
|
78
|
-
setTimeout(() => {
|
|
79
|
-
window.location.href = result.webUrl;
|
|
80
|
-
}, 2500);
|
|
81
|
-
} else {
|
|
82
|
-
window.open(result.webUrl, '_blank');
|
|
83
|
-
}
|
|
50
|
+
const result = generateDeepLink('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
|
|
51
|
+
const os = detectOS();
|
|
52
|
+
|
|
53
|
+
if (os === 'ios' && result.ios) {
|
|
54
|
+
window.location.href = result.ios;
|
|
55
|
+
} else if (os === 'android' && result.android) {
|
|
56
|
+
window.location.href = result.android;
|
|
57
|
+
} else {
|
|
58
|
+
window.open(result.webUrl, '_blank');
|
|
84
59
|
}
|
|
85
60
|
```
|
|
86
61
|
|
|
87
62
|
### CommonJS Usage
|
|
88
63
|
|
|
89
64
|
```javascript
|
|
90
|
-
const {
|
|
65
|
+
const { openLink, generateDeepLink } = require('universal-app-opener');
|
|
91
66
|
|
|
92
|
-
|
|
93
|
-
console.log(result.ios);
|
|
67
|
+
openLink('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
|
|
94
68
|
```
|
|
95
69
|
|
|
96
70
|
## API Reference
|
|
97
71
|
|
|
72
|
+
### `openLink(url: string, options?: OpenLinkOptions): void`
|
|
73
|
+
|
|
74
|
+
Opens a URL in the appropriate app or browser. Automatically detects platform and handles deep linking.
|
|
75
|
+
|
|
76
|
+
**Parameters:**
|
|
77
|
+
- `url` (string): The web URL to open (YouTube or LinkedIn)
|
|
78
|
+
- `options` (optional): Configuration object
|
|
79
|
+
- `fallbackToWeb` (boolean): Fallback to web URL if app not installed (default: `true`)
|
|
80
|
+
- `fallbackDelay` (number): Delay in milliseconds before fallback (default: `2500`)
|
|
81
|
+
- `openInNewTab` (boolean): Open web URL in new tab (default: `false`)
|
|
82
|
+
|
|
83
|
+
**Example:**
|
|
84
|
+
```typescript
|
|
85
|
+
openLink('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
|
|
86
|
+
```
|
|
87
|
+
|
|
98
88
|
### `generateDeepLink(url: string): DeepLinkResult`
|
|
99
89
|
|
|
100
|
-
Converts a web URL into platform-specific deep links.
|
|
90
|
+
Converts a web URL into platform-specific deep links. Returns the deep link data without opening it.
|
|
101
91
|
|
|
102
92
|
**Parameters:**
|
|
103
93
|
- `url` (string): The web URL to convert (YouTube or LinkedIn)
|
package/dist/index.d.mts
CHANGED
|
@@ -6,5 +6,11 @@ interface DeepLinkResult {
|
|
|
6
6
|
}
|
|
7
7
|
declare function generateDeepLink(url: string): DeepLinkResult;
|
|
8
8
|
declare function detectOS(): 'ios' | 'android' | 'desktop';
|
|
9
|
+
interface OpenLinkOptions {
|
|
10
|
+
fallbackToWeb?: boolean;
|
|
11
|
+
fallbackDelay?: number;
|
|
12
|
+
openInNewTab?: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare function openLink(url: string, options?: OpenLinkOptions): void;
|
|
9
15
|
|
|
10
|
-
export { type DeepLinkResult, detectOS, generateDeepLink };
|
|
16
|
+
export { type DeepLinkResult, type OpenLinkOptions, detectOS, generateDeepLink, openLink };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,11 @@ interface DeepLinkResult {
|
|
|
6
6
|
}
|
|
7
7
|
declare function generateDeepLink(url: string): DeepLinkResult;
|
|
8
8
|
declare function detectOS(): 'ios' | 'android' | 'desktop';
|
|
9
|
+
interface OpenLinkOptions {
|
|
10
|
+
fallbackToWeb?: boolean;
|
|
11
|
+
fallbackDelay?: number;
|
|
12
|
+
openInNewTab?: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare function openLink(url: string, options?: OpenLinkOptions): void;
|
|
9
15
|
|
|
10
|
-
export { type DeepLinkResult, detectOS, generateDeepLink };
|
|
16
|
+
export { type DeepLinkResult, type OpenLinkOptions, detectOS, generateDeepLink, openLink };
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
detectOS: () => detectOS,
|
|
24
|
-
generateDeepLink: () => generateDeepLink
|
|
24
|
+
generateDeepLink: () => generateDeepLink,
|
|
25
|
+
openLink: () => openLink
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(index_exports);
|
|
27
28
|
function generateDeepLink(url) {
|
|
@@ -67,9 +68,43 @@ function detectOS() {
|
|
|
67
68
|
}
|
|
68
69
|
return "desktop";
|
|
69
70
|
}
|
|
71
|
+
function openLink(url, options = {}) {
|
|
72
|
+
const {
|
|
73
|
+
fallbackToWeb = true,
|
|
74
|
+
fallbackDelay = 2500,
|
|
75
|
+
openInNewTab = false
|
|
76
|
+
} = options;
|
|
77
|
+
const os = detectOS();
|
|
78
|
+
const result = generateDeepLink(url);
|
|
79
|
+
let deepLink = null;
|
|
80
|
+
if (os === "ios" && result.ios) {
|
|
81
|
+
deepLink = result.ios;
|
|
82
|
+
} else if (os === "android" && result.android) {
|
|
83
|
+
deepLink = result.android;
|
|
84
|
+
}
|
|
85
|
+
if (deepLink && (os === "ios" || os === "android")) {
|
|
86
|
+
window.location.href = deepLink;
|
|
87
|
+
if (fallbackToWeb) {
|
|
88
|
+
setTimeout(() => {
|
|
89
|
+
if (openInNewTab) {
|
|
90
|
+
window.open(result.webUrl, "_blank");
|
|
91
|
+
} else {
|
|
92
|
+
window.location.href = result.webUrl;
|
|
93
|
+
}
|
|
94
|
+
}, fallbackDelay);
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
if (openInNewTab) {
|
|
98
|
+
window.open(result.webUrl, "_blank");
|
|
99
|
+
} else {
|
|
100
|
+
window.location.href = result.webUrl;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
70
104
|
// Annotate the CommonJS export names for ESM import in node:
|
|
71
105
|
0 && (module.exports = {
|
|
72
106
|
detectOS,
|
|
73
|
-
generateDeepLink
|
|
107
|
+
generateDeepLink,
|
|
108
|
+
openLink
|
|
74
109
|
});
|
|
75
110
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface DeepLinkResult {\n webUrl: string;\n ios: string | null;\n android: string | null;\n platform: 'youtube' | 'linkedin' | 'unknown';\n}\n\nexport function generateDeepLink(url: string): DeepLinkResult {\n const webUrl = url.trim();\n \n const youtubeWatchMatch = webUrl.match(/youtube\\.com\\/watch\\?v=([^&]+)/);\n const youtubeShortMatch = webUrl.match(/youtu\\.be\\/([^?]+)/);\n \n if (youtubeWatchMatch || youtubeShortMatch) {\n const videoId = youtubeWatchMatch ? youtubeWatchMatch[1] : youtubeShortMatch![1];\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 const linkedinMatch = webUrl.match(/linkedin\\.com\\/in\\/([^/?]+)/);\n if (linkedinMatch) {\n const profileId = linkedinMatch[1];\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 return {\n webUrl,\n ios: null,\n android: null,\n platform: 'unknown'\n };\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\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,iBAAiB,KAA6B;AAC5D,QAAM,SAAS,IAAI,KAAK;AAExB,QAAM,oBAAoB,OAAO,MAAM,gCAAgC;AACvE,QAAM,oBAAoB,OAAO,MAAM,oBAAoB;AAE3D,MAAI,qBAAqB,mBAAmB;AAC1C,UAAM,UAAU,oBAAoB,kBAAkB,CAAC,IAAI,kBAAmB,CAAC;AAC/E,WAAO;AAAA,MACL;AAAA,MACA,KAAK,yBAAyB,OAAO;AAAA,MACrC,SAAS,oBAAoB,OAAO;AAAA,MACpC,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,QAAM,gBAAgB,OAAO,MAAM,6BAA6B;AAChE,MAAI,eAAe;AACjB,UAAM,YAAY,cAAc,CAAC;AACjC,WAAO;AAAA,MACL;AAAA,MACA,KAAK,iBAAiB,SAAS;AAAA,MAC/B,SAAS,eAAe,SAAS;AAAA,MACjC,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA,KAAK;AAAA,IACL,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AACF;AAEO,SAAS,WAA0C;AACxD,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,UAAU,UAAU,YAAY;AAEzD,MAAI,mBAAmB,KAAK,SAAS,GAAG;AACtC,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,KAAK,SAAS,GAAG;AAC7B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface DeepLinkResult {\n webUrl: string;\n ios: string | null;\n android: string | null;\n platform: 'youtube' | 'linkedin' | 'unknown';\n}\n\nexport function generateDeepLink(url: string): DeepLinkResult {\n const webUrl = url.trim();\n \n const youtubeWatchMatch = webUrl.match(/youtube\\.com\\/watch\\?v=([^&]+)/);\n const youtubeShortMatch = webUrl.match(/youtu\\.be\\/([^?]+)/);\n \n if (youtubeWatchMatch || youtubeShortMatch) {\n const videoId = youtubeWatchMatch ? youtubeWatchMatch[1] : youtubeShortMatch![1];\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 const linkedinMatch = webUrl.match(/linkedin\\.com\\/in\\/([^/?]+)/);\n if (linkedinMatch) {\n const profileId = linkedinMatch[1];\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 return {\n webUrl,\n ios: null,\n android: null,\n platform: 'unknown'\n };\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,iBAAiB,KAA6B;AAC5D,QAAM,SAAS,IAAI,KAAK;AAExB,QAAM,oBAAoB,OAAO,MAAM,gCAAgC;AACvE,QAAM,oBAAoB,OAAO,MAAM,oBAAoB;AAE3D,MAAI,qBAAqB,mBAAmB;AAC1C,UAAM,UAAU,oBAAoB,kBAAkB,CAAC,IAAI,kBAAmB,CAAC;AAC/E,WAAO;AAAA,MACL;AAAA,MACA,KAAK,yBAAyB,OAAO;AAAA,MACrC,SAAS,oBAAoB,OAAO;AAAA,MACpC,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,QAAM,gBAAgB,OAAO,MAAM,6BAA6B;AAChE,MAAI,eAAe;AACjB,UAAM,YAAY,cAAc,CAAC;AACjC,WAAO;AAAA,MACL;AAAA,MACA,KAAK,iBAAiB,SAAS;AAAA,MAC/B,SAAS,eAAe,SAAS;AAAA,MACjC,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA,KAAK;AAAA,IACL,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AACF;AAEO,SAAS,WAA0C;AACxD,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,UAAU,UAAU,YAAY;AAEzD,MAAI,mBAAmB,KAAK,SAAS,GAAG;AACtC,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,KAAK,SAAS,GAAG;AAC7B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAQO,SAAS,SAAS,KAAa,UAA2B,CAAC,GAAS;AACzE,QAAM;AAAA,IACJ,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,eAAe;AAAA,EACjB,IAAI;AAEJ,QAAM,KAAK,SAAS;AACpB,QAAM,SAAS,iBAAiB,GAAG;AAEnC,MAAI,WAA0B;AAE9B,MAAI,OAAO,SAAS,OAAO,KAAK;AAC9B,eAAW,OAAO;AAAA,EACpB,WAAW,OAAO,aAAa,OAAO,SAAS;AAC7C,eAAW,OAAO;AAAA,EACpB;AAEA,MAAI,aAAa,OAAO,SAAS,OAAO,YAAY;AAClD,WAAO,SAAS,OAAO;AAEvB,QAAI,eAAe;AACjB,iBAAW,MAAM;AACf,YAAI,cAAc;AAChB,iBAAO,KAAK,OAAO,QAAQ,QAAQ;AAAA,QACrC,OAAO;AACL,iBAAO,SAAS,OAAO,OAAO;AAAA,QAChC;AAAA,MACF,GAAG,aAAa;AAAA,IAClB;AAAA,EACF,OAAO;AACL,QAAI,cAAc;AAChB,aAAO,KAAK,OAAO,QAAQ,QAAQ;AAAA,IACrC,OAAO;AACL,aAAO,SAAS,OAAO,OAAO;AAAA,IAChC;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -42,8 +42,42 @@ function detectOS() {
|
|
|
42
42
|
}
|
|
43
43
|
return "desktop";
|
|
44
44
|
}
|
|
45
|
+
function openLink(url, options = {}) {
|
|
46
|
+
const {
|
|
47
|
+
fallbackToWeb = true,
|
|
48
|
+
fallbackDelay = 2500,
|
|
49
|
+
openInNewTab = false
|
|
50
|
+
} = options;
|
|
51
|
+
const os = detectOS();
|
|
52
|
+
const result = generateDeepLink(url);
|
|
53
|
+
let deepLink = null;
|
|
54
|
+
if (os === "ios" && result.ios) {
|
|
55
|
+
deepLink = result.ios;
|
|
56
|
+
} else if (os === "android" && result.android) {
|
|
57
|
+
deepLink = result.android;
|
|
58
|
+
}
|
|
59
|
+
if (deepLink && (os === "ios" || os === "android")) {
|
|
60
|
+
window.location.href = deepLink;
|
|
61
|
+
if (fallbackToWeb) {
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
if (openInNewTab) {
|
|
64
|
+
window.open(result.webUrl, "_blank");
|
|
65
|
+
} else {
|
|
66
|
+
window.location.href = result.webUrl;
|
|
67
|
+
}
|
|
68
|
+
}, fallbackDelay);
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
if (openInNewTab) {
|
|
72
|
+
window.open(result.webUrl, "_blank");
|
|
73
|
+
} else {
|
|
74
|
+
window.location.href = result.webUrl;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
45
78
|
export {
|
|
46
79
|
detectOS,
|
|
47
|
-
generateDeepLink
|
|
80
|
+
generateDeepLink,
|
|
81
|
+
openLink
|
|
48
82
|
};
|
|
49
83
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface DeepLinkResult {\n webUrl: string;\n ios: string | null;\n android: string | null;\n platform: 'youtube' | 'linkedin' | 'unknown';\n}\n\nexport function generateDeepLink(url: string): DeepLinkResult {\n const webUrl = url.trim();\n \n const youtubeWatchMatch = webUrl.match(/youtube\\.com\\/watch\\?v=([^&]+)/);\n const youtubeShortMatch = webUrl.match(/youtu\\.be\\/([^?]+)/);\n \n if (youtubeWatchMatch || youtubeShortMatch) {\n const videoId = youtubeWatchMatch ? youtubeWatchMatch[1] : youtubeShortMatch![1];\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 const linkedinMatch = webUrl.match(/linkedin\\.com\\/in\\/([^/?]+)/);\n if (linkedinMatch) {\n const profileId = linkedinMatch[1];\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 return {\n webUrl,\n ios: null,\n android: null,\n platform: 'unknown'\n };\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\n"],"mappings":";AAOO,SAAS,iBAAiB,KAA6B;AAC5D,QAAM,SAAS,IAAI,KAAK;AAExB,QAAM,oBAAoB,OAAO,MAAM,gCAAgC;AACvE,QAAM,oBAAoB,OAAO,MAAM,oBAAoB;AAE3D,MAAI,qBAAqB,mBAAmB;AAC1C,UAAM,UAAU,oBAAoB,kBAAkB,CAAC,IAAI,kBAAmB,CAAC;AAC/E,WAAO;AAAA,MACL;AAAA,MACA,KAAK,yBAAyB,OAAO;AAAA,MACrC,SAAS,oBAAoB,OAAO;AAAA,MACpC,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,QAAM,gBAAgB,OAAO,MAAM,6BAA6B;AAChE,MAAI,eAAe;AACjB,UAAM,YAAY,cAAc,CAAC;AACjC,WAAO;AAAA,MACL;AAAA,MACA,KAAK,iBAAiB,SAAS;AAAA,MAC/B,SAAS,eAAe,SAAS;AAAA,MACjC,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA,KAAK;AAAA,IACL,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AACF;AAEO,SAAS,WAA0C;AACxD,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,UAAU,UAAU,YAAY;AAEzD,MAAI,mBAAmB,KAAK,SAAS,GAAG;AACtC,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,KAAK,SAAS,GAAG;AAC7B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export interface DeepLinkResult {\n webUrl: string;\n ios: string | null;\n android: string | null;\n platform: 'youtube' | 'linkedin' | 'unknown';\n}\n\nexport function generateDeepLink(url: string): DeepLinkResult {\n const webUrl = url.trim();\n \n const youtubeWatchMatch = webUrl.match(/youtube\\.com\\/watch\\?v=([^&]+)/);\n const youtubeShortMatch = webUrl.match(/youtu\\.be\\/([^?]+)/);\n \n if (youtubeWatchMatch || youtubeShortMatch) {\n const videoId = youtubeWatchMatch ? youtubeWatchMatch[1] : youtubeShortMatch![1];\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 const linkedinMatch = webUrl.match(/linkedin\\.com\\/in\\/([^/?]+)/);\n if (linkedinMatch) {\n const profileId = linkedinMatch[1];\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 return {\n webUrl,\n ios: null,\n android: null,\n platform: 'unknown'\n };\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":";AAOO,SAAS,iBAAiB,KAA6B;AAC5D,QAAM,SAAS,IAAI,KAAK;AAExB,QAAM,oBAAoB,OAAO,MAAM,gCAAgC;AACvE,QAAM,oBAAoB,OAAO,MAAM,oBAAoB;AAE3D,MAAI,qBAAqB,mBAAmB;AAC1C,UAAM,UAAU,oBAAoB,kBAAkB,CAAC,IAAI,kBAAmB,CAAC;AAC/E,WAAO;AAAA,MACL;AAAA,MACA,KAAK,yBAAyB,OAAO;AAAA,MACrC,SAAS,oBAAoB,OAAO;AAAA,MACpC,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,QAAM,gBAAgB,OAAO,MAAM,6BAA6B;AAChE,MAAI,eAAe;AACjB,UAAM,YAAY,cAAc,CAAC;AACjC,WAAO;AAAA,MACL;AAAA,MACA,KAAK,iBAAiB,SAAS;AAAA,MAC/B,SAAS,eAAe,SAAS;AAAA,MACjC,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA,KAAK;AAAA,IACL,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AACF;AAEO,SAAS,WAA0C;AACxD,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,UAAU,UAAU,YAAY;AAEzD,MAAI,mBAAmB,KAAK,SAAS,GAAG;AACtC,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,KAAK,SAAS,GAAG;AAC7B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAQO,SAAS,SAAS,KAAa,UAA2B,CAAC,GAAS;AACzE,QAAM;AAAA,IACJ,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,eAAe;AAAA,EACjB,IAAI;AAEJ,QAAM,KAAK,SAAS;AACpB,QAAM,SAAS,iBAAiB,GAAG;AAEnC,MAAI,WAA0B;AAE9B,MAAI,OAAO,SAAS,OAAO,KAAK;AAC9B,eAAW,OAAO;AAAA,EACpB,WAAW,OAAO,aAAa,OAAO,SAAS;AAC7C,eAAW,OAAO;AAAA,EACpB;AAEA,MAAI,aAAa,OAAO,SAAS,OAAO,YAAY;AAClD,WAAO,SAAS,OAAO;AAEvB,QAAI,eAAe;AACjB,iBAAW,MAAM;AACf,YAAI,cAAc;AAChB,iBAAO,KAAK,OAAO,QAAQ,QAAQ;AAAA,QACrC,OAAO;AACL,iBAAO,SAAS,OAAO,OAAO;AAAA,QAChC;AAAA,MACF,GAAG,aAAa;AAAA,IAClB;AAAA,EACF,OAAO;AACL,QAAI,cAAc;AAChB,aAAO,KAAK,OAAO,QAAQ,QAAQ;AAAA,IACrC,OAAO;AACL,aAAO,SAAS,OAAO,OAAO;AAAA,IAChC;AAAA,EACF;AACF;","names":[]}
|