favicon-stealer 1.0.0 → 1.0.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/.gitattributes +2 -0
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/package.json +2 -2
- package/dist/lib/utils/index.js +0 -17
- package/dist/src/Favicon.js +0 -93
- package/dist/src/index.js +0 -8
- package/dist/types/lib/utils/index.d.ts +0 -1
- package/dist/types/src/Favicon.d.ts +0 -9
- package/dist/types/src/index.d.ts +0 -1
package/.gitattributes
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Corey Chiu
|
|
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,32 @@
|
|
|
1
|
+
# favicon-stealer
|
|
2
|
+
favicon stealer npm package
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# installation
|
|
6
|
+
```shell
|
|
7
|
+
npm install favicon-stealer
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
# usage
|
|
11
|
+
```typescript
|
|
12
|
+
import { Favicon } from 'favicon-stealer';
|
|
13
|
+
|
|
14
|
+
<Favicon url="https://example.com" />
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## props
|
|
18
|
+
| Name | Type | Description |
|
|
19
|
+
| ---- | ---- | ----------- |
|
|
20
|
+
| `url` | `string` | The URL of the website to fetch the favicon for. |
|
|
21
|
+
| `size` | `number` | The size of the favicon in pixels. Default is 32. |
|
|
22
|
+
| `className` | `string` | A class name to apply to the element. |
|
|
23
|
+
| `timeout` | `number` | The timeout in milliseconds for fetching the favicon. Default is 1000 (1 second). |
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# license
|
|
27
|
+
MIT License
|
|
28
|
+
|
|
29
|
+
# Changelog
|
|
30
|
+
- v1.0.0: Initial release (2025.1.21)
|
|
31
|
+
- v1.0.1: Add README.md (2025.1.21)
|
|
32
|
+
- v1.0.2: Update license to MIT (2025.1.21)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "favicon-stealer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"keywords": [],
|
|
11
11
|
"author": "",
|
|
12
|
-
"license": "
|
|
12
|
+
"license": "MIT",
|
|
13
13
|
"description": "",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"react": "^19.0.0",
|
package/dist/lib/utils/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDomain = void 0;
|
|
4
|
-
const getDomain = (url) => {
|
|
5
|
-
try {
|
|
6
|
-
// Add https:// protocol if not present
|
|
7
|
-
const urlWithProtocol = url.startsWith('http') ? url : `https://${url}`;
|
|
8
|
-
const domain = new URL(urlWithProtocol).hostname;
|
|
9
|
-
// Remove 'www.' prefix if exists
|
|
10
|
-
return domain.replace(/^www\./, '');
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
// Return original input if URL parsing fails
|
|
14
|
-
return url;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
exports.getDomain = getDomain;
|
package/dist/src/Favicon.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
const utils_1 = require("@/lib/utils");
|
|
38
|
-
const react_1 = __importStar(require("react"));
|
|
39
|
-
const Favicon = ({ url, size = 32, className = "", timeout = 1000, // 1 second
|
|
40
|
-
}) => {
|
|
41
|
-
const domain = (0, utils_1.getDomain)(url);
|
|
42
|
-
const [imgSrc, setImgSrc] = (0, react_1.useState)(`https://${domain}/logo.svg`);
|
|
43
|
-
const [fallbackIndex, setFallbackIndex] = (0, react_1.useState)(0);
|
|
44
|
-
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
45
|
-
const [hasError, setHasError] = (0, react_1.useState)(false);
|
|
46
|
-
const fallbackSources = [
|
|
47
|
-
`https://${domain}/logo.svg`,
|
|
48
|
-
`https://${domain}/logo.png`,
|
|
49
|
-
`https://${domain}/apple-touch-icon.png`,
|
|
50
|
-
`https://${domain}/apple-touch-icon-precomposed.png`,
|
|
51
|
-
`https://www.google.com/s2/favicons?domain=${domain}&sz=64`,
|
|
52
|
-
`https://icons.duckduckgo.com/ip3/${domain}.ico`,
|
|
53
|
-
`https://${domain}/favicon.ico`,
|
|
54
|
-
];
|
|
55
|
-
(0, react_1.useEffect)(() => {
|
|
56
|
-
let timeoutId;
|
|
57
|
-
if (isLoading) {
|
|
58
|
-
timeoutId = setTimeout(() => {
|
|
59
|
-
handleError();
|
|
60
|
-
}, timeout);
|
|
61
|
-
}
|
|
62
|
-
return () => {
|
|
63
|
-
if (timeoutId) {
|
|
64
|
-
clearTimeout(timeoutId);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}, [imgSrc, isLoading]);
|
|
68
|
-
const handleError = () => {
|
|
69
|
-
const nextIndex = fallbackIndex + 1;
|
|
70
|
-
if (nextIndex < fallbackSources.length) {
|
|
71
|
-
setFallbackIndex(nextIndex);
|
|
72
|
-
setImgSrc(fallbackSources[nextIndex]);
|
|
73
|
-
setIsLoading(true);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
setHasError(true);
|
|
77
|
-
setIsLoading(false);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
const handleLoad = () => {
|
|
81
|
-
setIsLoading(false);
|
|
82
|
-
setHasError(false);
|
|
83
|
-
};
|
|
84
|
-
return (react_1.default.createElement("div", { className: `relative inline-block ${className}`, style: { width: size, height: size } },
|
|
85
|
-
isLoading && (react_1.default.createElement("div", { className: "absolute inset-0 animate-pulse" },
|
|
86
|
-
react_1.default.createElement("div", { className: "w-full h-full rounded-md bg-gray-200/60" }))),
|
|
87
|
-
react_1.default.createElement("img", { src: imgSrc, alt: `${domain} logo`, width: size, height: size, onError: handleError, onLoad: handleLoad, className: `inline-block transition-opacity duration-300 ${isLoading ? "opacity-0" : "opacity-100"}`, style: {
|
|
88
|
-
objectFit: "contain",
|
|
89
|
-
display: hasError ? "none" : "inline-block",
|
|
90
|
-
} }),
|
|
91
|
-
hasError && (react_1.default.createElement("div", { className: "w-full h-full flex items-center justify-center bg-gray-100 rounded-md", style: { fontSize: `${size * 0.5}px` } }, domain.charAt(0).toUpperCase()))));
|
|
92
|
-
};
|
|
93
|
-
exports.default = Favicon;
|
package/dist/src/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Favicon = void 0;
|
|
7
|
-
var Favicon_1 = require("./Favicon");
|
|
8
|
-
Object.defineProperty(exports, "Favicon", { enumerable: true, get: function () { return __importDefault(Favicon_1).default; } });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getDomain: (url: string) => string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as Favicon } from './Favicon';
|