@saiballo/eleventy-plugin-favicon-factory 1.0.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/README.md ADDED
@@ -0,0 +1,117 @@
1
+ <p align="center">
2
+ <img src="https://www.11ty.dev/img/logo-github.svg" width="100" height="100" alt="11ty logo">
3
+ </p>
4
+
5
+ # eleventy-plugin-favicon-factory
6
+
7
+ > A plugin for Eleventy that, starting from an SVG file, generates favicons in various sizes and, if requested, also creates the manifest file. The plugin also takes care of injecting the generated HTML code into your pages.
8
+
9
+
10
+ ![](https://img.shields.io/badge/Made%20with%20love%20and%20with-javascript%2C%20node-blue)
11
+ [![MIT license](https://img.shields.io/badge/License-MIT-green.svg)](https://lbesson.mit-license.org/)
12
+
13
+ ## Installation
14
+
15
+ Available on [npm](https://www.npmjs.com/package/@saiballo/eleventy-plugin-svg-embed):
16
+
17
+ ```sh
18
+ npm install @saiballo/eleventy-plugin-favicon-factory --save
19
+ ```
20
+ Add the plugin to your `eleventy.config.js`:
21
+
22
+ ```js
23
+ const favicon = require("@saiballo/eleventy-plugin-favicon-factory");
24
+
25
+ module.exports = function(eleventyConfig) {
26
+
27
+ eleventyConfig.addPlugin(favicon);
28
+ };
29
+ ```
30
+
31
+ #### Options Parameters
32
+ You can add an options object to the plugin configuration. Below is the complete list of default available parameters.
33
+
34
+ ```js
35
+ module.exports = function(eleventyConfig) {
36
+
37
+ eleventyConfig.addPlugin(favicon, {
38
+ "outputFolder": "favicon",
39
+ "prefixName": "favicon",
40
+ "imgPathHref": "",
41
+ "manifestGenerate": true,
42
+ "manifestName": "manifest",
43
+ "manifestOutputFolder": "",
44
+ "manifestData": {
45
+ "name": "MyApp",
46
+ "shortName": "MyApp but short",
47
+ "description": "Progressive Web App",
48
+ "startUrl": "/",
49
+ "display": "standalone",
50
+ "backgroundColor": "#ffffff",
51
+ "themeColor": "#000000"
52
+ },
53
+ "sizeList": [16, 32, 48, 57, 72, 76, 96, 114, 120, 144, 152, 180, 192, 256, 512],
54
+ "runOnlyDevMode": true,
55
+ "tabIndent": 2
56
+ });
57
+ };
58
+ ```
59
+
60
+ #### Parameters
61
+ ```js
62
+ // output folder for image files. path is relative to "dist" project folder. e.g. this html value for links will be set to "/dist/assets/img/favicon/favicon.[png,ico,svg]"
63
+ // if folder structure does not exsist it will be created
64
+ "outputFolder": "assets/img/favicon"
65
+
66
+ // image name used for the generated favicons
67
+ "prefixName": "favicon",
68
+
69
+ // usually left empty. if not, it overrides the default HTML href value. e.g. for "https://www.site.com" it will be se to https://www.site.com/favicon.[png,ico,svg]
70
+ "imgPathHref": ""
71
+
72
+ // true | false. if "true", a manifest file will be generated
73
+ "manifestGenerate": true
74
+
75
+ // manifest filename to use in the generated HTML snippet
76
+ "manifestName": "manifest"
77
+
78
+ // output folder for the manifest file. path is relative to "dist" project folder. leave empty to place it in the root "dist" folder
79
+ "manifestOutputFolder": ""
80
+
81
+ // set your main manifest data (icon entries will be added by the plugin)
82
+ "manifestData": {
83
+ "name": "MyApp",
84
+ "shortName": "MyApp but short",
85
+ "description": "Progressive Web App",
86
+ "startUrl": "/",
87
+ "display": "standalone",
88
+ "backgroundColor": "#ffffff",
89
+ "themeColor": "#000000"
90
+ },
91
+
92
+ // choose which icon sizes to generate. these are the recommended values
93
+ "sizeList": [16, 32, 48, 57, 72, 76, 96, 114, 120, 144, 152, 180, 192, 256, 512]
94
+
95
+ // true | false. if set to "true" favicons (and optionally the manifest) are generated only once in dev mode. if "false" favicons are regenerated even in production
96
+ "runOnlyDevMode": true
97
+
98
+ // set the number of tab indentations for the generated HTML snippet
99
+ "tabIndent": 2
100
+ ```
101
+
102
+ ## Usage
103
+
104
+ In your template you can add a shortcut (the example below is for Nunjucks). The Favicon file must be in svg format and it will be copied into "outputFolder" folder:
105
+
106
+ ```js
107
+ {% favicon "path/to/your/image/favicon.svg" %}
108
+ ```
109
+
110
+ ## Team ARMADA 429
111
+ <img src="https://raw.githubusercontent.com/saiballo/saiballo/refs/heads/master/armada429.png" width="100" height="100">
112
+
113
+ * Lorenzo "Saibal" Forti
114
+
115
+ ## License
116
+
117
+ ![](https://img.shields.io/badge/License-Copyleft%20Saibal%20--%20All%20Rights%20Reserved-red)
package/jsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "compilerOptions": {
3
+ "checkJs": false
4
+ },
5
+ "exclude": [
6
+ "node_modules"
7
+ ]
8
+ }
package/main.js ADDED
@@ -0,0 +1,99 @@
1
+ /**
2
+ * @preserve
3
+ * Filename: main.js
4
+ *
5
+ * Created: 15/04/2024 (18:41:03)
6
+ * Created by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
7
+ *
8
+ * Last update: 22/04/2025 (16:11:28)
9
+ * Updated by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
10
+ *
11
+ * Copyleft: 2024 - Tutti i diritti riservati
12
+ *
13
+ * Comments:
14
+ */
15
+
16
+ const favicon = require("./src/favicon.js");
17
+ const pkg = require("./package.json");
18
+ const toLog = require("./src/log.js");
19
+
20
+ const defaultConfig = {
21
+ // output folder for img files. it's relative to "dist" project folder
22
+ "outputFolder": "favicon",
23
+ // image name prefix for generated img files
24
+ "prefixName": "favicon",
25
+ // usually left empty
26
+ "imgPathHref": "",
27
+ // generate manifest file
28
+ "manifestGenerate": true,
29
+ // manifest file name
30
+ "manifestName": "manifest",
31
+ // output folder for the manifest file. it's relative to "dist" project folder. leave it empty to put in root dist
32
+ "manifestOutputFolder": "",
33
+ // manifest data
34
+ "manifestData": {
35
+ "name": "MyApp",
36
+ "shortName": "MyApp but short",
37
+ "description": "Progressive Web App",
38
+ "startUrl": "/",
39
+ "display": "standalone",
40
+ "backgroundColor": "#ffffff",
41
+ "themeColor": "#000000"
42
+ },
43
+ "sizeList": [
44
+ // standard favicon for old browsers address bar
45
+ 16,
46
+ // hd favicon for browser address bar. minimun size for windows 10
47
+ 32,
48
+ // windows app / desktop
49
+ 48,
50
+ // iphone (ios 6 or below)
51
+ 57,
52
+ // ipad (ios 6 or below)
53
+ 72,
54
+ // ipad (ios 7+)
55
+ 76,
56
+ // android chrome (tab icon or shortcut)
57
+ 96,
58
+ // iphone retina (ios 6 or below)
59
+ 114,
60
+ // iphone retina (ios 7+)
61
+ 120,
62
+ // android, windows
63
+ 144,
64
+ // ipad retina (ios 7+)
65
+ 152,
66
+ // iphone retina hd (ios 8+) – most common today
67
+ 180,
68
+ // android or pwa
69
+ 192,
70
+ // windows/chrome desktop
71
+ 256,
72
+ // required for android 8.0+ and pwa
73
+ 512
74
+ ],
75
+ // generate favicon files and manifest only in dev mode. set to false to generate them in production mode too
76
+ "runOnlyDevMode": true,
77
+ // indentation for generated html code
78
+ "tabIndent": 2
79
+ };
80
+
81
+ module.exports = (eleventyconfig, config = {}) => {
82
+
83
+ try {
84
+
85
+ // merge defaultConfig with custom config
86
+ const pluginConfig = {
87
+ ...defaultConfig,
88
+ ...config
89
+ };
90
+
91
+ eleventyconfig.versionCheck(pkg["11ty"].compatibility);
92
+
93
+ favicon(eleventyconfig, pluginConfig);
94
+
95
+ } catch (err) {
96
+
97
+ toLog(err, "error");
98
+ }
99
+ };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@saiballo/eleventy-plugin-favicon-factory",
3
+ "version": "1.0.0",
4
+ "description": "A plugin for 11ty that creates favicons and a manifest",
5
+ "main": "main.js",
6
+ "keywords": [
7
+ "11ty",
8
+ "eleventy",
9
+ "eleventy-plugin",
10
+ "favicon",
11
+ "manifest"
12
+ ],
13
+ "license": "MIT",
14
+ "author": {
15
+ "name": "Lorenzo \"Saibal\" Forti",
16
+ "email": "lorenzo.forti@gmail.com"
17
+ },
18
+ "homepage": "https://github.com/saiballo/eleventy-plugin-favicon-factory#readme",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/saiballo/eleventy-plugin-favicon-factory.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/saiballo/eleventy-plugin-favicon-factory"
25
+ },
26
+ "engines": {
27
+ "node": ">=16"
28
+ },
29
+ "11ty": {
30
+ "compatibility": ">=2.0.0"
31
+ },
32
+ "scripts": {
33
+ "refresh": "rm -rf node_modules && rm package-lock.json && npm install"
34
+ },
35
+ "dependencies": {
36
+ "sharp": "^0.34.1",
37
+ "sharp-ico": "^0.1.5"
38
+ }
39
+ }
package/src/favicon.js ADDED
@@ -0,0 +1,210 @@
1
+ /**
2
+ * @preserve
3
+ * Filename: favicon.js
4
+ *
5
+ * Created: 15/04/2024 (18:41:03)
6
+ * Created by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
7
+ *
8
+ * Last update: 22/04/2025 (13:39:25)
9
+ * Updated by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
10
+ *
11
+ * Copyleft: 2024 - Tutti i diritti riservati
12
+ *
13
+ * Comments:
14
+ */
15
+
16
+ const fs = require("node:fs");
17
+ const fsp = fs.promises;
18
+ const path = require("node:path");
19
+ const sharp = require("sharp");
20
+ const sharpIco = require("sharp-ico");
21
+ const toLog = require("./log.js");
22
+ const util = require("./utils.js");
23
+
24
+ /**
25
+ * The function `createManifest` generates a manifest.json file with specified data and icons for a web application.
26
+ * @param eleventyconfig - `eleventyconfig` is an object containing configuration settings for the Eleventy static site generator.
27
+ * @param pluginconfig - pluginconfig is an object containing configuration settings for a plugin.
28
+ * @param sizelist - The `sizelist` parameter is an array of sizes used to filter and map the iconList. It filters to include only 192, 256, and 512
29
+ */
30
+ const createManifest = async (eleventyconfig, pluginconfig, sizelist) => {
31
+
32
+ try {
33
+
34
+ const filePath = util.getFilePath(pluginconfig.imgPathHref, pluginconfig.outputFolder);
35
+
36
+ // if missing, create the output folder
37
+ await util.isFolder(path.join(eleventyconfig.dir.output, pluginconfig.manifestOutputFolder));
38
+
39
+ // create the icon list filtering only 3 sizes
40
+ const iconList = sizelist.filter((size) => [192, 256, 512].includes(size)).map((size) => ({
41
+ "src": path.posix.join(filePath, `${pluginconfig.prefixName}-${size}x${size}.png`),
42
+ "sizes": `${size}x${size}`,
43
+ "type": "image/png"
44
+ }));
45
+
46
+ const manifestData = {
47
+ "name": pluginconfig.manifestData.name,
48
+ "short_name": pluginconfig.manifestData.shortName,
49
+ "description": pluginconfig.manifestData.description,
50
+ "start_url": pluginconfig.manifestData.startUrl,
51
+ "display": pluginconfig.manifestData.display,
52
+ "background_color": pluginconfig.manifestData.backgroundColor,
53
+ "theme_color": pluginconfig.manifestData.themeColor,
54
+ "icons": iconList
55
+ };
56
+
57
+ const manifestPath = path.join(eleventyconfig.dir.output, pluginconfig.manifestOutputFolder, `${pluginconfig.manifestName}.json`);
58
+
59
+ await fsp.writeFile(manifestPath, JSON.stringify(manifestData, null, 2), "utf-8");
60
+
61
+ toLog("manifest.json created successfully", "info");
62
+
63
+ } catch (err) {
64
+
65
+ toLog(`error while creating manifest.json: ${err.message}`, "error");
66
+ }
67
+ };
68
+
69
+ /**
70
+ * The function `getHtmlCode` generates HTML code for favicon and touch icons based on the provided configuration.
71
+ * @param eleventyconfig - `eleventyconfig` is an object containing configuration settings for the Eleventy static site generator.
72
+ * @param pluginconfig - pluginconfig is an object containing configuration settings for a plugin.
73
+ * @returns it returns a formatted HTML code snippet based on the provided `eleventyconfig` and `pluginconfig` parameters.
74
+ */
75
+ const getHtmlCode = (eleventyconfig, pluginconfig) => {
76
+
77
+ const filePath = util.getFilePath(pluginconfig.imgPathHref, pluginconfig.outputFolder);
78
+
79
+ const htmlCode = [
80
+ // universal fallback
81
+ `<link rel="shortcut icon" href="${filePath}/${pluginconfig.prefixName}.ico" type="image/x-icon"></link>`,
82
+ // modern browsers
83
+ `<link rel="icon" href="${filePath}/${pluginconfig.prefixName}.svg" type="image/svg+xml">`
84
+ ];
85
+
86
+ // fallback some desktop browsers and modern mobile browsers: Chrome/Edge mobile
87
+ if (pluginconfig.sizeList.includes(32)) {
88
+
89
+ htmlCode.push(`<link rel="icon" type="image/png" sizes="32x32" href="${filePath}/${pluginconfig.prefixName}-32x32.png">`);
90
+ }
91
+
92
+ if (pluginconfig.sizeList.includes(16)) {
93
+
94
+ htmlCode.push(`<link rel="icon" type="image/png" sizes="16x16" href="${filePath}/${pluginconfig.prefixName}-16x16.png">`);
95
+ }
96
+
97
+ if (pluginconfig.sizeList.includes(512)) {
98
+
99
+ htmlCode.push(`<link rel="apple-touch-icon" href="${filePath}/apple-touch-icon.png">`);
100
+ }
101
+
102
+ // apple icon
103
+ pluginconfig.sizeList.forEach((size) => {
104
+
105
+ if ([57, 72, 76, 114, 120, 144, 152, 180].includes(size)) {
106
+
107
+ htmlCode.push(`<link rel="apple-touch-icon" sizes="${size}x${size}" href="${filePath}/apple-touch-icon-${size}x${size}.png">`);
108
+ }
109
+ });
110
+
111
+ // if required, generate the manifest html link
112
+ if (pluginconfig.manifestGenerate) {
113
+
114
+ const manifestPath = path.join(pluginconfig.manifestOutputFolder, `${pluginconfig.manifestName}.json`);
115
+
116
+ htmlCode.push(`<link rel="manifest" href="/${manifestPath}">`);
117
+ }
118
+
119
+ // tutta questa pippa solo per mantenere la formattazione corretta. la prima riga viene ignorata
120
+ return htmlCode.map((singleLine, index) => {
121
+
122
+ if (index === 0) return singleLine;
123
+
124
+ return "\t".repeat(pluginconfig.tabIndent) + singleLine;
125
+
126
+ }).join("\n");
127
+ };
128
+
129
+ /**
130
+ * The `favicon` function generates favicon files based on specified configurations and source image, and optionally creates a web app manifest file.
131
+ * @param eleventyconfig - `eleventyconfig` is an object containing Eleventy configuration settings and methods. It is used to configure how Eleventy generates the static site.
132
+ * @param pluginconfig - pluginconfig is an object containing configuration options for the favicon plugin.
133
+ */
134
+ const favicon = (eleventyconfig, pluginconfig) => {
135
+
136
+ eleventyconfig.addShortcode("favicon", async (sourceimg) => {
137
+
138
+ if (pluginconfig.runOnlyDevMode === true && process.env.NODE_ENV === "production") {
139
+
140
+ toLog("favicon compilation is required only in dev mode", "info");
141
+
142
+ return getHtmlCode(eleventyconfig, pluginconfig);
143
+ }
144
+
145
+ try {
146
+
147
+ const outputDir = path.join(eleventyconfig.dir.output, pluginconfig.outputFolder);
148
+ const isOutputFolder = await util.isFolder(outputDir);
149
+
150
+ // if the folder didn't exist, it was created and therefore the favicons must be processed or the build is done
151
+ if (!isOutputFolder || process.env.NODE_ENV === "production") {
152
+
153
+ // check if the source image exists
154
+ const isValidSource = await util.isFile(sourceimg);
155
+
156
+ // if it doesn't exist, i can't proceed
157
+ if (!isValidSource) return false;
158
+
159
+ toLog("starting favicons creation...", "info");
160
+
161
+ util.copyFile(sourceimg, `${outputDir}/${pluginconfig.prefixName}.svg`);
162
+
163
+ const isValidSizeList = Array.isArray(pluginconfig.sizeList) && pluginconfig.sizeList.length > 0;
164
+ const sizeList = [
165
+ ...isValidSizeList ? pluginconfig.sizeList : [],
166
+ ...[512]
167
+ ];
168
+ const uniqueSizeList = [...new Set(sizeList)];
169
+
170
+ await Promise.all(
171
+ uniqueSizeList.map((size) => sharp(sourceimg).resize(size).toFile(`${outputDir}/${pluginconfig.prefixName}-${size}x${size}.png`))
172
+ );
173
+
174
+ // check if the 512x512 image exists
175
+ const png512Path = `${outputDir}/${pluginconfig.prefixName}-512x512.png`;
176
+ const isValid512 = await util.isFile(png512Path);
177
+
178
+ if (!isValid512) return false;
179
+
180
+ // create the icon file format
181
+ await sharpIco.sharpsToIco(
182
+ [
183
+ sharp(`${outputDir}/${pluginconfig.prefixName}-512x512.png`)
184
+ ],
185
+ `${outputDir}/${pluginconfig.prefixName}.ico`,
186
+ {
187
+ "sizes": [64, 32, 24],
188
+ "resizeOptions": {
189
+ "fit": "cover"
190
+ }
191
+ }
192
+ );
193
+
194
+ // if needed, create the manifest file
195
+ if (pluginconfig.manifestGenerate) {
196
+
197
+ await createManifest(eleventyconfig, pluginconfig, uniqueSizeList);
198
+ }
199
+ }
200
+
201
+ return getHtmlCode(eleventyconfig, pluginconfig);
202
+
203
+ } catch (err) {
204
+
205
+ toLog(`${err["message"]}`, "error");
206
+ }
207
+ });
208
+ };
209
+
210
+ module["exports"] = favicon;
package/src/log.js ADDED
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @preserve
3
+ * Filename: log.js
4
+ *
5
+ * Created: 15/04/2024 (18:41:03)
6
+ * Created by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
7
+ *
8
+ * Last update: 22/04/2025 (12:47:51)
9
+ * Updated by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
10
+ *
11
+ * Copyleft: 2024 - Tutti i diritti riservati
12
+ *
13
+ * Comments:
14
+ */
15
+
16
+ "use strict";
17
+
18
+ /**
19
+ * The function `toLog` logs messages with different icons based on the type of message.
20
+ * @param [message] - it is a string that represents the message to be logged. If no message is provided, the default message "OPS! An error has occurred" will be used.
21
+ * @param [type=default] - it specifies the type of log message being displayed. It can have one of the following values: info, error
22
+ */
23
+ const toLog = (message = "OPS! An error has occured", type = "default") => {
24
+
25
+ let logIcon;
26
+
27
+ switch (type) {
28
+ case "info":
29
+ logIcon = "✅";
30
+ break;
31
+ case "error":
32
+ logIcon = "❌";
33
+ break;
34
+ default:
35
+ logIcon = "📣";
36
+ break;
37
+ }
38
+
39
+ const logLabel = `${logIcon} plugin-favicon-factory -`;
40
+
41
+ console.error(`${logLabel} ${message}`);
42
+ };
43
+
44
+ module["exports"] = toLog;
package/src/utils.js ADDED
@@ -0,0 +1,121 @@
1
+ /**
2
+ * @preserve
3
+ * Filename: utils.js
4
+ *
5
+ * Created: 15/04/2024 (18:41:03)
6
+ * Created by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
7
+ *
8
+ * Last update: 22/04/2025 (13:38:40)
9
+ * Updated by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
10
+ *
11
+ * Copyleft: 2024 - Tutti i diritti riservati
12
+ *
13
+ * Comments:
14
+ */
15
+
16
+ "use strict";
17
+
18
+ const fs = require("node:fs");
19
+ const fsp = fs.promises;
20
+ const toLog = require("./log.js");
21
+
22
+ /**
23
+ * The function `getFilePath` returns a file path based on the input filepath and output folder.
24
+ * @param filepath - The `filepath` parameter is a string representing the path to a file.
25
+ * @param outputfolder - The `outputfolder` parameter is a string representing the folder where the output file will be saved.
26
+ * @returns The function `getFilePath` returns the `filePath` variable, which is determined based on the `filepath` and `outputfolder` parameters.
27
+ */
28
+ const getFilePath = (filepath, outputfolder) => {
29
+
30
+ // eslint-disable-next-line prefer-template
31
+ const filePath = filepath !== "" ? filepath : "/" + outputfolder.replace(/^\/+/, "");
32
+
33
+ return filePath;
34
+ };
35
+
36
+ /**
37
+ * The `copyFile` function copies a file from a source location to a destination location and logs the result.
38
+ * @param source - The `source` parameter in the `copyFile` function is the path to the file that you want to copy.
39
+ * @param destination - The `destination` parameter in the `copyFile` function refers to the path where the source file will be copied to.
40
+ */
41
+ const copyFile = async (source, destination) => {
42
+
43
+ try {
44
+
45
+ const fileName = source.split("/").pop();
46
+
47
+ await fsp.copyFile(source, destination);
48
+
49
+ toLog(`${fileName} copied successfully`, "info");
50
+
51
+ } catch (err) {
52
+
53
+ toLog(`error copy source file ${source}: ${err.message}`, "error");
54
+
55
+ throw err;
56
+ }
57
+ };
58
+
59
+ /**
60
+ * The function `isFolder` checks if a folder exists, creates it if it doesn't, and logs any errors encountered.
61
+ * @param folder - it represents the path to a directory that you want to check if it exists. If the directory exists, the function will return `true`.
62
+ * If the directory does not exist, the function will create it using `fsp.mkdir` with the `recursive
63
+ * @returns If the folder exists, `true` is being returned. If the folder does not exist and is successfully created, `false` is being returned.
64
+ */
65
+ const isFolder = async (folder) => {
66
+
67
+ try {
68
+
69
+ if (fs.existsSync(folder)) return true;
70
+
71
+ // se non esiste, la creiamo
72
+ await fsp.mkdir(folder, {
73
+ "recursive": true
74
+ });
75
+
76
+ toLog("output folder created. Processing favicons...", "info");
77
+
78
+ return false;
79
+
80
+ } catch (err) {
81
+
82
+ toLog(`error creating folder ${folder}: ${err.message}`, "error");
83
+
84
+ throw err;
85
+ }
86
+ };
87
+
88
+ /**
89
+ * The function `isFile` checks if a file exists at the specified filepath and returns true if it does, false if it doesn't.
90
+ * @param filepath - The `filepath` parameter in the `isFile` function is a string that represents the path to a file that you want to check for existence.
91
+ * @returns The `isFile` function returns a boolean value. It returns `true` if the file at the specified `filepath` exists, and `false` if the file does not exist.
92
+ */
93
+ const isFile = async (filepath) => {
94
+
95
+ try {
96
+
97
+ await fsp.access(filepath);
98
+
99
+ return true;
100
+
101
+ } catch (err) {
102
+
103
+ if (err["code"] === "ENOENT") {
104
+
105
+ toLog(`file ${filepath} does not exist`, "error");
106
+
107
+ return false;
108
+ }
109
+
110
+ toLog(err, "error");
111
+
112
+ throw err;
113
+ }
114
+ };
115
+
116
+ module["exports"] = {
117
+ getFilePath,
118
+ copyFile,
119
+ isFile,
120
+ isFolder
121
+ };