universal-app-opener 0.1.0 → 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 ADDED
@@ -0,0 +1,152 @@
1
+ # Universal App Opener
2
+
3
+ A zero-dependency JavaScript library that converts standard HTTP URLs (YouTube, LinkedIn) into Native Mobile Deep Links (Custom Schemes & Android Intents).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install universal-app-opener
9
+ ```
10
+
11
+ ```bash
12
+ pnpm add universal-app-opener
13
+ ```
14
+
15
+ ```bash
16
+ yarn add universal-app-opener
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### One-Click Open (Recommended)
22
+
23
+ The simplest way to open a link - automatically detects platform and opens the appropriate app or web URL:
24
+
25
+ ```typescript
26
+ import { openLink } from 'universal-app-opener';
27
+
28
+ openLink('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
29
+ ```
30
+
31
+ **With options:**
32
+
33
+ ```typescript
34
+ import { openLink } from 'universal-app-opener';
35
+
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
+ });
41
+ ```
42
+
43
+ ### Advanced Usage
44
+
45
+ If you need more control, you can use the lower-level APIs:
46
+
47
+ ```typescript
48
+ import { generateDeepLink, detectOS } from 'universal-app-opener';
49
+
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');
59
+ }
60
+ ```
61
+
62
+ ### CommonJS Usage
63
+
64
+ ```javascript
65
+ const { openLink, generateDeepLink } = require('universal-app-opener');
66
+
67
+ openLink('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
68
+ ```
69
+
70
+ ## API Reference
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
+
88
+ ### `generateDeepLink(url: string): DeepLinkResult`
89
+
90
+ Converts a web URL into platform-specific deep links. Returns the deep link data without opening it.
91
+
92
+ **Parameters:**
93
+ - `url` (string): The web URL to convert (YouTube or LinkedIn)
94
+
95
+ **Returns:**
96
+ ```typescript
97
+ interface DeepLinkResult {
98
+ webUrl: string; // Original web URL
99
+ ios: string | null; // iOS deep link (custom scheme)
100
+ android: string | null; // Android deep link (intent URL)
101
+ platform: 'youtube' | 'linkedin' | 'unknown';
102
+ }
103
+ ```
104
+
105
+ **Supported Platforms:**
106
+ - YouTube: `youtube.com/watch?v=*` and `youtu.be/*`
107
+ - LinkedIn: `linkedin.com/in/*`
108
+
109
+ ### `detectOS(): 'ios' | 'android' | 'desktop'`
110
+
111
+ Detects the current operating system based on user agent.
112
+
113
+ **Returns:**
114
+ - `'ios'` - iPhone, iPad, or iPod
115
+ - `'android'` - Android devices
116
+ - `'desktop'` - Desktop browsers or unknown
117
+
118
+ ## Examples
119
+
120
+ ### YouTube Video
121
+
122
+ ```typescript
123
+ const result = generateDeepLink('https://www.youtube.com/watch?v=BdgwH614LM0');
124
+ // result.ios: 'vnd.youtube://watch?v=BdgwH614LM0'
125
+ // result.android: 'intent://watch?v=BdgwH614LM0#Intent;scheme=vnd.youtube;package=com.google.android.youtube;end'
126
+ ```
127
+
128
+ ### LinkedIn Profile
129
+
130
+ ```typescript
131
+ const result = generateDeepLink('https://www.linkedin.com/in/iamsaban/');
132
+ // result.ios: 'linkedin://in/iamsaban'
133
+ // result.android: 'intent://in/iamsaban#Intent;scheme=linkedin;package=com.linkedin.android;end'
134
+ ```
135
+
136
+ ### Unknown URL
137
+
138
+ ```typescript
139
+ const result = generateDeepLink('https://example.com');
140
+ // result.ios: null
141
+ // result.android: null
142
+ // result.platform: 'unknown'
143
+ ```
144
+
145
+ ## Demo
146
+
147
+ Try it out: [Live Demo](https://mdsaban.github.io/universal-app-opener/)
148
+
149
+ ## License
150
+
151
+ MIT
152
+
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
@@ -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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "universal-app-opener",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "A zero-dependency library to generate deep links from HTTP URLs",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
@@ -14,7 +14,8 @@
14
14
  }
15
15
  },
16
16
  "files": [
17
- "dist"
17
+ "dist",
18
+ "README.md"
18
19
  ],
19
20
  "scripts": {
20
21
  "build": "tsup",
@@ -35,6 +36,10 @@
35
36
  "type": "git",
36
37
  "url": "https://github.com/mdsaban/universal-app-opener.git"
37
38
  },
39
+ "homepage": "https://github.com/mdsaban/universal-app-opener#readme",
40
+ "bugs": {
41
+ "url": "https://github.com/mdsaban/universal-app-opener/issues"
42
+ },
38
43
  "devDependencies": {
39
44
  "tsup": "^8.0.0",
40
45
  "typescript": "^5.3.0"