universal-app-opener 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +162 -0
  2. package/package.json +7 -2
package/README.md ADDED
@@ -0,0 +1,162 @@
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
+ ### Basic Example
22
+
23
+ ```typescript
24
+ import { generateDeepLink, detectOS } from 'universal-app-opener';
25
+
26
+ const url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
27
+ const result = generateDeepLink(url);
28
+
29
+ console.log(result);
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
+ // }
36
+ ```
37
+
38
+ ### Opening Deep Links Based on Platform
39
+
40
+ ```typescript
41
+ import { generateDeepLink, detectOS } from 'universal-app-opener';
42
+
43
+ function openLink(url: string) {
44
+ const os = detectOS();
45
+ const result = generateDeepLink(url);
46
+
47
+ if (os === 'ios' && result.ios) {
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/');
57
+ ```
58
+
59
+ ### With Fallback to Web
60
+
61
+ ```typescript
62
+ import { generateDeepLink, detectOS } from 'universal-app-opener';
63
+
64
+ function openLinkWithFallback(url: string) {
65
+ const os = detectOS();
66
+ const result = generateDeepLink(url);
67
+
68
+ let deepLink: string | null = null;
69
+
70
+ if (os === 'ios' && result.ios) {
71
+ deepLink = result.ios;
72
+ } else if (os === 'android' && result.android) {
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
+ }
84
+ }
85
+ ```
86
+
87
+ ### CommonJS Usage
88
+
89
+ ```javascript
90
+ const { generateDeepLink, detectOS } = require('universal-app-opener');
91
+
92
+ const result = generateDeepLink('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
93
+ console.log(result.ios);
94
+ ```
95
+
96
+ ## API Reference
97
+
98
+ ### `generateDeepLink(url: string): DeepLinkResult`
99
+
100
+ Converts a web URL into platform-specific deep links.
101
+
102
+ **Parameters:**
103
+ - `url` (string): The web URL to convert (YouTube or LinkedIn)
104
+
105
+ **Returns:**
106
+ ```typescript
107
+ interface DeepLinkResult {
108
+ webUrl: string; // Original web URL
109
+ ios: string | null; // iOS deep link (custom scheme)
110
+ android: string | null; // Android deep link (intent URL)
111
+ platform: 'youtube' | 'linkedin' | 'unknown';
112
+ }
113
+ ```
114
+
115
+ **Supported Platforms:**
116
+ - YouTube: `youtube.com/watch?v=*` and `youtu.be/*`
117
+ - LinkedIn: `linkedin.com/in/*`
118
+
119
+ ### `detectOS(): 'ios' | 'android' | 'desktop'`
120
+
121
+ Detects the current operating system based on user agent.
122
+
123
+ **Returns:**
124
+ - `'ios'` - iPhone, iPad, or iPod
125
+ - `'android'` - Android devices
126
+ - `'desktop'` - Desktop browsers or unknown
127
+
128
+ ## Examples
129
+
130
+ ### YouTube Video
131
+
132
+ ```typescript
133
+ const result = generateDeepLink('https://www.youtube.com/watch?v=BdgwH614LM0');
134
+ // result.ios: 'vnd.youtube://watch?v=BdgwH614LM0'
135
+ // result.android: 'intent://watch?v=BdgwH614LM0#Intent;scheme=vnd.youtube;package=com.google.android.youtube;end'
136
+ ```
137
+
138
+ ### LinkedIn Profile
139
+
140
+ ```typescript
141
+ const result = generateDeepLink('https://www.linkedin.com/in/iamsaban/');
142
+ // result.ios: 'linkedin://in/iamsaban'
143
+ // result.android: 'intent://in/iamsaban#Intent;scheme=linkedin;package=com.linkedin.android;end'
144
+ ```
145
+
146
+ ### Unknown URL
147
+
148
+ ```typescript
149
+ const result = generateDeepLink('https://example.com');
150
+ // result.ios: null
151
+ // result.android: null
152
+ // result.platform: 'unknown'
153
+ ```
154
+
155
+ ## Demo
156
+
157
+ Try it out: [Live Demo](https://mdsaban.github.io/universal-app-opener/)
158
+
159
+ ## License
160
+
161
+ MIT
162
+
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.1",
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"