is-x-browser 0.1.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/LICENSE +21 -0
- package/README.md +40 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +20 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ryohidaka
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# is-x-browser
|
|
2
|
+
|
|
3
|
+
[](https://github.com/ryohidaka/is-x-browser/actions/workflows/ci.yml)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
JavaScript library to detect if it's an X In-app browser
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm i is-x-browser
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import isXBrowser from 'is-x-browser';
|
|
18
|
+
|
|
19
|
+
if (isXBrowser()) {
|
|
20
|
+
console.log('Inside X browser');
|
|
21
|
+
} else {
|
|
22
|
+
console.log('Regular browser');
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Demo
|
|
27
|
+
|
|
28
|
+
* [Demo](https://ryohidaka.github.io/is-x-browser/)
|
|
29
|
+
|
|
30
|
+
| iOS App | Android App | Browser |
|
|
31
|
+
| -------------------------------------------- | ------------------------------------------------ | ------------------------------------------- |
|
|
32
|
+
| <img src="./images/ios-app.jpg" width=500 /> | <img src="./images/android-app.png" width=500 /> | <img src="./images/normal.png" width=500 /> |
|
|
33
|
+
|
|
34
|
+
## Contributing
|
|
35
|
+
|
|
36
|
+
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for contribution guidelines.
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect X (Twitter) in-app browser.
|
|
3
|
+
*
|
|
4
|
+
* Checks `navigator.userAgent` and `document.referrer`.
|
|
5
|
+
*
|
|
6
|
+
* @returns {boolean} Return `true` if inside X WebView, otherwise `false`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import isXBrowser from 'is-x-browser'
|
|
11
|
+
*
|
|
12
|
+
* if (isXBrowser()) {
|
|
13
|
+
* console.log('Inside X browser')
|
|
14
|
+
* } else {
|
|
15
|
+
* console.log('Regular browser')
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function isXBrowser(): boolean;
|
|
20
|
+
export { isXBrowser as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function isXBrowser() {
|
|
3
|
+
try {
|
|
4
|
+
if (typeof navigator === "undefined" || typeof document === "undefined") {
|
|
5
|
+
console.error("navigator or document is not defined.");
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
const ua = navigator.userAgent;
|
|
9
|
+
const referer = document.referrer.toLowerCase();
|
|
10
|
+
const isUAWithX = /Twitter for i(Phone|Pad)|TwitterAndroid/i.test(ua);
|
|
11
|
+
const isRefererFromX = referer.includes("t.co");
|
|
12
|
+
return isUAWithX || isRefererFromX;
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error("Error occurred while detecting X browser.", err);
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
isXBrowser as default
|
|
20
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "is-x-browser",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "JavaScript library to detect if it's an X In-app browser",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"twitter",
|
|
7
|
+
"x",
|
|
8
|
+
"browser",
|
|
9
|
+
"useragent",
|
|
10
|
+
"user-agent"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/ryohidaka/is-x-browser#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/ryohidaka/is-x-browser/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/ryohidaka/is-x-browser.git"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "bunup",
|
|
26
|
+
"dev": "bunup --watch",
|
|
27
|
+
"postinstall": "bun simple-git-hooks",
|
|
28
|
+
"lint": "biome check .",
|
|
29
|
+
"lint:fix": "biome check --write .",
|
|
30
|
+
"release": "bumpp --commit --push --tag",
|
|
31
|
+
"test": "bun test",
|
|
32
|
+
"test:coverage": "bun test --coverage",
|
|
33
|
+
"test:watch": "bun test --watch",
|
|
34
|
+
"type-check": "tsc --noEmit"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@biomejs/biome": "^2.3.11",
|
|
38
|
+
"@types/bun": "^1.3.5",
|
|
39
|
+
"bumpp": "^10.3.2",
|
|
40
|
+
"bunup": "^0.16.17",
|
|
41
|
+
"simple-git-hooks": "^2.13.1",
|
|
42
|
+
"typescript": "^5.9.3"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"typescript": ">=4.5.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"typescript": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"type": "module",
|
|
53
|
+
"exports": {
|
|
54
|
+
".": {
|
|
55
|
+
"import": {
|
|
56
|
+
"types": "./dist/index.d.ts",
|
|
57
|
+
"default": "./dist/index.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"./package.json": "./package.json"
|
|
61
|
+
},
|
|
62
|
+
"module": "./dist/index.js",
|
|
63
|
+
"simple-git-hooks": {
|
|
64
|
+
"pre-commit": "bun run lint && bun run type-check"
|
|
65
|
+
},
|
|
66
|
+
"types": "./dist/index.d.ts"
|
|
67
|
+
}
|