diff --git a/.editorconfig b/.editorconfig index 00d5c44..9333c67 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,11 +3,16 @@ root = true [*] charset = utf-8 end_of_line = lf -indent_size = 2 -indent_style = space +indent_size = 4 +indent_style = tab insert_final_newline = false trim_trailing_whitespace = true -tab_width = 2 +tab_width = 4 [*.js] max_line_length = 120 + +[{*.yml, *.yaml}] +indent_size = 2 +indent_style = space +tab_width = 2 \ No newline at end of file diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 113e0ed..0000000 --- a/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -/dist/ -/docs/ -/test/ -node_modules/** diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 59655d8..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "env": { - "commonjs": true, - "es6": true, - "node": true - }, - "extends": ["plugin:prettier/recommended", "eslint:recommended"], - "globals": {}, - "parser": "babel-eslint", - "parserOptions": { - "allowImportExportEverywhere": true, - "ecmaVersion": 2018, - "sourceType": "module" - }, - "plugins": ["prettier", "jsdoc"], - "rules": { - "eqeqeq": ["error", "always"], - "id-length": [ - "error", - { - "exceptions": ["x", "y", "z"], - "min": 2, - "properties": "never" - } - ], - "jsdoc/check-alignment": 1, - "jsdoc/check-param-names": 1, - "jsdoc/check-tag-names": 1, - "jsdoc/check-types": 1, - "jsdoc/implements-on-classes": 1, - "jsdoc/newline-after-description": 0, - "jsdoc/no-undefined-types": 1, - "jsdoc/require-jsdoc": 1, - "jsdoc/require-param": 1, - "jsdoc/require-param-description": 0, - "jsdoc/require-param-name": 1, - "jsdoc/require-param-type": 1, - "jsdoc/require-returns": 1, - "jsdoc/require-returns-check": 1, - "jsdoc/require-returns-description": 0, - "jsdoc/require-returns-type": 1, - "jsdoc/valid-types": 1, - "linebreak-style": ["error", "unix"], - "no-console": "warn", - "no-implicit-coercion": "error", - "no-multi-assign": "error", - "no-param-reassign": "error", - "no-ternary": "warn", - "prettier/prettier": "error", - "quotes": [ - "error", - "double", - { - "allowTemplateLiterals": true, - "avoidEscape": true - } - ], - "semi": ["error", "always"], - "yoda": "error" - } -} diff --git a/.mailmap b/.mailmap deleted file mode 100644 index 8d030fa..0000000 --- a/.mailmap +++ /dev/null @@ -1 +0,0 @@ -r37r0m0d3l # Anton Trofimenko diff --git a/.node-version b/.node-version new file mode 100644 index 0000000..a05e3d4 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +18.20.2 \ No newline at end of file diff --git a/.nvmrc b/.nvmrc index f7ae049..a05e3d4 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -20.1.0 \ No newline at end of file +18.20.2 \ No newline at end of file diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index e69de29..0000000 diff --git a/.prettierrc b/.prettierrc index a37ee05..47c0b9d 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,15 +1,12 @@ { - "arrowParens": "always", - "bracketSpacing": true, - "endOfLine": "lf", - "htmlWhitespaceSensitivity": "strict", - "jsxBracketSameLine": false, - "jsxSingleQuote": false, - "printWidth": 120, - "quoteProps": "consistent", - "semi": true, - "singleQuote": false, - "tabWidth": 2, - "trailingComma": "all", - "useTabs": false -} \ No newline at end of file + "arrowParens": "always", + "bracketSpacing": true, + "endOfLine": "lf", + "printWidth": 120, + "quoteProps": "consistent", + "semi": true, + "singleQuote": false, + "tabWidth": 4, + "trailingComma": "all", + "useTabs": true +} diff --git a/.remarkrc b/.remarkrc deleted file mode 100644 index 3d37edf..0000000 --- a/.remarkrc +++ /dev/null @@ -1,23 +0,0 @@ -{ - "plugins": [ - "remark-preset-lint-consistent", - "remark-preset-lint-markdown-style-guide", - "remark-preset-lint-recommended", - [ - "lint-no-file-name-irregular-characters", - false - ], - [ - "remark-lint-maximum-line-length", - 180 - ], - [ - "remark-lint-list-item-spacing", - false - ], - [ - "remark-lint-table-pipe-alignment", - false - ] - ] -} \ No newline at end of file diff --git a/.tool-versions b/.tool-versions index f91d2a8..ab0ac7d 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -nodejs 20.5.0 \ No newline at end of file +nodejs 18.20.2 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 346cfd9..021ca5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,9 @@ language: node_js before_install: - "npm install npm -g" node_js: - - "14.15.1" + - "18.20.2" npm: - - "6.14.8" + - "10.5.0" env: - TEST_SUITE=test script: diff --git a/CHANGELOG.md b/CHANGELOG.md index 53e951e..dc43bb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,21 +2,41 @@ --- +## [1.2.0] + +### Requirements + +- Minimal required Node.js version is now `18.20.2`. + +--- + +## [1.1.1] - 2023-08-14 + +### Added + +- `hashMulti` - Get hash of multiple files. + +### Changed + +- `writeJSON` renamed to `writeJson`. + +--- + ## [1.1.0] - 2023-07-25 ### Added -- `getLinkStatus` - Get file status unless `path` refers to a symbolic link. +- `getLinkStatus` - Get file status unless `path` refers to a symbolic link. ### Dependencies -- Removed `@await-of/of` dependency. +- Removed `@await-of/of` dependency. ### Requirements -- Minimal required Node.js version is now `16.17.0`. +- Minimal required Node.js version is now `16.17.0`. -- Removed `browser` module support. +- Removed `browser` module support. --- @@ -24,7 +44,7 @@ ### Changed -- `dirIsEmpty` now returns throw error when path is not a directory or is not readable. +- `dirIsEmpty` now returns throw error when path is not a directory or is not readable. --- @@ -32,13 +52,13 @@ ### Added -- Added `writeFileTail` function to write strin to the end of a file. Extremely useful for logging. +- Added `writeFileTail` function to write string to the end of a file. Extremely useful for logging. --- ## [1.0.0] - 2023-04-20 -- Initial release 🍾πŸ₯‚ +- Initial release 🍾πŸ₯‚ --- diff --git a/README.md b/README.md index a0e34e1..08937a7 100644 --- a/README.md +++ b/README.md @@ -16,19 +16,49 @@ Filesystem abstraction layer and common function wrappers. ```javascript import { - HileSystemLocal, - absolutePathFrom, pathFrom, - createDirectory, createFile, - readFileToBase64, readFileToBuffer, readFileToString, - dirIsEmpty, dirIsExecutable, dirIsReadable, dirIsVisible, dirIsWritable, - fileIsExecutable, fileIsReadable, fileIsVisible, fileIsWritable, - getStatus, isDirExists, isFileExists, isPathExists, - fileExtension, fileName, fileNameExt, filePath, - listContents, listDirectories, listFiles, - move, - remove, removeNonBlocking, removeSilent, - fileTruncate, writeFile, writeFileTail, writeJSON, - hash, hashCrc32, hashMd5, hashSha1, hashSha256, hashSha512, size, + HileSystemLocal, + absolutePathFrom, + pathFrom, + createDirectory, + createFile, + readFileToBase64, + readFileToBuffer, + readFileToString, + dirIsEmpty, + dirIsExecutable, + dirIsReadable, + dirIsVisible, + dirIsWritable, + fileIsExecutable, + fileIsReadable, + fileIsVisible, + fileIsWritable, + getStatus, + isDirExists, + isFileExists, + isPathExists, + fileExtension, + fileName, + fileNameExt, + filePath, + listContents, + listDirectories, + listFiles, + move, + remove, + removeNonBlocking, + removeSilent, + fileTruncate, + writeFile, + writeFileTail, + writeJson, + hash, + hashCrc32, + hashMd5, + hashSha1, + hashSha256, + hashSha512, + size, } from "@hilesystem/local"; ``` @@ -59,8 +89,9 @@ Join all arguments together and normalize the resulting path. ```javascript const paths = ["path", "to", "file.txt"]; -const str = absolutePathFrom(paths) // "/user/me/path/to/file.txt" +const str = absolutePathFrom(paths); // "/user/me/path/to/file.txt" ``` +
@@ -70,6 +101,7 @@ Get file extension. ```javascript const str = fileExtension("path/to/file.txt"); // "txt" ``` +
@@ -79,6 +111,7 @@ Return the file name without extension. ```javascript const str = fileName("path/to/file.txt"); // "file" ``` +
@@ -88,6 +121,7 @@ Return the last portion of a path. ```javascript const str = fileNameExt("path/to/file.txt"); // "file.txt" ``` +
@@ -97,6 +131,7 @@ Return the directory name of a path. ```javascript const str = filePath("path/to/file.txt"); // "path/to" ``` +
@@ -104,8 +139,9 @@ const str = filePath("path/to/file.txt"); // "path/to" Join all arguments together and normalize the resulting path. ```javascript -const str = pathFrom(["path", "to", "file.txt"]) // "path/to/file.txt" +const str = pathFrom(["path", "to", "file.txt"]); // "path/to/file.txt" ``` +
### Create @@ -117,6 +153,7 @@ Asynchronous create a directory. ```javascript const trueOrError = await createDirectory("path/to/dir", "0777", true); ``` +
@@ -126,6 +163,7 @@ Asynchronous create a file. ```javascript const trueOrError = await createFile("path/to/dir", "0777"); ``` +
### Read @@ -137,6 +175,7 @@ Reads the file into a string. ```javascript const stringOrError = await readFileToBase64("path/to/img.png"); ``` +
@@ -146,6 +185,7 @@ Reads the file into a buffer. ```javascript const bufferOrError = await readFileToBuffer("path/to/file.txt"); ``` +
@@ -155,6 +195,7 @@ Reads the file into a string. ```javascript const stringOrError = await readFileToString("path/to/file.txt"); ``` +
### Move @@ -166,6 +207,7 @@ Change the name or location of a file or directory. ```javascript const trueOrError = await move("path/to/file.ext", "path/to-another/file.ext"); ``` + ### Write @@ -177,6 +219,7 @@ Truncate a file to a specified length. ```javascript const trueOrError = await fileTruncate("path/to/file.ext"); ``` +
@@ -189,6 +232,7 @@ const data = "Text"; const options = { encoding: "utf8" }; const trueOrError = await writeFile(filePath, data, options); ``` +
@@ -201,10 +245,11 @@ const data = "Text to add to the end of the file."; const options = { encoding: "utf8" }; const trueOrError = await writeFileTail(filePath, data, options); ``` +
- writeJSON(filePath, data, options, configuration) + writeJson(filePath, data, options, configuration) Asynchronously writes data to a file, replacing the file if it already exists. ```javascript @@ -212,11 +257,12 @@ const filePath = "./file.json"; const data = { key: "value" }; const options = { encoding: "utf8" }; const config = { - sort: true, - space: "\t" + sort: true, + space: "\t", }; -const trueOrError = await writeJSON(filePath, data, options, config); +const trueOrError = await writeJson(filePath, data, options, config); ``` +
### Delete @@ -228,6 +274,7 @@ Removes a file or directory. ```javascript const voidOrError = await remove("path/to/file.txt"); ``` +
@@ -237,6 +284,7 @@ Non-blocking remove of a file or directory. ```javascript removeNonBlocking("path/to/file.txt"); ``` +
@@ -246,6 +294,7 @@ Removes files and directories (modeled on the standard POSIX rm utility). ```javascript removeSilent("path/to/file.txt"); ``` +
### Information @@ -257,6 +306,7 @@ Get file status. ```javascript const [status, error] = await getStatus("path/to/file.ext"); ``` +
@@ -266,6 +316,7 @@ Get directory status. ```javascript const trueOrFalse = await isDirExists("path/to/"); ``` +
@@ -275,6 +326,7 @@ Get file status. ```javascript const trueOrFalse = await isFileExists("path/to/file.ext"); ``` +
@@ -284,6 +336,7 @@ Get path status. ```javascript const trueOrFalse = await isPathExists("path/to/file_or_directory"); ``` +
### Check @@ -295,6 +348,7 @@ Check if a directory is empty. ```javascript const booleanOrError = await dirIsEmpty("path/to/dir", true); ``` +
@@ -304,6 +358,7 @@ Is directory executable. ```javascript const trueOrError = await dirIsExecutable("path/to/dir"); ``` +
@@ -313,6 +368,7 @@ Is directory readable. ```javascript const trueOrError = await dirIsReadable("path/to/dir"); ``` +
@@ -322,6 +378,7 @@ Is directory visible. ```javascript const trueOrError = await dirIsVisible("path/to/dir"); ``` +
@@ -331,6 +388,7 @@ Is directory writable. ```javascript const trueOrError = await dirIsWritable("path/to/dir"); ``` +
@@ -340,6 +398,7 @@ Is file executable. ```javascript const trueOrError = await fileIsExecutable("path/to/file.ext"); ``` +
@@ -349,6 +408,7 @@ Is file readable. ```javascript const trueOrError = await fileIsReadable("path/to/file.ext"); ``` +
@@ -358,6 +418,7 @@ Is file visible. ```javascript const trueOrError = await fileIsVisible("path/to/file.ext"); ``` +
@@ -367,6 +428,7 @@ Is file writable. ```javascript const trueOrError = await fileIsWritable("path/to/file.ext"); ``` +
--- @@ -380,6 +442,7 @@ Lists files and directories in path. ```javascript const arrayOfStringsOrError = await listContents("path/to/dir"); ``` +
@@ -389,6 +452,7 @@ Lists files and directories in path. ```javascript const arrayOfStringsOrError = await listDirectories("path/to/dir"); ``` +
@@ -398,6 +462,7 @@ Lists files in path. ```javascript const arrayOfStringsOrError = await listFiles("path/to/dir"); ``` +
--- @@ -411,6 +476,7 @@ Calculate hash. ```javascript const hash = await hash("path/to/file", "md5"); ``` +
@@ -420,6 +486,17 @@ CRC32. ```javascript const hash = await hashCrc32("path/to/file"); ``` + +
+ +
+ hashMulti(pathToFile) +Calculates multiple hashes. + +```javascript +const hashes = await hashMulti("path/to/file"); +``` +
@@ -429,6 +506,7 @@ MD5. ```javascript const hash = await hashMd5("path/to/file"); ``` +
@@ -438,6 +516,7 @@ SHA-1. ```javascript const hash = await hashSha1("path/to/file"); ``` +
@@ -447,6 +526,7 @@ SHA-256. ```javascript const hash = await hashSha256("path/to/file"); ``` +
@@ -456,6 +536,7 @@ SHA-512. ```javascript const hash = await hashSha512("path/to/file"); ``` +
@@ -466,6 +547,7 @@ File size in bytes. const sizeInBytes = await size("path/to/file"); const sizeAsString = await size("path/to/file", true); ``` +
--- @@ -474,12 +556,12 @@ const sizeAsString = await size("path/to/file", true); [My other projects](https://r37r0m0d3l.icu/open_source_map) - +Projects map [codacy-img]: https://api.codacy.com/project/badge/Grade/3a4f33788cd44b799242cae7e080f9e3 -[codacy-url]: https://www.codacy.com/gh/hilesystem/local?utm_source=github.com&utm_medium=referral&utm_content=hilesystem/local&utm_campaign=Badge_Grade +[codacy-url]: https://www.codacy.com/gh/hilesystem/local?utm_source=github.com&utm_medium=referral&utm_content=hilesystem/local&utm_campaign=Badge_Grade [npm-downloads-img]: https://badgen.net/npm/dt/@hilesystem/local?&icon=terminal&label=downloads&color=009688 [npm-downloads-url]: https://npmjs.com/package/@hilesystem/local [npm-version-img]: https://badgen.net/npm/v/@hilesystem/local?&icon=npm&label=npm&color=DD3636 diff --git a/ROADMAP.md b/ROADMAP.md index fc52d75..9690510 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,5 +1,7 @@ # RoadMap +## Links + - implement all from [https://medium.com/javascript-in-plain-english/6-useful-node-js-internal-modules-b3748c89c899](https://medium.com/javascript-in-plain-english/6-useful-node-js-internal-modules-b3748c89c899) - implement [https://github.com/thecodrr/fdir](https://github.com/thecodrr/fdir) @@ -22,4 +24,61 @@ - https://github.com/jsenv/jsenv-util -- https://twitter.com/tshemsedinov/status/1681888355288489984 \ No newline at end of file +- https://deno.land/std/fs + +- https://github.com/denoland/deno/issues/5916 + +- Make checksumers not only async but also streamable https://github.com/archiverjs/node-crc32-stream + +## TODO + +```ts +class Roadmap { + //#region File + + clearFile() {} + copyDirectory() {} + createDirectory() {} + deleteDirectory() {} + ensureFileExists() {} + ensureSymlinkExists() {} + getDirectoryVisibility() {} + getFileLastModified() {} + getFileMimeType() {} + getFileSize() {} + getFileTimestamp() {} + getFileVisibility() {} + isFileExists() {} + moveFile() {} + putStringToFile() {} + readFileIntoJson() {} + readStreamFromFile() {} + readStringFromFile() {} + renameFile() {} + setFileVisibility() {} + writeJsonFile() {} + writeStreamToFile() {} + writeStringToFile() {} + + //#endregion + + //#region Directory + + addStringToFile() {} + clearDirectory() {} + copyFile() {} + deleteFile() {} + ensureDirectoryExists() {} + getDirectoryLastModified() {} + getDirectorySize() {} + getDirectoryTimestamp() {} + isDirectoryExists() {} + listDirectoryContent() {} + moveDirectory() {} + removeDirectoryContents() {} + renameDirectory() {} + setDirectoryVisibility() {} + + //#endregion +} +``` diff --git a/dist/index.cjs b/dist/index.cjs index 60a038c..7b17b45 100644 --- a/dist/index.cjs +++ b/dist/index.cjs @@ -1,2 +1,2 @@ -"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("node:fs/promises"),t=require("node:path"),r=require("node:fs"),i=require("node:crypto"),s=_interopDefault(require("os")),n=_interopDefault(require("fs")),a=_interopDefault(require("node:assert"));async function createDirectory(t,r="0777",i=!0){try{return await e.mkdir(t,{mode:r,recursive:i}),!0}catch(e){return e}}async function getStatus(t){try{return[await e.stat(t)]}catch(e){return[void 0,e]}}async function writeFile(t,r,i){try{return await e.writeFile(t,r,i),!0}catch(e){return e}}async function createFile(r,i="0777"){const[s,n]=await getStatus(r);if(!n&&s.isFile())return!0;const a=t.dirname(r);if(n&&"ENOENT"===n.code){const e=await createDirectory(a,i);if(!0!==e)return e;const t=await writeFile(r,"",{mode:i,flag:"w"});return!0===t||t}if(s.isDirectory())return await writeFile(r,"",{mode:i,flag:"w"});try{return void await e.readdir(a)}catch(n){return n}}async function accessWrapper(t,r){try{return await e.access(r,t),!0}catch(e){return e}}async function dirIsReadable(e){return accessWrapper(r.constants.R_OK,e)}const o=new RegExp(["^npm-debug\\.log$","^\\..*\\.swp$","^\\.DS_Store$","^\\.AppleDouble$","^\\.LSOverride$","^Icon\\r$","^\\._.*","^\\.Spotlight-V100(?:$|\\/)","\\.Trashes","^__MACOSX$","~$","^Thumbs\\.db$","^ehthumbs\\.db$","^Desktop\\.ini$","@eaDir$","^\\$RECYCLE.BIN$","^System Volume Information$"].join("|"));function isNotSystemJunk(e){return!function isSystemJunk(e){return o.test(e)}(e)}async function listContents(t,r=!0){try{const i=await e.readdir(t);return r?i.filter(isNotSystemJunk):i}catch(e){return e}}const c=[".AppleDB",".AppleDesktop",".AppleDouble",".DS_Store",".DocumentRevisions-V100",".LSOverride",".Spotlight-V100",".TemporaryItems",".Trashes",".VolumeIcon.icns",".apdisk",".com.apple.timemachine.donotpresent",".fseventsd","Network Trash Folder","Temporary Items","$RECYCLE.BIN/","Desktop.ini","Thumbs.db","Thumbs.db:encryptable","desktop.ini","ehthumbs.db","ehthumbs_vista.db",".directory"];async function dirIsEmpty(e,t=!0){const r=await dirIsReadable(e);if(!0!==r)throw new Error(r.message,function errorExtractOptions(e){return e instanceof Error?"code"in e&&"errno"in e&&"path"in e&&"syscall"in e?{cause:{code:e.code,values:{errno:e.errno,path:e.path,syscall:e.syscall}}}:void 0:{cause:e}}(r));let i=await listContents(e);if(i instanceof Error)throw i;return 0===i.length||!!t&&function isEmptyContent(e){const t=new Set(e);return e.length=0,t.forEach(e=>{for(const r of c)e&&(e===r||e.match(RegExp(r)))&&t.delete(e)}),0===t.size}(i)}async function dirIsExecutable(e){return accessWrapper(r.constants.X_OK,e)}async function dirIsVisible(e){return accessWrapper(r.constants.F_OK,e)}async function dirIsWritable(e){return accessWrapper(r.constants.W_OK,e)}async function hash(t,r){if(!i.getHashes().includes(r))throw new TypeError(`Digest algorithm [${r}] is not supported.`);return i.createHash(r).update(await e.readFile(t)).digest("hex")}async function hashCrc32(t){return function crc32(e){let t,r=[];for(let e=0;e<256;e++){t=e;for(let e=0;e<8;e++)t=1&t?3988292384^t>>>1:t>>>1;r[e]=t}let i=-1,s=0;for(;s>>8^r[255&(i^e.charCodeAt(s))];return(-1^i)>>>0}((await e.readFile(t)).toString("binary")).toString(16)}async function hashMd5(e){return hash(e,"md5")}async function hashSha1(e){return hash(e,"sha1")}async function hashSha256(e){return hash(e,"sha256")}async function hashSha512(e){return hash(e,"sha512")}async function size(t,r=!1){const i=await e.stat(t);return r?i.size.toLocaleString("en").replace(/,/g,"_"):i.size}async function fileIsExecutable(e){return accessWrapper(r.constants.X_OK,e)}async function fileIsReadable(e){return accessWrapper(r.constants.R_OK,e)}async function fileIsVisible(e){return accessWrapper(r.constants.F_OK,e)}async function fileIsWritable(e){return accessWrapper(r.constants.W_OK,e)}async function fileTruncate(t,r=0){try{return await e.truncate(t,r),!0}catch(e){return e}}function pathFrom(e,...r){let i;return i=Array.isArray(e)?e.map(e=>e.toString()):[e.toString()],r.length&&(i=i.concat(r.map(e=>e.toString()))),t.normalize(t.join(...i))}async function listDirectories(e){const t=await listContents(e);if(!Array.isArray(t))return t;return(await Promise.all(t.map(async t=>{const r=pathFrom(e,t),[i,s]=await getStatus(r);if(!s&&i.isDirectory())return t}))).filter(e=>e)}async function listFiles(e){const t=await listContents(e);if(!Array.isArray(t))return t;return(await Promise.all(t.map(async t=>{const r=pathFrom(e,t),[i,s]=await getStatus(r);if(!s&&!i.isDirectory())return t}))).filter(e=>e)}async function move(t,r){try{return await e.rename(t,r),!0}catch(e){return e}}const l=s.homedir();function absolutePath(e){return l?String(e).replace(/^~(?=$|\/|\\)/,l):String(e)}function absolutePathFrom(e,...r){let i;return i=Array.isArray(e)?e.map(e=>e.toString()):[e.toString()],r.length&&(i=i.concat(r.map(e=>e.toString()))),absolutePath(t.resolve(...i))}function fileExtension(e){return t.extname(e).substring(1)}function fileName(e){return t.parse(e).name}function fileNameExt(e){return t.basename(e)}function filePath(e){return t.dirname(e)}async function readFileToBase64(t){try{return(await e.readFile(t,"base64")).toString()}catch(e){return e}}async function readFileToBuffer(t){try{const r=await e.readFile(t,"binary");return Buffer.from(r)}catch(e){return e}}async function readFileToString(t){try{return(await e.readFile(absolutePath(t),"utf8")).toString()}catch(e){return e}}const u="win32"===process.platform;function rimraf(e,t,r){let i=0,s=r,o=t;"function"==typeof o&&(s=o,o={}),a(e,"remove(): missing path"),a.strictEqual(typeof e,"string","remove(): path should be a string"),a.strictEqual(typeof s,"function","remove(): callback function required"),a(o,"remove(): invalid options argument provided"),a.strictEqual(typeof o,"object","remove(): options should be object"),function defaults(e){["unlink","chmod","stat","lstat","rmdir","readdir"].forEach(t=>{e[t]=e[t]||n[t]}),e.maxBusyTries=e.maxBusyTries||3}(o),rimraf_(e,o,(function callbackRimraf(t){if(t){if(("EBUSY"===t.code||"ENOTEMPTY"===t.code||"EPERM"===t.code)&&irimraf_(e,o,callbackRimraf),100*i)}if("ENOENT"===t.code)return void s(null)}s(t)}))}function rimraf_(e,t,r){a(e),a(t),a("function"==typeof r),t.lstat(e,(i,s)=>i&&"ENOENT"===i.code?r(null):i&&"EPERM"===i.code&&u?fixWinEPERM(e,t,i,r):s&&s.isDirectory()?rmdir(e,t,i,r):void t.unlink(e,i=>{if(i){if("ENOENT"===i.code)return r(null);if("EPERM"===i.code)return u?fixWinEPERM(e,t,i,r):rmdir(e,t,i,r);if("EISDIR"===i.code)return rmdir(e,t,i,r)}return r(i)}))}function fixWinEPERM(e,t,r,i){return a(e),a(t),a("function"==typeof i),r&&a(r instanceof Error),t.chmod(e,438,s=>{s?"ENOENT"===s.code?i(null):i(r):t.stat(e,(s,n)=>{s?"ENOENT"===s.code?i(null):i(r):n.isDirectory()?rmdir(e,t,r,i):t.unlink(e,i)})}),null}function rmdir(e,r,i,s){return a(e),a(r),i&&a(i instanceof Error),a("function"==typeof s),r.rmdir(e,n=>{!n||"ENOTEMPTY"!==n.code&&"EEXIST"!==n.code&&"EPERM"!==n.code?n&&"ENOTDIR"===n.code?s(i):s(n):function removeSubPath(e,r,i){a(e),a(r),a("function"==typeof i),r.readdir(e,(s,n)=>{if(s)return i(s);let a,o=n.length;if(0===o)return r.rmdir(e,i);n.forEach(s=>{rimraf(t.join(e,s),r,t=>{a||(t?i(a=t):(--o,0===o&&r.rmdir(e,i)))})})})}(e,r,s)}),null}async function remove(e){return new Promise(t=>{rimraf(e,{},e=>{e?t(e):t()})})}function removeNonBlocking(e){remove(e).then(()=>{}).catch(()=>{})}async function removeSilent(t,r){try{await e.rm(t,{force:!0,recursive:!0,...r})}catch(e){}}async function getLinkStatus(t){try{return[await e.lstat(t)]}catch(e){return[void 0,e]}}async function isDirExists(e){const[t,r]=await getStatus(e);return!r&&t.isDirectory()}async function isFileExists(e){const[t,r]=await getStatus(e);return!r&&t.isFile()}async function isPathExists(e){const[t]=await getStatus(e);return Boolean(t)}async function writeFileTail(e,t,r){if(!1===await isFileExists(e)){const t=await createFile(e);if(!0!==t)return t}const i=await readFileToString(e);return i instanceof Error?i:new Promise((s,n)=>{setTimeout(()=>{writeFile(e,`${String(i)}${String(t)}`,r).then(()=>{s(!0)}).catch(e=>{n(e)})},1)})}function isObjectLike(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function collectionSortKeys(e,t=!0){if(!isObjectLike(e))return Array.isArray(e)?e.map(e=>collectionSortKeys(e,t)):e;const r=function objectKeys(e){return Object.keys(e).sort((e,t)=>e.localeCompare(t))}(e);return r.length?r.reduce((r,i)=>(t&&isObjectLike(e[i])||t&&Array.isArray(e[i])?r[i]=collectionSortKeys(e[i],t):r[i]=e[i],r),{}):e}async function writeJSON(e,t,r,i){let s,n=t;try{i?(i.sort&&(n=isObjectLike(t)?collectionSortKeys(JSON.parse(JSON.stringify(t))):Array.isArray(t)?JSON.parse(JSON.stringify(t)):t),i.space&&(s=JSON.stringify(n,null,i.space))):s=JSON.stringify(n)}catch(e){return e}return writeFile(e,s,r)}function _defineProperty(e,t,r){return(t=function _toPropertyKey(e){var t=function _toPrimitive(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}exports.HileSystemLocal=class HileSystemLocal{constructor(){_defineProperty(this,"absolutePathFrom",absolutePathFrom),_defineProperty(this,"createDirectory",createDirectory),_defineProperty(this,"createFile",createFile),_defineProperty(this,"dirIsExecutable",dirIsExecutable),_defineProperty(this,"dirIsReadable",dirIsReadable),_defineProperty(this,"dirIsVisible",dirIsVisible),_defineProperty(this,"dirIsWritable",dirIsWritable),_defineProperty(this,"dirIsEmpty",dirIsEmpty),_defineProperty(this,"getLinkStatus",getLinkStatus),_defineProperty(this,"getStatus",getStatus),_defineProperty(this,"isDirExists",isDirExists),_defineProperty(this,"isFileExists",isFileExists),_defineProperty(this,"isPathExists",isPathExists),_defineProperty(this,"fileExtension",fileExtension),_defineProperty(this,"fileName",fileName),_defineProperty(this,"fileNameExt",fileNameExt),_defineProperty(this,"filePath",filePath),_defineProperty(this,"fileIsExecutable",fileIsExecutable),_defineProperty(this,"fileIsReadable",fileIsReadable),_defineProperty(this,"fileIsVisible",fileIsVisible),_defineProperty(this,"fileIsWritable",fileIsWritable),_defineProperty(this,"fileTruncate",fileTruncate),_defineProperty(this,"hash",hash),_defineProperty(this,"hashCrc32",hashCrc32),_defineProperty(this,"hashMd5",hashMd5),_defineProperty(this,"hashSha1",hashSha1),_defineProperty(this,"hashSha256",hashSha256),_defineProperty(this,"hashSha512",hashSha512),_defineProperty(this,"listContents",listContents),_defineProperty(this,"listDirectories",listDirectories),_defineProperty(this,"listFiles",listFiles),_defineProperty(this,"move",move),_defineProperty(this,"pathFrom",pathFrom),_defineProperty(this,"readFileToBase64",readFileToBase64),_defineProperty(this,"readFileToBuffer",readFileToBuffer),_defineProperty(this,"readFileToString",readFileToString),_defineProperty(this,"remove",remove),_defineProperty(this,"removeNonBlocking",removeNonBlocking),_defineProperty(this,"removeSilent",removeSilent),_defineProperty(this,"size",size),_defineProperty(this,"writeFile",writeFile),_defineProperty(this,"writeFileTail",writeFileTail),_defineProperty(this,"writeJSON",writeJSON)}},exports.absolutePathFrom=absolutePathFrom,exports.createDirectory=createDirectory,exports.createFile=createFile,exports.dirIsEmpty=dirIsEmpty,exports.dirIsExecutable=dirIsExecutable,exports.dirIsReadable=dirIsReadable,exports.dirIsVisible=dirIsVisible,exports.dirIsWritable=dirIsWritable,exports.fileExtension=fileExtension,exports.fileIsExecutable=fileIsExecutable,exports.fileIsReadable=fileIsReadable,exports.fileIsVisible=fileIsVisible,exports.fileIsWritable=fileIsWritable,exports.fileName=fileName,exports.fileNameExt=fileNameExt,exports.filePath=filePath,exports.fileTruncate=fileTruncate,exports.getLinkStatus=getLinkStatus,exports.getStatus=getStatus,exports.hash=hash,exports.hashCrc32=hashCrc32,exports.hashMd5=hashMd5,exports.hashSha1=hashSha1,exports.hashSha256=hashSha256,exports.hashSha512=hashSha512,exports.isDirExists=isDirExists,exports.isFileExists=isFileExists,exports.isPathExists=isPathExists,exports.listContents=listContents,exports.listDirectories=listDirectories,exports.listFiles=listFiles,exports.move=move,exports.pathFrom=pathFrom,exports.readFileToBase64=readFileToBase64,exports.readFileToBuffer=readFileToBuffer,exports.readFileToString=readFileToString,exports.remove=remove,exports.removeNonBlocking=removeNonBlocking,exports.removeSilent=removeSilent,exports.size=size,exports.writeFile=writeFile,exports.writeFileTail=writeFileTail,exports.writeJSON=writeJSON; +"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("node:fs/promises"),f=require("node:path"),l=require("node:fs"),p=require("node:crypto"),yt=require("node:os"),u=require("node:assert");async function F(t,e="0777",r=!0){try{return await c.mkdir(t,{mode:e,recursive:r}),!0}catch(i){return i}}async function h(t){try{return[await c.stat(t),void 0]}catch(e){return[void 0,e]}}async function y(t,e,r=null){try{return await c.writeFile(t,e,r),!0}catch(i){return i}}async function T(t,e="0777"){const[r,i]=await h(t);if(!i&&r.isFile())return!0;const n=f.dirname(t);if(i&&i.code==="ENOENT"){const s=await F(n,e);if(s!==!0)return s;const a=await y(t,"",{mode:e,flag:"w"});return a!==!0?a:!0}if(r.isDirectory())return await y(t,"",{mode:e,flag:"w"});try{await c.readdir(n);return}catch(s){return s}}function mt(t){return t instanceof Error?"code"in t&&"errno"in t&&"path"in t&&"syscall"in t?{cause:{code:t.code,values:{errno:t.errno,path:t.path,syscall:t.syscall}}}:{cause:t}:{cause:t}}async function d(t,e){try{return await c.access(e,t),!0}catch(r){return r}}async function x(t){var e,r;if(((e=process==null?void 0:process.permission)==null?void 0:e.has("fs.read"))!==void 0){const i=(r=process.permission)==null?void 0:r.has("fs.read",t);if(i!==void 0)return i}return d(l.constants.R_OK,t)}const Et=["^npm-debug\\.log$","^\\..*\\.swp$","^\\.DS_Store$","^\\.AppleDouble$","^\\.LSOverride$","^Icon\\r$","^\\._.*","^\\.Spotlight-V100(?:$|\\/)","\\.Trashes","^__MACOSX$","~$","^Thumbs\\.db$","^ehthumbs\\.db$","^Desktop\\.ini$","@eaDir$","^\\$RECYCLE.BIN$","^System Volume Information$"],St=new RegExp(Et.join("|"));function wt(t){return St.test(t)}function gt(t){return!wt(t)}async function E(t,e=!0){try{const r=await c.readdir(t);return e?r.filter(gt):r}catch(r){return r}}const bt=[".AppleDB",".AppleDesktop",".AppleDouble",".DS_Store",".DocumentRevisions-V100",".LSOverride",".Spotlight-V100",".TemporaryItems",".Trashes",".VolumeIcon.icns",".apdisk",".com.apple.timemachine.donotpresent",".fseventsd","Network Trash Folder","Temporary Items","$RECYCLE.BIN/","Desktop.ini","Thumbs.db","Thumbs.db:encryptable","desktop.ini","ehthumbs.db","ehthumbs_vista.db",".directory"];function It(t){const e=new Set(t);return t.length=0,e.forEach(r=>{for(const i of bt)r&&(r===i||r.match(RegExp(i)))&&e.delete(r)}),e.size===0}async function W(t,e=!0){const r=await x(t);if(r!==!0)throw new Error(r.message,mt(r));let i=await E(t);if(i instanceof Error)throw i;return i.length===0?!0:e?It(i):!1}async function J(t){return d(l.constants.X_OK,t)}async function V(t){return d(l.constants.F_OK,t)}async function j(t){var e,r;if(((e=process==null?void 0:process.permission)==null?void 0:e.has("fs.write"))!==void 0){const i=(r=process.permission)==null?void 0:r.has("fs.write",t);if(i!==void 0)return i}return d(l.constants.W_OK,t)}async function m(t,e){if(!p.getHashes().includes(e))throw new TypeError(`Digest algorithm [${e}] is not supported.`);return p.createHash(e).update(await c.readFile(t)).digest("hex")}function Ft(t){let e=[],r;for(let s=0;s<256;s++){r=s;for(let a=0;a<8;a++)r=1&r?3988292384^r>>>1:r>>>1;e[s]=r}let i=-1,n=0;for(;n>>8^e[255&(i^t.charCodeAt(n))];return(-1^i)>>>0}async function O(t){return Ft((await c.readFile(t)).toString("binary")).toString(16)}async function N(t){return m(t,"md5")}async function v(t){return m(t,"sha1")}async function R(t){return m(t,"sha256")}async function _(t){return m(t,"sha512")}async function K(t){return await Promise.all([O(t),N(t),v(t),R(t),_(t)]).then(([e,r,i,n,s])=>({crc32:e,md5:r,sha1:i,sha256:n,sha512:s}))}async function z(t,e=!1){const r=await c.stat(t);return e?r.size.toLocaleString("en").replace(/,/g,"_"):r.size}async function q(t){return d(l.constants.X_OK,t)}async function Y(t){return d(l.constants.R_OK,t)}async function H(t){return d(l.constants.F_OK,t)}async function X(t){return d(l.constants.W_OK,t)}async function U(t,e=0){try{return await c.truncate(t,e),!0}catch(r){return r}}function b(t,...e){let r;return Array.isArray(t)?r=t.map(i=>i.toString()):r=[t.toString()],e.length&&(r=r.concat(e.map(i=>i.toString()))),f.normalize(f.join(...r))}async function G(t){const e=await E(t);return Array.isArray(e)?(await Promise.all(e.map(async i=>{const n=b(t,i),[s,a]=await h(n);if(!a&&s.isDirectory())return i}))).filter(i=>i):e}async function Q(t){const e=await E(t);return Array.isArray(e)?(await Promise.all(e.map(async i=>{const n=b(t,i),[s,a]=await h(n);if(!a&&!s.isDirectory())return i}))).filter(i=>i):e}async function Z(t,e){try{return await c.rename(t,e),!0}catch(r){return r}}const $=yt.homedir();function L(t){return $?String(t).replace(/^~(?=$|\/|\\)/,$):String(t)}function k(t,...e){let r;return Array.isArray(t)?r=t.map(i=>i.toString()):r=[t.toString()],e.length&&(r=r.concat(e.map(i=>i.toString()))),L(f.resolve(...r))}function tt(t){return f.extname(t).substring(1)}function et(t){return f.parse(t).name}function rt(t){return f.basename(t)}function it(t){return f.dirname(t)}async function nt(t){try{return(await c.readFile(t,"base64")).toString()}catch(e){return e}}async function st(t){try{const e=await c.readFile(t,"binary");return Buffer.from(e)}catch(e){return e}}async function A(t){try{return(await c.readFile(L(t),"utf8")).toString()}catch(e){return e}}const B=process.platform==="win32";function Tt(t){["unlink","chmod","stat","lstat","rmdir","readdir"].forEach(r=>{t[r]=t[r]||l[r]}),t.maxBusyTries=t.maxBusyTries||3}function at(t,e,r){let i=0,n=r,s=e;typeof s=="function"&&(n=s,s={}),u(t,"remove(): missing path"),u(s,"remove(): invalid options argument provided"),Tt(s),C(t,s,function a(o){if(o){if((o.code==="EBUSY"||o.code==="ENOTEMPTY"||o.code==="EPERM")&&iC(t,s,a),S);return}if(o.code==="ENOENT"){n(null);return}}n(o)})}function C(t,e,r){u(t),u(e),u(typeof r=="function"),e.lstat(t,(i,n)=>{if(i&&i.code==="ENOENT")return r(null);if(i&&i.code==="EPERM"&&B)return M(t,e,i,r);if(n&&n.isDirectory())return w(t,e,i,r);e.unlink(t,s=>{if(s){if(s.code==="ENOENT")return r(null);if(s.code==="EPERM")return B?M(t,e,s,r):w(t,e,s,r);if(s.code==="EISDIR")return w(t,e,s,r)}return r(s)})})}function M(t,e,r,i){return u(t),u(e),u(typeof i=="function"),r&&u(r instanceof Error),e.chmod(t,438,n=>{n?n.code==="ENOENT"?i(null):i(r):e.stat(t,(s,a)=>{s?s.code==="ENOENT"?i(null):i(r):a.isDirectory()?w(t,e,r,i):e.unlink(t,i)})}),null}function w(t,e,r,i){return u(t),u(e),r&&u(r instanceof Error),u(typeof i=="function"),e.rmdir(t,n=>{n&&(n.code==="ENOTEMPTY"||n.code==="EEXIST"||n.code==="EPERM")?xt(t,e,i):n&&n.code==="ENOTDIR"?i(r):i(n)}),null}function xt(t,e,r){u(t),u(e),u(typeof r=="function"),e.readdir(t,(i,n)=>{if(i)return r(i);let s=n.length,a=null;if(s===0)return e.rmdir(t,r);n.forEach(o=>{at(f.join(t,o),e,S=>{if(!a){if(S){r(a=S);return}--s,s===0&&e.rmdir(t,r)}})})})}async function D(t){return new Promise(e=>{at(t,{},r=>{e(r||!0)})})}function ut(t){D(t).then(()=>{}).catch(()=>{})}async function ct(t,e){try{await c.rm(t,{force:!0,recursive:!0,...e})}catch{}}async function ot(t){try{return[await c.lstat(t),void 0]}catch(e){return[void 0,e]}}async function ft(t){const[e,r]=await h(t);return r?!1:e.isDirectory()}async function P(t){const[e,r]=await h(t);return r?!1:e.isFile()}async function lt(t){const[e]=await h(t);return!!e}async function ht(t,e,r=null){if(!await P(t)){const s=await T(t);if(s!==!0)return s}const n=await A(t);return n instanceof Error?n:new Promise((s,a)=>{setTimeout(()=>{y(t,`${String(n)}${String(e)}`,r).then(()=>{s(!0)}).catch(o=>{a(o)})},1)})}function Ot(t){return Object.keys(t).sort((e,r)=>e.localeCompare(r))}function I(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function g(t,e=!0){if(!I(t))return Array.isArray(t)?t.map(i=>g(i,e)):t;const r=Ot(t);return r.length?r.reduce((i,n)=>(e&&I(t[n])||e&&Array.isArray(t[n])?i[n]=g(t[n],e):i[n]=t[n],i),{}):t}async function dt(t,e,r=null,i){let n,s=e;try{i?(i.sort&&(I(e)?s=g(JSON.parse(JSON.stringify(e))):Array.isArray(e)&&(s=JSON.parse(JSON.stringify(e)))),i.space&&(n=JSON.stringify(s,null,i.space))):n=JSON.stringify(s)}catch(a){return a}return y(t,n,r)}class Nt{constructor(){this.absolutePathFrom=k,this.createDirectory=F,this.createFile=T,this.dirIsExecutable=J,this.dirIsReadable=x,this.dirIsVisible=V,this.dirIsWritable=j,this.dirIsEmpty=W,this.getLinkStatus=ot,this.getStatus=h,this.isDirExists=ft,this.isFileExists=P,this.isPathExists=lt,this.fileExtension=tt,this.fileName=et,this.fileNameExt=rt,this.filePath=it,this.fileIsExecutable=q,this.fileIsReadable=Y,this.fileIsVisible=H,this.fileIsWritable=X,this.fileTruncate=U,this.hash=m,this.hashCrc32=O,this.hashMd5=N,this.hashMulti=K,this.hashSha1=v,this.hashSha256=R,this.hashSha512=_,this.listContents=E,this.listDirectories=G,this.listFiles=Q,this.move=Z,this.pathFrom=b,this.readFileToBase64=nt,this.readFileToBuffer=st,this.readFileToString=A,this.remove=D,this.removeNonBlocking=ut,this.removeSilent=ct,this.size=z,this.writeFile=y,this.writeFileTail=ht,this.writeJson=dt}}exports.HileSystemLocal=Nt;exports.absolutePathFrom=k;exports.createDirectory=F;exports.createFile=T;exports.dirIsEmpty=W;exports.dirIsExecutable=J;exports.dirIsReadable=x;exports.dirIsVisible=V;exports.dirIsWritable=j;exports.fileExtension=tt;exports.fileIsExecutable=q;exports.fileIsReadable=Y;exports.fileIsVisible=H;exports.fileIsWritable=X;exports.fileName=et;exports.fileNameExt=rt;exports.filePath=it;exports.fileTruncate=U;exports.getLinkStatus=ot;exports.getStatus=h;exports.hash=m;exports.hashCrc32=O;exports.hashMd5=N;exports.hashMulti=K;exports.hashSha1=v;exports.hashSha256=R;exports.hashSha512=_;exports.isDirExists=ft;exports.isFileExists=P;exports.isPathExists=lt;exports.listContents=E;exports.listDirectories=G;exports.listFiles=Q;exports.move=Z;exports.pathFrom=b;exports.readFileToBase64=nt;exports.readFileToBuffer=st;exports.readFileToString=A;exports.remove=D;exports.removeNonBlocking=ut;exports.removeSilent=ct;exports.size=z;exports.writeFile=y;exports.writeFileTail=ht;exports.writeJson=dt; //# sourceMappingURL=index.cjs.map diff --git a/dist/index.cjs.map b/dist/index.cjs.map index f3b651e..fb017bd 100644 --- a/dist/index.cjs.map +++ b/dist/index.cjs.map @@ -1 +1 @@ -{"version":3,"file":"index.cjs","sources":["../src/core/create/createDirectory.js","../src/core/status/getStatus.js","../src/core/write/writeFile.js","../src/core/create/createFile.js","../src/core/access/wrapper.js","../src/core/dir/dirIsReadable.js","../src/core/list/is-system-junk.js","../src/core/list/is-not-system-junk.js","../src/core/list/contents.js","../src/core/dir/dirIsEmpty.js","../src/core/error/errorExtractOptions.js","../src/core/dir/dirIsExecutable.js","../src/core/dir/dirIsVisible.js","../src/core/dir/dirIsWritable.js","../src/core/info/hash.js","../src/core/info/hash-crc32.js","../src/core/info/hash-md5.js","../src/core/info/hash-sha1.js","../src/core/info/hash-sha256.js","../src/core/info/hash-sha512.js","../src/core/info/size.js","../src/core/file/fileIsExecutable.js","../src/core/file/fileIsReadable.js","../src/core/file/fileIsVisible.js","../src/core/file/fileIsWritable.js","../src/core/file/fileTruncate.js","../src/core/path/pathFrom.js","../src/core/list/directories.js","../src/core/list/files.js","../src/core/move/move.js","../src/core/path/absolutePath.js","../src/core/path/absolutePathFrom.js","../src/core/path/fileExtension.js","../src/core/path/fileName.js","../src/core/path/fileNameExt.js","../src/core/path/filePath.js","../src/core/read/readFileToBase64.js","../src/core/read/readFileToBuffer.js","../src/core/read/readFileToString.js","../src/core/remove/remove.js","../src/core/remove/removeNonBlocking.js","../src/core/remove/removeSilent.js","../src/core/status/getLinkStatus.js","../src/core/status/isDirExists.js","../src/core/status/isFileExists.js","../src/core/status/isPathExists.js","../src/core/write/writeFileTail.js","../src/core/write/writeJSON.js","../src/core/HileSystemLocal.js"],"sourcesContent":["import { mkdir } from \"node:fs/promises\";\n\n/**\n * @name createDirectory\n * @description Asynchronous create a directory.\n * @since 0.0.10\n * @async\n * @param {string|Buffer|URL} dirPath\n * @param {number|string=} mode\n * @param {boolean=} recursive\n * @returns {Promise}\n */\nexport async function createDirectory(dirPath, mode = \"0777\", recursive = true) {\n try {\n await mkdir(dirPath, { mode, recursive });\n return true;\n } catch (error) {\n return error;\n }\n}\n","import { stat } from \"node:fs/promises\";\n\n/**\n * @name getStatus\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise>}\n */\nexport async function getStatus(path) {\n try {\n return [await stat(path)];\n } catch (error) {\n return [undefined, error];\n }\n}\n","import { writeFile as writeFileNative } from \"node:fs/promises\";\n\n/**\n * @name writeFile\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.0.10\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n * @example\n * const controller = new AbortController();\n * const { signal } = controller;\n * const data = new Uint8Array(Buffer.from('Hello Node.js'));\n * (async () => {\n * try {\n * await writeFile('message.txt', data, { signal });\n * } catch (error) {\n * // When a request is aborted - error is an AbortError\n * }\n * })();\n * // When the request should be aborted\n * controller.abort();\n */\nexport async function writeFile(filePath, data, options) {\n try {\n await writeFileNative(filePath, data, options);\n return true;\n } catch (error) {\n return error;\n }\n}\n","import { dirname } from \"node:path\";\nimport { readdir } from \"node:fs/promises\";\n\nimport { createDirectory } from \"./createDirectory.js\";\nimport { getStatus } from \"../status/getStatus.js\";\nimport { writeFile } from \"../write/writeFile.js\";\n\n/**\n * @name createFile\n * @description Asynchronous create a file.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {number|string=} mode\n * @returns {Promise}\n */\nexport async function createFile(pathLike, mode = \"0777\") {\n const [status, error] = await getStatus(pathLike);\n if (!error && status.isFile()) {\n return true;\n }\n const dirPath = dirname(pathLike);\n if (error) {\n if (error.code === \"ENOENT\") {\n const dirCreated = await createDirectory(dirPath, mode);\n if (dirCreated !== true) {\n return dirCreated;\n }\n const fileWritten = await writeFile(pathLike, \"\", { mode, flag: \"w\" });\n if (fileWritten !== true) {\n return fileWritten;\n }\n return true;\n }\n }\n if (status.isDirectory()) {\n return await writeFile(pathLike, \"\", { mode, flag: \"w\" });\n } else {\n try {\n await readdir(dirPath);\n return undefined;\n } catch (error) {\n return error;\n }\n }\n}\n","import { access } from \"node:fs/promises\";\n\n/**\n * @name accessWrapper\n * @description Asynchronously tests a user's permissions for the file specified by path.\n * @since 0.0.1\n * @async\n * @param {number} mode\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function accessWrapper(mode, path) {\n try {\n await access(path, mode);\n return true;\n } catch (error) {\n return error;\n }\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name dirIsReadable\n * @description Directory is visible to the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsReadable(pathToDir) {\n return accessWrapper(constants.R_OK, pathToDir);\n}\n","// keep updated https://github.com/sindresorhus/junk\n\nconst ignoreList = [\n // # All\n \"^npm-debug\\\\.log$\", // Error log for npm\n \"^\\\\..*\\\\.swp$\", // Swap file for vim state\n\n // # macOS\n \"^\\\\.DS_Store$\", // Stores custom folder attributes\n \"^\\\\.AppleDouble$\", // Stores additional file resources\n \"^\\\\.LSOverride$\", // Contains the absolute path to the app to be used\n \"^Icon\\\\r$\", // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop\n \"^\\\\._.*\", // Thumbnail\n \"^\\\\.Spotlight-V100(?:$|\\\\/)\", // Directory that might appear on external disk\n \"\\\\.Trashes\", // File that might appear on external disk\n \"^__MACOSX$\", // Resource fork\n\n // # Linux\n \"~$\", // Backup file\n\n // # Windows\n \"^Thumbs\\\\.db$\", // Image file cache\n \"^ehthumbs\\\\.db$\", // Folder config file\n \"^Desktop\\\\.ini$\", // Stores custom folder attributes\n \"@eaDir$\", // Synology Diskstation \"hidden\" folder where the server stores thumbnails\n \"^\\\\$RECYCLE.BIN$\", // Special folder with columns like Date deleted and Original location\n \"^System Volume Information$\",\n];\n\nexport const junkRegex = new RegExp(ignoreList.join(\"|\"));\n\n/**\n * @name isSystemJunk\n * @description Returns true if filename matches a system junk file.\n * @param {string} [fileName]\n * @returns {boolean}\n * @since 0.2.0\n */\nexport function isSystemJunk(fileName) {\n return junkRegex.test(fileName);\n}\n","import { isSystemJunk } from \"./is-system-junk.js\";\n\n/**\n * @name isNotSystemJunk\n * @description Returns true if filename matches a system junk file.\n * @param {string} [fileName]\n * @returns {boolean}\n * @since 0.2.0\n */\nexport function isNotSystemJunk(fileName) {\n return !isSystemJunk(fileName);\n}\n","import { readdir } from \"node:fs/promises\";\n\nimport { isNotSystemJunk } from \"./is-not-system-junk.js\";\n\n/**\n * @name listContents\n * @description Lists files and directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean} [ignoreJunk=true]\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\nexport async function listContents(pathToDir, ignoreJunk = true) {\n try {\n const contents = await readdir(pathToDir);\n if (ignoreJunk) {\n return contents.filter(isNotSystemJunk);\n }\n return contents;\n } catch (error) {\n return error;\n }\n}\n","import { errorExtractOptions } from \"../error/errorExtractOptions.js\";\nimport { dirIsReadable } from \"./dirIsReadable.js\";\nimport { listContents } from \"../list/contents.js\";\n\nconst EXCLUDE = [\n // macOS\n \".AppleDB\",\n \".AppleDesktop\",\n \".AppleDouble\",\n \".DS_Store\",\n \".DocumentRevisions-V100\",\n \".LSOverride\",\n \".Spotlight-V100\",\n \".TemporaryItems\",\n \".Trashes\",\n \".VolumeIcon.icns\",\n // \"._*\",\n \".apdisk\",\n \".com.apple.timemachine.donotpresent\",\n \".fseventsd\",\n \"Network Trash Folder\",\n \"Temporary Items\",\n // Windows\n \"$RECYCLE.BIN/\",\n // \"*.cab\",\n // \"*.lnk\",\n // \"*.msi\",\n // \"*.msix\",\n // \"*.msm\",\n // \"*.msp\",\n // \"*.stackdump\",\n \"Desktop.ini\",\n \"Thumbs.db\",\n \"Thumbs.db:encryptable\",\n \"desktop.ini\",\n \"ehthumbs.db\",\n \"ehthumbs_vista.db\",\n // Linux\n // \"*~\",\n // \".Trash-*\",\n \".directory\",\n // \".fuse_hidden*\",\n // \".nfs*\",\n];\n\n/**\n * @name isEmptyContent\n * @param {Array.} listOfDirsAndFiles\n * @returns {boolean}\n */\nfunction isEmptyContent(listOfDirsAndFiles) {\n const content = new Set(listOfDirsAndFiles);\n listOfDirsAndFiles.length = 0;\n content.forEach((dirOrFileName) => {\n for (const nameToExclude of EXCLUDE) {\n if (!dirOrFileName) {\n continue;\n }\n if (dirOrFileName === nameToExclude || dirOrFileName.match(RegExp(nameToExclude))) {\n content.delete(dirOrFileName);\n }\n }\n });\n return content.size === 0;\n}\n\n/**\n * @name dirIsEmpty\n * @description Check if a directory is empty\n * @since 0.1.33\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean=} excludeSystemFiles\n * @returns {Promise}\n * @throws {Error} If path is not a dir or is not readable.\n */\nexport async function dirIsEmpty(pathToDir, excludeSystemFiles = true) {\n const isReadableOrError = await dirIsReadable(pathToDir);\n if (isReadableOrError !== true) {\n throw new Error(isReadableOrError.message, errorExtractOptions(isReadableOrError));\n }\n let listOfDirsAndFiles = await listContents(pathToDir);\n if (listOfDirsAndFiles instanceof Error) {\n throw listOfDirsAndFiles;\n }\n if (listOfDirsAndFiles.length === 0) {\n return true;\n }\n if (!excludeSystemFiles) {\n return false;\n }\n return isEmptyContent(listOfDirsAndFiles);\n}\n","/**\n * @name errorExtractOptions\n * @param {Error} error\n * @returns {{ cause: Error } | { cause: { code?: string, values?: any[] | { [key: string]: any } }}}\n */\nexport function errorExtractOptions(error) {\n if (!(error instanceof Error)) {\n return { cause: error };\n }\n if (\"code\" in error && \"errno\" in error && \"path\" in error && \"syscall\" in error) {\n return {\n cause: {\n code: error.code,\n values: {\n errno: error.errno,\n path: error.path,\n syscall: error.syscall,\n },\n },\n };\n }\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name dirIsExecutable\n * @description Directory can be executed by the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsExecutable(pathToDir) {\n return accessWrapper(constants.X_OK, pathToDir);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name dirIsVisible\n * @description Directory is visible to the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsVisible(pathToDir) {\n return accessWrapper(constants.F_OK, pathToDir);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name dirIsWritable\n * @description Directory can be written by the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsWritable(pathToDir) {\n return accessWrapper(constants.W_OK, pathToDir);\n}\n","import { createHash, getHashes } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\n\n/**\n * @name hash\n * @description Calculate hash.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {string} algorithm\n * @returns {Promise}\n * @throws {TypeError} If algorithm is not supported.\n */\nexport async function hash(pathToFile, algorithm) {\n if (!getHashes().includes(algorithm)) {\n throw new TypeError(`Digest algorithm [${algorithm}] is not supported.`);\n }\n return createHash(algorithm)\n .update(await readFile(pathToFile))\n .digest(\"hex\");\n}\n","import { readFile } from \"node:fs/promises\";\n\nfunction crc32(text) {\n let chars = [];\n let actual;\n for (let current = 0; current < 256; current++) {\n actual = current;\n for (let f = 0; f < 8; f++) {\n actual = 1 & actual ? 3988292384 ^ (actual >>> 1) : actual >>> 1;\n }\n chars[current] = actual;\n }\n let number = -1;\n let index = 0;\n for (; index < text.length; index++) {\n number = (number >>> 8) ^ chars[255 & (number ^ text.charCodeAt(index))];\n }\n return (-1 ^ number) >>> 0;\n}\n\n/**\n * @name hashCrc32\n * @description CRC32.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashCrc32(pathToFile) {\n return crc32((await readFile(pathToFile)).toString(\"binary\")).toString(16);\n}\n","import { hash } from \"./hash.js\";\n\n/**\n * @name hashMd5\n * @description MD5.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashMd5(pathToFile) {\n return hash(pathToFile, \"md5\");\n}\n","import { hash } from \"./hash.js\";\n\n/**\n * @name hashSha1\n * @description SHA-1.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha1(pathToFile) {\n return hash(pathToFile, \"sha1\");\n}\n","import { hash } from \"./hash.js\";\n\n/**\n * @name hashSha256\n * @description SHA-256.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha256(pathToFile) {\n return hash(pathToFile, \"sha256\");\n}\n","import { hash } from \"./hash.js\";\n\n/**\n * @name hashSha512\n * @description SHA-512.\n * @since 0.2.6\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha512(pathToFile) {\n return hash(pathToFile, \"sha512\");\n}\n","import { stat } from \"node:fs/promises\";\n\n/**\n * @name size\n * @description File size in bytes.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {boolean=} [asString=false]\n * @returns {Promise}\n */\nexport async function size(pathToFile, asString = false) {\n const fileStats = await stat(pathToFile);\n if (!asString) {\n return fileStats.size;\n }\n return fileStats.size.toLocaleString(\"en\").replace(/,/g, \"_\");\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name fileIsExecutable\n * @description File can be executed by the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsExecutable(pathToFile) {\n return accessWrapper(constants.X_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name fileIsReadable\n * @description File is visible to the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsReadable(pathToFile) {\n return accessWrapper(constants.R_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name fileIsVisible\n * @description File is visible to the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsVisible(pathToFile) {\n return accessWrapper(constants.F_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name fileIsWritable\n * @description File can be written by the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsWritable(pathToFile) {\n return accessWrapper(constants.W_OK, pathToFile);\n}\n","import { truncate } from \"node:fs/promises\";\n\n/**\n * @name fileTruncate\n * @description Truncate a file to a specified length\n * @since 0.0.6\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {number=} length\n * @returns {Promise}\n */\nexport async function fileTruncate(pathToFile, length = 0) {\n try {\n await truncate(pathToFile, length);\n return true;\n } catch (error) {\n return error;\n }\n}\n","import { join, normalize } from \"node:path\";\n\n/**\n * @name pathFrom\n * @description Join all arguments together and normalize the resulting path.\n * @since 0.1.3\n * @param {string|Array.} paths\n * @param {...string} morePaths\n * @returns {string}\n */\nexport function pathFrom(paths, ...morePaths) {\n let routes;\n if (Array.isArray(paths)) {\n routes = paths.map((path) => path.toString());\n } else {\n routes = [paths.toString()];\n }\n if (morePaths.length) {\n routes = routes.concat(morePaths.map((path) => path.toString()));\n }\n return normalize(join(...routes));\n}\n","import { getStatus } from \"../status/getStatus.js\";\nimport { listContents } from \"./contents.js\";\nimport { pathFrom } from \"../path/pathFrom.js\";\n\n/**\n * @name listDirectories\n * @description Lists directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\nexport async function listDirectories(pathToDir) {\n const contents = await listContents(pathToDir);\n if (!Array.isArray(contents)) {\n return contents;\n }\n const directories = await Promise.all(\n contents.map(async (content) => {\n const contentPath = pathFrom(pathToDir, content);\n const [status, error] = await getStatus(contentPath);\n if (error) {\n return undefined;\n }\n if (!status.isDirectory()) {\n return undefined;\n }\n return content;\n }),\n );\n return directories.filter((content) => content);\n}\n","import { getStatus } from \"../status/getStatus.js\";\nimport { listContents } from \"./contents.js\";\nimport { pathFrom } from \"../path/pathFrom.js\";\n\n/**\n * @name listFiles\n * @description Lists files in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\nexport async function listFiles(pathToDir) {\n const contents = await listContents(pathToDir);\n if (!Array.isArray(contents)) {\n return contents;\n }\n const files = await Promise.all(\n contents.map(async (content) => {\n const contentPath = pathFrom(pathToDir, content);\n const [status, error] = await getStatus(contentPath);\n if (error) {\n return undefined;\n }\n if (status.isDirectory()) {\n return undefined;\n }\n return content;\n }),\n );\n return files.filter((content) => content);\n}\n","import { rename } from \"node:fs/promises\";\n\n/**\n * @name move\n * @description Change the name or location of a file or directory.\n * @since 0.1.29\n * @param {string} pathFrom\n * @param {string} pathTo\n * @returns {Promise}\n */\nexport async function move(pathFrom, pathTo) {\n try {\n await rename(pathFrom, pathTo);\n return true;\n } catch (error) {\n return error;\n }\n}\n","import os from \"os\";\n\nconst HOME_DIRECTORY = os.homedir();\n\n/**\n * @description deConvert a tilde path to an absolute path: ~/projects β†’ /Users/anon/projects\n * @param {string} pathWithTilde\n * @returns {string}\n */\nexport function absolutePath(pathWithTilde) {\n if (HOME_DIRECTORY) {\n return String(pathWithTilde).replace(/^~(?=$|\\/|\\\\)/, HOME_DIRECTORY);\n }\n return String(pathWithTilde);\n}\n","import { resolve } from \"node:path\";\n\nimport { absolutePath } from \"./absolutePath.js\";\n\n/**\n * @name absolutePathFrom\n * @description Join all arguments together and normalize the resulting path.\n * Creates absolute path from right to left until an absolute path is constructed.\n * @since 0.1.5\n * @param {string|Array.} paths\n * @param {...string} morePaths\n * @returns {string}\n */\nexport function absolutePathFrom(paths, ...morePaths) {\n let routes;\n if (Array.isArray(paths)) {\n routes = paths.map((path) => path.toString());\n } else {\n routes = [paths.toString()];\n }\n if (morePaths.length) {\n routes = routes.concat(morePaths.map((path) => path.toString()));\n }\n return absolutePath(resolve(...routes));\n}\n","import { extname } from \"node:path\";\n\n/**\n * @name fileExtension\n * @description Get file extension.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileExtension(path) {\n return extname(path).substring(1);\n}\n","import { parse } from \"node:path\";\n\n/**\n * @name fileName\n * @description Return the file name without extension.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileName(path) {\n return parse(path).name;\n}\n","import { basename } from \"node:path\";\n\n/**\n * @name fileNameExt\n * @description Return the last portion of a path.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileNameExt(path) {\n return basename(path);\n}\n","import { dirname } from \"node:path\";\n\n/**\n * @name filePath\n * @description Return the directory name of a path.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function filePath(path) {\n return dirname(path);\n}\n","import { readFile } from \"node:fs/promises\";\n\n/**\n * @name readFileToBase64\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.21\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToBase64(pathLike) {\n try {\n const result = await readFile(pathLike, \"base64\");\n return result.toString();\n } catch (error) {\n return error;\n }\n}\n","import { readFile } from \"node:fs/promises\";\n\n/**\n * @name readFileToBuffer\n * @description Asynchronously reads the entire contents of a file into buffer.\n * @since 0.1.19\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToBuffer(pathLike) {\n try {\n const result = await readFile(pathLike, \"binary\");\n return Buffer.from(result);\n } catch (error) {\n return error;\n }\n}\n","import { readFile } from \"node:fs/promises\";\n\nimport { absolutePath } from \"../path/absolutePath.js\";\n\n/**\n * @name readFileToString\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.7\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToString(pathLike) {\n try {\n const result = await readFile(absolutePath(pathLike), \"utf8\");\n return result.toString();\n } catch (error) {\n return error;\n }\n}\n","import fs from \"fs\";\nimport assert from \"node:assert\";\nimport { join } from \"node:path\";\n\nconst IS_WINDOWS = process.platform === \"win32\";\n\n/**\n * @param {object} options\n */\nfunction defaults(options) {\n const methods = [\"unlink\", \"chmod\", \"stat\", \"lstat\", \"rmdir\", \"readdir\"];\n methods.forEach((method) => {\n options[method] = options[method] || fs[method];\n });\n options.maxBusyTries = options.maxBusyTries || 3;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction rimraf(pathLike, options, callback) {\n let busyTries = 0;\n let localCallback = callback;\n let localOptions = options;\n if (typeof localOptions === \"function\") {\n localCallback = localOptions;\n localOptions = {};\n }\n assert(pathLike, \"remove(): missing path\");\n assert.strictEqual(typeof pathLike, \"string\", \"remove(): path should be a string\");\n assert.strictEqual(typeof localCallback, \"function\", \"remove(): callback function required\");\n assert(localOptions, \"remove(): invalid options argument provided\");\n assert.strictEqual(typeof localOptions, \"object\", \"remove(): options should be object\");\n defaults(localOptions);\n rimraf_(pathLike, localOptions, function callbackRimraf(error) {\n if (error) {\n if (\n (error.code === \"EBUSY\" || error.code === \"ENOTEMPTY\" || error.code === \"EPERM\") &&\n busyTries < localOptions.maxBusyTries\n ) {\n busyTries++;\n const time = busyTries * 100;\n setTimeout(() => rimraf_(pathLike, localOptions, callbackRimraf), time);\n return;\n }\n if (error.code === \"ENOENT\") {\n localCallback(null);\n return;\n }\n }\n localCallback(error);\n });\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction rimraf_(pathLike, options, callback) {\n assert(pathLike);\n assert(options);\n assert(typeof callback === \"function\");\n options.lstat(pathLike, (error, stats) => {\n if (error && error.code === \"ENOENT\") {\n return callback(null);\n }\n if (error && error.code === \"EPERM\" && IS_WINDOWS) {\n return fixWinEPERM(pathLike, options, error, callback);\n }\n if (stats && stats.isDirectory()) {\n return rmdir(pathLike, options, error, callback);\n }\n options.unlink(pathLike, (error) => {\n if (error) {\n if (error.code === \"ENOENT\") {\n return callback(null);\n }\n if (error.code === \"EPERM\") {\n if (IS_WINDOWS) {\n return fixWinEPERM(pathLike, options, error, callback);\n } else {\n return rmdir(pathLike, options, error, callback);\n }\n }\n if (error.code === \"EISDIR\") {\n return rmdir(pathLike, options, error, callback);\n }\n }\n return callback(error);\n });\n });\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Error|null} error\n * @param {Function=} callback\n * @returns {null}\n */\nfunction fixWinEPERM(pathLike, options, error, callback) {\n assert(pathLike);\n assert(options);\n assert(typeof callback === \"function\");\n if (error) {\n assert(error instanceof Error);\n }\n options.chmod(pathLike, 0o666, (errorChMod) => {\n if (errorChMod) {\n if (errorChMod.code === \"ENOENT\") {\n callback(null);\n } else {\n callback(error);\n }\n } else {\n options.stat(pathLike, (errorStat, stats) => {\n if (errorStat) {\n if (errorStat.code === \"ENOENT\") {\n callback(null);\n } else {\n callback(error);\n }\n } else if (stats.isDirectory()) {\n rmdir(pathLike, options, error, callback);\n } else {\n options.unlink(pathLike, callback);\n }\n });\n }\n });\n return null;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Error|null} originalError\n * @param {Function=} callback\n * @returns {null}\n */\nfunction rmdir(pathLike, options, originalError, callback) {\n assert(pathLike);\n assert(options);\n if (originalError) {\n assert(originalError instanceof Error);\n }\n assert(typeof callback === \"function\");\n options.rmdir(pathLike, (error) => {\n if (error && (error.code === \"ENOTEMPTY\" || error.code === \"EEXIST\" || error.code === \"EPERM\")) {\n removeSubPath(pathLike, options, callback);\n } else if (error && error.code === \"ENOTDIR\") {\n callback(originalError);\n } else {\n callback(error);\n }\n });\n return null;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction removeSubPath(pathLike, options, callback) {\n assert(pathLike);\n assert(options);\n assert(typeof callback === \"function\");\n options.readdir(pathLike, (error, files) => {\n if (error) {\n return callback(error);\n }\n let count = files.length;\n let errState;\n if (count === 0) {\n return options.rmdir(pathLike, callback);\n }\n files.forEach((filePath) => {\n rimraf(join(pathLike, filePath), options, (error) => {\n if (errState) {\n return;\n }\n if (error) {\n callback((errState = error));\n return;\n }\n --count;\n if (count === 0) {\n options.rmdir(pathLike, callback);\n }\n });\n });\n });\n}\n\n/**\n * @name remove\n * @description Removes a file or directory.\n * @since 0.1.1\n * @async\n * @param {string} pathLike\n * @returns {Promise}\n */\nexport async function remove(pathLike) {\n return new Promise((resolve) => {\n rimraf(pathLike, {}, (error) => {\n if (error) {\n resolve(error);\n } else {\n resolve();\n }\n });\n });\n}\n","import { remove } from \"./remove.js\";\n\n/**\n * @name removeNonBlocking\n * @description Non-blocking remove of a file or directory.\n * @since 0.1.18\n * @param {string|Buffer|URL} pathLike\n * @returns {void}\n */\nexport function removeNonBlocking(pathLike) {\n remove(pathLike)\n .then(() => undefined)\n .catch(() => undefined); // don't put it into next tick\n}\n","import { rm } from \"node:fs/promises\";\n\n/**\n * @name removeSilent\n * @description Removes files and directories (modeled on the standard POSIX rm utility).\n * @summary Minimum Node version 14.14.0\n * @since 0.1.36\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {object=} options\n * @returns {Promise}\n */\nexport async function removeSilent(pathLike, options) {\n try {\n await rm(pathLike, {\n force: true,\n recursive: true,\n ...options,\n });\n } catch (__error) {\n //\n }\n}\n","import { lstat } from \"node:fs/promises\";\n\n/**\n * @name getLinkStatus\n * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to.\n * @url http://man7.org/linux/man-pages/man2/lstat.2.html\n * @since 1.1.0\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise>}\n */\nexport async function getLinkStatus(path) {\n try {\n return [await lstat(path)];\n } catch (error) {\n return [undefined, error];\n }\n}\n","import { getStatus } from \"./getStatus.js\";\n\n/**\n * @name isDirExists\n * @description Get directory status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isDirExists(path) {\n const [status, error] = await getStatus(path);\n if (error) {\n return false;\n }\n return status.isDirectory();\n}\n","import { getStatus } from \"./getStatus.js\";\n\n/**\n * @name isFileExists\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isFileExists(path) {\n const [status, error] = await getStatus(path);\n if (error) {\n return false;\n }\n return status.isFile();\n}\n","import { getStatus } from \"./getStatus.js\";\n\n/**\n * @name isPathExists\n * @description Get path status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isPathExists(path) {\n const [status] = await getStatus(path);\n return Boolean(status);\n}\n","import { createFile } from \"../create/createFile.js\";\nimport { isFileExists } from \"../status/isFileExists.js\";\nimport { readFileToString } from \"../read/readFileToString.js\";\nimport { writeFile } from \"./writeFile.js\";\n\n/**\n * @name writeFileTail\n * @description Asynchronously writes data to the end of a file.\n * @since 1.0.1\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\nexport async function writeFileTail(filePath, data, options) {\n const isFileExist = await isFileExists(filePath);\n if (isFileExist === false) {\n const isFileCreatedOrError = await createFile(filePath);\n if (isFileCreatedOrError !== true) {\n return isFileCreatedOrError;\n }\n }\n const contentOrError = await readFileToString(filePath);\n if (contentOrError instanceof Error) {\n return contentOrError;\n }\n return new Promise((resolve, reject) => {\n setTimeout(() => {\n writeFile(filePath, `${String(contentOrError)}${String(data)}`, options)\n .then(() => {\n resolve(true);\n })\n .catch((error) => {\n reject(error);\n });\n }, 1);\n });\n}\n","import { writeFile } from \"./writeFile.js\";\n\n/**\n * @name objectKeys\n * @param {object} object\n * @returns {Array.}\n */\nfunction objectKeys(object) {\n return Object.keys(object).sort((alpha, beta) => alpha.localeCompare(beta));\n}\n\n/**\n * name isObjectLike\n * @param {*} value\n * @returns {boolean}\n */\nfunction isObjectLike(value) {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\n/**\n * @name collectionSortKeys\n * @param {*} value\n * @param {boolean=} [isDeep=true]\n * @returns {*}\n */\nfunction collectionSortKeys(value, isDeep = true) {\n if (!isObjectLike(value)) {\n if (Array.isArray(value)) {\n return value.map((arrayValue) => collectionSortKeys(arrayValue, isDeep));\n }\n return value;\n }\n const keys = objectKeys(value);\n if (!keys.length) {\n return value;\n }\n return keys.reduce((sorted, key) => {\n if (isDeep && isObjectLike(value[key])) {\n sorted[key] = collectionSortKeys(value[key], isDeep);\n } else if (isDeep && Array.isArray(value[key])) {\n sorted[key] = collectionSortKeys(value[key], isDeep);\n } else {\n sorted[key] = value[key];\n }\n return sorted;\n }, {});\n}\n\n/**\n * @name writeJSON\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.1.25\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {*} data\n * @param {*|null|string=} options\n * @param {{sort: boolean, space: number|string}=} configuration\n * @returns {Promise}\n */\nexport async function writeJSON(filePath, data, options, configuration) {\n let json;\n let stringify = data;\n try {\n if (configuration) {\n if (configuration.sort) {\n if (isObjectLike(data)) {\n stringify = collectionSortKeys(JSON.parse(JSON.stringify(data)));\n } else if (Array.isArray(data)) {\n stringify = JSON.parse(JSON.stringify(data));\n } else {\n stringify = data;\n }\n }\n if (configuration.space) {\n json = JSON.stringify(stringify, null, configuration.space);\n }\n } else {\n json = JSON.stringify(stringify);\n }\n } catch (error) {\n return error;\n }\n return writeFile(filePath, json, options);\n}\n","import { absolutePathFrom } from \"./path/absolutePathFrom.js\";\n\nimport { createDirectory } from \"./create/createDirectory.js\";\nimport { createFile } from \"./create/createFile.js\";\n\nimport { dirIsExecutable } from \"./dir/dirIsExecutable.js\";\nimport { dirIsReadable } from \"./dir/dirIsReadable.js\";\nimport { dirIsVisible } from \"./dir/dirIsVisible.js\";\nimport { dirIsWritable } from \"./dir/dirIsWritable.js\";\nimport { dirIsEmpty } from \"./dir/dirIsEmpty.js\";\n\nimport { fileExtension } from \"./path/fileExtension.js\";\nimport { fileIsExecutable } from \"./file/fileIsExecutable.js\";\nimport { fileIsReadable } from \"./file/fileIsReadable.js\";\nimport { fileIsVisible } from \"./file/fileIsVisible.js\";\nimport { fileIsWritable } from \"./file/fileIsWritable.js\";\nimport { fileName } from \"./path/fileName.js\";\nimport { fileNameExt } from \"./path/fileNameExt.js\";\nimport { filePath } from \"./path/filePath.js\";\nimport { fileTruncate } from \"./file/fileTruncate.js\";\n\nimport { listContents } from \"./list/contents.js\";\nimport { listDirectories } from \"./list/directories.js\";\nimport { listFiles } from \"./list/files.js\";\n\nimport { getLinkStatus } from \"./status/getLinkStatus.js\";\nimport { getStatus } from \"./status/getStatus.js\";\n\nimport { isDirExists } from \"./status/isDirExists.js\";\nimport { isFileExists } from \"./status/isFileExists.js\";\nimport { isPathExists } from \"./status/isPathExists.js\";\n\nimport { move } from \"./move/move.js\";\n\nimport { pathFrom } from \"./path/pathFrom.js\";\n\nimport { readFileToBase64 } from \"./read/readFileToBase64.js\";\nimport { readFileToBuffer } from \"./read/readFileToBuffer.js\";\nimport { readFileToString } from \"./read/readFileToString.js\";\nimport { remove } from \"./remove/remove.js\";\nimport { removeNonBlocking } from \"./remove/removeNonBlocking.js\";\nimport { removeSilent } from \"./remove/removeSilent.js\";\n\nimport { writeFile } from \"./write/writeFile.js\";\nimport { writeFileTail } from \"./write/writeFileTail.js\";\nimport { writeJSON } from \"./write/writeJSON.js\";\n\nimport { hash } from \"./info/hash.js\";\nimport { hashCrc32 } from \"./info/hash-crc32.js\";\nimport { hashMd5 } from \"./info/hash-md5.js\";\nimport { hashSha1 } from \"./info/hash-sha1.js\";\nimport { hashSha256 } from \"./info/hash-sha256.js\";\nimport { hashSha512 } from \"./info/hash-sha512.js\";\n\nimport { size } from \"./info/size.js\";\n\nexport class HileSystemLocal {\n /**\n * @name absolutePathFrom\n * @description Join all arguments together and normalize the resulting path.\n * reates absolute path from right to left until an absolute path is constructed.\n * @since 0.1.5\n * @public\n * @param {string|Array.} paths\n * @param {...string} morePaths\n * @returns {string}\n */\n absolutePathFrom = absolutePathFrom;\n /**\n * @name createDirectory\n * @description Asynchronous create a directory.\n * @since 0.0.10\n * @async\n * @public\n * @param {string|Buffer|URL} dirPath\n * @param {number|string=} mode\n * @param {boolean=} recursive\n * @returns {Promise}\n */\n createDirectory = createDirectory;\n /**\n * @name createFile\n * @description Asynchronous create a file.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} pathLike\n * @param {number|string=} mode\n * @returns {Promise}\n */\n createFile = createFile;\n /**\n * @name dirIsExecutable\n * @description Directory can be executed by the calling process\n * @since 0.0.5\n * @async\n * @public\n * @param {string} pathToDir\n * @returns {Promise}\n */\n dirIsExecutable = dirIsExecutable;\n /**\n * @name dirIsReadable\n * @description Directory is visible to the calling process\n * @since 0.0.1\n * @async\n * @public\n * @param {string} pathToDir\n * @returns {Promise}\n */\n dirIsReadable = dirIsReadable;\n /**\n * @name dirIsVisible\n * @description Directory is visible to the calling process\n * @since 0.0.5\n * @async\n * @public\n * @param {string} pathToDir\n * @returns {Promise}\n */\n dirIsVisible = dirIsVisible;\n /**\n * @name dirIsWritable\n * @description Directory can be written by the calling process\n * @since 0.0.1\n * @async\n * @public\n * @param {string} pathToDir\n * @returns {Promise}\n */\n dirIsWritable = dirIsWritable;\n /**\n * @name dirIsEmpty\n * @description Check if a directory is empty\n * @since 0.1.33\n * @async\n * @public\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean=} excludeSystemFiles\n * @returns {Promise}\n * @throws {Error} If path is not a dir or is not readable.\n */\n dirIsEmpty = dirIsEmpty;\n /**\n * @name getLinkStatus\n * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to.\n * @url http://man7.org/linux/man-pages/man2/lstat.2.html\n * @since 1.1.0\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise>}\n */\n getLinkStatus = getLinkStatus;\n /**\n * @name getStatus\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} path\n * @returns {Promise>}\n */\n getStatus = getStatus;\n /**\n * @name isDirExists\n * @description Get directory status.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\n isDirExists = isDirExists;\n /**\n * @name isFileExists\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\n isFileExists = isFileExists;\n /**\n * @name isPathExists\n * @description Get path status.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\n isPathExists = isPathExists;\n /**\n * @name fileExtension\n * @description Get file extension.\n * @since 0.1.1\n * @public\n * @param {string} path\n * @returns {string}\n */\n fileExtension = fileExtension;\n /**\n * @name fileName\n * @description Return the file name without extension.\n * @since 0.1.1\n * @public\n * @param {string} path\n * @returns {string}\n */\n fileName = fileName;\n /**\n * @name fileNameExt\n * @description Return the last portion of a path.\n * @since 0.1.1\n * @public\n * @param {string} path\n * @returns {string}\n */\n fileNameExt = fileNameExt;\n /**\n * @name filePath\n * @description Return the directory name of a path.\n * @since 0.1.1\n * @public\n * @param {string} path\n * @returns {string}\n */\n filePath = filePath;\n /**\n * @name fileIsExecutable\n * @description File can be executed by the calling process\n * @since 0.0.5\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n fileIsExecutable = fileIsExecutable;\n /**\n * @name fileIsReadable\n * @description File is visible to the calling process\n * @since 0.0.1\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n fileIsReadable = fileIsReadable;\n /**\n * @name fileIsVisible\n * @description File is visible to the calling process\n * @since 0.0.5\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n fileIsVisible = fileIsVisible;\n /**\n * @name fileIsWritable\n * @description File can be written by the calling process\n * @since 0.0.1\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n fileIsWritable = fileIsWritable;\n /**\n * @name fileTruncate\n * @description Truncate a file to a specified length\n * @since 0.0.6\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @param {number=} length\n * @returns {Promise}\n */\n fileTruncate = fileTruncate;\n /**\n * @name hash\n * @description Calculate hash.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @param {string} algorithm\n * @returns {Promise}\n * @throws {TypeError} If algorithm is not supported.\n */\n hash = hash;\n /**\n * @name hashCrc32\n * @description CRC32.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashCrc32 = hashCrc32;\n /**\n * @name hashMd5\n * @description MD5.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashMd5 = hashMd5;\n /**\n * @name hashSha1\n * @description SHA-1.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashSha1 = hashSha1;\n /**\n * @name hashSha256\n * @description SHA-256.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashSha256 = hashSha256;\n /**\n * @name hashSha512\n * @description SHA-512.\n * @since 0.2.6\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashSha512 = hashSha512;\n /**\n * @name listContents\n * @description Lists files and directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\n listContents = listContents;\n /**\n * @name listDirectories\n * @description Lists directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\n listDirectories = listDirectories;\n /**\n * @name listFiles\n * @description Lists files in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\n listFiles = listFiles;\n /**\n * @name move\n * @description Change the name or location of a file or directory.\n * @since 0.1.29\n * @public\n * @param {string} pathFrom\n * @param {string} pathTo\n * @returns {Promise}\n */\n move = move;\n /**\n * @name pathFrom\n * @description Join all arguments together and normalize the resulting path.\n * @since 0.1.3\n * @public\n * @param {string|Array.} paths\n * @param {...string} morePaths\n * @returns {string}\n */\n pathFrom = pathFrom;\n /**\n * @name readFileToBase64\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.21\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\n readFileToBase64 = readFileToBase64;\n /**\n * @name readFileToBuffer\n * @description Asynchronously reads the entire contents of a file into buffer.\n * @since 0.1.19\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\n readFileToBuffer = readFileToBuffer;\n /**\n * @name readFileToString\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.7\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\n readFileToString = readFileToString;\n /**\n * @name remove\n * @description Removes a file or directory.\n * @since 0.1.1\n * @async\n * @public\n * @param {string} pathLike\n * @returns {Promise}\n */\n remove = remove;\n /**\n * @name removeNonBlocking\n * @description Non-blocking remove of a file or directory.\n * @since 0.1.18\n * @public\n * @param {string} pathLike\n * @returns {void}\n */\n removeNonBlocking = removeNonBlocking;\n /**\n * @name removeSilent\n * @description Removes files and directories (modeled on the standard POSIX rm utility).\n * @summary Minimum Node version 14.14.0\n * @since 0.1.36\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {object=} options\n * @returns {Promise}\n */\n removeSilent = removeSilent;\n /**\n * @name size\n * @description File size in bytes.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @param {boolean=} [asString=false]\n * @returns {Promise}\n */\n size = size;\n /**\n * @name writeFile\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.0.10\n * @async\n * @public\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\n writeFile = writeFile;\n /**\n * @name writeFileTail\n * @description Asynchronously writes data to the end of a file.\n * @since 1.0.1\n * @async\n * @public\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\n writeFileTail = writeFileTail;\n /**\n * @name writeJSON\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.1.25\n * @async\n * @public\n * @param {string|Buffer|URL} filePath\n * @param {*} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\n writeJSON = writeJSON;\n}\n"],"names":["async","createDirectory","dirPath","mode","recursive","mkdir","error","getStatus","path","stat","undefined","writeFile","filePath","data","options","writeFileNative","createFile","pathLike","status","isFile","dirname","code","dirCreated","fileWritten","flag","isDirectory","readdir","accessWrapper","access","dirIsReadable","pathToDir","constants","R_OK","junkRegex","RegExp","join","isNotSystemJunk","fileName","isSystemJunk","test","listContents","ignoreJunk","contents","filter","EXCLUDE","dirIsEmpty","excludeSystemFiles","isReadableOrError","Error","message","errorExtractOptions","cause","values","errno","syscall","listOfDirsAndFiles","length","isEmptyContent","content","Set","forEach","dirOrFileName","nameToExclude","match","delete","size","dirIsExecutable","X_OK","dirIsVisible","F_OK","dirIsWritable","W_OK","hash","pathToFile","algorithm","getHashes","includes","TypeError","createHash","update","readFile","digest","hashCrc32","crc32","text","actual","chars","current","f","number","index","charCodeAt","toString","hashMd5","hashSha1","hashSha256","hashSha512","asString","fileStats","toLocaleString","replace","fileIsExecutable","fileIsReadable","fileIsVisible","fileIsWritable","fileTruncate","truncate","pathFrom","paths","morePaths","routes","Array","isArray","map","concat","normalize","listDirectories","Promise","all","contentPath","listFiles","move","pathTo","rename","HOME_DIRECTORY","os","homedir","absolutePath","pathWithTilde","String","absolutePathFrom","resolve","fileExtension","extname","substring","parse","name","fileNameExt","basename","readFileToBase64","readFileToBuffer","result","Buffer","from","readFileToString","IS_WINDOWS","process","platform","rimraf","callback","busyTries","localCallback","localOptions","assert","strictEqual","defaults","method","fs","maxBusyTries","rimraf_","callbackRimraf","setTimeout","lstat","stats","fixWinEPERM","rmdir","unlink","chmod","errorChMod","errorStat","originalError","removeSubPath","files","errState","count","remove","removeNonBlocking","then","catch","removeSilent","rm","force","__error","getLinkStatus","isDirExists","isFileExists","isPathExists","Boolean","writeFileTail","isFileCreatedOrError","contentOrError","reject","isObjectLike","value","collectionSortKeys","isDeep","arrayValue","keys","objectKeys","object","Object","sort","alpha","beta","localeCompare","reduce","sorted","key","writeJSON","configuration","json","stringify","JSON","space","HileSystemLocal","constructor","_defineProperty"],"mappings":"2WAYOA,eAAeC,gBAAgBC,EAASC,EAAO,OAAQC,GAAY,GACxE,IAEE,aADMC,QAAMH,EAAS,CAAEC,KAAAA,EAAMC,UAAAA,KACtB,EACP,MAAOE,GACP,OAAOA,GCPJN,eAAeO,UAAUC,GAC9B,IACE,MAAO,OAAOC,OAAKD,IACnB,MAAOF,GACP,MAAO,MAACI,EAAWJ,ICWhBN,eAAeW,UAAUC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DkG,MAAMC,QAAQnG,GACXuM,KAAK7E,MAAM6E,KAAKD,UAAUtM,IAE1BA,GAGZoM,EAAcI,QAChBH,EAAOE,KAAKD,UAAUA,EAAW,KAAMF,EAAcI,SAGvDH,EAAOE,KAAKD,UAAUA,GAExB,MAAO7M,GACP,OAAOA,EAET,OAAOK,UAAUC,EAAUsM,EAAMpM,6gBC3B5B,MAAMwM,gBAAgBC,cAAAC,wCAWRtF,kBAAgBsF,uCAYjBvN,iBAAeuN,kCAWpBxM,YAAUwM,uCAULtJ,iBAAesJ,qCAUjB3L,eAAa2L,oCAUdpJ,cAAYoJ,qCAUXlJ,eAAakJ,kCAYhB3K,YAAU2K,qCAUPjC,eAAaiC,iCAUjBjN,WAASiN,mCAUPhC,aAAWgC,oCAUV/B,cAAY+B,oCAUZ9B,cAAY8B,qCASXpF,eAAaoF,gCASlBnL,UAAQmL,mCASL/E,aAAW+E,gCASd5M,UAAQ4M,wCAUAnH,kBAAgBmH,sCAUlBlH,gBAAckH,qCAUfjH,eAAaiH,sCAUZhH,gBAAcgH,oCAWhB/G,cAAY+G,4BAYpBhJ,MAAIgJ,iCAUCtI,WAASsI,+BAUX3H,SAAO2H,gCAUN1H,UAAQ0H,kCAUNzH,YAAUyH,kCAUVxH,YAAUwH,oCASRhL,cAAYgL,uCASTpG,iBAAeoG,iCASrBhG,WAASgG,4BAUd/F,MAAI+F,gCAUA7G,UAAQ6G,wCASA7E,kBAAgB6E,wCAShB5E,kBAAgB4E,wCAShBxE,kBAAgBwE,8BAU1BzC,QAAMyC,yCASKxC,mBAAiBwC,oCAWtBrC,cAAYqC,4BAWpBvJ,MAAIuJ,iCAYC7M,WAAS6M,qCAYL5B,eAAa4B,iCAYjBR"} \ No newline at end of file +{"version":3,"file":"index.cjs","sources":["../src/core/create/create-directory.ts","../src/core/status/get-status.ts","../src/core/write/write-file.ts","../src/core/create/create-file.ts","../src/core/error/error-extract-options.ts","../src/core/access/wrapper.ts","../src/core/dir/dir-is-readable.ts","../src/core/list/is-system-junk.ts","../src/core/list/is-not-system-junk.ts","../src/core/list/contents.ts","../src/core/dir/dir-is-empty.ts","../src/core/dir/dir-is-executable.ts","../src/core/dir/dir-is-visible.ts","../src/core/dir/dir-is-writable.ts","../src/core/info/hash.ts","../src/core/info/hash-crc32.ts","../src/core/info/hash-md5.ts","../src/core/info/hash-sha1.ts","../src/core/info/hash-sha256.ts","../src/core/info/hash-sha512.ts","../src/core/info/hash-multi.ts","../src/core/info/size.ts","../src/core/file/file-is-executable.ts","../src/core/file/file-is-readable.ts","../src/core/file/file-is-visible.ts","../src/core/file/file-is-writable.ts","../src/core/file/file-truncate.ts","../src/core/path/path-from.ts","../src/core/list/directories.ts","../src/core/list/files.ts","../src/core/move/move.ts","../src/core/path/absolute-path.ts","../src/core/path/absolute-path-from.ts","../src/core/path/file-extension.ts","../src/core/path/file-name.ts","../src/core/path/file-name-ext.ts","../src/core/path/file-path.ts","../src/core/read/read-file-to-base64.ts","../src/core/read/read-file-to-buffer.ts","../src/core/read/read-file-to-string.ts","../src/core/remove/remove.ts","../src/core/remove/remove-non-blocking.ts","../src/core/remove/remove-silent.ts","../src/core/status/get-link-status.ts","../src/core/status/is-dir-exists.ts","../src/core/status/is-file-exists.ts","../src/core/status/is-path-exists.ts","../src/core/write/write-file-tail.ts","../src/core/write/write-json.ts","../src/core/hile-system-local.ts"],"sourcesContent":["import { mkdir } from \"node:fs/promises\";\n\n/**\n * @name createDirectory\n * @description Asynchronous create a directory.\n * @since 0.0.10\n * @async\n * @param {string|Buffer|URL} dirPath\n * @param {number|string=} mode\n * @param {boolean=} recursive\n * @returns {Promise}\n */\nexport async function createDirectory(\n\t//\n\tdirPath: string | Buffer | URL,\n\tmode: (number | string) | undefined = \"0777\",\n\trecursive: boolean | undefined = true,\n): Promise {\n\ttry {\n\t\tawait mkdir(dirPath, { mode, recursive });\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { stat } from \"node:fs/promises\";\n\n/**\n * @name getStatus\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise<[import(\"node:fs\").Stats|undefined, Error|undefined]>}\n */\nexport async function getStatus(\n\tpath: string | Buffer | URL,\n): Promise<[import(\"node:fs\").Stats | undefined, Error | undefined]> {\n\ttry {\n\t\treturn [await stat(path), undefined];\n\t} catch (error: unknown) {\n\t\treturn [undefined, error as Error];\n\t}\n}\n","import { writeFile as writeFileNative } from \"node:fs/promises\";\n\n/**\n * @name writeFile\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.0.10\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n * @example\n * const controller = new AbortController();\n * const { signal } = controller;\n * const data = new Uint8Array(Buffer.from('Hello Node.js'));\n * (async () => {\n * try {\n * await writeFile('message.txt', data, { signal });\n * } catch (error) {\n * // When a request is aborted - error is an AbortError\n * }\n * })();\n * // When the request should be aborted\n * controller.abort();\n */\nexport async function writeFile(\n\tfilePath: string | Buffer | URL,\n\tdata: any,\n\toptions: any | null | string = null,\n): Promise {\n\ttry {\n\t\tawait writeFileNative(filePath, data, options);\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { dirname } from \"node:path\";\nimport { readdir } from \"node:fs/promises\";\n\nimport { createDirectory } from \"./create-directory\";\nimport { getStatus } from \"../status/get-status\";\nimport { writeFile } from \"../write/write-file\";\n\n/**\n * @name createFile\n * @description Asynchronous create a file.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {number|string=} mode\n * @returns {Promise}\n */\nexport async function createFile(\n\tpathLike: string | Buffer | URL,\n\tmode: string = \"0777\",\n): Promise {\n\tconst [status, error] = await getStatus(pathLike);\n\tif (!error && (status as import(\"node:fs\").Stats).isFile()) {\n\t\treturn true;\n\t}\n\tconst dirPath = dirname(pathLike as string);\n\tif (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\tconst dirCreated = await createDirectory(dirPath, mode);\n\t\t\tif (dirCreated !== true) {\n\t\t\t\treturn dirCreated;\n\t\t\t}\n\t\t\tconst fileWritten = await writeFile(pathLike, \"\", { mode, flag: \"w\" });\n\t\t\tif (fileWritten !== true) {\n\t\t\t\treturn fileWritten;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t}\n\tif ((status as import(\"node:fs\").Stats).isDirectory()) {\n\t\treturn await writeFile(pathLike, \"\", { mode, flag: \"w\" });\n\t} else {\n\t\ttry {\n\t\t\tawait readdir(dirPath);\n\t\t\treturn undefined;\n\t\t} catch (error: unknown) {\n\t\t\treturn error as Error;\n\t\t}\n\t}\n}\n","/**\n * @name errorExtractOptions\n * @param {Error} error\n * @returns {{ cause: Error } | { cause: { code?: string, values?: any[] | { [key: string]: any } }}}\n */\nexport function errorExtractOptions(\n\terror: any,\n): { cause: Error } | { cause: { code?: string; values?: any[] | { [key: string]: any } } } {\n\tif (!(error instanceof Error)) {\n\t\treturn { cause: error };\n\t}\n\tif (\"code\" in error && \"errno\" in error && \"path\" in error && \"syscall\" in error) {\n\t\treturn {\n\t\t\tcause: {\n\t\t\t\tcode: (error as NodeJS.ErrnoException).code as string,\n\t\t\t\tvalues: {\n\t\t\t\t\terrno: error.errno,\n\t\t\t\t\tpath: error.path,\n\t\t\t\t\tsyscall: error.syscall,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\treturn { cause: error };\n}\n","import { access } from \"node:fs/promises\";\n\n/**\n * @name accessWrapper\n * @description Asynchronously tests a user's permissions for the file specified by path.\n * @since 0.0.1\n * @async\n * @param {number} mode\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function accessWrapper(mode: number, path: string | Buffer | URL): Promise {\n\ttry {\n\t\tawait access(path, mode);\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name dirIsReadable\n * @description Directory is visible to the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsReadable(pathToDir: string | Buffer | URL): Promise {\n\tif (process?.permission?.has(\"fs.read\") !== undefined) {\n\t\tconst isWritable = process.permission?.has(\"fs.read\", pathToDir as string);\n\t\tif (isWritable !== undefined) {\n\t\t\treturn isWritable;\n\t\t}\n\t}\n\treturn accessWrapper(constants.R_OK, pathToDir);\n}\n","// keep updated https://github.com/sindresorhus/junk\n\nconst ignoreList = [\n\t// # All\n\t\"^npm-debug\\\\.log$\", // Error log for npm\n\t\"^\\\\..*\\\\.swp$\", // Swap file for vim state\n\n\t// # macOS\n\t\"^\\\\.DS_Store$\", // Stores custom folder attributes\n\t\"^\\\\.AppleDouble$\", // Stores additional file resources\n\t\"^\\\\.LSOverride$\", // Contains the absolute path to the app to be used\n\t\"^Icon\\\\r$\", // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop\n\t\"^\\\\._.*\", // Thumbnail\n\t\"^\\\\.Spotlight-V100(?:$|\\\\/)\", // Directory that might appear on external disk\n\t\"\\\\.Trashes\", // File that might appear on external disk\n\t\"^__MACOSX$\", // Resource fork\n\n\t// # Linux\n\t\"~$\", // Backup file\n\n\t// # Windows\n\t\"^Thumbs\\\\.db$\", // Image file cache\n\t\"^ehthumbs\\\\.db$\", // Folder config file\n\t\"^Desktop\\\\.ini$\", // Stores custom folder attributes\n\t\"@eaDir$\", // Synology Diskstation \"hidden\" folder where the server stores thumbnails\n\t\"^\\\\$RECYCLE.BIN$\", // Special folder with columns like Date deleted and Original location\n\t\"^System Volume Information$\",\n];\n\nexport const junkRegex = new RegExp(ignoreList.join(\"|\"));\n\n/**\n * @name isSystemJunk\n * @description Returns true if filename matches a system junk file.\n * @param {string} [fileName]\n * @returns {boolean}\n * @since 0.2.0\n */\nexport function isSystemJunk(fileName: string): boolean {\n\treturn junkRegex.test(fileName);\n}\n","import { isSystemJunk } from \"./is-system-junk\";\n\n/**\n * @name isNotSystemJunk\n * @description Returns true if filename matches a system junk file.\n * @param {string} [fileName]\n * @returns {boolean}\n * @since 0.2.0\n */\nexport function isNotSystemJunk(fileName: string): boolean {\n\treturn !isSystemJunk(fileName);\n}\n","import { readdir } from \"node:fs/promises\";\n\nimport { isNotSystemJunk } from \"./is-not-system-junk\";\n\n/**\n * @name listContents\n * @description Lists files and directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean} [ignoreJunk=true]\n * @returns {Promise}\n */\nexport async function listContents(pathToDir: string | Buffer | URL, ignoreJunk = true): Promise {\n\ttry {\n\t\tconst contents = await readdir(pathToDir);\n\t\tif (ignoreJunk) {\n\t\t\treturn contents.filter(isNotSystemJunk);\n\t\t}\n\t\treturn contents;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { errorExtractOptions } from \"../error/error-extract-options\";\nimport { dirIsReadable } from \"./dir-is-readable\";\nimport { listContents } from \"../list/contents\";\n\nconst EXCLUDE = [\n\t// macOS\n\t\".AppleDB\",\n\t\".AppleDesktop\",\n\t\".AppleDouble\",\n\t\".DS_Store\",\n\t\".DocumentRevisions-V100\",\n\t\".LSOverride\",\n\t\".Spotlight-V100\",\n\t\".TemporaryItems\",\n\t\".Trashes\",\n\t\".VolumeIcon.icns\",\n\t// \"._*\",\n\t\".apdisk\",\n\t\".com.apple.timemachine.donotpresent\",\n\t\".fseventsd\",\n\t\"Network Trash Folder\",\n\t\"Temporary Items\",\n\t// Windows\n\t\"$RECYCLE.BIN/\",\n\t// \"*.cab\",\n\t// \"*.lnk\",\n\t// \"*.msi\",\n\t// \"*.msix\",\n\t// \"*.msm\",\n\t// \"*.msp\",\n\t// \"*.stackdump\",\n\t\"Desktop.ini\",\n\t\"Thumbs.db\",\n\t\"Thumbs.db:encryptable\",\n\t\"desktop.ini\",\n\t\"ehthumbs.db\",\n\t\"ehthumbs_vista.db\",\n\t// Linux\n\t// \"*~\",\n\t// \".Trash-*\",\n\t\".directory\",\n\t// \".fuse_hidden*\",\n\t// \".nfs*\",\n];\n\n/**\n * @name isEmptyContent\n * @param {string[]} listOfDirsAndFiles\n * @returns {boolean}\n */\nfunction isEmptyContent(listOfDirsAndFiles: string[]): boolean {\n\tconst content = new Set(listOfDirsAndFiles);\n\tlistOfDirsAndFiles.length = 0;\n\tcontent.forEach((dirOrFileName: string) => {\n\t\tfor (const nameToExclude of EXCLUDE) {\n\t\t\tif (!dirOrFileName) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (dirOrFileName === nameToExclude || dirOrFileName.match(RegExp(nameToExclude))) {\n\t\t\t\tcontent.delete(dirOrFileName);\n\t\t\t}\n\t\t}\n\t});\n\treturn content.size === 0;\n}\n\n/**\n * @name dirIsEmpty\n * @description Check if a directory is empty\n * @since 0.1.33\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean=} excludeSystemFiles\n * @returns {Promise}\n * @throws {Error} If path is not a dir or is not readable.\n */\nexport async function dirIsEmpty(\n\tpathToDir: string | Buffer | URL,\n\texcludeSystemFiles: boolean = true,\n): Promise {\n\tconst isReadableOrError = await dirIsReadable(pathToDir);\n\tif (isReadableOrError !== true) {\n\t\tthrow new Error((isReadableOrError as Error).message, errorExtractOptions(isReadableOrError));\n\t}\n\tlet listOfDirsAndFiles = await listContents(pathToDir);\n\tif (listOfDirsAndFiles instanceof Error) {\n\t\tthrow listOfDirsAndFiles;\n\t}\n\tif ((listOfDirsAndFiles as string[]).length === 0) {\n\t\treturn true;\n\t}\n\tif (!excludeSystemFiles) {\n\t\treturn false;\n\t}\n\treturn isEmptyContent(listOfDirsAndFiles as string[]);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name dirIsExecutable\n * @description Directory can be executed by the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsExecutable(pathToDir: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.X_OK, pathToDir);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name dirIsVisible\n * @description Directory is visible to the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsVisible(pathToDir: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.F_OK, pathToDir);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name dirIsWritable\n * @description Directory can be written by the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsWritable(pathToDir: string | Buffer | URL): Promise {\n\tif (process?.permission?.has(\"fs.write\") !== undefined) {\n\t\tconst isWritable = process.permission?.has(\"fs.write\", pathToDir as string);\n\t\tif (isWritable !== undefined) {\n\t\t\treturn isWritable;\n\t\t}\n\t}\n\treturn accessWrapper(constants.W_OK, pathToDir);\n}\n","import { createHash, getHashes } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\n\n/**\n * @name hash\n * @description Calculate hash.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {string} algorithm\n * @returns {Promise}\n * @throws {TypeError} If algorithm is not supported.\n */\nexport async function hash(pathToFile: string | Buffer | URL, algorithm: string): Promise {\n\tif (!getHashes().includes(algorithm)) {\n\t\tthrow new TypeError(`Digest algorithm [${algorithm}] is not supported.`);\n\t}\n\treturn createHash(algorithm)\n\t\t.update(await readFile(pathToFile))\n\t\t.digest(\"hex\");\n}\n","import { readFile } from \"node:fs/promises\";\n\nfunction crc32(text: string): number {\n\tlet chars = [];\n\tlet actual;\n\tfor (let current = 0; current < 256; current++) {\n\t\tactual = current;\n\t\tfor (let f = 0; f < 8; f++) {\n\t\t\tactual = 1 & actual ? 3988292384 ^ (actual >>> 1) : actual >>> 1;\n\t\t}\n\t\tchars[current] = actual;\n\t}\n\tlet number = -1;\n\tlet index = 0;\n\tfor (; index < text.length; index++) {\n\t\t// @ts-ignore\n\t\tnumber = (number >>> 8) ^ chars[255 & (number ^ text.charCodeAt(index))];\n\t}\n\treturn (-1 ^ number) >>> 0;\n}\n\n/**\n * @name hashCrc32\n * @description CRC32.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashCrc32(pathToFile: string | Buffer | URL): Promise {\n\treturn crc32((await readFile(pathToFile)).toString(\"binary\")).toString(16);\n}\n","import { hash } from \"./hash\";\n\n/**\n * @name hashMd5\n * @description MD5.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashMd5(pathToFile: string | Buffer | URL): Promise {\n\treturn hash(pathToFile, \"md5\");\n}\n","import { hash } from \"./hash\";\n\n/**\n * @name hashSha1\n * @description SHA-1.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha1(pathToFile: string | Buffer | URL): Promise {\n\treturn hash(pathToFile, \"sha1\");\n}\n","import { hash } from \"./hash\";\n\n/**\n * @name hashSha256\n * @description SHA-256.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha256(pathToFile: string | Buffer | URL): Promise {\n\treturn hash(pathToFile, \"sha256\");\n}\n","import { hash } from \"./hash\";\n\n/**\n * @name hashSha512\n * @description SHA-512.\n * @since 0.2.6\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha512(pathToFile: string | Buffer | URL): Promise {\n\treturn hash(pathToFile, \"sha512\");\n}\n","import { hashCrc32 } from \"./hash-crc32\";\nimport { hashMd5 } from \"./hash-md5\";\nimport { hashSha1 } from \"./hash-sha1\";\nimport { hashSha256 } from \"./hash-sha256\";\nimport { hashSha512 } from \"./hash-sha512\";\n\n/**\n * @name hashMulti\n * @description Calculates multiple hashes.\n * @summary The objective of the \"hashMulti\" function is to calculate multiple hashes (CRC32, MD5, SHA-1, SHA-256, and SHA-512) for a given file path and return them as an object.\n * @since 1.1.1\n * @async\n * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed.\n * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>}\n * @throws {Error|TypeError}\n */\nexport async function hashMulti(\n\tpathToFile: string | Buffer | URL,\n): Promise<{ crc32: string; md5: string; sha1: string; sha256: string; sha512: string }> {\n\treturn await Promise.all([\n\t\thashCrc32(pathToFile) as Promise,\n\t\thashMd5(pathToFile) as Promise,\n\t\thashSha1(pathToFile) as Promise,\n\t\thashSha256(pathToFile) as Promise,\n\t\thashSha512(pathToFile) as Promise,\n\t]).then(\n\t\t([\n\t\t\t//\n\t\t\tcrc32,\n\t\t\tmd5,\n\t\t\tsha1,\n\t\t\tsha256,\n\t\t\tsha512,\n\t\t]) => ({ crc32, md5, sha1, sha256, sha512 }),\n\t);\n}\n","import { stat } from \"node:fs/promises\";\n\n/**\n * @name size\n * @description File size in bytes.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {boolean=} [asString=false]\n * @returns {Promise}\n */\nexport async function size(\n\tpathToFile: string | Buffer | URL,\n\tasString: boolean = false,\n): Promise {\n\tconst fileStats = await stat(pathToFile);\n\tif (!asString) {\n\t\treturn fileStats.size;\n\t}\n\treturn fileStats.size.toLocaleString(\"en\").replace(/,/g, \"_\");\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name fileIsExecutable\n * @description File can be executed by the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsExecutable(pathToFile: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.X_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name fileIsReadable\n * @description File is visible to the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsReadable(pathToFile: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.R_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name fileIsVisible\n * @description File is visible to the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsVisible(pathToFile: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.F_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name fileIsWritable\n * @description File can be written by the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsWritable(pathToFile: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.W_OK, pathToFile);\n}\n","import { truncate } from \"node:fs/promises\";\n\n/**\n * @name fileTruncate\n * @description Truncate a file to a specified length\n * @since 0.0.6\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {number=} length\n * @returns {Promise}\n */\nexport async function fileTruncate(pathToFile: string | Buffer | URL, length: number = 0): Promise {\n\ttry {\n\t\tawait truncate(pathToFile, length);\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { join, normalize } from \"node:path\";\n\n/**\n * @name pathFrom\n * @description Join all arguments together and normalize the resulting path.\n * @since 0.1.3\n * @param {string|Buffer|URL|string[]|Buffer[]|URL[]} paths\n * @param {...string} morePaths\n * @returns {string}\n */\nexport function pathFrom(paths: string | Buffer | URL | string[] | Buffer[] | URL[], ...morePaths: string[]): string {\n\tlet routes;\n\tif (Array.isArray(paths)) {\n\t\troutes = paths.map((path) => path.toString());\n\t} else {\n\t\troutes = [paths.toString()];\n\t}\n\tif (morePaths.length) {\n\t\troutes = routes.concat(morePaths.map((path) => path.toString()));\n\t}\n\treturn normalize(join(...routes));\n}\n","import { getStatus } from \"../status/get-status\";\nimport { listContents } from \"./contents\";\nimport { pathFrom } from \"../path/path-from\";\n\n/**\n * @name listDirectories\n * @description Lists directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function listDirectories(pathToDir: string | Buffer | URL): Promise {\n\tconst contents = await listContents(pathToDir);\n\tif (!Array.isArray(contents)) {\n\t\treturn contents;\n\t}\n\tconst directories = await Promise.all(\n\t\tcontents.map(async (content) => {\n\t\t\tconst contentPath = pathFrom(pathToDir, content);\n\t\t\tconst [status, error] = await getStatus(contentPath);\n\t\t\tif (error) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (!(status as import(\"node:fs\").Stats).isDirectory()) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn content;\n\t\t}),\n\t);\n\treturn directories.filter((content) => content) as string[];\n}\n","import { getStatus } from \"../status/get-status\";\nimport { listContents } from \"./contents\";\nimport { pathFrom } from \"../path/path-from\";\n\n/**\n * @name listFiles\n * @description Lists files in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function listFiles(pathToDir: string | Buffer | URL): Promise {\n\tconst contents = await listContents(pathToDir);\n\tif (!Array.isArray(contents)) {\n\t\treturn contents;\n\t}\n\tconst files = await Promise.all(\n\t\tcontents.map(async (content) => {\n\t\t\tconst contentPath = pathFrom(pathToDir, content);\n\t\t\tconst [status, error] = await getStatus(contentPath);\n\t\t\tif (error) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif ((status as import(\"node:fs\").Stats).isDirectory()) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn content;\n\t\t}),\n\t);\n\treturn files.filter((content) => content) as string[];\n}\n","import { rename } from \"node:fs/promises\";\n\n/**\n * @name move\n * @description Change the name or location of a file or directory.\n * @since 0.1.29\n * @param {string} pathFrom\n * @param {string} pathTo\n * @returns {Promise}\n */\nexport async function move(pathFrom: string, pathTo: string): Promise {\n\ttry {\n\t\tawait rename(pathFrom, pathTo);\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { homedir } from \"node:os\";\n\nconst HOME_DIRECTORY = homedir();\n\n/**\n * @description deConvert a tilde path to an absolute path: ~/projects β†’ /Users/anon/projects\n * @param {string} pathWithTilde\n * @returns {string}\n */\nexport function absolutePath(pathWithTilde: string): string {\n\tif (HOME_DIRECTORY) {\n\t\treturn String(pathWithTilde).replace(/^~(?=$|\\/|\\\\)/, HOME_DIRECTORY);\n\t}\n\treturn String(pathWithTilde);\n}\n","import { resolve } from \"node:path\";\n\nimport { absolutePath } from \"./absolute-path\";\n\n/**\n * @name absolutePathFrom\n * @description Join all arguments together and normalize the resulting path.\n * Creates absolute path from right to left until an absolute path is constructed.\n * @since 0.1.5\n * @param {string|string[]} paths\n * @param {...string} morePaths\n * @returns {string}\n */\nexport function absolutePathFrom(paths: string | string[], ...morePaths: string[]): string {\n\tlet routes: string[];\n\tif (Array.isArray(paths)) {\n\t\troutes = paths.map((path) => path.toString());\n\t} else {\n\t\troutes = [paths.toString()];\n\t}\n\tif (morePaths.length) {\n\t\troutes = routes.concat(morePaths.map((path) => path.toString()));\n\t}\n\treturn absolutePath(resolve(...routes));\n}\n","import { extname } from \"node:path\";\n\n/**\n * @name fileExtension\n * @description Get file extension.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileExtension(path: string): string {\n\treturn extname(path).substring(1);\n}\n","import { parse } from \"node:path\";\n\n/**\n * @name fileName\n * @description Return the file name without extension.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileName(path: string): string {\n\treturn parse(path).name;\n}\n","import { basename } from \"node:path\";\n\n/**\n * @name fileNameExt\n * @description Return the last portion of a path.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileNameExt(path: string): string {\n\treturn basename(path);\n}\n","import { dirname } from \"node:path\";\n\n/**\n * @name filePath\n * @description Return the directory name of a path.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function filePath(path: string): string {\n\treturn dirname(path);\n}\n","import { readFile } from \"node:fs/promises\";\n\n/**\n * @name readFileToBase64\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.21\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToBase64(pathLike: string | Buffer | URL): Promise {\n\ttry {\n\t\tconst result = await readFile(pathLike, \"base64\");\n\t\treturn result.toString();\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { readFile } from \"node:fs/promises\";\n\n/**\n * @name readFileToBuffer\n * @description Asynchronously reads the entire contents of a file into buffer.\n * @since 0.1.19\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToBuffer(pathLike: string | Buffer | URL): Promise {\n\ttry {\n\t\tconst result = await readFile(pathLike, \"binary\");\n\t\treturn Buffer.from(result);\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { readFile } from \"node:fs/promises\";\n\nimport { absolutePath } from \"../path/absolute-path\";\n\n/**\n * @name readFileToString\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.7\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToString(pathLike: string | Buffer | URL): Promise {\n\ttry {\n\t\tconst result = await readFile(absolutePath(pathLike as string), \"utf8\");\n\t\treturn result.toString();\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","// @ts-ignore\nimport fs from \"node:fs\";\n// @ts-ignore\nimport assert from \"node:assert\";\nimport { join } from \"node:path\";\n\nconst IS_WINDOWS = process.platform === \"win32\";\n\n/**\n * @param {object} options\n */\nfunction defaults(options: any) {\n\tconst methods = [\"unlink\", \"chmod\", \"stat\", \"lstat\", \"rmdir\", \"readdir\"];\n\tmethods.forEach((method) => {\n\t\toptions[method] = options[method] || fs[method];\n\t});\n\toptions.maxBusyTries = options.maxBusyTries || 3;\n}\n\n/**\n * @param {string | Buffer | URL} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction rimraf(\n\tpathLike: string | Buffer | URL,\n\toptions: any,\n\tcallback: (error: NodeJS.ErrnoException | null) => void,\n): void {\n\tlet busyTries = 0;\n\tlet localCallback = callback;\n\tlet localOptions = options;\n\tif (typeof localOptions === \"function\") {\n\t\tlocalCallback = localOptions;\n\t\tlocalOptions = {};\n\t}\n\tassert(pathLike, \"remove(): missing path\");\n\t// assert.strictEqual(typeof pathLike, \"string\", \"remove(): path should be a string\");\n\t// assert.strictEqual(typeof localCallback, \"function\", \"remove(): callback function required\");\n\tassert(localOptions, \"remove(): invalid options argument provided\");\n\t// assert.strictEqual(typeof localOptions, \"object\", \"remove(): options should be an object?\");\n\tdefaults(localOptions);\n\trimraf_(pathLike as string, localOptions, function callbackRimraf(error: NodeJS.ErrnoException | null) {\n\t\tif (error) {\n\t\t\tif (\n\t\t\t\t(error.code === \"EBUSY\" || error.code === \"ENOTEMPTY\" || error.code === \"EPERM\") &&\n\t\t\t\tbusyTries < localOptions.maxBusyTries\n\t\t\t) {\n\t\t\t\tbusyTries++;\n\t\t\t\tconst time = busyTries * 100;\n\t\t\t\tsetTimeout(() => rimraf_(pathLike as string, localOptions, callbackRimraf), time);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\tlocalCallback(null);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tlocalCallback(error);\n\t});\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction rimraf_(pathLike: string, options: any, callback: (error: NodeJS.ErrnoException | null) => void): void {\n\tassert(pathLike);\n\tassert(options);\n\tassert(typeof callback === \"function\");\n\toptions.lstat(pathLike, (error: NodeJS.ErrnoException | null, stats: fs.Stats | fs.BigIntStats | undefined) => {\n\t\tif (error && error.code === \"ENOENT\") {\n\t\t\treturn callback(null);\n\t\t}\n\t\tif (error && error.code === \"EPERM\" && IS_WINDOWS) {\n\t\t\treturn fixWinEPERM(pathLike, options, error, callback);\n\t\t}\n\t\tif (stats && stats.isDirectory()) {\n\t\t\treturn rmdir(pathLike, options, error as NodeJS.ErrnoException, callback);\n\t\t}\n\t\toptions.unlink(pathLike, (error: NodeJS.ErrnoException | null): void | any => {\n\t\t\tif (error) {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn callback(null);\n\t\t\t\t}\n\t\t\t\tif (error.code === \"EPERM\") {\n\t\t\t\t\tif (IS_WINDOWS) {\n\t\t\t\t\t\treturn fixWinEPERM(pathLike, options, error, callback);\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn rmdir(pathLike, options, error, callback);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (error.code === \"EISDIR\") {\n\t\t\t\t\treturn rmdir(pathLike, options, error, callback);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn callback(error);\n\t\t});\n\t});\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Error|null} error\n * @param {Function=} callback\n * @returns {null}\n */\nfunction fixWinEPERM(\n\tpathLike: string,\n\toptions: any,\n\terror: NodeJS.ErrnoException | null,\n\tcallback: (error: NodeJS.ErrnoException | null) => void,\n): null {\n\tassert(pathLike);\n\tassert(options);\n\tassert(typeof callback === \"function\");\n\tif (error) {\n\t\tassert(error instanceof Error);\n\t}\n\toptions.chmod(pathLike, 0o666, (errorChMod: NodeJS.ErrnoException | null): void => {\n\t\tif (errorChMod) {\n\t\t\tif (errorChMod.code === \"ENOENT\") {\n\t\t\t\tcallback(null);\n\t\t\t} else {\n\t\t\t\tcallback(error);\n\t\t\t}\n\t\t} else {\n\t\t\toptions.stat(\n\t\t\t\tpathLike,\n\t\t\t\t(errorStat: NodeJS.ErrnoException | null, stats: fs.Stats | fs.BigIntStats | undefined) => {\n\t\t\t\t\tif (errorStat) {\n\t\t\t\t\t\tif (errorStat.code === \"ENOENT\") {\n\t\t\t\t\t\t\tcallback(null);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcallback(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (stats.isDirectory()) {\n\t\t\t\t\t\trmdir(pathLike, options, error as NodeJS.ErrnoException, callback);\n\t\t\t\t\t} else {\n\t\t\t\t\t\toptions.unlink(pathLike, callback);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t});\n\treturn null;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Error|null} originalError\n * @param {Function=} callback\n * @returns {null}\n */\nfunction rmdir(\n\tpathLike: string,\n\toptions: any,\n\toriginalError: NodeJS.ErrnoException,\n\tcallback: (error: NodeJS.ErrnoException | null) => void,\n) {\n\tassert(pathLike);\n\tassert(options);\n\tif (originalError) {\n\t\tassert(originalError instanceof Error);\n\t}\n\tassert(typeof callback === \"function\");\n\toptions.rmdir(pathLike, (error: NodeJS.ErrnoException): void => {\n\t\tif (error && (error.code === \"ENOTEMPTY\" || error.code === \"EEXIST\" || error.code === \"EPERM\")) {\n\t\t\tremoveSubPath(pathLike, options, callback);\n\t\t} else if (error && error.code === \"ENOTDIR\") {\n\t\t\tcallback(originalError);\n\t\t} else {\n\t\t\tcallback(error);\n\t\t}\n\t});\n\treturn null;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction removeSubPath(pathLike: string, options: any, callback: (error: NodeJS.ErrnoException | null) => void): void {\n\tassert(pathLike);\n\tassert(options);\n\tassert(typeof callback === \"function\");\n\toptions.readdir(pathLike, (error: Error | null, files: string[] | Buffer[] | fs.Dirent[]) => {\n\t\tif (error) {\n\t\t\treturn callback(error);\n\t\t}\n\t\tlet count = files.length;\n\t\tlet errState: Error | null = null;\n\t\tif (count === 0) {\n\t\t\treturn options.rmdir(pathLike, callback);\n\t\t}\n\t\tfiles.forEach((filePath: string): void => {\n\t\t\trimraf(join(pathLike, filePath), options, (error): void => {\n\t\t\t\tif (errState) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (error) {\n\t\t\t\t\tcallback((errState = error));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t--count;\n\t\t\t\tif (count === 0) {\n\t\t\t\t\toptions.rmdir(pathLike, callback);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t});\n}\n\n/**\n * @name remove\n * @description Removes a file or directory.\n * @since 0.1.1\n * @async\n * @param {string | Buffer | URL} pathLike\n * @returns {Promise}\n */\nexport async function remove(pathLike: string | Buffer | URL): Promise {\n\treturn new Promise((resolve) => {\n\t\trimraf(pathLike, {}, (error: unknown) => {\n\t\t\tif (error) {\n\t\t\t\tresolve(error as Error);\n\t\t\t} else {\n\t\t\t\tresolve(true);\n\t\t\t}\n\t\t});\n\t});\n}\n","import { remove } from \"./remove\";\n\n/**\n * @name removeNonBlocking\n * @description Non-blocking remove of a file or directory.\n * @since 0.1.18\n * @param {string|Buffer|URL} pathLike\n * @returns {void}\n */\nexport function removeNonBlocking(pathLike: string | Buffer | URL): void {\n\tremove(pathLike)\n\t\t.then(() => undefined)\n\t\t.catch(() => undefined); // don't put it into next tick\n}\n","import { rm } from \"node:fs/promises\";\n\nimport type { RmOptions } from \"node:fs\";\n\n/**\n * @name removeSilent\n * @description Removes files and directories (modeled on the standard POSIX rm utility).\n * @summary Minimum Node version 14.14.0\n * @since 0.1.36\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {RmOptions=} options\n * @returns {Promise}\n */\nexport async function removeSilent(pathLike: string | Buffer | URL, options: RmOptions): Promise {\n\ttry {\n\t\tawait rm(pathLike, {\n\t\t\tforce: true,\n\t\t\trecursive: true,\n\t\t\t...options,\n\t\t});\n\t} catch (__error) {\n\t\t//\n\t}\n}\n","import { lstat } from \"node:fs/promises\";\n\n/**\n * @name getLinkStatus\n * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to.\n * @url http://man7.org/linux/man-pages/man2/lstat.2.html\n * @since 1.1.0\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise<[import(\"node:fs\").Stats|undefined, Error|undefined]>}\n */\nexport async function getLinkStatus(\n\tpath: string | Buffer | URL,\n): Promise<[import(\"node:fs\").Stats | undefined, Error | undefined]> {\n\ttry {\n\t\treturn [await lstat(path), undefined];\n\t} catch (error: unknown) {\n\t\treturn [undefined, error as Error];\n\t}\n}\n","import { getStatus } from \"./get-status\";\n\n/**\n * @name isDirExists\n * @description Get directory status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isDirExists(path: string | Buffer | URL): Promise {\n\tconst [status, error] = await getStatus(path);\n\tif (error) {\n\t\treturn false;\n\t}\n\treturn (status as import(\"node:fs\").Stats).isDirectory();\n}\n","import { getStatus } from \"./get-status\";\n\n/**\n * @name isFileExists\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isFileExists(path: string | Buffer | URL): Promise {\n\tconst [status, error] = await getStatus(path);\n\tif (error) {\n\t\treturn false;\n\t}\n\treturn (status as import(\"node:fs\").Stats).isFile();\n}\n","import { getStatus } from \"./get-status\";\n\n/**\n * @name isPathExists\n * @description Get path status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isPathExists(path: string | Buffer | URL): Promise {\n\tconst [status] = await getStatus(path);\n\treturn Boolean(status);\n}\n","import { createFile } from \"../create/create-file\";\nimport { isFileExists } from \"../status/is-file-exists\";\nimport { readFileToString } from \"../read/read-file-to-string\";\nimport { writeFile } from \"./write-file\";\n\n/**\n * @name writeFileTail\n * @description Asynchronously writes data to the end of a file.\n * @since 1.0.1\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\nexport async function writeFileTail(\n\tfilePath: string | Buffer | URL,\n\tdata: any,\n\toptions: any | null | string = null,\n): Promise {\n\tconst isFileExist = await isFileExists(filePath);\n\tif (!isFileExist) {\n\t\tconst isFileCreatedOrError = await createFile(filePath);\n\t\tif (isFileCreatedOrError !== true) {\n\t\t\treturn isFileCreatedOrError as Error;\n\t\t}\n\t}\n\tconst contentOrError = await readFileToString(filePath);\n\tif (contentOrError instanceof Error) {\n\t\treturn contentOrError;\n\t}\n\treturn new Promise((resolve, reject) => {\n\t\tsetTimeout(() => {\n\t\t\twriteFile(filePath, `${String(contentOrError)}${String(data)}`, options)\n\t\t\t\t.then(() => {\n\t\t\t\t\tresolve(true);\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\treject(error);\n\t\t\t\t});\n\t\t}, 1);\n\t});\n}\n","import { writeFile } from \"./write-file\";\n\n/**\n * @name objectKeys\n * @param {object} object\n * @returns {string[]}\n */\nfunction objectKeys(object: object) {\n\treturn Object.keys(object).sort((alpha, beta) => alpha.localeCompare(beta));\n}\n\n/**\n * name isObjectLike\n * @param {*} value\n * @returns {boolean}\n */\nfunction isObjectLike(value: any) {\n\treturn value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\n/**\n * @name collectionSortKeys\n * @param {*} value\n * @param {boolean=} [isDeep=true]\n * @returns {Record|any[]}\n */\nfunction collectionSortKeys(value: any, isDeep = true): Record | any[] {\n\tif (!isObjectLike(value)) {\n\t\tif (Array.isArray(value)) {\n\t\t\treturn value.map((arrayValue) => collectionSortKeys(arrayValue, isDeep));\n\t\t}\n\t\treturn value;\n\t}\n\tconst keys = objectKeys(value);\n\tif (!keys.length) {\n\t\treturn value;\n\t}\n\treturn keys.reduce((sorted: Record, key) => {\n\t\tif (isDeep && isObjectLike(value[key])) {\n\t\t\tsorted[key] = collectionSortKeys(value[key], isDeep);\n\t\t} else if (isDeep && Array.isArray(value[key])) {\n\t\t\tsorted[key] = collectionSortKeys(value[key], isDeep);\n\t\t} else {\n\t\t\tsorted[key] = value[key];\n\t\t}\n\t\treturn sorted;\n\t}, {});\n}\n\n/**\n * @name writeJson\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.1.25\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {*} data\n * @param {*|null|string=} options\n * @param {{sort: boolean, space: number|string}=} configuration\n * @returns {Promise}\n */\nexport async function writeJson(\n\tfilePath: string | Buffer | URL,\n\tdata: any,\n\toptions: any | null | string = null,\n\tconfiguration: { sort: boolean; space: number | string } | undefined,\n): Promise {\n\tlet json;\n\tlet stringify = data;\n\ttry {\n\t\tif (configuration) {\n\t\t\tif (configuration.sort) {\n\t\t\t\tif (isObjectLike(data)) {\n\t\t\t\t\tstringify = collectionSortKeys(JSON.parse(JSON.stringify(data)));\n\t\t\t\t} else if (Array.isArray(data)) {\n\t\t\t\t\tstringify = JSON.parse(JSON.stringify(data));\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (configuration.space) {\n\t\t\t\tjson = JSON.stringify(stringify, null, configuration.space);\n\t\t\t}\n\t\t} else {\n\t\t\tjson = JSON.stringify(stringify);\n\t\t}\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n\treturn writeFile(filePath, json, options);\n}\n","import { absolutePathFrom } from \"./path/absolute-path-from\";\n\nimport { createDirectory } from \"./create/create-directory\";\nimport { createFile } from \"./create/create-file\";\n\nimport { dirIsExecutable } from \"./dir/dir-is-executable\";\nimport { dirIsReadable } from \"./dir/dir-is-readable\";\nimport { dirIsVisible } from \"./dir/dir-is-visible\";\nimport { dirIsWritable } from \"./dir/dir-is-writable\";\nimport { dirIsEmpty } from \"./dir/dir-is-empty\";\n\nimport { fileExtension } from \"./path/file-extension\";\nimport { fileIsExecutable } from \"./file/file-is-executable\";\nimport { fileIsReadable } from \"./file/file-is-readable\";\nimport { fileIsVisible } from \"./file/file-is-visible\";\nimport { fileIsWritable } from \"./file/file-is-writable\";\nimport { fileName } from \"./path/file-name\";\nimport { fileNameExt } from \"./path/file-name-ext\";\nimport { filePath } from \"./path/file-path\";\nimport { fileTruncate } from \"./file/file-truncate\";\n\nimport { listContents } from \"./list/contents\";\nimport { listDirectories } from \"./list/directories\";\nimport { listFiles } from \"./list/files\";\n\nimport { getLinkStatus } from \"./status/get-link-status\";\nimport { getStatus } from \"./status/get-status\";\n\nimport { isDirExists } from \"./status/is-dir-exists\";\nimport { isFileExists } from \"./status/is-file-exists\";\nimport { isPathExists } from \"./status/is-path-exists\";\n\nimport { move } from \"./move/move\";\n\nimport { pathFrom } from \"./path/path-from\";\n\nimport { readFileToBase64 } from \"./read/read-file-to-base64\";\nimport { readFileToBuffer } from \"./read/read-file-to-buffer\";\nimport { readFileToString } from \"./read/read-file-to-string\";\nimport { remove } from \"./remove/remove\";\nimport { removeNonBlocking } from \"./remove/remove-non-blocking\";\nimport { removeSilent } from \"./remove/remove-silent\";\n\nimport { writeFile } from \"./write/write-file\";\nimport { writeFileTail } from \"./write/write-file-tail\";\nimport { writeJson } from \"./write/write-json\";\n\nimport { hash } from \"./info/hash\";\nimport { hashCrc32 } from \"./info/hash-crc32\";\nimport { hashMd5 } from \"./info/hash-md5\";\nimport { hashMulti } from \"./info/hash-multi\";\nimport { hashSha1 } from \"./info/hash-sha1\";\nimport { hashSha256 } from \"./info/hash-sha256\";\nimport { hashSha512 } from \"./info/hash-sha512\";\n\nimport { size } from \"./info/size\";\n\nexport class HileSystemLocal {\n\t/**\n\t * @name absolutePathFrom\n\t * @description Join all arguments together and normalize the resulting path.\n\t * Creates absolute path from right to left until an absolute path is constructed.\n\t * @since 0.1.5\n\t * @public\n\t * @param {string|string[]} paths\n\t * @param {...string} morePaths\n\t * @returns {string}\n\t */\n\tabsolutePathFrom = absolutePathFrom;\n\t/**\n\t * @name createDirectory\n\t * @description Asynchronous create a directory.\n\t * @since 0.0.10\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} dirPath\n\t * @param {number|string=} mode\n\t * @param {boolean=} recursive\n\t * @returns {Promise}\n\t */\n\tcreateDirectory = createDirectory;\n\t/**\n\t * @name createFile\n\t * @description Asynchronous create a file.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathLike\n\t * @param {number|string=} mode\n\t * @returns {Promise}\n\t */\n\tcreateFile = createFile;\n\t/**\n\t * @name dirIsExecutable\n\t * @description Directory can be executed by the calling process\n\t * @since 0.0.5\n\t * @async\n\t * @public\n\t * @param {string} pathToDir\n\t * @returns {Promise}\n\t */\n\tdirIsExecutable = dirIsExecutable;\n\t/**\n\t * @name dirIsReadable\n\t * @description Directory is visible to the calling process\n\t * @since 0.0.1\n\t * @async\n\t * @public\n\t * @param {string} pathToDir\n\t * @returns {Promise}\n\t */\n\tdirIsReadable = dirIsReadable;\n\t/**\n\t * @name dirIsVisible\n\t * @description Directory is visible to the calling process\n\t * @since 0.0.5\n\t * @async\n\t * @public\n\t * @param {string} pathToDir\n\t * @returns {Promise}\n\t */\n\tdirIsVisible = dirIsVisible;\n\t/**\n\t * @name dirIsWritable\n\t * @description Directory can be written by the calling process\n\t * @since 0.0.1\n\t * @async\n\t * @public\n\t * @param {string} pathToDir\n\t * @returns {Promise}\n\t */\n\tdirIsWritable = dirIsWritable;\n\t/**\n\t * @name dirIsEmpty\n\t * @description Check if a directory is empty\n\t * @since 0.1.33\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToDir\n\t * @param {boolean=} excludeSystemFiles\n\t * @returns {Promise}\n\t * @throws {Error} If path is not a dir or is not readable.\n\t */\n\tdirIsEmpty = dirIsEmpty;\n\t/**\n\t * @name getLinkStatus\n\t * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to.\n\t * @url http://man7.org/linux/man-pages/man2/lstat.2.html\n\t * @since 1.1.0\n\t * @async\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise>}\n\t */\n\tgetLinkStatus = getLinkStatus;\n\t/**\n\t * @name getStatus\n\t * @description Get file status.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise>}\n\t */\n\tgetStatus = getStatus;\n\t/**\n\t * @name isDirExists\n\t * @description Get directory status.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise}\n\t */\n\tisDirExists = isDirExists;\n\t/**\n\t * @name isFileExists\n\t * @description Get file status.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise}\n\t */\n\tisFileExists = isFileExists;\n\t/**\n\t * @name isPathExists\n\t * @description Get path status.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise}\n\t */\n\tisPathExists = isPathExists;\n\t/**\n\t * @name fileExtension\n\t * @description Get file extension.\n\t * @since 0.1.1\n\t * @public\n\t * @param {string} path\n\t * @returns {string}\n\t */\n\tfileExtension = fileExtension;\n\t/**\n\t * @name fileName\n\t * @description Return the file name without extension.\n\t * @since 0.1.1\n\t * @public\n\t * @param {string} path\n\t * @returns {string}\n\t */\n\tfileName = fileName;\n\t/**\n\t * @name fileNameExt\n\t * @description Return the last portion of a path.\n\t * @since 0.1.1\n\t * @public\n\t * @param {string} path\n\t * @returns {string}\n\t */\n\tfileNameExt = fileNameExt;\n\t/**\n\t * @name filePath\n\t * @description Return the directory name of a path.\n\t * @since 0.1.1\n\t * @public\n\t * @param {string} path\n\t * @returns {string}\n\t */\n\tfilePath = filePath;\n\t/**\n\t * @name fileIsExecutable\n\t * @description File can be executed by the calling process\n\t * @since 0.0.5\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\tfileIsExecutable = fileIsExecutable;\n\t/**\n\t * @name fileIsReadable\n\t * @description File is visible to the calling process\n\t * @since 0.0.1\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\tfileIsReadable = fileIsReadable;\n\t/**\n\t * @name fileIsVisible\n\t * @description File is visible to the calling process\n\t * @since 0.0.5\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\tfileIsVisible = fileIsVisible;\n\t/**\n\t * @name fileIsWritable\n\t * @description File can be written by the calling process\n\t * @since 0.0.1\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\tfileIsWritable = fileIsWritable;\n\t/**\n\t * @name fileTruncate\n\t * @description Truncate a file to a specified length\n\t * @since 0.0.6\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @param {number=} length\n\t * @returns {Promise}\n\t */\n\tfileTruncate = fileTruncate;\n\t/**\n\t * @name hash\n\t * @description Calculate hash.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @param {string} algorithm\n\t * @returns {Promise}\n\t * @throws {TypeError} If algorithm is not supported.\n\t */\n\thash = hash;\n\t/**\n\t * @name hashCrc32\n\t * @description CRC32.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashCrc32 = hashCrc32;\n\t/**\n\t * @name hashMd5\n\t * @description MD5.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashMd5 = hashMd5;\n\t/**\n\t * @name hashMulti\n\t * @description Calculates multiple hashes.\n\t * @since 1.1.1\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed.\n\t * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>}\n\t * @throws {Error|TypeError}\n\t */\n\thashMulti = hashMulti;\n\t/**\n\t * @name hashSha1\n\t * @description SHA-1.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashSha1 = hashSha1;\n\t/**\n\t * @name hashSha256\n\t * @description SHA-256.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashSha256 = hashSha256;\n\t/**\n\t * @name hashSha512\n\t * @description SHA-512.\n\t * @since 0.2.6\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashSha512 = hashSha512;\n\t/**\n\t * @name listContents\n\t * @description Lists files and directories in path\n\t * @since 0.1.32\n\t * @async\n\t * @param {string|Buffer|URL} pathToDir\n\t * @returns {Promise}\n\t */\n\tlistContents = listContents;\n\t/**\n\t * @name listDirectories\n\t * @description Lists directories in path\n\t * @since 0.1.32\n\t * @async\n\t * @param {string|Buffer|URL} pathToDir\n\t * @returns {Promise}\n\t */\n\tlistDirectories = listDirectories;\n\t/**\n\t * @name listFiles\n\t * @description Lists files in path\n\t * @since 0.1.32\n\t * @async\n\t * @param {string|Buffer|URL} pathToDir\n\t * @returns {Promise}\n\t */\n\tlistFiles = listFiles;\n\t/**\n\t * @name move\n\t * @description Change the name or location of a file or directory.\n\t * @since 0.1.29\n\t * @public\n\t * @param {string} pathFrom\n\t * @param {string} pathTo\n\t * @returns {Promise}\n\t */\n\tmove = move;\n\t/**\n\t * @name pathFrom\n\t * @description Join all arguments together and normalize the resulting path.\n\t * @since 0.1.3\n\t * @public\n\t * @param {string|string[]} paths\n\t * @param {...string} morePaths\n\t * @returns {string}\n\t */\n\tpathFrom = pathFrom;\n\t/**\n\t * @name readFileToBase64\n\t * @description Asynchronously reads the entire contents of a file into string.\n\t * @since 0.1.21\n\t * @async\n\t * @param {string|Buffer|URL} pathLike\n\t * @returns {Promise}\n\t */\n\treadFileToBase64 = readFileToBase64;\n\t/**\n\t * @name readFileToBuffer\n\t * @description Asynchronously reads the entire contents of a file into buffer.\n\t * @since 0.1.19\n\t * @async\n\t * @param {string|Buffer|URL} pathLike\n\t * @returns {Promise}\n\t */\n\treadFileToBuffer = readFileToBuffer;\n\t/**\n\t * @name readFileToString\n\t * @description Asynchronously reads the entire contents of a file into string.\n\t * @since 0.1.7\n\t * @async\n\t * @param {string|Buffer|URL} pathLike\n\t * @returns {Promise}\n\t */\n\treadFileToString = readFileToString;\n\t/**\n\t * @name remove\n\t * @description Removes a file or directory.\n\t * @since 0.1.1\n\t * @async\n\t * @public\n\t * @param {string} pathLike\n\t * @returns {Promise}\n\t */\n\tremove = remove;\n\t/**\n\t * @name removeNonBlocking\n\t * @description Non-blocking remove of a file or directory.\n\t * @since 0.1.18\n\t * @public\n\t * @param {string} pathLike\n\t * @returns {void}\n\t */\n\tremoveNonBlocking = removeNonBlocking;\n\t/**\n\t * @name removeSilent\n\t * @description Removes files and directories (modeled on the standard POSIX rm utility).\n\t * @summary Minimum Node version 14.14.0\n\t * @since 0.1.36\n\t * @async\n\t * @param {string|Buffer|URL} pathLike\n\t * @param {object=} options\n\t * @returns {Promise}\n\t */\n\tremoveSilent = removeSilent;\n\t/**\n\t * @name size\n\t * @description File size in bytes.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @param {boolean=} [asString=false]\n\t * @returns {Promise}\n\t */\n\tsize = size;\n\t/**\n\t * @name writeFile\n\t * @description Asynchronously writes data to a file, replacing the file if it already exists.\n\t * @since 0.0.10\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} filePath\n\t * @param {string} data\n\t * @param {*|null|string=} options\n\t * @returns {Promise}\n\t */\n\twriteFile = writeFile;\n\t/**\n\t * @name writeFileTail\n\t * @description Asynchronously writes data to the end of a file.\n\t * @since 1.0.1\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} filePath\n\t * @param {string} data\n\t * @param {*|null|string=} options\n\t * @returns {Promise}\n\t */\n\twriteFileTail = writeFileTail;\n\t/**\n\t * @name writeJson\n\t * @description Asynchronously writes data to a file, replacing the file if it already exists.\n\t * @since 0.1.25\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} filePath\n\t * @param {*} data\n\t * @param {*|null|string=} options\n\t * @returns {Promise}\n\t */\n\twriteJson = writeJson;\n}\n"],"names":["createDirectory","dirPath","mode","recursive","mkdir","error","getStatus","path","stat","writeFile","filePath","data","options","writeFileNative","createFile","pathLike","status","dirname","dirCreated","fileWritten","readdir","errorExtractOptions","accessWrapper","access","dirIsReadable","pathToDir","_a","isWritable","_b","constants","ignoreList","junkRegex","isSystemJunk","fileName","isNotSystemJunk","listContents","ignoreJunk","contents","EXCLUDE","isEmptyContent","listOfDirsAndFiles","content","dirOrFileName","nameToExclude","dirIsEmpty","excludeSystemFiles","isReadableOrError","dirIsExecutable","dirIsVisible","dirIsWritable","hash","pathToFile","algorithm","getHashes","createHash","readFile","crc32","text","chars","actual","current","f","number","index","hashCrc32","hashMd5","hashSha1","hashSha256","hashSha512","hashMulti","md5","sha1","sha256","sha512","size","asString","fileStats","fileIsExecutable","fileIsReadable","fileIsVisible","fileIsWritable","fileTruncate","length","truncate","pathFrom","paths","morePaths","routes","normalize","join","listDirectories","contentPath","listFiles","move","pathTo","rename","HOME_DIRECTORY","homedir","absolutePath","pathWithTilde","absolutePathFrom","resolve","fileExtension","extname","parse","fileNameExt","basename","readFileToBase64","readFileToBuffer","result","readFileToString","IS_WINDOWS","defaults","method","fs","rimraf","callback","busyTries","localCallback","localOptions","assert","rimraf_","callbackRimraf","time","stats","fixWinEPERM","rmdir","errorChMod","errorStat","originalError","removeSubPath","files","count","errState","remove","removeNonBlocking","removeSilent","rm","getLinkStatus","lstat","isDirExists","isFileExists","isPathExists","writeFileTail","isFileCreatedOrError","contentOrError","reject","objectKeys","object","alpha","beta","isObjectLike","value","collectionSortKeys","isDeep","arrayValue","keys","sorted","key","writeJson","configuration","json","stringify","HileSystemLocal"],"mappings":"wOAYA,eAAsBA,EAErBC,EACAC,EAAsC,OACtCC,EAAiC,GACN,CACvB,GAAA,CACH,aAAMC,EAAM,MAAAH,EAAS,CAAE,KAAAC,EAAM,UAAAC,CAAW,CAAA,EACjC,SACCE,EAAgB,CACjB,OAAAA,CACR,CACD,CCdA,eAAsBC,EACrBC,EACoE,CAChE,GAAA,CACH,MAAO,CAAC,MAAMC,EAAK,KAAAD,CAAI,EAAG,MAAS,QAC3BF,EAAgB,CACjB,MAAA,CAAC,OAAWA,CAAc,CAClC,CACD,CCOA,eAAsBI,EACrBC,EACAC,EACAC,EAA+B,KACJ,CACvB,GAAA,CACG,aAAAC,YAAgBH,EAAUC,EAAMC,CAAO,EACtC,SACCP,EAAgB,CACjB,OAAAA,CACR,CACD,CCpBsB,eAAAS,EACrBC,EACAb,EAAe,OACwB,CACvC,KAAM,CAACc,EAAQX,CAAK,EAAI,MAAMC,EAAUS,CAAQ,EAChD,GAAI,CAACV,GAAUW,EAAmC,SAC1C,MAAA,GAEF,MAAAf,EAAUgB,UAAQF,CAAkB,EAC1C,GAAIV,GACEA,EAAgC,OAAS,SAAU,CACvD,MAAMa,EAAa,MAAMlB,EAAgBC,EAASC,CAAI,EACtD,GAAIgB,IAAe,GACX,OAAAA,EAEF,MAAAC,EAAc,MAAMV,EAAUM,EAAU,GAAI,CAAE,KAAAb,EAAM,KAAM,GAAA,CAAK,EACrE,OAAIiB,IAAgB,GACZA,EAED,EACR,CAEI,GAAAH,EAAmC,cAChC,OAAA,MAAMP,EAAUM,EAAU,GAAI,CAAE,KAAAb,EAAM,KAAM,IAAK,EAEpD,GAAA,CACH,MAAMkB,EAAAA,QAAQnB,CAAO,EACd,aACCI,EAAgB,CACjBA,OAAAA,CACR,CAEF,CC3CO,SAASgB,GACfhB,EAC2F,CACvF,OAAEA,aAAiB,MAGnB,SAAUA,GAAS,UAAWA,GAAS,SAAUA,GAAS,YAAaA,EACnE,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,UAAUC,EAAW,KAAMF,EAAc,KAAK,IAGpDC,EAAA,KAAK,UAAUC,CAAS,QAExB7J,EAAgB,CACjB,OAAAA,CACR,CACO,OAAAI,EAAUC,EAAUuJ,EAAMrJ,CAAO,CACzC,CC9BO,MAAMuJ,EAAgB,CAAtB,aAAA,CAWa,KAAA,iBAAA/D,EAYD,KAAA,gBAAApG,EAWL,KAAA,WAAAc,EAUK,KAAA,gBAAAiC,EAUF,KAAA,cAAAvB,EAUD,KAAA,aAAAwB,EAUC,KAAA,cAAAC,EAYH,KAAA,WAAAL,EAUG,KAAA,cAAA8F,GAUJ,KAAA,UAAApI,EAUE,KAAA,YAAAsI,GAUC,KAAA,aAAAC,EAUA,KAAA,aAAAC,GASC,KAAA,cAAAxC,GASL,KAAA,SAAArE,GASG,KAAA,YAAAwE,GASH,KAAA,SAAA/F,GAUQ,KAAA,iBAAAmE,EAUF,KAAA,eAAAC,EAUD,KAAA,cAAAC,EAUC,KAAA,eAAAC,EAWF,KAAA,aAAAC,EAYR,KAAA,KAAA/B,EAUK,KAAA,UAAAc,EAUF,KAAA,QAAAC,EAWE,KAAA,UAAAI,EAUD,KAAA,SAAAH,EAUE,KAAA,WAAAC,EAUA,KAAA,WAAAC,EASE,KAAA,aAAAjC,EASG,KAAA,gBAAAuD,EASN,KAAA,UAAAE,EAUL,KAAA,KAAAC,EAUI,KAAA,SAAAT,EASQ,KAAA,iBAAAuB,GASA,KAAA,iBAAAC,GASA,KAAA,iBAAAE,EAUV,KAAA,OAAAwB,EASW,KAAA,kBAAAC,GAWL,KAAA,aAAAC,GAWR,KAAA,KAAA9D,EAYK,KAAA,UAAAjE,EAYI,KAAA,cAAAsI,GAYJ,KAAA,UAAAgB,EAAA,CACb"} \ No newline at end of file diff --git a/dist/index.d.cts b/dist/index.d.cts index 59c0b3c..29ce49b 100644 --- a/dist/index.d.cts +++ b/dist/index.d.cts @@ -1,35 +1,5 @@ -import type { PathLike, Stats } from "fs"; - -export interface RmOptions { - /** - * When `true`, exceptions will be ignored if `path` does not exist. - * @default false - */ - force?: boolean | undefined; - /** - * If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or - * `EPERM` error is encountered, Node.js will retry the operation with a linear - * backoff wait of `retryDelay` ms longer on each try. This option represents the - * number of retries. This option is ignored if the `recursive` option is not - * `true`. - * @default 0 - */ - maxRetries?: number | undefined; - /** - * If `true`, perform a recursive directory removal. In - * recursive mode, operations are retried on failure. - * @default false - */ - recursive?: boolean | undefined; - /** - * The amount of time in milliseconds to wait between retries. - * This option is ignored if the `recursive` option is not `true`. - * @default 100 - */ - retryDelay?: number | undefined; -} - -//#region create +import * as node_fs from 'node:fs'; +import { RmOptions } from 'node:fs'; /** * @name createDirectory @@ -39,9 +9,9 @@ export interface RmOptions { * @param {string|Buffer|URL} dirPath * @param {number|string=} mode * @param {boolean=} recursive - * @returns {Promise} + * @returns {Promise} */ -export function createDirectory(dirPath: PathLike, mode?: number | string, recursive?: boolean): Promise; +declare function createDirectory(dirPath: string | Buffer | URL, mode?: (number | string) | undefined, recursive?: boolean | undefined): Promise; /** * @name createFile @@ -50,13 +20,21 @@ export function createDirectory(dirPath: PathLike, mode?: number | string, recur * @async * @param {string|Buffer|URL} pathLike * @param {number|string=} mode - * @returns {Promise} + * @returns {Promise} */ -export function createFile(pathLike: PathLike, mode?: number | string): Promise; +declare function createFile(pathLike: string | Buffer | URL, mode?: string): Promise; -//#endregion - -//#region dir +/** + * @name dirIsEmpty + * @description Check if a directory is empty + * @since 0.1.33 + * @async + * @param {string|Buffer|URL} pathToDir + * @param {boolean=} excludeSystemFiles + * @returns {Promise} + * @throws {Error} If path is not a dir or is not readable. + */ +declare function dirIsEmpty(pathToDir: string | Buffer | URL, excludeSystemFiles?: boolean): Promise; /** * @name dirIsExecutable @@ -64,9 +42,9 @@ export function createFile(pathLike: PathLike, mode?: number | string): Promise< * @since 0.0.5 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise} + * @returns {Promise} */ -export function dirIsExecutable(pathToDir: PathLike): Promise; +declare function dirIsExecutable(pathToDir: string | Buffer | URL): Promise; /** * @name dirIsReadable @@ -74,9 +52,9 @@ export function dirIsExecutable(pathToDir: PathLike): Promise; * @since 0.0.1 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise} + * @returns {Promise} */ -export function dirIsReadable(pathToDir: PathLike): Promise; +declare function dirIsReadable(pathToDir: string | Buffer | URL): Promise; /** * @name dirIsVisible @@ -84,9 +62,9 @@ export function dirIsReadable(pathToDir: PathLike): Promise; * @since 0.0.5 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise} + * @returns {Promise} */ -export function dirIsVisible(pathToDir: PathLike): Promise; +declare function dirIsVisible(pathToDir: string | Buffer | URL): Promise; /** * @name dirIsWritable @@ -94,146 +72,151 @@ export function dirIsVisible(pathToDir: PathLike): Promise; * @since 0.0.1 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise} + * @returns {Promise} */ -export function dirIsWritable(pathToDir: PathLike): Promise; +declare function dirIsWritable(pathToDir: string | Buffer | URL): Promise; /** - * @name dirIsEmpty - * @description Check If a directory is empty - * @since 0.1.33 + * @name hash + * @description Calculate hash. + * @since 0.2.3 * @async - * @param {string|Buffer|URL} pathToDir - * @param {boolean=} excludeSystemFiles - * @returns {Promise} + * @param {string|Buffer|URL} pathToFile + * @param {string} algorithm + * @returns {Promise} + * @throws {TypeError} If algorithm is not supported. */ -export function dirIsEmpty(pathToDir: PathLike, excludeSystemFiles: boolean): Promise; - -//#endregion - -//#region file +declare function hash(pathToFile: string | Buffer | URL, algorithm: string): Promise; /** - * @name fileIsExecutable - * @description File can be executed by the calling process - * @since 0.0.5 + * @name hashCrc32 + * @description CRC32. + * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function fileIsExecutable(pathToFile: PathLike): Promise; +declare function hashCrc32(pathToFile: string | Buffer | URL): Promise; /** - * @name fileIsReadable - * @description File is visible to the calling process - * @since 0.0.1 + * @name hashMd5 + * @description MD5. + * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function fileIsReadable(pathToFile: PathLike): Promise; +declare function hashMd5(pathToFile: string | Buffer | URL): Promise; /** - * @name fileIsVisible - * @description File is visible to the calling process - * @since 0.0.5 + * @name hashMulti + * @description Calculates multiple hashes. + * @summary The objective of the "hashMulti" function is to calculate multiple hashes (CRC32, MD5, SHA-1, SHA-256, and SHA-512) for a given file path and return them as an object. + * @since 1.1.1 * @async - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed. + * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>} + * @throws {Error|TypeError} */ -export function fileIsVisible(pathToFile: PathLike): Promise; +declare function hashMulti(pathToFile: string | Buffer | URL): Promise<{ + crc32: string; + md5: string; + sha1: string; + sha256: string; + sha512: string; +}>; /** - * @name fileIsWritable - * @description File can be written by the calling process - * @since 0.0.1 + * @name hashSha1 + * @description SHA-1. + * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function fileIsWritable(pathToFile: PathLike): Promise; +declare function hashSha1(pathToFile: string | Buffer | URL): Promise; /** - * @name fileTruncate - * @description Truncate a file to a specified length - * @since 0.0.6 + * @name hashSha256 + * @description SHA-256. + * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @param {number=} length - * @returns {Promise} + * @returns {Promise} */ -export function fileTruncate(pathToFile: PathLike, length?: number): Promise; - -//#endregion - -//#region info +declare function hashSha256(pathToFile: string | Buffer | URL): Promise; /** - * @name hash - * @description Calculate hash. - * @since 0.2.3 + * @name hashSha512 + * @description SHA-512. + * @since 0.2.6 * @async * @param {string|Buffer|URL} pathToFile - * @param {string} algorithm - * @returns {Promise} - * @throws {TypeError} If algorithm is not supported. + * @returns {Promise} */ -export function hash(pathToFile: PathLike, algorithm: string): Promise; +declare function hashSha512(pathToFile: string | Buffer | URL): Promise; /** - * @name hashCrc32 - * @description CRC32. + * @name size + * @description File size in bytes. * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @param {boolean=} [asString=false] + * @returns {Promise} */ -export function hashCrc32(pathToFile: PathLike): Promise; +declare function size(pathToFile: string | Buffer | URL, asString?: boolean): Promise; /** - * @name hashMd5 - * @description MD5. - * @since 0.2.3 + * @name fileIsExecutable + * @description File can be executed by the calling process + * @since 0.0.5 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function hashMd5(pathToFile: PathLike): Promise; +declare function fileIsExecutable(pathToFile: string | Buffer | URL): Promise; /** - * @name hashSha1 - * @description SHA-1. - * @since 0.2.3 + * @name fileIsReadable + * @description File is visible to the calling process + * @since 0.0.1 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function hashSha1(pathToFile: PathLike): Promise; +declare function fileIsReadable(pathToFile: string | Buffer | URL): Promise; /** - * @name hashSha256 - * @description SHA-256. - * @since 0.2.3 + * @name fileIsVisible + * @description File is visible to the calling process + * @since 0.0.5 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function hashSha256(pathToFile: PathLike): Promise; +declare function fileIsVisible(pathToFile: string | Buffer | URL): Promise; /** - * @name size - * @description File size in bytes. - * @since 0.2.3 + * @name fileIsWritable + * @description File can be written by the calling process + * @since 0.0.1 * @async * @param {string|Buffer|URL} pathToFile - * @param {boolean=} [asString=false] - * @returns {Promise} + * @returns {Promise} */ -export function size(pathToFile: PathLike, asString?: boolean): Promise; - -//#endregion +declare function fileIsWritable(pathToFile: string | Buffer | URL): Promise; -//#region list +/** + * @name fileTruncate + * @description Truncate a file to a specified length + * @since 0.0.6 + * @async + * @param {string|Buffer|URL} pathToFile + * @param {number=} length + * @returns {Promise} + */ +declare function fileTruncate(pathToFile: string | Buffer | URL, length?: number): Promise; /** * @name listContents @@ -242,9 +225,9 @@ export function size(pathToFile: PathLike, asString?: boolean): Promise|Error|{name: string, message: string, stack?: string}>} + * @returns {Promise} */ -export function listContents(pathToDir: PathLike, ignoreJunk?: boolean): Promise; +declare function listContents(pathToDir: string | Buffer | URL, ignoreJunk?: boolean): Promise; /** * @name listDirectories @@ -252,9 +235,9 @@ export function listContents(pathToDir: PathLike, ignoreJunk?: boolean): Promise * @since 0.1.32 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} + * @returns {Promise} */ -export function listDirectories(pathToDir: PathLike): Promise; +declare function listDirectories(pathToDir: string | Buffer | URL): Promise; /** * @name listFiles @@ -262,13 +245,9 @@ export function listDirectories(pathToDir: PathLike): Promise; * @since 0.1.32 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} + * @returns {Promise} */ -export function listFiles(pathToDir: PathLike): Promise; - -//#endregion - -//#region move +declare function listFiles(pathToDir: string | Buffer | URL): Promise; /** * @name move @@ -276,24 +255,20 @@ export function listFiles(pathToDir: PathLike): Promise; * @since 0.1.29 * @param {string} pathFrom * @param {string} pathTo - * @returns {Promise} + * @returns {Promise} */ -export function move(pathFrom: PathLike, pathTo: PathLike): Promise; - -//#endregion - -//#region path +declare function move(pathFrom: string, pathTo: string): Promise; /** * @name absolutePathFrom * @description Join all arguments together and normalize the resulting path. * Creates absolute path from right to left until an absolute path is constructed. * @since 0.1.5 - * @param {string|Array.} paths + * @param {string|string[]} paths * @param {...string} morePaths * @returns {string} */ -export function absolutePathFrom(paths: string | string[], ...morePaths: string[]): string; +declare function absolutePathFrom(paths: string | string[], ...morePaths: string[]): string; /** * @name fileExtension @@ -302,7 +277,7 @@ export function absolutePathFrom(paths: string | string[], ...morePaths: string[ * @param {string} path * @returns {string} */ -export function fileExtension(path: string): string; +declare function fileExtension(path: string): string; /** * @name fileName @@ -311,7 +286,7 @@ export function fileExtension(path: string): string; * @param {string} path * @returns {string} */ -export function fileName(path: string): string; +declare function fileName(path: string): string; /** * @name fileNameExt @@ -320,7 +295,7 @@ export function fileName(path: string): string; * @param {string} path * @returns {string} */ -export function fileNameExt(path: string): string; +declare function fileNameExt(path: string): string; /** * @name filePath @@ -329,21 +304,17 @@ export function fileNameExt(path: string): string; * @param {string} path * @returns {string} */ -export function filePath(path: string): string; +declare function filePath(path: string): string; /** * @name pathFrom * @description Join all arguments together and normalize the resulting path. * @since 0.1.3 - * @param {string|Array.} paths + * @param {string|Buffer|URL|string[]|Buffer[]|URL[]} paths * @param {...string} morePaths * @returns {string} */ -export function pathFrom(paths: string | string[], ...morePaths: string[]): string; - -//#endregion - -//#region read +declare function pathFrom(paths: string | Buffer | URL | string[] | Buffer[] | URL[], ...morePaths: string[]): string; /** * @name readFileToBase64 @@ -351,9 +322,9 @@ export function pathFrom(paths: string | string[], ...morePaths: string[]): stri * @since 0.1.21 * @async * @param {string|Buffer|URL} pathLike - * @returns {Promise} + * @returns {Promise} */ -export function readFileToBase64(pathLike: string): Promise; +declare function readFileToBase64(pathLike: string | Buffer | URL): Promise; /** * @name readFileToBuffer @@ -361,9 +332,9 @@ export function readFileToBase64(pathLike: string): Promise; * @since 0.1.19 * @async * @param {string|Buffer|URL} pathLike - * @returns {Promise} + * @returns {Promise} */ -export function readFileToBuffer(pathLike: string): Promise; +declare function readFileToBuffer(pathLike: string | Buffer | URL): Promise; /** * @name readFileToString @@ -371,33 +342,28 @@ export function readFileToBuffer(pathLike: string): Promise; * @since 0.1.7 * @async * @param {string|Buffer|URL} pathLike - * @returns {Promise} + * @returns {Promise} */ -export function readFileToString(pathLike: string): Promise; - -//#endregion - -//#region remove +declare function readFileToString(pathLike: string | Buffer | URL): Promise; /** * @name remove * @description Removes a file or directory. * @since 0.1.1 * @async - * @param {string} pathLike - * @returns {Promise} + * @param {string | Buffer | URL} pathLike + * @returns {Promise} */ -export function remove(pathLike: string): Promise; +declare function remove(pathLike: string | Buffer | URL): Promise; /** * @name removeNonBlocking * @description Non-blocking remove of a file or directory. * @since 0.1.18 - * @sync - * @param {string} pathLike + * @param {string|Buffer|URL} pathLike * @returns {void} */ -export function removeNonBlocking(pathLike: string): void; +declare function removeNonBlocking(pathLike: string | Buffer | URL): void; /** * @name removeSilent @@ -406,14 +372,10 @@ export function removeNonBlocking(pathLike: string): void; * @since 0.1.36 * @async * @param {string|Buffer|URL} pathLike - * @param {object=} options + * @param {RmOptions=} options * @returns {Promise} */ -export function removeSilent(pathLike: string, options?: RmOptions): Promise; - -//#endregion - -//#region status +declare function removeSilent(pathLike: string | Buffer | URL, options: RmOptions): Promise; /** * @name getLinkStatus @@ -422,9 +384,9 @@ export function removeSilent(pathLike: string, options?: RmOptions): Promise>} + * @returns {Promise<[import("node:fs").Stats|undefined, Error|undefined]>} */ -export function getLinkStatus(path: PathLike): Promise<[Stats?, Error?]>; +declare function getLinkStatus(path: string | Buffer | URL): Promise<[node_fs.Stats | undefined, Error | undefined]>; /** * @name getStatus @@ -432,9 +394,9 @@ export function getLinkStatus(path: PathLike): Promise<[Stats?, Error?]>; * @since 0.0.11 * @async * @param {string|Buffer|URL} path - * @returns {Promise<[fs.Stats|undefined],[Error|{name: string, message: string, stack?: string}]>} + * @returns {Promise<[import("node:fs").Stats|undefined, Error|undefined]>} */ -export function getStatus(path: PathLike): Promise<[Stats?, Error?]>; +declare function getStatus(path: string | Buffer | URL): Promise<[node_fs.Stats | undefined, Error | undefined]>; /** * @name isDirExists @@ -444,7 +406,7 @@ export function getStatus(path: PathLike): Promise<[Stats?, Error?]>; * @param {string|Buffer|URL} path * @returns {Promise} */ -export function isDirExists(path: PathLike): Promise; +declare function isDirExists(path: string | Buffer | URL): Promise; /** * @name isFileExists @@ -454,7 +416,7 @@ export function isDirExists(path: PathLike): Promise; * @param {string|Buffer|URL} path * @returns {Promise} */ -export function isFileExists(path: PathLike): Promise; +declare function isFileExists(path: string | Buffer | URL): Promise; /** * @name isPathExists @@ -464,46 +426,47 @@ export function isFileExists(path: PathLike): Promise; * @param {string|Buffer|URL} path * @returns {Promise} */ -export function isPathExists(path: PathLike): Promise; - -//#endregion - -//#region write +declare function isPathExists(path: string | Buffer | URL): Promise; /** * @name writeFile * @description Asynchronously writes data to a file, replacing the file if it already exists. * @since 0.0.10 * @async - * @param {string|Buffer|URL|FileHandle} filePath + * @param {string|Buffer|URL} filePath * @param {string} data * @param {*|null|string=} options - * @returns {Promise} - */ -export function writeFile( - filePath: PathLike, - data: string, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, -): Promise; + * @returns {Promise} + * @example + * const controller = new AbortController(); + * const { signal } = controller; + * const data = new Uint8Array(Buffer.from('Hello Node.js')); + * (async () => { + * try { + * await writeFile('message.txt', data, { signal }); + * } catch (error) { + * // When a request is aborted - error is an AbortError + * } + * })(); + * // When the request should be aborted + * controller.abort(); + */ +declare function writeFile(filePath: string | Buffer | URL, data: any, options?: any | null | string): Promise; /** * @name writeFileTail * @description Asynchronously writes data to the end of a file. * @since 1.0.1 * @async - * @param {string|Buffer|URL|FileHandle} filePath + * @param {string|Buffer|URL} filePath * @param {string} data * @param {*|null|string=} options - * @returns {Promise} + * @returns {Promise} */ -export function writeFileTail( - filePath: PathLike, - data: string, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, -): Promise; +declare function writeFileTail(filePath: string | Buffer | URL, data: any, options?: any | null | string): Promise; /** - * @name writeJSON + * @name writeJson * @description Asynchronously writes data to a file, replacing the file if it already exists. * @since 0.1.25 * @async @@ -511,501 +474,461 @@ export function writeFileTail( * @param {*} data * @param {*|null|string=} options * @param {{sort: boolean, space: number|string}=} configuration - * @returns {Promise} - */ -export function writeJSON( - filePath: PathLike, - data: any, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, - configuration?: { sort?: boolean; space?: number | string }, -): Promise; - -//#endregion - -//#region default - -export class HileSystemLocal { - //#region create - - /** - * @name createDirectory - * @description Asynchronous create a directory. - * @since 0.0.10 - * @async - * @public - * @param {string|Buffer|URL} dirPath - * @param {number|string=} mode - * @param {boolean=} recursive - * @returns {Promise} - */ - public createDirectory(dirPath: PathLike, mode?: number | string, recursive?: boolean): Promise; - /** - * @name createFile - * @description Asynchronous create a file. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} pathLike - * @param {number|string=} mode - * @returns {Promise} - */ - public createFile(pathLike: PathLike, mode?: number | string): Promise; - - //#endregion - - //#region dir - - /** - * @name dirIsExecutable - * @description Directory can be executed by the calling process - * @since 0.0.5 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - public dirIsExecutable(pathToDir: PathLike): Promise; - /** - * @name dirIsReadable - * @description Directory is visible to the calling process - * @since 0.0.1 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - public dirIsReadable(pathToDir: PathLike): Promise; - /** - * @name dirIsVisible - * @description Directory is visible to the calling process - * @since 0.0.5 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - public dirIsVisible(pathToDir: PathLike): Promise; - /** - * @name dirIsWritable - * @description Directory can be written by the calling process - * @since 0.0.1 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - public dirIsWritable(pathToDir: PathLike): Promise; - - /** - * @name dirIsEmpty - * @description Check If a directory is empty - * @since 0.1.33 - * @async - * @public - * @param {string|Buffer|URL} pathToDir - * @param {boolean=} excludeSystemFiles - * @returns {Promise} - */ - public dirIsEmpty(pathToDir: PathLike, excludeSystemFiles: boolean): Promise; - - //#endregion - - //#region file - - /** - * @name fileIsExecutable - * @description File can be executed by the calling process - * @since 0.0.5 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public fileIsExecutable(pathToFile: PathLike): Promise; - /** - * @name fileIsReadable - * @description File is visible to the calling process - * @since 0.0.1 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public fileIsReadable(pathToFile: PathLike): Promise; - /** - * @name fileIsVisible - * @description File is visible to the calling process - * @since 0.0.5 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public fileIsVisible(pathToFile: PathLike): Promise; - /** - * @name fileIsWritable - * @description File can be written by the calling process - * @since 0.0.1 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public fileIsWritable(pathToFile: PathLike): Promise; - /** - * @name fileTruncate - * @description Truncate a file to a specified length - * @since 0.0.6 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @param {number=} length - * @returns {Promise} - */ - public fileTruncate(pathToFile: PathLike, length?: number): Promise; - - //#endregion - - //#region info - - /** - * @name hash - * @description Calculate hash. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @param {string} algorithm - * @returns {Promise} - * @throws {TypeError} If algorithm is not supported. - */ - public hash(pathToFile: PathLike, algorithm: string): Promise; - - /** - * @name hashCrc32 - * @description CRC32. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public hashCrc32(pathToFile: PathLike): Promise; - - /** - * @name hashMd5 - * @description MD5. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public hashMd5(pathToFile: PathLike): Promise; - - /** - * @name hashSha1 - * @description SHA-1. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public hashSha1(pathToFile: PathLike): Promise; - - /** - * @name hashSha256 - * @description SHA-256. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public hashSha256(pathToFile: PathLike): Promise; - - /** - * @name size - * @description File size in bytes. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @param {boolean=} [asString=false] - * @returns {Promise} - */ - public size(pathToFile: PathLike, asString?: boolean): Promise; - - //#endregion - - //#region list - - /** - * @name listContents - * @description Lists files and directories in path - * @since 0.1.32 - * @async - * @param {string|Buffer|URL} pathToDir - * @param {boolean} [ignoreJunk=true] - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ - public listContents(pathToDir: PathLike, ignoreJunk?: boolean): Promise; - - /** - * @name listDirectories - * @description Lists directories path - * @since 0.1.32 - * @async - * @public - * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ - public listDirectories(pathToDir: PathLike): Promise; - - /** - * @name listFiles - * @description Lists files path - * @since 0.1.32 - * @async - * @public - * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ - public listFiles(pathToDir: PathLike): Promise; - - //#endregion - - //#region move - - /** - * @name move - * @description Change the name or location of a file or directory. - * @since 0.1.29 - * @async - * @public - * @param {string} pathFrom - * @param {string} pathTo - * @returns {Promise} - */ - public move(pathFrom: PathLike, pathTo: PathLike): Promise; - - //#endregion - - //#region read - - /** - * @name readFileToString - * @description Asynchronously reads the entire contents of a file into string. - * @since 0.1.21 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ - public readFileToBase64(pathLike: string): Promise; - - /** - * @name readFileToBuffer - * @description Asynchronously reads the entire contents of a file into buffer. - * @since 0.1.19 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ - public readFileToBuffer(pathLike: string): Promise; - - /** - * @name readFileToString - * @description Asynchronously reads the entire contents of a file into string. - * @since 0.1.7 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ - public readFileToString(pathLike: string): Promise; - - //#endregion - - //#region remove - - /** - * @name remove - * @description Removes a file or directory. - * @since 0.1.1 - * @async - * @public - * @param {string} pathLike - * @returns {Promise} - */ - public remove(pathLike: string): Promise; - - //#endregion - - //#region path - - /** - * @name fileExtension - * @description Get file extension. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - public fileExtension(path: string): string; - - /** - * @name fileName - * @description Return the file name without extension. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - public fileName(path: string): string; - - /** - * @name fileNameExt - * @description Return the last portion of a path. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - public fileNameExt(path: string): string; - - /** - * @name filePath - * @description Return the directory name of a path. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - public filePath(path: string): string; - - /** - * @name pathFrom - * @description Join all arguments together and normalize the resulting path. - * @since 0.1.3 - * @public - * @param {string|Array.} paths - * @param {...string} morePaths - * @returns {string} - */ - public pathFrom(paths: string | string[], ...morePaths: string[]): string; - - //#endregion - - //#region status - /** - * @name getLinkStatus - * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to. - * @url http://man7.org/linux/man-pages/man2/lstat.2.html - * @since 1.1.0 - * @async - * @param {string|Buffer|URL} path - * @returns {Promise>} - */ - public getLinkStatus(path: PathLike): Promise<[Stats?, Error?]>; - /** - * @name getStatus - * @description Get file status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise<[fs.Stats|undefined],[Error|{name: string, message: string, stack?: string}]>} - */ - public getStatus(path: PathLike): Promise<[Stats?, Error?]>; - /** - * @name isDirExists - * @description Get directory status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise} - */ - public isDirExists(path: PathLike): Promise; - /** - * @name isFileExists - * @description Get file status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise} - */ - public isFileExists(path: PathLike): Promise; - /** - * @name isPathExists - * @description Get path status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise} - */ - public isPathExists(path: PathLike): Promise; - - //#endregion - - //#region write - - /** - * @name writeFile - * @description Asynchronously writes data to a file, replacing the file if it already exists. - * @since 0.0.10 - * @async - * @public - * @param {string|Buffer|URL|FileHandle} filePath - * @param {*=} data - * @param {*|null|string=} options - * @returns {Promise} - */ - public writeFile( - filePath: PathLike, - data: string, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, - ): Promise; - - /** - * @name writeFileTail - * @description Asynchronously writes data to the end of a file. - * @since 1.0.1 - * @async - * @public - * @param {string|Buffer|URL|FileHandle} filePath - * @param {*=} data - * @param {*|null|string=} options - * @returns {Promise} - */ - public writeFileTail( - filePath: PathLike, - data: string, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, - ): Promise; - - /** - * @name writeJSON - * @description Asynchronously writes data to a file, replacing the file if it already exists. - * @since 0.1.25 - * @async - * @public - * @param {string|Buffer|URL} filePath - * @param {*} data - * @param {*|null|string=} options - * @param {{sort: boolean, space: number|string}=} configuration - * @returns {Promise} - */ - public writeJSON( - filePath: PathLike, - data: any, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, - configuration?: { sort?: boolean; space?: number | string }, - ): Promise; - - //#endregion + * @returns {Promise} + */ +declare function writeJson(filePath: string | Buffer | URL, data: any, options: any, configuration: { + sort: boolean; + space: number | string; +} | undefined): Promise; + +declare class HileSystemLocal { + /** + * @name absolutePathFrom + * @description Join all arguments together and normalize the resulting path. + * Creates absolute path from right to left until an absolute path is constructed. + * @since 0.1.5 + * @public + * @param {string|string[]} paths + * @param {...string} morePaths + * @returns {string} + */ + absolutePathFrom: typeof absolutePathFrom; + /** + * @name createDirectory + * @description Asynchronous create a directory. + * @since 0.0.10 + * @async + * @public + * @param {string|Buffer|URL} dirPath + * @param {number|string=} mode + * @param {boolean=} recursive + * @returns {Promise} + */ + createDirectory: typeof createDirectory; + /** + * @name createFile + * @description Asynchronous create a file. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} pathLike + * @param {number|string=} mode + * @returns {Promise} + */ + createFile: typeof createFile; + /** + * @name dirIsExecutable + * @description Directory can be executed by the calling process + * @since 0.0.5 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsExecutable: typeof dirIsExecutable; + /** + * @name dirIsReadable + * @description Directory is visible to the calling process + * @since 0.0.1 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsReadable: typeof dirIsReadable; + /** + * @name dirIsVisible + * @description Directory is visible to the calling process + * @since 0.0.5 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsVisible: typeof dirIsVisible; + /** + * @name dirIsWritable + * @description Directory can be written by the calling process + * @since 0.0.1 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsWritable: typeof dirIsWritable; + /** + * @name dirIsEmpty + * @description Check if a directory is empty + * @since 0.1.33 + * @async + * @public + * @param {string|Buffer|URL} pathToDir + * @param {boolean=} excludeSystemFiles + * @returns {Promise} + * @throws {Error} If path is not a dir or is not readable. + */ + dirIsEmpty: typeof dirIsEmpty; + /** + * @name getLinkStatus + * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to. + * @url http://man7.org/linux/man-pages/man2/lstat.2.html + * @since 1.1.0 + * @async + * @param {string|Buffer|URL} path + * @returns {Promise>} + */ + getLinkStatus: typeof getLinkStatus; + /** + * @name getStatus + * @description Get file status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise>} + */ + getStatus: typeof getStatus; + /** + * @name isDirExists + * @description Get directory status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise} + */ + isDirExists: typeof isDirExists; + /** + * @name isFileExists + * @description Get file status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise} + */ + isFileExists: typeof isFileExists; + /** + * @name isPathExists + * @description Get path status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise} + */ + isPathExists: typeof isPathExists; + /** + * @name fileExtension + * @description Get file extension. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + fileExtension: typeof fileExtension; + /** + * @name fileName + * @description Return the file name without extension. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + fileName: typeof fileName; + /** + * @name fileNameExt + * @description Return the last portion of a path. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + fileNameExt: typeof fileNameExt; + /** + * @name filePath + * @description Return the directory name of a path. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + filePath: typeof filePath; + /** + * @name fileIsExecutable + * @description File can be executed by the calling process + * @since 0.0.5 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsExecutable: typeof fileIsExecutable; + /** + * @name fileIsReadable + * @description File is visible to the calling process + * @since 0.0.1 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsReadable: typeof fileIsReadable; + /** + * @name fileIsVisible + * @description File is visible to the calling process + * @since 0.0.5 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsVisible: typeof fileIsVisible; + /** + * @name fileIsWritable + * @description File can be written by the calling process + * @since 0.0.1 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsWritable: typeof fileIsWritable; + /** + * @name fileTruncate + * @description Truncate a file to a specified length + * @since 0.0.6 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @param {number=} length + * @returns {Promise} + */ + fileTruncate: typeof fileTruncate; + /** + * @name hash + * @description Calculate hash. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @param {string} algorithm + * @returns {Promise} + * @throws {TypeError} If algorithm is not supported. + */ + hash: typeof hash; + /** + * @name hashCrc32 + * @description CRC32. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashCrc32: typeof hashCrc32; + /** + * @name hashMd5 + * @description MD5. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashMd5: typeof hashMd5; + /** + * @name hashMulti + * @description Calculates multiple hashes. + * @since 1.1.1 + * @async + * @public + * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed. + * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>} + * @throws {Error|TypeError} + */ + hashMulti: typeof hashMulti; + /** + * @name hashSha1 + * @description SHA-1. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashSha1: typeof hashSha1; + /** + * @name hashSha256 + * @description SHA-256. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashSha256: typeof hashSha256; + /** + * @name hashSha512 + * @description SHA-512. + * @since 0.2.6 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashSha512: typeof hashSha512; + /** + * @name listContents + * @description Lists files and directories in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ + listContents: typeof listContents; + /** + * @name listDirectories + * @description Lists directories in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ + listDirectories: typeof listDirectories; + /** + * @name listFiles + * @description Lists files in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ + listFiles: typeof listFiles; + /** + * @name move + * @description Change the name or location of a file or directory. + * @since 0.1.29 + * @public + * @param {string} pathFrom + * @param {string} pathTo + * @returns {Promise} + */ + move: typeof move; + /** + * @name pathFrom + * @description Join all arguments together and normalize the resulting path. + * @since 0.1.3 + * @public + * @param {string|string[]} paths + * @param {...string} morePaths + * @returns {string} + */ + pathFrom: typeof pathFrom; + /** + * @name readFileToBase64 + * @description Asynchronously reads the entire contents of a file into string. + * @since 0.1.21 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ + readFileToBase64: typeof readFileToBase64; + /** + * @name readFileToBuffer + * @description Asynchronously reads the entire contents of a file into buffer. + * @since 0.1.19 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ + readFileToBuffer: typeof readFileToBuffer; + /** + * @name readFileToString + * @description Asynchronously reads the entire contents of a file into string. + * @since 0.1.7 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ + readFileToString: typeof readFileToString; + /** + * @name remove + * @description Removes a file or directory. + * @since 0.1.1 + * @async + * @public + * @param {string} pathLike + * @returns {Promise} + */ + remove: typeof remove; + /** + * @name removeNonBlocking + * @description Non-blocking remove of a file or directory. + * @since 0.1.18 + * @public + * @param {string} pathLike + * @returns {void} + */ + removeNonBlocking: typeof removeNonBlocking; + /** + * @name removeSilent + * @description Removes files and directories (modeled on the standard POSIX rm utility). + * @summary Minimum Node version 14.14.0 + * @since 0.1.36 + * @async + * @param {string|Buffer|URL} pathLike + * @param {object=} options + * @returns {Promise} + */ + removeSilent: typeof removeSilent; + /** + * @name size + * @description File size in bytes. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @param {boolean=} [asString=false] + * @returns {Promise} + */ + size: typeof size; + /** + * @name writeFile + * @description Asynchronously writes data to a file, replacing the file if it already exists. + * @since 0.0.10 + * @async + * @public + * @param {string|Buffer|URL} filePath + * @param {string} data + * @param {*|null|string=} options + * @returns {Promise} + */ + writeFile: typeof writeFile; + /** + * @name writeFileTail + * @description Asynchronously writes data to the end of a file. + * @since 1.0.1 + * @async + * @public + * @param {string|Buffer|URL} filePath + * @param {string} data + * @param {*|null|string=} options + * @returns {Promise} + */ + writeFileTail: typeof writeFileTail; + /** + * @name writeJson + * @description Asynchronously writes data to a file, replacing the file if it already exists. + * @since 0.1.25 + * @async + * @public + * @param {string|Buffer|URL} filePath + * @param {*} data + * @param {*|null|string=} options + * @returns {Promise} + */ + writeJson: typeof writeJson; } -//#endregion +export { HileSystemLocal, absolutePathFrom, createDirectory, createFile, dirIsEmpty, dirIsExecutable, dirIsReadable, dirIsVisible, dirIsWritable, fileExtension, fileIsExecutable, fileIsReadable, fileIsVisible, fileIsWritable, fileName, fileNameExt, filePath, fileTruncate, getLinkStatus, getStatus, hash, hashCrc32, hashMd5, hashMulti, hashSha1, hashSha256, hashSha512, isDirExists, isFileExists, isPathExists, listContents, listDirectories, listFiles, move, pathFrom, readFileToBase64, readFileToBuffer, readFileToString, remove, removeNonBlocking, removeSilent, size, writeFile, writeFileTail, writeJson }; diff --git a/dist/index.d.mts b/dist/index.d.mts index 59c0b3c..29ce49b 100644 --- a/dist/index.d.mts +++ b/dist/index.d.mts @@ -1,35 +1,5 @@ -import type { PathLike, Stats } from "fs"; - -export interface RmOptions { - /** - * When `true`, exceptions will be ignored if `path` does not exist. - * @default false - */ - force?: boolean | undefined; - /** - * If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or - * `EPERM` error is encountered, Node.js will retry the operation with a linear - * backoff wait of `retryDelay` ms longer on each try. This option represents the - * number of retries. This option is ignored if the `recursive` option is not - * `true`. - * @default 0 - */ - maxRetries?: number | undefined; - /** - * If `true`, perform a recursive directory removal. In - * recursive mode, operations are retried on failure. - * @default false - */ - recursive?: boolean | undefined; - /** - * The amount of time in milliseconds to wait between retries. - * This option is ignored if the `recursive` option is not `true`. - * @default 100 - */ - retryDelay?: number | undefined; -} - -//#region create +import * as node_fs from 'node:fs'; +import { RmOptions } from 'node:fs'; /** * @name createDirectory @@ -39,9 +9,9 @@ export interface RmOptions { * @param {string|Buffer|URL} dirPath * @param {number|string=} mode * @param {boolean=} recursive - * @returns {Promise} + * @returns {Promise} */ -export function createDirectory(dirPath: PathLike, mode?: number | string, recursive?: boolean): Promise; +declare function createDirectory(dirPath: string | Buffer | URL, mode?: (number | string) | undefined, recursive?: boolean | undefined): Promise; /** * @name createFile @@ -50,13 +20,21 @@ export function createDirectory(dirPath: PathLike, mode?: number | string, recur * @async * @param {string|Buffer|URL} pathLike * @param {number|string=} mode - * @returns {Promise} + * @returns {Promise} */ -export function createFile(pathLike: PathLike, mode?: number | string): Promise; +declare function createFile(pathLike: string | Buffer | URL, mode?: string): Promise; -//#endregion - -//#region dir +/** + * @name dirIsEmpty + * @description Check if a directory is empty + * @since 0.1.33 + * @async + * @param {string|Buffer|URL} pathToDir + * @param {boolean=} excludeSystemFiles + * @returns {Promise} + * @throws {Error} If path is not a dir or is not readable. + */ +declare function dirIsEmpty(pathToDir: string | Buffer | URL, excludeSystemFiles?: boolean): Promise; /** * @name dirIsExecutable @@ -64,9 +42,9 @@ export function createFile(pathLike: PathLike, mode?: number | string): Promise< * @since 0.0.5 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise} + * @returns {Promise} */ -export function dirIsExecutable(pathToDir: PathLike): Promise; +declare function dirIsExecutable(pathToDir: string | Buffer | URL): Promise; /** * @name dirIsReadable @@ -74,9 +52,9 @@ export function dirIsExecutable(pathToDir: PathLike): Promise; * @since 0.0.1 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise} + * @returns {Promise} */ -export function dirIsReadable(pathToDir: PathLike): Promise; +declare function dirIsReadable(pathToDir: string | Buffer | URL): Promise; /** * @name dirIsVisible @@ -84,9 +62,9 @@ export function dirIsReadable(pathToDir: PathLike): Promise; * @since 0.0.5 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise} + * @returns {Promise} */ -export function dirIsVisible(pathToDir: PathLike): Promise; +declare function dirIsVisible(pathToDir: string | Buffer | URL): Promise; /** * @name dirIsWritable @@ -94,146 +72,151 @@ export function dirIsVisible(pathToDir: PathLike): Promise; * @since 0.0.1 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise} + * @returns {Promise} */ -export function dirIsWritable(pathToDir: PathLike): Promise; +declare function dirIsWritable(pathToDir: string | Buffer | URL): Promise; /** - * @name dirIsEmpty - * @description Check If a directory is empty - * @since 0.1.33 + * @name hash + * @description Calculate hash. + * @since 0.2.3 * @async - * @param {string|Buffer|URL} pathToDir - * @param {boolean=} excludeSystemFiles - * @returns {Promise} + * @param {string|Buffer|URL} pathToFile + * @param {string} algorithm + * @returns {Promise} + * @throws {TypeError} If algorithm is not supported. */ -export function dirIsEmpty(pathToDir: PathLike, excludeSystemFiles: boolean): Promise; - -//#endregion - -//#region file +declare function hash(pathToFile: string | Buffer | URL, algorithm: string): Promise; /** - * @name fileIsExecutable - * @description File can be executed by the calling process - * @since 0.0.5 + * @name hashCrc32 + * @description CRC32. + * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function fileIsExecutable(pathToFile: PathLike): Promise; +declare function hashCrc32(pathToFile: string | Buffer | URL): Promise; /** - * @name fileIsReadable - * @description File is visible to the calling process - * @since 0.0.1 + * @name hashMd5 + * @description MD5. + * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function fileIsReadable(pathToFile: PathLike): Promise; +declare function hashMd5(pathToFile: string | Buffer | URL): Promise; /** - * @name fileIsVisible - * @description File is visible to the calling process - * @since 0.0.5 + * @name hashMulti + * @description Calculates multiple hashes. + * @summary The objective of the "hashMulti" function is to calculate multiple hashes (CRC32, MD5, SHA-1, SHA-256, and SHA-512) for a given file path and return them as an object. + * @since 1.1.1 * @async - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed. + * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>} + * @throws {Error|TypeError} */ -export function fileIsVisible(pathToFile: PathLike): Promise; +declare function hashMulti(pathToFile: string | Buffer | URL): Promise<{ + crc32: string; + md5: string; + sha1: string; + sha256: string; + sha512: string; +}>; /** - * @name fileIsWritable - * @description File can be written by the calling process - * @since 0.0.1 + * @name hashSha1 + * @description SHA-1. + * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function fileIsWritable(pathToFile: PathLike): Promise; +declare function hashSha1(pathToFile: string | Buffer | URL): Promise; /** - * @name fileTruncate - * @description Truncate a file to a specified length - * @since 0.0.6 + * @name hashSha256 + * @description SHA-256. + * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @param {number=} length - * @returns {Promise} + * @returns {Promise} */ -export function fileTruncate(pathToFile: PathLike, length?: number): Promise; - -//#endregion - -//#region info +declare function hashSha256(pathToFile: string | Buffer | URL): Promise; /** - * @name hash - * @description Calculate hash. - * @since 0.2.3 + * @name hashSha512 + * @description SHA-512. + * @since 0.2.6 * @async * @param {string|Buffer|URL} pathToFile - * @param {string} algorithm - * @returns {Promise} - * @throws {TypeError} If algorithm is not supported. + * @returns {Promise} */ -export function hash(pathToFile: PathLike, algorithm: string): Promise; +declare function hashSha512(pathToFile: string | Buffer | URL): Promise; /** - * @name hashCrc32 - * @description CRC32. + * @name size + * @description File size in bytes. * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @param {boolean=} [asString=false] + * @returns {Promise} */ -export function hashCrc32(pathToFile: PathLike): Promise; +declare function size(pathToFile: string | Buffer | URL, asString?: boolean): Promise; /** - * @name hashMd5 - * @description MD5. - * @since 0.2.3 + * @name fileIsExecutable + * @description File can be executed by the calling process + * @since 0.0.5 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function hashMd5(pathToFile: PathLike): Promise; +declare function fileIsExecutable(pathToFile: string | Buffer | URL): Promise; /** - * @name hashSha1 - * @description SHA-1. - * @since 0.2.3 + * @name fileIsReadable + * @description File is visible to the calling process + * @since 0.0.1 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function hashSha1(pathToFile: PathLike): Promise; +declare function fileIsReadable(pathToFile: string | Buffer | URL): Promise; /** - * @name hashSha256 - * @description SHA-256. - * @since 0.2.3 + * @name fileIsVisible + * @description File is visible to the calling process + * @since 0.0.5 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function hashSha256(pathToFile: PathLike): Promise; +declare function fileIsVisible(pathToFile: string | Buffer | URL): Promise; /** - * @name size - * @description File size in bytes. - * @since 0.2.3 + * @name fileIsWritable + * @description File can be written by the calling process + * @since 0.0.1 * @async * @param {string|Buffer|URL} pathToFile - * @param {boolean=} [asString=false] - * @returns {Promise} + * @returns {Promise} */ -export function size(pathToFile: PathLike, asString?: boolean): Promise; - -//#endregion +declare function fileIsWritable(pathToFile: string | Buffer | URL): Promise; -//#region list +/** + * @name fileTruncate + * @description Truncate a file to a specified length + * @since 0.0.6 + * @async + * @param {string|Buffer|URL} pathToFile + * @param {number=} length + * @returns {Promise} + */ +declare function fileTruncate(pathToFile: string | Buffer | URL, length?: number): Promise; /** * @name listContents @@ -242,9 +225,9 @@ export function size(pathToFile: PathLike, asString?: boolean): Promise|Error|{name: string, message: string, stack?: string}>} + * @returns {Promise} */ -export function listContents(pathToDir: PathLike, ignoreJunk?: boolean): Promise; +declare function listContents(pathToDir: string | Buffer | URL, ignoreJunk?: boolean): Promise; /** * @name listDirectories @@ -252,9 +235,9 @@ export function listContents(pathToDir: PathLike, ignoreJunk?: boolean): Promise * @since 0.1.32 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} + * @returns {Promise} */ -export function listDirectories(pathToDir: PathLike): Promise; +declare function listDirectories(pathToDir: string | Buffer | URL): Promise; /** * @name listFiles @@ -262,13 +245,9 @@ export function listDirectories(pathToDir: PathLike): Promise; * @since 0.1.32 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} + * @returns {Promise} */ -export function listFiles(pathToDir: PathLike): Promise; - -//#endregion - -//#region move +declare function listFiles(pathToDir: string | Buffer | URL): Promise; /** * @name move @@ -276,24 +255,20 @@ export function listFiles(pathToDir: PathLike): Promise; * @since 0.1.29 * @param {string} pathFrom * @param {string} pathTo - * @returns {Promise} + * @returns {Promise} */ -export function move(pathFrom: PathLike, pathTo: PathLike): Promise; - -//#endregion - -//#region path +declare function move(pathFrom: string, pathTo: string): Promise; /** * @name absolutePathFrom * @description Join all arguments together and normalize the resulting path. * Creates absolute path from right to left until an absolute path is constructed. * @since 0.1.5 - * @param {string|Array.} paths + * @param {string|string[]} paths * @param {...string} morePaths * @returns {string} */ -export function absolutePathFrom(paths: string | string[], ...morePaths: string[]): string; +declare function absolutePathFrom(paths: string | string[], ...morePaths: string[]): string; /** * @name fileExtension @@ -302,7 +277,7 @@ export function absolutePathFrom(paths: string | string[], ...morePaths: string[ * @param {string} path * @returns {string} */ -export function fileExtension(path: string): string; +declare function fileExtension(path: string): string; /** * @name fileName @@ -311,7 +286,7 @@ export function fileExtension(path: string): string; * @param {string} path * @returns {string} */ -export function fileName(path: string): string; +declare function fileName(path: string): string; /** * @name fileNameExt @@ -320,7 +295,7 @@ export function fileName(path: string): string; * @param {string} path * @returns {string} */ -export function fileNameExt(path: string): string; +declare function fileNameExt(path: string): string; /** * @name filePath @@ -329,21 +304,17 @@ export function fileNameExt(path: string): string; * @param {string} path * @returns {string} */ -export function filePath(path: string): string; +declare function filePath(path: string): string; /** * @name pathFrom * @description Join all arguments together and normalize the resulting path. * @since 0.1.3 - * @param {string|Array.} paths + * @param {string|Buffer|URL|string[]|Buffer[]|URL[]} paths * @param {...string} morePaths * @returns {string} */ -export function pathFrom(paths: string | string[], ...morePaths: string[]): string; - -//#endregion - -//#region read +declare function pathFrom(paths: string | Buffer | URL | string[] | Buffer[] | URL[], ...morePaths: string[]): string; /** * @name readFileToBase64 @@ -351,9 +322,9 @@ export function pathFrom(paths: string | string[], ...morePaths: string[]): stri * @since 0.1.21 * @async * @param {string|Buffer|URL} pathLike - * @returns {Promise} + * @returns {Promise} */ -export function readFileToBase64(pathLike: string): Promise; +declare function readFileToBase64(pathLike: string | Buffer | URL): Promise; /** * @name readFileToBuffer @@ -361,9 +332,9 @@ export function readFileToBase64(pathLike: string): Promise; * @since 0.1.19 * @async * @param {string|Buffer|URL} pathLike - * @returns {Promise} + * @returns {Promise} */ -export function readFileToBuffer(pathLike: string): Promise; +declare function readFileToBuffer(pathLike: string | Buffer | URL): Promise; /** * @name readFileToString @@ -371,33 +342,28 @@ export function readFileToBuffer(pathLike: string): Promise; * @since 0.1.7 * @async * @param {string|Buffer|URL} pathLike - * @returns {Promise} + * @returns {Promise} */ -export function readFileToString(pathLike: string): Promise; - -//#endregion - -//#region remove +declare function readFileToString(pathLike: string | Buffer | URL): Promise; /** * @name remove * @description Removes a file or directory. * @since 0.1.1 * @async - * @param {string} pathLike - * @returns {Promise} + * @param {string | Buffer | URL} pathLike + * @returns {Promise} */ -export function remove(pathLike: string): Promise; +declare function remove(pathLike: string | Buffer | URL): Promise; /** * @name removeNonBlocking * @description Non-blocking remove of a file or directory. * @since 0.1.18 - * @sync - * @param {string} pathLike + * @param {string|Buffer|URL} pathLike * @returns {void} */ -export function removeNonBlocking(pathLike: string): void; +declare function removeNonBlocking(pathLike: string | Buffer | URL): void; /** * @name removeSilent @@ -406,14 +372,10 @@ export function removeNonBlocking(pathLike: string): void; * @since 0.1.36 * @async * @param {string|Buffer|URL} pathLike - * @param {object=} options + * @param {RmOptions=} options * @returns {Promise} */ -export function removeSilent(pathLike: string, options?: RmOptions): Promise; - -//#endregion - -//#region status +declare function removeSilent(pathLike: string | Buffer | URL, options: RmOptions): Promise; /** * @name getLinkStatus @@ -422,9 +384,9 @@ export function removeSilent(pathLike: string, options?: RmOptions): Promise>} + * @returns {Promise<[import("node:fs").Stats|undefined, Error|undefined]>} */ -export function getLinkStatus(path: PathLike): Promise<[Stats?, Error?]>; +declare function getLinkStatus(path: string | Buffer | URL): Promise<[node_fs.Stats | undefined, Error | undefined]>; /** * @name getStatus @@ -432,9 +394,9 @@ export function getLinkStatus(path: PathLike): Promise<[Stats?, Error?]>; * @since 0.0.11 * @async * @param {string|Buffer|URL} path - * @returns {Promise<[fs.Stats|undefined],[Error|{name: string, message: string, stack?: string}]>} + * @returns {Promise<[import("node:fs").Stats|undefined, Error|undefined]>} */ -export function getStatus(path: PathLike): Promise<[Stats?, Error?]>; +declare function getStatus(path: string | Buffer | URL): Promise<[node_fs.Stats | undefined, Error | undefined]>; /** * @name isDirExists @@ -444,7 +406,7 @@ export function getStatus(path: PathLike): Promise<[Stats?, Error?]>; * @param {string|Buffer|URL} path * @returns {Promise} */ -export function isDirExists(path: PathLike): Promise; +declare function isDirExists(path: string | Buffer | URL): Promise; /** * @name isFileExists @@ -454,7 +416,7 @@ export function isDirExists(path: PathLike): Promise; * @param {string|Buffer|URL} path * @returns {Promise} */ -export function isFileExists(path: PathLike): Promise; +declare function isFileExists(path: string | Buffer | URL): Promise; /** * @name isPathExists @@ -464,46 +426,47 @@ export function isFileExists(path: PathLike): Promise; * @param {string|Buffer|URL} path * @returns {Promise} */ -export function isPathExists(path: PathLike): Promise; - -//#endregion - -//#region write +declare function isPathExists(path: string | Buffer | URL): Promise; /** * @name writeFile * @description Asynchronously writes data to a file, replacing the file if it already exists. * @since 0.0.10 * @async - * @param {string|Buffer|URL|FileHandle} filePath + * @param {string|Buffer|URL} filePath * @param {string} data * @param {*|null|string=} options - * @returns {Promise} - */ -export function writeFile( - filePath: PathLike, - data: string, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, -): Promise; + * @returns {Promise} + * @example + * const controller = new AbortController(); + * const { signal } = controller; + * const data = new Uint8Array(Buffer.from('Hello Node.js')); + * (async () => { + * try { + * await writeFile('message.txt', data, { signal }); + * } catch (error) { + * // When a request is aborted - error is an AbortError + * } + * })(); + * // When the request should be aborted + * controller.abort(); + */ +declare function writeFile(filePath: string | Buffer | URL, data: any, options?: any | null | string): Promise; /** * @name writeFileTail * @description Asynchronously writes data to the end of a file. * @since 1.0.1 * @async - * @param {string|Buffer|URL|FileHandle} filePath + * @param {string|Buffer|URL} filePath * @param {string} data * @param {*|null|string=} options - * @returns {Promise} + * @returns {Promise} */ -export function writeFileTail( - filePath: PathLike, - data: string, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, -): Promise; +declare function writeFileTail(filePath: string | Buffer | URL, data: any, options?: any | null | string): Promise; /** - * @name writeJSON + * @name writeJson * @description Asynchronously writes data to a file, replacing the file if it already exists. * @since 0.1.25 * @async @@ -511,501 +474,461 @@ export function writeFileTail( * @param {*} data * @param {*|null|string=} options * @param {{sort: boolean, space: number|string}=} configuration - * @returns {Promise} - */ -export function writeJSON( - filePath: PathLike, - data: any, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, - configuration?: { sort?: boolean; space?: number | string }, -): Promise; - -//#endregion - -//#region default - -export class HileSystemLocal { - //#region create - - /** - * @name createDirectory - * @description Asynchronous create a directory. - * @since 0.0.10 - * @async - * @public - * @param {string|Buffer|URL} dirPath - * @param {number|string=} mode - * @param {boolean=} recursive - * @returns {Promise} - */ - public createDirectory(dirPath: PathLike, mode?: number | string, recursive?: boolean): Promise; - /** - * @name createFile - * @description Asynchronous create a file. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} pathLike - * @param {number|string=} mode - * @returns {Promise} - */ - public createFile(pathLike: PathLike, mode?: number | string): Promise; - - //#endregion - - //#region dir - - /** - * @name dirIsExecutable - * @description Directory can be executed by the calling process - * @since 0.0.5 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - public dirIsExecutable(pathToDir: PathLike): Promise; - /** - * @name dirIsReadable - * @description Directory is visible to the calling process - * @since 0.0.1 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - public dirIsReadable(pathToDir: PathLike): Promise; - /** - * @name dirIsVisible - * @description Directory is visible to the calling process - * @since 0.0.5 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - public dirIsVisible(pathToDir: PathLike): Promise; - /** - * @name dirIsWritable - * @description Directory can be written by the calling process - * @since 0.0.1 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - public dirIsWritable(pathToDir: PathLike): Promise; - - /** - * @name dirIsEmpty - * @description Check If a directory is empty - * @since 0.1.33 - * @async - * @public - * @param {string|Buffer|URL} pathToDir - * @param {boolean=} excludeSystemFiles - * @returns {Promise} - */ - public dirIsEmpty(pathToDir: PathLike, excludeSystemFiles: boolean): Promise; - - //#endregion - - //#region file - - /** - * @name fileIsExecutable - * @description File can be executed by the calling process - * @since 0.0.5 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public fileIsExecutable(pathToFile: PathLike): Promise; - /** - * @name fileIsReadable - * @description File is visible to the calling process - * @since 0.0.1 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public fileIsReadable(pathToFile: PathLike): Promise; - /** - * @name fileIsVisible - * @description File is visible to the calling process - * @since 0.0.5 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public fileIsVisible(pathToFile: PathLike): Promise; - /** - * @name fileIsWritable - * @description File can be written by the calling process - * @since 0.0.1 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public fileIsWritable(pathToFile: PathLike): Promise; - /** - * @name fileTruncate - * @description Truncate a file to a specified length - * @since 0.0.6 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @param {number=} length - * @returns {Promise} - */ - public fileTruncate(pathToFile: PathLike, length?: number): Promise; - - //#endregion - - //#region info - - /** - * @name hash - * @description Calculate hash. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @param {string} algorithm - * @returns {Promise} - * @throws {TypeError} If algorithm is not supported. - */ - public hash(pathToFile: PathLike, algorithm: string): Promise; - - /** - * @name hashCrc32 - * @description CRC32. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public hashCrc32(pathToFile: PathLike): Promise; - - /** - * @name hashMd5 - * @description MD5. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public hashMd5(pathToFile: PathLike): Promise; - - /** - * @name hashSha1 - * @description SHA-1. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public hashSha1(pathToFile: PathLike): Promise; - - /** - * @name hashSha256 - * @description SHA-256. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public hashSha256(pathToFile: PathLike): Promise; - - /** - * @name size - * @description File size in bytes. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @param {boolean=} [asString=false] - * @returns {Promise} - */ - public size(pathToFile: PathLike, asString?: boolean): Promise; - - //#endregion - - //#region list - - /** - * @name listContents - * @description Lists files and directories in path - * @since 0.1.32 - * @async - * @param {string|Buffer|URL} pathToDir - * @param {boolean} [ignoreJunk=true] - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ - public listContents(pathToDir: PathLike, ignoreJunk?: boolean): Promise; - - /** - * @name listDirectories - * @description Lists directories path - * @since 0.1.32 - * @async - * @public - * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ - public listDirectories(pathToDir: PathLike): Promise; - - /** - * @name listFiles - * @description Lists files path - * @since 0.1.32 - * @async - * @public - * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ - public listFiles(pathToDir: PathLike): Promise; - - //#endregion - - //#region move - - /** - * @name move - * @description Change the name or location of a file or directory. - * @since 0.1.29 - * @async - * @public - * @param {string} pathFrom - * @param {string} pathTo - * @returns {Promise} - */ - public move(pathFrom: PathLike, pathTo: PathLike): Promise; - - //#endregion - - //#region read - - /** - * @name readFileToString - * @description Asynchronously reads the entire contents of a file into string. - * @since 0.1.21 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ - public readFileToBase64(pathLike: string): Promise; - - /** - * @name readFileToBuffer - * @description Asynchronously reads the entire contents of a file into buffer. - * @since 0.1.19 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ - public readFileToBuffer(pathLike: string): Promise; - - /** - * @name readFileToString - * @description Asynchronously reads the entire contents of a file into string. - * @since 0.1.7 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ - public readFileToString(pathLike: string): Promise; - - //#endregion - - //#region remove - - /** - * @name remove - * @description Removes a file or directory. - * @since 0.1.1 - * @async - * @public - * @param {string} pathLike - * @returns {Promise} - */ - public remove(pathLike: string): Promise; - - //#endregion - - //#region path - - /** - * @name fileExtension - * @description Get file extension. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - public fileExtension(path: string): string; - - /** - * @name fileName - * @description Return the file name without extension. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - public fileName(path: string): string; - - /** - * @name fileNameExt - * @description Return the last portion of a path. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - public fileNameExt(path: string): string; - - /** - * @name filePath - * @description Return the directory name of a path. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - public filePath(path: string): string; - - /** - * @name pathFrom - * @description Join all arguments together and normalize the resulting path. - * @since 0.1.3 - * @public - * @param {string|Array.} paths - * @param {...string} morePaths - * @returns {string} - */ - public pathFrom(paths: string | string[], ...morePaths: string[]): string; - - //#endregion - - //#region status - /** - * @name getLinkStatus - * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to. - * @url http://man7.org/linux/man-pages/man2/lstat.2.html - * @since 1.1.0 - * @async - * @param {string|Buffer|URL} path - * @returns {Promise>} - */ - public getLinkStatus(path: PathLike): Promise<[Stats?, Error?]>; - /** - * @name getStatus - * @description Get file status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise<[fs.Stats|undefined],[Error|{name: string, message: string, stack?: string}]>} - */ - public getStatus(path: PathLike): Promise<[Stats?, Error?]>; - /** - * @name isDirExists - * @description Get directory status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise} - */ - public isDirExists(path: PathLike): Promise; - /** - * @name isFileExists - * @description Get file status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise} - */ - public isFileExists(path: PathLike): Promise; - /** - * @name isPathExists - * @description Get path status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise} - */ - public isPathExists(path: PathLike): Promise; - - //#endregion - - //#region write - - /** - * @name writeFile - * @description Asynchronously writes data to a file, replacing the file if it already exists. - * @since 0.0.10 - * @async - * @public - * @param {string|Buffer|URL|FileHandle} filePath - * @param {*=} data - * @param {*|null|string=} options - * @returns {Promise} - */ - public writeFile( - filePath: PathLike, - data: string, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, - ): Promise; - - /** - * @name writeFileTail - * @description Asynchronously writes data to the end of a file. - * @since 1.0.1 - * @async - * @public - * @param {string|Buffer|URL|FileHandle} filePath - * @param {*=} data - * @param {*|null|string=} options - * @returns {Promise} - */ - public writeFileTail( - filePath: PathLike, - data: string, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, - ): Promise; - - /** - * @name writeJSON - * @description Asynchronously writes data to a file, replacing the file if it already exists. - * @since 0.1.25 - * @async - * @public - * @param {string|Buffer|URL} filePath - * @param {*} data - * @param {*|null|string=} options - * @param {{sort: boolean, space: number|string}=} configuration - * @returns {Promise} - */ - public writeJSON( - filePath: PathLike, - data: any, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, - configuration?: { sort?: boolean; space?: number | string }, - ): Promise; - - //#endregion + * @returns {Promise} + */ +declare function writeJson(filePath: string | Buffer | URL, data: any, options: any, configuration: { + sort: boolean; + space: number | string; +} | undefined): Promise; + +declare class HileSystemLocal { + /** + * @name absolutePathFrom + * @description Join all arguments together and normalize the resulting path. + * Creates absolute path from right to left until an absolute path is constructed. + * @since 0.1.5 + * @public + * @param {string|string[]} paths + * @param {...string} morePaths + * @returns {string} + */ + absolutePathFrom: typeof absolutePathFrom; + /** + * @name createDirectory + * @description Asynchronous create a directory. + * @since 0.0.10 + * @async + * @public + * @param {string|Buffer|URL} dirPath + * @param {number|string=} mode + * @param {boolean=} recursive + * @returns {Promise} + */ + createDirectory: typeof createDirectory; + /** + * @name createFile + * @description Asynchronous create a file. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} pathLike + * @param {number|string=} mode + * @returns {Promise} + */ + createFile: typeof createFile; + /** + * @name dirIsExecutable + * @description Directory can be executed by the calling process + * @since 0.0.5 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsExecutable: typeof dirIsExecutable; + /** + * @name dirIsReadable + * @description Directory is visible to the calling process + * @since 0.0.1 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsReadable: typeof dirIsReadable; + /** + * @name dirIsVisible + * @description Directory is visible to the calling process + * @since 0.0.5 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsVisible: typeof dirIsVisible; + /** + * @name dirIsWritable + * @description Directory can be written by the calling process + * @since 0.0.1 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsWritable: typeof dirIsWritable; + /** + * @name dirIsEmpty + * @description Check if a directory is empty + * @since 0.1.33 + * @async + * @public + * @param {string|Buffer|URL} pathToDir + * @param {boolean=} excludeSystemFiles + * @returns {Promise} + * @throws {Error} If path is not a dir or is not readable. + */ + dirIsEmpty: typeof dirIsEmpty; + /** + * @name getLinkStatus + * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to. + * @url http://man7.org/linux/man-pages/man2/lstat.2.html + * @since 1.1.0 + * @async + * @param {string|Buffer|URL} path + * @returns {Promise>} + */ + getLinkStatus: typeof getLinkStatus; + /** + * @name getStatus + * @description Get file status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise>} + */ + getStatus: typeof getStatus; + /** + * @name isDirExists + * @description Get directory status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise} + */ + isDirExists: typeof isDirExists; + /** + * @name isFileExists + * @description Get file status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise} + */ + isFileExists: typeof isFileExists; + /** + * @name isPathExists + * @description Get path status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise} + */ + isPathExists: typeof isPathExists; + /** + * @name fileExtension + * @description Get file extension. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + fileExtension: typeof fileExtension; + /** + * @name fileName + * @description Return the file name without extension. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + fileName: typeof fileName; + /** + * @name fileNameExt + * @description Return the last portion of a path. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + fileNameExt: typeof fileNameExt; + /** + * @name filePath + * @description Return the directory name of a path. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + filePath: typeof filePath; + /** + * @name fileIsExecutable + * @description File can be executed by the calling process + * @since 0.0.5 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsExecutable: typeof fileIsExecutable; + /** + * @name fileIsReadable + * @description File is visible to the calling process + * @since 0.0.1 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsReadable: typeof fileIsReadable; + /** + * @name fileIsVisible + * @description File is visible to the calling process + * @since 0.0.5 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsVisible: typeof fileIsVisible; + /** + * @name fileIsWritable + * @description File can be written by the calling process + * @since 0.0.1 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsWritable: typeof fileIsWritable; + /** + * @name fileTruncate + * @description Truncate a file to a specified length + * @since 0.0.6 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @param {number=} length + * @returns {Promise} + */ + fileTruncate: typeof fileTruncate; + /** + * @name hash + * @description Calculate hash. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @param {string} algorithm + * @returns {Promise} + * @throws {TypeError} If algorithm is not supported. + */ + hash: typeof hash; + /** + * @name hashCrc32 + * @description CRC32. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashCrc32: typeof hashCrc32; + /** + * @name hashMd5 + * @description MD5. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashMd5: typeof hashMd5; + /** + * @name hashMulti + * @description Calculates multiple hashes. + * @since 1.1.1 + * @async + * @public + * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed. + * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>} + * @throws {Error|TypeError} + */ + hashMulti: typeof hashMulti; + /** + * @name hashSha1 + * @description SHA-1. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashSha1: typeof hashSha1; + /** + * @name hashSha256 + * @description SHA-256. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashSha256: typeof hashSha256; + /** + * @name hashSha512 + * @description SHA-512. + * @since 0.2.6 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashSha512: typeof hashSha512; + /** + * @name listContents + * @description Lists files and directories in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ + listContents: typeof listContents; + /** + * @name listDirectories + * @description Lists directories in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ + listDirectories: typeof listDirectories; + /** + * @name listFiles + * @description Lists files in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ + listFiles: typeof listFiles; + /** + * @name move + * @description Change the name or location of a file or directory. + * @since 0.1.29 + * @public + * @param {string} pathFrom + * @param {string} pathTo + * @returns {Promise} + */ + move: typeof move; + /** + * @name pathFrom + * @description Join all arguments together and normalize the resulting path. + * @since 0.1.3 + * @public + * @param {string|string[]} paths + * @param {...string} morePaths + * @returns {string} + */ + pathFrom: typeof pathFrom; + /** + * @name readFileToBase64 + * @description Asynchronously reads the entire contents of a file into string. + * @since 0.1.21 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ + readFileToBase64: typeof readFileToBase64; + /** + * @name readFileToBuffer + * @description Asynchronously reads the entire contents of a file into buffer. + * @since 0.1.19 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ + readFileToBuffer: typeof readFileToBuffer; + /** + * @name readFileToString + * @description Asynchronously reads the entire contents of a file into string. + * @since 0.1.7 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ + readFileToString: typeof readFileToString; + /** + * @name remove + * @description Removes a file or directory. + * @since 0.1.1 + * @async + * @public + * @param {string} pathLike + * @returns {Promise} + */ + remove: typeof remove; + /** + * @name removeNonBlocking + * @description Non-blocking remove of a file or directory. + * @since 0.1.18 + * @public + * @param {string} pathLike + * @returns {void} + */ + removeNonBlocking: typeof removeNonBlocking; + /** + * @name removeSilent + * @description Removes files and directories (modeled on the standard POSIX rm utility). + * @summary Minimum Node version 14.14.0 + * @since 0.1.36 + * @async + * @param {string|Buffer|URL} pathLike + * @param {object=} options + * @returns {Promise} + */ + removeSilent: typeof removeSilent; + /** + * @name size + * @description File size in bytes. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @param {boolean=} [asString=false] + * @returns {Promise} + */ + size: typeof size; + /** + * @name writeFile + * @description Asynchronously writes data to a file, replacing the file if it already exists. + * @since 0.0.10 + * @async + * @public + * @param {string|Buffer|URL} filePath + * @param {string} data + * @param {*|null|string=} options + * @returns {Promise} + */ + writeFile: typeof writeFile; + /** + * @name writeFileTail + * @description Asynchronously writes data to the end of a file. + * @since 1.0.1 + * @async + * @public + * @param {string|Buffer|URL} filePath + * @param {string} data + * @param {*|null|string=} options + * @returns {Promise} + */ + writeFileTail: typeof writeFileTail; + /** + * @name writeJson + * @description Asynchronously writes data to a file, replacing the file if it already exists. + * @since 0.1.25 + * @async + * @public + * @param {string|Buffer|URL} filePath + * @param {*} data + * @param {*|null|string=} options + * @returns {Promise} + */ + writeJson: typeof writeJson; } -//#endregion +export { HileSystemLocal, absolutePathFrom, createDirectory, createFile, dirIsEmpty, dirIsExecutable, dirIsReadable, dirIsVisible, dirIsWritable, fileExtension, fileIsExecutable, fileIsReadable, fileIsVisible, fileIsWritable, fileName, fileNameExt, filePath, fileTruncate, getLinkStatus, getStatus, hash, hashCrc32, hashMd5, hashMulti, hashSha1, hashSha256, hashSha512, isDirExists, isFileExists, isPathExists, listContents, listDirectories, listFiles, move, pathFrom, readFileToBase64, readFileToBuffer, readFileToString, remove, removeNonBlocking, removeSilent, size, writeFile, writeFileTail, writeJson }; diff --git a/dist/index.d.ts b/dist/index.d.ts index 59c0b3c..29ce49b 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,35 +1,5 @@ -import type { PathLike, Stats } from "fs"; - -export interface RmOptions { - /** - * When `true`, exceptions will be ignored if `path` does not exist. - * @default false - */ - force?: boolean | undefined; - /** - * If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or - * `EPERM` error is encountered, Node.js will retry the operation with a linear - * backoff wait of `retryDelay` ms longer on each try. This option represents the - * number of retries. This option is ignored if the `recursive` option is not - * `true`. - * @default 0 - */ - maxRetries?: number | undefined; - /** - * If `true`, perform a recursive directory removal. In - * recursive mode, operations are retried on failure. - * @default false - */ - recursive?: boolean | undefined; - /** - * The amount of time in milliseconds to wait between retries. - * This option is ignored if the `recursive` option is not `true`. - * @default 100 - */ - retryDelay?: number | undefined; -} - -//#region create +import * as node_fs from 'node:fs'; +import { RmOptions } from 'node:fs'; /** * @name createDirectory @@ -39,9 +9,9 @@ export interface RmOptions { * @param {string|Buffer|URL} dirPath * @param {number|string=} mode * @param {boolean=} recursive - * @returns {Promise} + * @returns {Promise} */ -export function createDirectory(dirPath: PathLike, mode?: number | string, recursive?: boolean): Promise; +declare function createDirectory(dirPath: string | Buffer | URL, mode?: (number | string) | undefined, recursive?: boolean | undefined): Promise; /** * @name createFile @@ -50,13 +20,21 @@ export function createDirectory(dirPath: PathLike, mode?: number | string, recur * @async * @param {string|Buffer|URL} pathLike * @param {number|string=} mode - * @returns {Promise} + * @returns {Promise} */ -export function createFile(pathLike: PathLike, mode?: number | string): Promise; +declare function createFile(pathLike: string | Buffer | URL, mode?: string): Promise; -//#endregion - -//#region dir +/** + * @name dirIsEmpty + * @description Check if a directory is empty + * @since 0.1.33 + * @async + * @param {string|Buffer|URL} pathToDir + * @param {boolean=} excludeSystemFiles + * @returns {Promise} + * @throws {Error} If path is not a dir or is not readable. + */ +declare function dirIsEmpty(pathToDir: string | Buffer | URL, excludeSystemFiles?: boolean): Promise; /** * @name dirIsExecutable @@ -64,9 +42,9 @@ export function createFile(pathLike: PathLike, mode?: number | string): Promise< * @since 0.0.5 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise} + * @returns {Promise} */ -export function dirIsExecutable(pathToDir: PathLike): Promise; +declare function dirIsExecutable(pathToDir: string | Buffer | URL): Promise; /** * @name dirIsReadable @@ -74,9 +52,9 @@ export function dirIsExecutable(pathToDir: PathLike): Promise; * @since 0.0.1 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise} + * @returns {Promise} */ -export function dirIsReadable(pathToDir: PathLike): Promise; +declare function dirIsReadable(pathToDir: string | Buffer | URL): Promise; /** * @name dirIsVisible @@ -84,9 +62,9 @@ export function dirIsReadable(pathToDir: PathLike): Promise; * @since 0.0.5 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise} + * @returns {Promise} */ -export function dirIsVisible(pathToDir: PathLike): Promise; +declare function dirIsVisible(pathToDir: string | Buffer | URL): Promise; /** * @name dirIsWritable @@ -94,146 +72,151 @@ export function dirIsVisible(pathToDir: PathLike): Promise; * @since 0.0.1 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise} + * @returns {Promise} */ -export function dirIsWritable(pathToDir: PathLike): Promise; +declare function dirIsWritable(pathToDir: string | Buffer | URL): Promise; /** - * @name dirIsEmpty - * @description Check If a directory is empty - * @since 0.1.33 + * @name hash + * @description Calculate hash. + * @since 0.2.3 * @async - * @param {string|Buffer|URL} pathToDir - * @param {boolean=} excludeSystemFiles - * @returns {Promise} + * @param {string|Buffer|URL} pathToFile + * @param {string} algorithm + * @returns {Promise} + * @throws {TypeError} If algorithm is not supported. */ -export function dirIsEmpty(pathToDir: PathLike, excludeSystemFiles: boolean): Promise; - -//#endregion - -//#region file +declare function hash(pathToFile: string | Buffer | URL, algorithm: string): Promise; /** - * @name fileIsExecutable - * @description File can be executed by the calling process - * @since 0.0.5 + * @name hashCrc32 + * @description CRC32. + * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function fileIsExecutable(pathToFile: PathLike): Promise; +declare function hashCrc32(pathToFile: string | Buffer | URL): Promise; /** - * @name fileIsReadable - * @description File is visible to the calling process - * @since 0.0.1 + * @name hashMd5 + * @description MD5. + * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function fileIsReadable(pathToFile: PathLike): Promise; +declare function hashMd5(pathToFile: string | Buffer | URL): Promise; /** - * @name fileIsVisible - * @description File is visible to the calling process - * @since 0.0.5 + * @name hashMulti + * @description Calculates multiple hashes. + * @summary The objective of the "hashMulti" function is to calculate multiple hashes (CRC32, MD5, SHA-1, SHA-256, and SHA-512) for a given file path and return them as an object. + * @since 1.1.1 * @async - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed. + * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>} + * @throws {Error|TypeError} */ -export function fileIsVisible(pathToFile: PathLike): Promise; +declare function hashMulti(pathToFile: string | Buffer | URL): Promise<{ + crc32: string; + md5: string; + sha1: string; + sha256: string; + sha512: string; +}>; /** - * @name fileIsWritable - * @description File can be written by the calling process - * @since 0.0.1 + * @name hashSha1 + * @description SHA-1. + * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function fileIsWritable(pathToFile: PathLike): Promise; +declare function hashSha1(pathToFile: string | Buffer | URL): Promise; /** - * @name fileTruncate - * @description Truncate a file to a specified length - * @since 0.0.6 + * @name hashSha256 + * @description SHA-256. + * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @param {number=} length - * @returns {Promise} + * @returns {Promise} */ -export function fileTruncate(pathToFile: PathLike, length?: number): Promise; - -//#endregion - -//#region info +declare function hashSha256(pathToFile: string | Buffer | URL): Promise; /** - * @name hash - * @description Calculate hash. - * @since 0.2.3 + * @name hashSha512 + * @description SHA-512. + * @since 0.2.6 * @async * @param {string|Buffer|URL} pathToFile - * @param {string} algorithm - * @returns {Promise} - * @throws {TypeError} If algorithm is not supported. + * @returns {Promise} */ -export function hash(pathToFile: PathLike, algorithm: string): Promise; +declare function hashSha512(pathToFile: string | Buffer | URL): Promise; /** - * @name hashCrc32 - * @description CRC32. + * @name size + * @description File size in bytes. * @since 0.2.3 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @param {boolean=} [asString=false] + * @returns {Promise} */ -export function hashCrc32(pathToFile: PathLike): Promise; +declare function size(pathToFile: string | Buffer | URL, asString?: boolean): Promise; /** - * @name hashMd5 - * @description MD5. - * @since 0.2.3 + * @name fileIsExecutable + * @description File can be executed by the calling process + * @since 0.0.5 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function hashMd5(pathToFile: PathLike): Promise; +declare function fileIsExecutable(pathToFile: string | Buffer | URL): Promise; /** - * @name hashSha1 - * @description SHA-1. - * @since 0.2.3 + * @name fileIsReadable + * @description File is visible to the calling process + * @since 0.0.1 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function hashSha1(pathToFile: PathLike): Promise; +declare function fileIsReadable(pathToFile: string | Buffer | URL): Promise; /** - * @name hashSha256 - * @description SHA-256. - * @since 0.2.3 + * @name fileIsVisible + * @description File is visible to the calling process + * @since 0.0.5 * @async * @param {string|Buffer|URL} pathToFile - * @returns {Promise} + * @returns {Promise} */ -export function hashSha256(pathToFile: PathLike): Promise; +declare function fileIsVisible(pathToFile: string | Buffer | URL): Promise; /** - * @name size - * @description File size in bytes. - * @since 0.2.3 + * @name fileIsWritable + * @description File can be written by the calling process + * @since 0.0.1 * @async * @param {string|Buffer|URL} pathToFile - * @param {boolean=} [asString=false] - * @returns {Promise} + * @returns {Promise} */ -export function size(pathToFile: PathLike, asString?: boolean): Promise; - -//#endregion +declare function fileIsWritable(pathToFile: string | Buffer | URL): Promise; -//#region list +/** + * @name fileTruncate + * @description Truncate a file to a specified length + * @since 0.0.6 + * @async + * @param {string|Buffer|URL} pathToFile + * @param {number=} length + * @returns {Promise} + */ +declare function fileTruncate(pathToFile: string | Buffer | URL, length?: number): Promise; /** * @name listContents @@ -242,9 +225,9 @@ export function size(pathToFile: PathLike, asString?: boolean): Promise|Error|{name: string, message: string, stack?: string}>} + * @returns {Promise} */ -export function listContents(pathToDir: PathLike, ignoreJunk?: boolean): Promise; +declare function listContents(pathToDir: string | Buffer | URL, ignoreJunk?: boolean): Promise; /** * @name listDirectories @@ -252,9 +235,9 @@ export function listContents(pathToDir: PathLike, ignoreJunk?: boolean): Promise * @since 0.1.32 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} + * @returns {Promise} */ -export function listDirectories(pathToDir: PathLike): Promise; +declare function listDirectories(pathToDir: string | Buffer | URL): Promise; /** * @name listFiles @@ -262,13 +245,9 @@ export function listDirectories(pathToDir: PathLike): Promise; * @since 0.1.32 * @async * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} + * @returns {Promise} */ -export function listFiles(pathToDir: PathLike): Promise; - -//#endregion - -//#region move +declare function listFiles(pathToDir: string | Buffer | URL): Promise; /** * @name move @@ -276,24 +255,20 @@ export function listFiles(pathToDir: PathLike): Promise; * @since 0.1.29 * @param {string} pathFrom * @param {string} pathTo - * @returns {Promise} + * @returns {Promise} */ -export function move(pathFrom: PathLike, pathTo: PathLike): Promise; - -//#endregion - -//#region path +declare function move(pathFrom: string, pathTo: string): Promise; /** * @name absolutePathFrom * @description Join all arguments together and normalize the resulting path. * Creates absolute path from right to left until an absolute path is constructed. * @since 0.1.5 - * @param {string|Array.} paths + * @param {string|string[]} paths * @param {...string} morePaths * @returns {string} */ -export function absolutePathFrom(paths: string | string[], ...morePaths: string[]): string; +declare function absolutePathFrom(paths: string | string[], ...morePaths: string[]): string; /** * @name fileExtension @@ -302,7 +277,7 @@ export function absolutePathFrom(paths: string | string[], ...morePaths: string[ * @param {string} path * @returns {string} */ -export function fileExtension(path: string): string; +declare function fileExtension(path: string): string; /** * @name fileName @@ -311,7 +286,7 @@ export function fileExtension(path: string): string; * @param {string} path * @returns {string} */ -export function fileName(path: string): string; +declare function fileName(path: string): string; /** * @name fileNameExt @@ -320,7 +295,7 @@ export function fileName(path: string): string; * @param {string} path * @returns {string} */ -export function fileNameExt(path: string): string; +declare function fileNameExt(path: string): string; /** * @name filePath @@ -329,21 +304,17 @@ export function fileNameExt(path: string): string; * @param {string} path * @returns {string} */ -export function filePath(path: string): string; +declare function filePath(path: string): string; /** * @name pathFrom * @description Join all arguments together and normalize the resulting path. * @since 0.1.3 - * @param {string|Array.} paths + * @param {string|Buffer|URL|string[]|Buffer[]|URL[]} paths * @param {...string} morePaths * @returns {string} */ -export function pathFrom(paths: string | string[], ...morePaths: string[]): string; - -//#endregion - -//#region read +declare function pathFrom(paths: string | Buffer | URL | string[] | Buffer[] | URL[], ...morePaths: string[]): string; /** * @name readFileToBase64 @@ -351,9 +322,9 @@ export function pathFrom(paths: string | string[], ...morePaths: string[]): stri * @since 0.1.21 * @async * @param {string|Buffer|URL} pathLike - * @returns {Promise} + * @returns {Promise} */ -export function readFileToBase64(pathLike: string): Promise; +declare function readFileToBase64(pathLike: string | Buffer | URL): Promise; /** * @name readFileToBuffer @@ -361,9 +332,9 @@ export function readFileToBase64(pathLike: string): Promise; * @since 0.1.19 * @async * @param {string|Buffer|URL} pathLike - * @returns {Promise} + * @returns {Promise} */ -export function readFileToBuffer(pathLike: string): Promise; +declare function readFileToBuffer(pathLike: string | Buffer | URL): Promise; /** * @name readFileToString @@ -371,33 +342,28 @@ export function readFileToBuffer(pathLike: string): Promise; * @since 0.1.7 * @async * @param {string|Buffer|URL} pathLike - * @returns {Promise} + * @returns {Promise} */ -export function readFileToString(pathLike: string): Promise; - -//#endregion - -//#region remove +declare function readFileToString(pathLike: string | Buffer | URL): Promise; /** * @name remove * @description Removes a file or directory. * @since 0.1.1 * @async - * @param {string} pathLike - * @returns {Promise} + * @param {string | Buffer | URL} pathLike + * @returns {Promise} */ -export function remove(pathLike: string): Promise; +declare function remove(pathLike: string | Buffer | URL): Promise; /** * @name removeNonBlocking * @description Non-blocking remove of a file or directory. * @since 0.1.18 - * @sync - * @param {string} pathLike + * @param {string|Buffer|URL} pathLike * @returns {void} */ -export function removeNonBlocking(pathLike: string): void; +declare function removeNonBlocking(pathLike: string | Buffer | URL): void; /** * @name removeSilent @@ -406,14 +372,10 @@ export function removeNonBlocking(pathLike: string): void; * @since 0.1.36 * @async * @param {string|Buffer|URL} pathLike - * @param {object=} options + * @param {RmOptions=} options * @returns {Promise} */ -export function removeSilent(pathLike: string, options?: RmOptions): Promise; - -//#endregion - -//#region status +declare function removeSilent(pathLike: string | Buffer | URL, options: RmOptions): Promise; /** * @name getLinkStatus @@ -422,9 +384,9 @@ export function removeSilent(pathLike: string, options?: RmOptions): Promise>} + * @returns {Promise<[import("node:fs").Stats|undefined, Error|undefined]>} */ -export function getLinkStatus(path: PathLike): Promise<[Stats?, Error?]>; +declare function getLinkStatus(path: string | Buffer | URL): Promise<[node_fs.Stats | undefined, Error | undefined]>; /** * @name getStatus @@ -432,9 +394,9 @@ export function getLinkStatus(path: PathLike): Promise<[Stats?, Error?]>; * @since 0.0.11 * @async * @param {string|Buffer|URL} path - * @returns {Promise<[fs.Stats|undefined],[Error|{name: string, message: string, stack?: string}]>} + * @returns {Promise<[import("node:fs").Stats|undefined, Error|undefined]>} */ -export function getStatus(path: PathLike): Promise<[Stats?, Error?]>; +declare function getStatus(path: string | Buffer | URL): Promise<[node_fs.Stats | undefined, Error | undefined]>; /** * @name isDirExists @@ -444,7 +406,7 @@ export function getStatus(path: PathLike): Promise<[Stats?, Error?]>; * @param {string|Buffer|URL} path * @returns {Promise} */ -export function isDirExists(path: PathLike): Promise; +declare function isDirExists(path: string | Buffer | URL): Promise; /** * @name isFileExists @@ -454,7 +416,7 @@ export function isDirExists(path: PathLike): Promise; * @param {string|Buffer|URL} path * @returns {Promise} */ -export function isFileExists(path: PathLike): Promise; +declare function isFileExists(path: string | Buffer | URL): Promise; /** * @name isPathExists @@ -464,46 +426,47 @@ export function isFileExists(path: PathLike): Promise; * @param {string|Buffer|URL} path * @returns {Promise} */ -export function isPathExists(path: PathLike): Promise; - -//#endregion - -//#region write +declare function isPathExists(path: string | Buffer | URL): Promise; /** * @name writeFile * @description Asynchronously writes data to a file, replacing the file if it already exists. * @since 0.0.10 * @async - * @param {string|Buffer|URL|FileHandle} filePath + * @param {string|Buffer|URL} filePath * @param {string} data * @param {*|null|string=} options - * @returns {Promise} - */ -export function writeFile( - filePath: PathLike, - data: string, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, -): Promise; + * @returns {Promise} + * @example + * const controller = new AbortController(); + * const { signal } = controller; + * const data = new Uint8Array(Buffer.from('Hello Node.js')); + * (async () => { + * try { + * await writeFile('message.txt', data, { signal }); + * } catch (error) { + * // When a request is aborted - error is an AbortError + * } + * })(); + * // When the request should be aborted + * controller.abort(); + */ +declare function writeFile(filePath: string | Buffer | URL, data: any, options?: any | null | string): Promise; /** * @name writeFileTail * @description Asynchronously writes data to the end of a file. * @since 1.0.1 * @async - * @param {string|Buffer|URL|FileHandle} filePath + * @param {string|Buffer|URL} filePath * @param {string} data * @param {*|null|string=} options - * @returns {Promise} + * @returns {Promise} */ -export function writeFileTail( - filePath: PathLike, - data: string, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, -): Promise; +declare function writeFileTail(filePath: string | Buffer | URL, data: any, options?: any | null | string): Promise; /** - * @name writeJSON + * @name writeJson * @description Asynchronously writes data to a file, replacing the file if it already exists. * @since 0.1.25 * @async @@ -511,501 +474,461 @@ export function writeFileTail( * @param {*} data * @param {*|null|string=} options * @param {{sort: boolean, space: number|string}=} configuration - * @returns {Promise} - */ -export function writeJSON( - filePath: PathLike, - data: any, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, - configuration?: { sort?: boolean; space?: number | string }, -): Promise; - -//#endregion - -//#region default - -export class HileSystemLocal { - //#region create - - /** - * @name createDirectory - * @description Asynchronous create a directory. - * @since 0.0.10 - * @async - * @public - * @param {string|Buffer|URL} dirPath - * @param {number|string=} mode - * @param {boolean=} recursive - * @returns {Promise} - */ - public createDirectory(dirPath: PathLike, mode?: number | string, recursive?: boolean): Promise; - /** - * @name createFile - * @description Asynchronous create a file. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} pathLike - * @param {number|string=} mode - * @returns {Promise} - */ - public createFile(pathLike: PathLike, mode?: number | string): Promise; - - //#endregion - - //#region dir - - /** - * @name dirIsExecutable - * @description Directory can be executed by the calling process - * @since 0.0.5 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - public dirIsExecutable(pathToDir: PathLike): Promise; - /** - * @name dirIsReadable - * @description Directory is visible to the calling process - * @since 0.0.1 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - public dirIsReadable(pathToDir: PathLike): Promise; - /** - * @name dirIsVisible - * @description Directory is visible to the calling process - * @since 0.0.5 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - public dirIsVisible(pathToDir: PathLike): Promise; - /** - * @name dirIsWritable - * @description Directory can be written by the calling process - * @since 0.0.1 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - public dirIsWritable(pathToDir: PathLike): Promise; - - /** - * @name dirIsEmpty - * @description Check If a directory is empty - * @since 0.1.33 - * @async - * @public - * @param {string|Buffer|URL} pathToDir - * @param {boolean=} excludeSystemFiles - * @returns {Promise} - */ - public dirIsEmpty(pathToDir: PathLike, excludeSystemFiles: boolean): Promise; - - //#endregion - - //#region file - - /** - * @name fileIsExecutable - * @description File can be executed by the calling process - * @since 0.0.5 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public fileIsExecutable(pathToFile: PathLike): Promise; - /** - * @name fileIsReadable - * @description File is visible to the calling process - * @since 0.0.1 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public fileIsReadable(pathToFile: PathLike): Promise; - /** - * @name fileIsVisible - * @description File is visible to the calling process - * @since 0.0.5 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public fileIsVisible(pathToFile: PathLike): Promise; - /** - * @name fileIsWritable - * @description File can be written by the calling process - * @since 0.0.1 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public fileIsWritable(pathToFile: PathLike): Promise; - /** - * @name fileTruncate - * @description Truncate a file to a specified length - * @since 0.0.6 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @param {number=} length - * @returns {Promise} - */ - public fileTruncate(pathToFile: PathLike, length?: number): Promise; - - //#endregion - - //#region info - - /** - * @name hash - * @description Calculate hash. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @param {string} algorithm - * @returns {Promise} - * @throws {TypeError} If algorithm is not supported. - */ - public hash(pathToFile: PathLike, algorithm: string): Promise; - - /** - * @name hashCrc32 - * @description CRC32. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public hashCrc32(pathToFile: PathLike): Promise; - - /** - * @name hashMd5 - * @description MD5. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public hashMd5(pathToFile: PathLike): Promise; - - /** - * @name hashSha1 - * @description SHA-1. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public hashSha1(pathToFile: PathLike): Promise; - - /** - * @name hashSha256 - * @description SHA-256. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - public hashSha256(pathToFile: PathLike): Promise; - - /** - * @name size - * @description File size in bytes. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @param {boolean=} [asString=false] - * @returns {Promise} - */ - public size(pathToFile: PathLike, asString?: boolean): Promise; - - //#endregion - - //#region list - - /** - * @name listContents - * @description Lists files and directories in path - * @since 0.1.32 - * @async - * @param {string|Buffer|URL} pathToDir - * @param {boolean} [ignoreJunk=true] - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ - public listContents(pathToDir: PathLike, ignoreJunk?: boolean): Promise; - - /** - * @name listDirectories - * @description Lists directories path - * @since 0.1.32 - * @async - * @public - * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ - public listDirectories(pathToDir: PathLike): Promise; - - /** - * @name listFiles - * @description Lists files path - * @since 0.1.32 - * @async - * @public - * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ - public listFiles(pathToDir: PathLike): Promise; - - //#endregion - - //#region move - - /** - * @name move - * @description Change the name or location of a file or directory. - * @since 0.1.29 - * @async - * @public - * @param {string} pathFrom - * @param {string} pathTo - * @returns {Promise} - */ - public move(pathFrom: PathLike, pathTo: PathLike): Promise; - - //#endregion - - //#region read - - /** - * @name readFileToString - * @description Asynchronously reads the entire contents of a file into string. - * @since 0.1.21 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ - public readFileToBase64(pathLike: string): Promise; - - /** - * @name readFileToBuffer - * @description Asynchronously reads the entire contents of a file into buffer. - * @since 0.1.19 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ - public readFileToBuffer(pathLike: string): Promise; - - /** - * @name readFileToString - * @description Asynchronously reads the entire contents of a file into string. - * @since 0.1.7 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ - public readFileToString(pathLike: string): Promise; - - //#endregion - - //#region remove - - /** - * @name remove - * @description Removes a file or directory. - * @since 0.1.1 - * @async - * @public - * @param {string} pathLike - * @returns {Promise} - */ - public remove(pathLike: string): Promise; - - //#endregion - - //#region path - - /** - * @name fileExtension - * @description Get file extension. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - public fileExtension(path: string): string; - - /** - * @name fileName - * @description Return the file name without extension. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - public fileName(path: string): string; - - /** - * @name fileNameExt - * @description Return the last portion of a path. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - public fileNameExt(path: string): string; - - /** - * @name filePath - * @description Return the directory name of a path. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - public filePath(path: string): string; - - /** - * @name pathFrom - * @description Join all arguments together and normalize the resulting path. - * @since 0.1.3 - * @public - * @param {string|Array.} paths - * @param {...string} morePaths - * @returns {string} - */ - public pathFrom(paths: string | string[], ...morePaths: string[]): string; - - //#endregion - - //#region status - /** - * @name getLinkStatus - * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to. - * @url http://man7.org/linux/man-pages/man2/lstat.2.html - * @since 1.1.0 - * @async - * @param {string|Buffer|URL} path - * @returns {Promise>} - */ - public getLinkStatus(path: PathLike): Promise<[Stats?, Error?]>; - /** - * @name getStatus - * @description Get file status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise<[fs.Stats|undefined],[Error|{name: string, message: string, stack?: string}]>} - */ - public getStatus(path: PathLike): Promise<[Stats?, Error?]>; - /** - * @name isDirExists - * @description Get directory status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise} - */ - public isDirExists(path: PathLike): Promise; - /** - * @name isFileExists - * @description Get file status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise} - */ - public isFileExists(path: PathLike): Promise; - /** - * @name isPathExists - * @description Get path status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise} - */ - public isPathExists(path: PathLike): Promise; - - //#endregion - - //#region write - - /** - * @name writeFile - * @description Asynchronously writes data to a file, replacing the file if it already exists. - * @since 0.0.10 - * @async - * @public - * @param {string|Buffer|URL|FileHandle} filePath - * @param {*=} data - * @param {*|null|string=} options - * @returns {Promise} - */ - public writeFile( - filePath: PathLike, - data: string, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, - ): Promise; - - /** - * @name writeFileTail - * @description Asynchronously writes data to the end of a file. - * @since 1.0.1 - * @async - * @public - * @param {string|Buffer|URL|FileHandle} filePath - * @param {*=} data - * @param {*|null|string=} options - * @returns {Promise} - */ - public writeFileTail( - filePath: PathLike, - data: string, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, - ): Promise; - - /** - * @name writeJSON - * @description Asynchronously writes data to a file, replacing the file if it already exists. - * @since 0.1.25 - * @async - * @public - * @param {string|Buffer|URL} filePath - * @param {*} data - * @param {*|null|string=} options - * @param {{sort: boolean, space: number|string}=} configuration - * @returns {Promise} - */ - public writeJSON( - filePath: PathLike, - data: any, - options?: { encoding?: string | null; mode?: string | number; flag?: string | number }, - configuration?: { sort?: boolean; space?: number | string }, - ): Promise; - - //#endregion + * @returns {Promise} + */ +declare function writeJson(filePath: string | Buffer | URL, data: any, options: any, configuration: { + sort: boolean; + space: number | string; +} | undefined): Promise; + +declare class HileSystemLocal { + /** + * @name absolutePathFrom + * @description Join all arguments together and normalize the resulting path. + * Creates absolute path from right to left until an absolute path is constructed. + * @since 0.1.5 + * @public + * @param {string|string[]} paths + * @param {...string} morePaths + * @returns {string} + */ + absolutePathFrom: typeof absolutePathFrom; + /** + * @name createDirectory + * @description Asynchronous create a directory. + * @since 0.0.10 + * @async + * @public + * @param {string|Buffer|URL} dirPath + * @param {number|string=} mode + * @param {boolean=} recursive + * @returns {Promise} + */ + createDirectory: typeof createDirectory; + /** + * @name createFile + * @description Asynchronous create a file. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} pathLike + * @param {number|string=} mode + * @returns {Promise} + */ + createFile: typeof createFile; + /** + * @name dirIsExecutable + * @description Directory can be executed by the calling process + * @since 0.0.5 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsExecutable: typeof dirIsExecutable; + /** + * @name dirIsReadable + * @description Directory is visible to the calling process + * @since 0.0.1 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsReadable: typeof dirIsReadable; + /** + * @name dirIsVisible + * @description Directory is visible to the calling process + * @since 0.0.5 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsVisible: typeof dirIsVisible; + /** + * @name dirIsWritable + * @description Directory can be written by the calling process + * @since 0.0.1 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsWritable: typeof dirIsWritable; + /** + * @name dirIsEmpty + * @description Check if a directory is empty + * @since 0.1.33 + * @async + * @public + * @param {string|Buffer|URL} pathToDir + * @param {boolean=} excludeSystemFiles + * @returns {Promise} + * @throws {Error} If path is not a dir or is not readable. + */ + dirIsEmpty: typeof dirIsEmpty; + /** + * @name getLinkStatus + * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to. + * @url http://man7.org/linux/man-pages/man2/lstat.2.html + * @since 1.1.0 + * @async + * @param {string|Buffer|URL} path + * @returns {Promise>} + */ + getLinkStatus: typeof getLinkStatus; + /** + * @name getStatus + * @description Get file status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise>} + */ + getStatus: typeof getStatus; + /** + * @name isDirExists + * @description Get directory status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise} + */ + isDirExists: typeof isDirExists; + /** + * @name isFileExists + * @description Get file status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise} + */ + isFileExists: typeof isFileExists; + /** + * @name isPathExists + * @description Get path status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise} + */ + isPathExists: typeof isPathExists; + /** + * @name fileExtension + * @description Get file extension. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + fileExtension: typeof fileExtension; + /** + * @name fileName + * @description Return the file name without extension. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + fileName: typeof fileName; + /** + * @name fileNameExt + * @description Return the last portion of a path. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + fileNameExt: typeof fileNameExt; + /** + * @name filePath + * @description Return the directory name of a path. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + filePath: typeof filePath; + /** + * @name fileIsExecutable + * @description File can be executed by the calling process + * @since 0.0.5 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsExecutable: typeof fileIsExecutable; + /** + * @name fileIsReadable + * @description File is visible to the calling process + * @since 0.0.1 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsReadable: typeof fileIsReadable; + /** + * @name fileIsVisible + * @description File is visible to the calling process + * @since 0.0.5 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsVisible: typeof fileIsVisible; + /** + * @name fileIsWritable + * @description File can be written by the calling process + * @since 0.0.1 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsWritable: typeof fileIsWritable; + /** + * @name fileTruncate + * @description Truncate a file to a specified length + * @since 0.0.6 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @param {number=} length + * @returns {Promise} + */ + fileTruncate: typeof fileTruncate; + /** + * @name hash + * @description Calculate hash. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @param {string} algorithm + * @returns {Promise} + * @throws {TypeError} If algorithm is not supported. + */ + hash: typeof hash; + /** + * @name hashCrc32 + * @description CRC32. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashCrc32: typeof hashCrc32; + /** + * @name hashMd5 + * @description MD5. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashMd5: typeof hashMd5; + /** + * @name hashMulti + * @description Calculates multiple hashes. + * @since 1.1.1 + * @async + * @public + * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed. + * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>} + * @throws {Error|TypeError} + */ + hashMulti: typeof hashMulti; + /** + * @name hashSha1 + * @description SHA-1. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashSha1: typeof hashSha1; + /** + * @name hashSha256 + * @description SHA-256. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashSha256: typeof hashSha256; + /** + * @name hashSha512 + * @description SHA-512. + * @since 0.2.6 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashSha512: typeof hashSha512; + /** + * @name listContents + * @description Lists files and directories in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ + listContents: typeof listContents; + /** + * @name listDirectories + * @description Lists directories in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ + listDirectories: typeof listDirectories; + /** + * @name listFiles + * @description Lists files in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ + listFiles: typeof listFiles; + /** + * @name move + * @description Change the name or location of a file or directory. + * @since 0.1.29 + * @public + * @param {string} pathFrom + * @param {string} pathTo + * @returns {Promise} + */ + move: typeof move; + /** + * @name pathFrom + * @description Join all arguments together and normalize the resulting path. + * @since 0.1.3 + * @public + * @param {string|string[]} paths + * @param {...string} morePaths + * @returns {string} + */ + pathFrom: typeof pathFrom; + /** + * @name readFileToBase64 + * @description Asynchronously reads the entire contents of a file into string. + * @since 0.1.21 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ + readFileToBase64: typeof readFileToBase64; + /** + * @name readFileToBuffer + * @description Asynchronously reads the entire contents of a file into buffer. + * @since 0.1.19 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ + readFileToBuffer: typeof readFileToBuffer; + /** + * @name readFileToString + * @description Asynchronously reads the entire contents of a file into string. + * @since 0.1.7 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ + readFileToString: typeof readFileToString; + /** + * @name remove + * @description Removes a file or directory. + * @since 0.1.1 + * @async + * @public + * @param {string} pathLike + * @returns {Promise} + */ + remove: typeof remove; + /** + * @name removeNonBlocking + * @description Non-blocking remove of a file or directory. + * @since 0.1.18 + * @public + * @param {string} pathLike + * @returns {void} + */ + removeNonBlocking: typeof removeNonBlocking; + /** + * @name removeSilent + * @description Removes files and directories (modeled on the standard POSIX rm utility). + * @summary Minimum Node version 14.14.0 + * @since 0.1.36 + * @async + * @param {string|Buffer|URL} pathLike + * @param {object=} options + * @returns {Promise} + */ + removeSilent: typeof removeSilent; + /** + * @name size + * @description File size in bytes. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @param {boolean=} [asString=false] + * @returns {Promise} + */ + size: typeof size; + /** + * @name writeFile + * @description Asynchronously writes data to a file, replacing the file if it already exists. + * @since 0.0.10 + * @async + * @public + * @param {string|Buffer|URL} filePath + * @param {string} data + * @param {*|null|string=} options + * @returns {Promise} + */ + writeFile: typeof writeFile; + /** + * @name writeFileTail + * @description Asynchronously writes data to the end of a file. + * @since 1.0.1 + * @async + * @public + * @param {string|Buffer|URL} filePath + * @param {string} data + * @param {*|null|string=} options + * @returns {Promise} + */ + writeFileTail: typeof writeFileTail; + /** + * @name writeJson + * @description Asynchronously writes data to a file, replacing the file if it already exists. + * @since 0.1.25 + * @async + * @public + * @param {string|Buffer|URL} filePath + * @param {*} data + * @param {*|null|string=} options + * @returns {Promise} + */ + writeJson: typeof writeJson; } -//#endregion +export { HileSystemLocal, absolutePathFrom, createDirectory, createFile, dirIsEmpty, dirIsExecutable, dirIsReadable, dirIsVisible, dirIsWritable, fileExtension, fileIsExecutable, fileIsReadable, fileIsVisible, fileIsWritable, fileName, fileNameExt, filePath, fileTruncate, getLinkStatus, getStatus, hash, hashCrc32, hashMd5, hashMulti, hashSha1, hashSha256, hashSha512, isDirExists, isFileExists, isPathExists, listContents, listDirectories, listFiles, move, pathFrom, readFileToBase64, readFileToBuffer, readFileToString, remove, removeNonBlocking, removeSilent, size, writeFile, writeFileTail, writeJson }; diff --git a/dist/index.js b/dist/index.js index 442b617..a144b89 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,559 @@ -"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("node:fs/promises"),t=require("node:path"),r=require("node:fs"),i=require("node:crypto"),s=_interopDefault(require("os")),n=_interopDefault(require("fs")),a=_interopDefault(require("node:assert"));async function createDirectory(t,r="0777",i=!0){try{return await e.mkdir(t,{mode:r,recursive:i}),!0}catch(e){return e}}async function getStatus(t){try{return[await e.stat(t)]}catch(e){return[void 0,e]}}async function writeFile(t,r,i){try{return await e.writeFile(t,r,i),!0}catch(e){return e}}async function createFile(r,i="0777"){const[s,n]=await getStatus(r);if(!n&&s.isFile())return!0;const a=t.dirname(r);if(n&&"ENOENT"===n.code){const e=await createDirectory(a,i);if(!0!==e)return e;const t=await writeFile(r,"",{mode:i,flag:"w"});return!0===t||t}if(s.isDirectory())return await writeFile(r,"",{mode:i,flag:"w"});try{return void await e.readdir(a)}catch(n){return n}}async function accessWrapper(t,r){try{return await e.access(r,t),!0}catch(e){return e}}async function dirIsReadable(e){return accessWrapper(r.constants.R_OK,e)}const o=new RegExp(["^npm-debug\\.log$","^\\..*\\.swp$","^\\.DS_Store$","^\\.AppleDouble$","^\\.LSOverride$","^Icon\\r$","^\\._.*","^\\.Spotlight-V100(?:$|\\/)","\\.Trashes","^__MACOSX$","~$","^Thumbs\\.db$","^ehthumbs\\.db$","^Desktop\\.ini$","@eaDir$","^\\$RECYCLE.BIN$","^System Volume Information$"].join("|"));function isNotSystemJunk(e){return!function isSystemJunk(e){return o.test(e)}(e)}async function listContents(t,r=!0){try{const i=await e.readdir(t);return r?i.filter(isNotSystemJunk):i}catch(e){return e}}const c=[".AppleDB",".AppleDesktop",".AppleDouble",".DS_Store",".DocumentRevisions-V100",".LSOverride",".Spotlight-V100",".TemporaryItems",".Trashes",".VolumeIcon.icns",".apdisk",".com.apple.timemachine.donotpresent",".fseventsd","Network Trash Folder","Temporary Items","$RECYCLE.BIN/","Desktop.ini","Thumbs.db","Thumbs.db:encryptable","desktop.ini","ehthumbs.db","ehthumbs_vista.db",".directory"];async function dirIsEmpty(e,t=!0){const r=await dirIsReadable(e);if(!0!==r)throw new Error(r.message,function errorExtractOptions(e){return e instanceof Error?"code"in e&&"errno"in e&&"path"in e&&"syscall"in e?{cause:{code:e.code,values:{errno:e.errno,path:e.path,syscall:e.syscall}}}:void 0:{cause:e}}(r));let i=await listContents(e);if(i instanceof Error)throw i;return 0===i.length||!!t&&function isEmptyContent(e){const t=new Set(e);return e.length=0,t.forEach(e=>{for(const r of c)e&&(e===r||e.match(RegExp(r)))&&t.delete(e)}),0===t.size}(i)}async function dirIsExecutable(e){return accessWrapper(r.constants.X_OK,e)}async function dirIsVisible(e){return accessWrapper(r.constants.F_OK,e)}async function dirIsWritable(e){return accessWrapper(r.constants.W_OK,e)}async function hash(t,r){if(!i.getHashes().includes(r))throw new TypeError(`Digest algorithm [${r}] is not supported.`);return i.createHash(r).update(await e.readFile(t)).digest("hex")}async function hashCrc32(t){return function crc32(e){let t,r=[];for(let e=0;e<256;e++){t=e;for(let e=0;e<8;e++)t=1&t?3988292384^t>>>1:t>>>1;r[e]=t}let i=-1,s=0;for(;s>>8^r[255&(i^e.charCodeAt(s))];return(-1^i)>>>0}((await e.readFile(t)).toString("binary")).toString(16)}async function hashMd5(e){return hash(e,"md5")}async function hashSha1(e){return hash(e,"sha1")}async function hashSha256(e){return hash(e,"sha256")}async function hashSha512(e){return hash(e,"sha512")}async function size(t,r=!1){const i=await e.stat(t);return r?i.size.toLocaleString("en").replace(/,/g,"_"):i.size}async function fileIsExecutable(e){return accessWrapper(r.constants.X_OK,e)}async function fileIsReadable(e){return accessWrapper(r.constants.R_OK,e)}async function fileIsVisible(e){return accessWrapper(r.constants.F_OK,e)}async function fileIsWritable(e){return accessWrapper(r.constants.W_OK,e)}async function fileTruncate(t,r=0){try{return await e.truncate(t,r),!0}catch(e){return e}}function pathFrom(e,...r){let i;return i=Array.isArray(e)?e.map(e=>e.toString()):[e.toString()],r.length&&(i=i.concat(r.map(e=>e.toString()))),t.normalize(t.join(...i))}async function listDirectories(e){const t=await listContents(e);if(!Array.isArray(t))return t;return(await Promise.all(t.map(async t=>{const r=pathFrom(e,t),[i,s]=await getStatus(r);if(!s&&i.isDirectory())return t}))).filter(e=>e)}async function listFiles(e){const t=await listContents(e);if(!Array.isArray(t))return t;return(await Promise.all(t.map(async t=>{const r=pathFrom(e,t),[i,s]=await getStatus(r);if(!s&&!i.isDirectory())return t}))).filter(e=>e)}async function move(t,r){try{return await e.rename(t,r),!0}catch(e){return e}}const l=s.homedir();function absolutePath(e){return l?String(e).replace(/^~(?=$|\/|\\)/,l):String(e)}function absolutePathFrom(e,...r){let i;return i=Array.isArray(e)?e.map(e=>e.toString()):[e.toString()],r.length&&(i=i.concat(r.map(e=>e.toString()))),absolutePath(t.resolve(...i))}function fileExtension(e){return t.extname(e).substring(1)}function fileName(e){return t.parse(e).name}function fileNameExt(e){return t.basename(e)}function filePath(e){return t.dirname(e)}async function readFileToBase64(t){try{return(await e.readFile(t,"base64")).toString()}catch(e){return e}}async function readFileToBuffer(t){try{const r=await e.readFile(t,"binary");return Buffer.from(r)}catch(e){return e}}async function readFileToString(t){try{return(await e.readFile(absolutePath(t),"utf8")).toString()}catch(e){return e}}const u="win32"===process.platform;function rimraf(e,t,r){let i=0,s=r,o=t;"function"==typeof o&&(s=o,o={}),a(e,"remove(): missing path"),a.strictEqual(typeof e,"string","remove(): path should be a string"),a.strictEqual(typeof s,"function","remove(): callback function required"),a(o,"remove(): invalid options argument provided"),a.strictEqual(typeof o,"object","remove(): options should be object"),function defaults(e){["unlink","chmod","stat","lstat","rmdir","readdir"].forEach(t=>{e[t]=e[t]||n[t]}),e.maxBusyTries=e.maxBusyTries||3}(o),rimraf_(e,o,(function callbackRimraf(t){if(t){if(("EBUSY"===t.code||"ENOTEMPTY"===t.code||"EPERM"===t.code)&&irimraf_(e,o,callbackRimraf),100*i)}if("ENOENT"===t.code)return void s(null)}s(t)}))}function rimraf_(e,t,r){a(e),a(t),a("function"==typeof r),t.lstat(e,(i,s)=>i&&"ENOENT"===i.code?r(null):i&&"EPERM"===i.code&&u?fixWinEPERM(e,t,i,r):s&&s.isDirectory()?rmdir(e,t,i,r):void t.unlink(e,i=>{if(i){if("ENOENT"===i.code)return r(null);if("EPERM"===i.code)return u?fixWinEPERM(e,t,i,r):rmdir(e,t,i,r);if("EISDIR"===i.code)return rmdir(e,t,i,r)}return r(i)}))}function fixWinEPERM(e,t,r,i){return a(e),a(t),a("function"==typeof i),r&&a(r instanceof Error),t.chmod(e,438,s=>{s?"ENOENT"===s.code?i(null):i(r):t.stat(e,(s,n)=>{s?"ENOENT"===s.code?i(null):i(r):n.isDirectory()?rmdir(e,t,r,i):t.unlink(e,i)})}),null}function rmdir(e,r,i,s){return a(e),a(r),i&&a(i instanceof Error),a("function"==typeof s),r.rmdir(e,n=>{!n||"ENOTEMPTY"!==n.code&&"EEXIST"!==n.code&&"EPERM"!==n.code?n&&"ENOTDIR"===n.code?s(i):s(n):function removeSubPath(e,r,i){a(e),a(r),a("function"==typeof i),r.readdir(e,(s,n)=>{if(s)return i(s);let a,o=n.length;if(0===o)return r.rmdir(e,i);n.forEach(s=>{rimraf(t.join(e,s),r,t=>{a||(t?i(a=t):(--o,0===o&&r.rmdir(e,i)))})})})}(e,r,s)}),null}async function remove(e){return new Promise(t=>{rimraf(e,{},e=>{e?t(e):t()})})}function removeNonBlocking(e){remove(e).then(()=>{}).catch(()=>{})}async function removeSilent(t,r){try{await e.rm(t,{force:!0,recursive:!0,...r})}catch(e){}}async function getLinkStatus(t){try{return[await e.lstat(t)]}catch(e){return[void 0,e]}}async function isDirExists(e){const[t,r]=await getStatus(e);return!r&&t.isDirectory()}async function isFileExists(e){const[t,r]=await getStatus(e);return!r&&t.isFile()}async function isPathExists(e){const[t]=await getStatus(e);return Boolean(t)}async function writeFileTail(e,t,r){if(!1===await isFileExists(e)){const t=await createFile(e);if(!0!==t)return t}const i=await readFileToString(e);return i instanceof Error?i:new Promise((s,n)=>{setTimeout(()=>{writeFile(e,`${String(i)}${String(t)}`,r).then(()=>{s(!0)}).catch(e=>{n(e)})},1)})}function isObjectLike(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function collectionSortKeys(e,t=!0){if(!isObjectLike(e))return Array.isArray(e)?e.map(e=>collectionSortKeys(e,t)):e;const r=function objectKeys(e){return Object.keys(e).sort((e,t)=>e.localeCompare(t))}(e);return r.length?r.reduce((r,i)=>(t&&isObjectLike(e[i])||t&&Array.isArray(e[i])?r[i]=collectionSortKeys(e[i],t):r[i]=e[i],r),{}):e}async function writeJSON(e,t,r,i){let s,n=t;try{i?(i.sort&&(n=isObjectLike(t)?collectionSortKeys(JSON.parse(JSON.stringify(t))):Array.isArray(t)?JSON.parse(JSON.stringify(t)):t),i.space&&(s=JSON.stringify(n,null,i.space))):s=JSON.stringify(n)}catch(e){return e}return writeFile(e,s,r)}function _defineProperty(e,t,r){return(t=function _toPropertyKey(e){var t=function _toPrimitive(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}exports.HileSystemLocal=class HileSystemLocal{constructor(){_defineProperty(this,"absolutePathFrom",absolutePathFrom),_defineProperty(this,"createDirectory",createDirectory),_defineProperty(this,"createFile",createFile),_defineProperty(this,"dirIsExecutable",dirIsExecutable),_defineProperty(this,"dirIsReadable",dirIsReadable),_defineProperty(this,"dirIsVisible",dirIsVisible),_defineProperty(this,"dirIsWritable",dirIsWritable),_defineProperty(this,"dirIsEmpty",dirIsEmpty),_defineProperty(this,"getLinkStatus",getLinkStatus),_defineProperty(this,"getStatus",getStatus),_defineProperty(this,"isDirExists",isDirExists),_defineProperty(this,"isFileExists",isFileExists),_defineProperty(this,"isPathExists",isPathExists),_defineProperty(this,"fileExtension",fileExtension),_defineProperty(this,"fileName",fileName),_defineProperty(this,"fileNameExt",fileNameExt),_defineProperty(this,"filePath",filePath),_defineProperty(this,"fileIsExecutable",fileIsExecutable),_defineProperty(this,"fileIsReadable",fileIsReadable),_defineProperty(this,"fileIsVisible",fileIsVisible),_defineProperty(this,"fileIsWritable",fileIsWritable),_defineProperty(this,"fileTruncate",fileTruncate),_defineProperty(this,"hash",hash),_defineProperty(this,"hashCrc32",hashCrc32),_defineProperty(this,"hashMd5",hashMd5),_defineProperty(this,"hashSha1",hashSha1),_defineProperty(this,"hashSha256",hashSha256),_defineProperty(this,"hashSha512",hashSha512),_defineProperty(this,"listContents",listContents),_defineProperty(this,"listDirectories",listDirectories),_defineProperty(this,"listFiles",listFiles),_defineProperty(this,"move",move),_defineProperty(this,"pathFrom",pathFrom),_defineProperty(this,"readFileToBase64",readFileToBase64),_defineProperty(this,"readFileToBuffer",readFileToBuffer),_defineProperty(this,"readFileToString",readFileToString),_defineProperty(this,"remove",remove),_defineProperty(this,"removeNonBlocking",removeNonBlocking),_defineProperty(this,"removeSilent",removeSilent),_defineProperty(this,"size",size),_defineProperty(this,"writeFile",writeFile),_defineProperty(this,"writeFileTail",writeFileTail),_defineProperty(this,"writeJSON",writeJSON)}},exports.absolutePathFrom=absolutePathFrom,exports.createDirectory=createDirectory,exports.createFile=createFile,exports.dirIsEmpty=dirIsEmpty,exports.dirIsExecutable=dirIsExecutable,exports.dirIsReadable=dirIsReadable,exports.dirIsVisible=dirIsVisible,exports.dirIsWritable=dirIsWritable,exports.fileExtension=fileExtension,exports.fileIsExecutable=fileIsExecutable,exports.fileIsReadable=fileIsReadable,exports.fileIsVisible=fileIsVisible,exports.fileIsWritable=fileIsWritable,exports.fileName=fileName,exports.fileNameExt=fileNameExt,exports.filePath=filePath,exports.fileTruncate=fileTruncate,exports.getLinkStatus=getLinkStatus,exports.getStatus=getStatus,exports.hash=hash,exports.hashCrc32=hashCrc32,exports.hashMd5=hashMd5,exports.hashSha1=hashSha1,exports.hashSha256=hashSha256,exports.hashSha512=hashSha512,exports.isDirExists=isDirExists,exports.isFileExists=isFileExists,exports.isPathExists=isPathExists,exports.listContents=listContents,exports.listDirectories=listDirectories,exports.listFiles=listFiles,exports.move=move,exports.pathFrom=pathFrom,exports.readFileToBase64=readFileToBase64,exports.readFileToBuffer=readFileToBuffer,exports.readFileToString=readFileToString,exports.remove=remove,exports.removeNonBlocking=removeNonBlocking,exports.removeSilent=removeSilent,exports.size=size,exports.writeFile=writeFile,exports.writeFileTail=writeFileTail,exports.writeJSON=writeJSON; -//# sourceMappingURL=index.js.map +import { mkdir as j, stat as x, writeFile as z, readdir as F, access as Y, readFile as y, truncate as X, rename as H, rm as U, lstat as q } from "node:fs/promises"; +import { dirname as v, normalize as G, join as R, resolve as Q, extname as Z, parse as L, basename as k } from "node:path"; +import tt, { constants as a } from "node:fs"; +import { getHashes as et, createHash as rt } from "node:crypto"; +import { homedir as nt } from "node:os"; +import c from "node:assert"; +async function p(t, e = "0777", r = !0) { + try { + return await j(t, { mode: e, recursive: r }), !0; + } catch (n) { + return n; + } +} +async function l(t) { + try { + return [await x(t), void 0]; + } catch (e) { + return [void 0, e]; + } +} +async function h(t, e, r = null) { + try { + return await z(t, e, r), !0; + } catch (n) { + return n; + } +} +async function A(t, e = "0777") { + const [r, n] = await l(t); + if (!n && r.isFile()) + return !0; + const i = v(t); + if (n && n.code === "ENOENT") { + const s = await p(i, e); + if (s !== !0) + return s; + const u = await h(t, "", { mode: e, flag: "w" }); + return u !== !0 ? u : !0; + } + if (r.isDirectory()) + return await h(t, "", { mode: e, flag: "w" }); + try { + await F(i); + return; + } catch (s) { + return s; + } +} +function it(t) { + return t instanceof Error ? "code" in t && "errno" in t && "path" in t && "syscall" in t ? { + cause: { + code: t.code, + values: { + errno: t.errno, + path: t.path, + syscall: t.syscall + } + } + } : { cause: t } : { cause: t }; +} +async function f(t, e) { + try { + return await Y(e, t), !0; + } catch (r) { + return r; + } +} +async function $(t) { + var e, r; + if (((e = process == null ? void 0 : process.permission) == null ? void 0 : e.has("fs.read")) !== void 0) { + const n = (r = process.permission) == null ? void 0 : r.has("fs.read", t); + if (n !== void 0) + return n; + } + return f(a.R_OK, t); +} +const st = [ + // # All + "^npm-debug\\.log$", + // Error log for npm + "^\\..*\\.swp$", + // Swap file for vim state + // # macOS + "^\\.DS_Store$", + // Stores custom folder attributes + "^\\.AppleDouble$", + // Stores additional file resources + "^\\.LSOverride$", + // Contains the absolute path to the app to be used + "^Icon\\r$", + // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop + "^\\._.*", + // Thumbnail + "^\\.Spotlight-V100(?:$|\\/)", + // Directory that might appear on external disk + "\\.Trashes", + // File that might appear on external disk + "^__MACOSX$", + // Resource fork + // # Linux + "~$", + // Backup file + // # Windows + "^Thumbs\\.db$", + // Image file cache + "^ehthumbs\\.db$", + // Folder config file + "^Desktop\\.ini$", + // Stores custom folder attributes + "@eaDir$", + // Synology Diskstation "hidden" folder where the server stores thumbnails + "^\\$RECYCLE.BIN$", + // Special folder with columns like Date deleted and Original location + "^System Volume Information$" +], ut = new RegExp(st.join("|")); +function ct(t) { + return ut.test(t); +} +function ot(t) { + return !ct(t); +} +async function S(t, e = !0) { + try { + const r = await F(t); + return e ? r.filter(ot) : r; + } catch (r) { + return r; + } +} +const at = [ + // macOS + ".AppleDB", + ".AppleDesktop", + ".AppleDouble", + ".DS_Store", + ".DocumentRevisions-V100", + ".LSOverride", + ".Spotlight-V100", + ".TemporaryItems", + ".Trashes", + ".VolumeIcon.icns", + // "._*", + ".apdisk", + ".com.apple.timemachine.donotpresent", + ".fseventsd", + "Network Trash Folder", + "Temporary Items", + // Windows + "$RECYCLE.BIN/", + // "*.cab", + // "*.lnk", + // "*.msi", + // "*.msix", + // "*.msm", + // "*.msp", + // "*.stackdump", + "Desktop.ini", + "Thumbs.db", + "Thumbs.db:encryptable", + "desktop.ini", + "ehthumbs.db", + "ehthumbs_vista.db", + // Linux + // "*~", + // ".Trash-*", + ".directory" + // ".fuse_hidden*", + // ".nfs*", +]; +function ft(t) { + const e = new Set(t); + return t.length = 0, e.forEach((r) => { + for (const n of at) + r && (r === n || r.match(RegExp(n))) && e.delete(r); + }), e.size === 0; +} +async function lt(t, e = !0) { + const r = await $(t); + if (r !== !0) + throw new Error(r.message, it(r)); + let n = await S(t); + if (n instanceof Error) + throw n; + return n.length === 0 ? !0 : e ? ft(n) : !1; +} +async function ht(t) { + return f(a.X_OK, t); +} +async function yt(t) { + return f(a.F_OK, t); +} +async function mt(t) { + var e, r; + if (((e = process == null ? void 0 : process.permission) == null ? void 0 : e.has("fs.write")) !== void 0) { + const n = (r = process.permission) == null ? void 0 : r.has("fs.write", t); + if (n !== void 0) + return n; + } + return f(a.W_OK, t); +} +async function m(t, e) { + if (!et().includes(e)) + throw new TypeError(`Digest algorithm [${e}] is not supported.`); + return rt(e).update(await y(t)).digest("hex"); +} +function dt(t) { + let e = [], r; + for (let s = 0; s < 256; s++) { + r = s; + for (let u = 0; u < 8; u++) + r = 1 & r ? 3988292384 ^ r >>> 1 : r >>> 1; + e[s] = r; + } + let n = -1, i = 0; + for (; i < t.length; i++) + n = n >>> 8 ^ e[255 & (n ^ t.charCodeAt(i))]; + return (-1 ^ n) >>> 0; +} +async function _(t) { + return dt((await y(t)).toString("binary")).toString(16); +} +async function D(t) { + return m(t, "md5"); +} +async function P(t) { + return m(t, "sha1"); +} +async function C(t) { + return m(t, "sha256"); +} +async function B(t) { + return m(t, "sha512"); +} +async function Et(t) { + return await Promise.all([ + _(t), + D(t), + P(t), + C(t), + B(t) + ]).then( + ([ + // + e, + r, + n, + i, + s + ]) => ({ crc32: e, md5: r, sha1: n, sha256: i, sha512: s }) + ); +} +async function wt(t, e = !1) { + const r = await x(t); + return e ? r.size.toLocaleString("en").replace(/,/g, "_") : r.size; +} +async function St(t) { + return f(a.X_OK, t); +} +async function gt(t) { + return f(a.R_OK, t); +} +async function Ot(t) { + return f(a.F_OK, t); +} +async function It(t) { + return f(a.W_OK, t); +} +async function bt(t, e = 0) { + try { + return await X(t, e), !0; + } catch (r) { + return r; + } +} +function O(t, ...e) { + let r; + return Array.isArray(t) ? r = t.map((n) => n.toString()) : r = [t.toString()], e.length && (r = r.concat(e.map((n) => n.toString()))), G(R(...r)); +} +async function Nt(t) { + const e = await S(t); + return Array.isArray(e) ? (await Promise.all( + e.map(async (n) => { + const i = O(t, n), [s, u] = await l(i); + if (!u && s.isDirectory()) + return n; + }) + )).filter((n) => n) : e; +} +async function Tt(t) { + const e = await S(t); + return Array.isArray(e) ? (await Promise.all( + e.map(async (n) => { + const i = O(t, n), [s, u] = await l(i); + if (!u && !s.isDirectory()) + return n; + }) + )).filter((n) => n) : e; +} +async function xt(t, e) { + try { + return await H(t, e), !0; + } catch (r) { + return r; + } +} +const I = nt(); +function M(t) { + return I ? String(t).replace(/^~(?=$|\/|\\)/, I) : String(t); +} +function Ft(t, ...e) { + let r; + return Array.isArray(t) ? r = t.map((n) => n.toString()) : r = [t.toString()], e.length && (r = r.concat(e.map((n) => n.toString()))), M(Q(...r)); +} +function vt(t) { + return Z(t).substring(1); +} +function Rt(t) { + return L(t).name; +} +function pt(t) { + return k(t); +} +function At(t) { + return v(t); +} +async function $t(t) { + try { + return (await y(t, "base64")).toString(); + } catch (e) { + return e; + } +} +async function _t(t) { + try { + const e = await y(t, "binary"); + return Buffer.from(e); + } catch (e) { + return e; + } +} +async function W(t) { + try { + return (await y(M(t), "utf8")).toString(); + } catch (e) { + return e; + } +} +const b = process.platform === "win32"; +function Dt(t) { + ["unlink", "chmod", "stat", "lstat", "rmdir", "readdir"].forEach((r) => { + t[r] = t[r] || tt[r]; + }), t.maxBusyTries = t.maxBusyTries || 3; +} +function J(t, e, r) { + let n = 0, i = r, s = e; + typeof s == "function" && (i = s, s = {}), c(t, "remove(): missing path"), c(s, "remove(): invalid options argument provided"), Dt(s), N(t, s, function u(o) { + if (o) { + if ((o.code === "EBUSY" || o.code === "ENOTEMPTY" || o.code === "EPERM") && n < s.maxBusyTries) { + n++; + const d = n * 100; + setTimeout(() => N(t, s, u), d); + return; + } + if (o.code === "ENOENT") { + i(null); + return; + } + } + i(o); + }); +} +function N(t, e, r) { + c(t), c(e), c(typeof r == "function"), e.lstat(t, (n, i) => { + if (n && n.code === "ENOENT") + return r(null); + if (n && n.code === "EPERM" && b) + return T(t, e, n, r); + if (i && i.isDirectory()) + return E(t, e, n, r); + e.unlink(t, (s) => { + if (s) { + if (s.code === "ENOENT") + return r(null); + if (s.code === "EPERM") + return b ? T(t, e, s, r) : E(t, e, s, r); + if (s.code === "EISDIR") + return E(t, e, s, r); + } + return r(s); + }); + }); +} +function T(t, e, r, n) { + return c(t), c(e), c(typeof n == "function"), r && c(r instanceof Error), e.chmod(t, 438, (i) => { + i ? i.code === "ENOENT" ? n(null) : n(r) : e.stat( + t, + (s, u) => { + s ? s.code === "ENOENT" ? n(null) : n(r) : u.isDirectory() ? E(t, e, r, n) : e.unlink(t, n); + } + ); + }), null; +} +function E(t, e, r, n) { + return c(t), c(e), r && c(r instanceof Error), c(typeof n == "function"), e.rmdir(t, (i) => { + i && (i.code === "ENOTEMPTY" || i.code === "EEXIST" || i.code === "EPERM") ? Pt(t, e, n) : i && i.code === "ENOTDIR" ? n(r) : n(i); + }), null; +} +function Pt(t, e, r) { + c(t), c(e), c(typeof r == "function"), e.readdir(t, (n, i) => { + if (n) + return r(n); + let s = i.length, u = null; + if (s === 0) + return e.rmdir(t, r); + i.forEach((o) => { + J(R(t, o), e, (d) => { + if (!u) { + if (d) { + r(u = d); + return; + } + --s, s === 0 && e.rmdir(t, r); + } + }); + }); + }); +} +async function K(t) { + return new Promise((e) => { + J(t, {}, (r) => { + e(r || !0); + }); + }); +} +function Ct(t) { + K(t).then(() => { + }).catch(() => { + }); +} +async function Bt(t, e) { + try { + await U(t, { + force: !0, + recursive: !0, + ...e + }); + } catch { + } +} +async function Mt(t) { + try { + return [await q(t), void 0]; + } catch (e) { + return [void 0, e]; + } +} +async function Wt(t) { + const [e, r] = await l(t); + return r ? !1 : e.isDirectory(); +} +async function V(t) { + const [e, r] = await l(t); + return r ? !1 : e.isFile(); +} +async function Jt(t) { + const [e] = await l(t); + return !!e; +} +async function Kt(t, e, r = null) { + if (!await V(t)) { + const s = await A(t); + if (s !== !0) + return s; + } + const i = await W(t); + return i instanceof Error ? i : new Promise((s, u) => { + setTimeout(() => { + h(t, `${String(i)}${String(e)}`, r).then(() => { + s(!0); + }).catch((o) => { + u(o); + }); + }, 1); + }); +} +function Vt(t) { + return Object.keys(t).sort((e, r) => e.localeCompare(r)); +} +function g(t) { + return t !== null && typeof t == "object" && !Array.isArray(t); +} +function w(t, e = !0) { + if (!g(t)) + return Array.isArray(t) ? t.map((n) => w(n, e)) : t; + const r = Vt(t); + return r.length ? r.reduce((n, i) => (e && g(t[i]) || e && Array.isArray(t[i]) ? n[i] = w(t[i], e) : n[i] = t[i], n), {}) : t; +} +async function jt(t, e, r = null, n) { + let i, s = e; + try { + n ? (n.sort && (g(e) ? s = w(JSON.parse(JSON.stringify(e))) : Array.isArray(e) && (s = JSON.parse(JSON.stringify(e)))), n.space && (i = JSON.stringify(s, null, n.space))) : i = JSON.stringify(s); + } catch (u) { + return u; + } + return h(t, i, r); +} +class Gt { + constructor() { + this.absolutePathFrom = Ft, this.createDirectory = p, this.createFile = A, this.dirIsExecutable = ht, this.dirIsReadable = $, this.dirIsVisible = yt, this.dirIsWritable = mt, this.dirIsEmpty = lt, this.getLinkStatus = Mt, this.getStatus = l, this.isDirExists = Wt, this.isFileExists = V, this.isPathExists = Jt, this.fileExtension = vt, this.fileName = Rt, this.fileNameExt = pt, this.filePath = At, this.fileIsExecutable = St, this.fileIsReadable = gt, this.fileIsVisible = Ot, this.fileIsWritable = It, this.fileTruncate = bt, this.hash = m, this.hashCrc32 = _, this.hashMd5 = D, this.hashMulti = Et, this.hashSha1 = P, this.hashSha256 = C, this.hashSha512 = B, this.listContents = S, this.listDirectories = Nt, this.listFiles = Tt, this.move = xt, this.pathFrom = O, this.readFileToBase64 = $t, this.readFileToBuffer = _t, this.readFileToString = W, this.remove = K, this.removeNonBlocking = Ct, this.removeSilent = Bt, this.size = wt, this.writeFile = h, this.writeFileTail = Kt, this.writeJson = jt; + } +} +export { + Gt as HileSystemLocal, + Ft as absolutePathFrom, + p as createDirectory, + A as createFile, + lt as dirIsEmpty, + ht as dirIsExecutable, + $ as dirIsReadable, + yt as dirIsVisible, + mt as dirIsWritable, + vt as fileExtension, + St as fileIsExecutable, + gt as fileIsReadable, + Ot as fileIsVisible, + It as fileIsWritable, + Rt as fileName, + pt as fileNameExt, + At as filePath, + bt as fileTruncate, + Mt as getLinkStatus, + l as getStatus, + m as hash, + _ as hashCrc32, + D as hashMd5, + Et as hashMulti, + P as hashSha1, + C as hashSha256, + B as hashSha512, + Wt as isDirExists, + V as isFileExists, + Jt as isPathExists, + S as listContents, + Nt as listDirectories, + Tt as listFiles, + xt as move, + O as pathFrom, + $t as readFileToBase64, + _t as readFileToBuffer, + W as readFileToString, + K as remove, + Ct as removeNonBlocking, + Bt as removeSilent, + wt as size, + h as writeFile, + Kt as writeFileTail, + jt as writeJson +}; +//# sourceMappingURL=index.mjs.map diff --git a/dist/index.js.map b/dist/index.js.map index 82d0409..99faf21 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["../src/core/create/createDirectory.js","../src/core/status/getStatus.js","../src/core/write/writeFile.js","../src/core/create/createFile.js","../src/core/access/wrapper.js","../src/core/dir/dirIsReadable.js","../src/core/list/is-system-junk.js","../src/core/list/is-not-system-junk.js","../src/core/list/contents.js","../src/core/dir/dirIsEmpty.js","../src/core/error/errorExtractOptions.js","../src/core/dir/dirIsExecutable.js","../src/core/dir/dirIsVisible.js","../src/core/dir/dirIsWritable.js","../src/core/info/hash.js","../src/core/info/hash-crc32.js","../src/core/info/hash-md5.js","../src/core/info/hash-sha1.js","../src/core/info/hash-sha256.js","../src/core/info/hash-sha512.js","../src/core/info/size.js","../src/core/file/fileIsExecutable.js","../src/core/file/fileIsReadable.js","../src/core/file/fileIsVisible.js","../src/core/file/fileIsWritable.js","../src/core/file/fileTruncate.js","../src/core/path/pathFrom.js","../src/core/list/directories.js","../src/core/list/files.js","../src/core/move/move.js","../src/core/path/absolutePath.js","../src/core/path/absolutePathFrom.js","../src/core/path/fileExtension.js","../src/core/path/fileName.js","../src/core/path/fileNameExt.js","../src/core/path/filePath.js","../src/core/read/readFileToBase64.js","../src/core/read/readFileToBuffer.js","../src/core/read/readFileToString.js","../src/core/remove/remove.js","../src/core/remove/removeNonBlocking.js","../src/core/remove/removeSilent.js","../src/core/status/getLinkStatus.js","../src/core/status/isDirExists.js","../src/core/status/isFileExists.js","../src/core/status/isPathExists.js","../src/core/write/writeFileTail.js","../src/core/write/writeJSON.js","../src/core/HileSystemLocal.js"],"sourcesContent":["import { mkdir } from \"node:fs/promises\";\n\n/**\n * @name createDirectory\n * @description Asynchronous create a directory.\n * @since 0.0.10\n * @async\n * @param {string|Buffer|URL} dirPath\n * @param {number|string=} mode\n * @param {boolean=} recursive\n * @returns {Promise}\n */\nexport async function createDirectory(dirPath, mode = \"0777\", recursive = true) {\n try {\n await mkdir(dirPath, { mode, recursive });\n return true;\n } catch (error) {\n return error;\n }\n}\n","import { stat } from \"node:fs/promises\";\n\n/**\n * @name getStatus\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise>}\n */\nexport async function getStatus(path) {\n try {\n return [await stat(path)];\n } catch (error) {\n return [undefined, error];\n }\n}\n","import { writeFile as writeFileNative } from \"node:fs/promises\";\n\n/**\n * @name writeFile\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.0.10\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n * @example\n * const controller = new AbortController();\n * const { signal } = controller;\n * const data = new Uint8Array(Buffer.from('Hello Node.js'));\n * (async () => {\n * try {\n * await writeFile('message.txt', data, { signal });\n * } catch (error) {\n * // When a request is aborted - error is an AbortError\n * }\n * })();\n * // When the request should be aborted\n * controller.abort();\n */\nexport async function writeFile(filePath, data, options) {\n try {\n await writeFileNative(filePath, data, options);\n return true;\n } catch (error) {\n return error;\n }\n}\n","import { dirname } from \"node:path\";\nimport { readdir } from \"node:fs/promises\";\n\nimport { createDirectory } from \"./createDirectory.js\";\nimport { getStatus } from \"../status/getStatus.js\";\nimport { writeFile } from \"../write/writeFile.js\";\n\n/**\n * @name createFile\n * @description Asynchronous create a file.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {number|string=} mode\n * @returns {Promise}\n */\nexport async function createFile(pathLike, mode = \"0777\") {\n const [status, error] = await getStatus(pathLike);\n if (!error && status.isFile()) {\n return true;\n }\n const dirPath = dirname(pathLike);\n if (error) {\n if (error.code === \"ENOENT\") {\n const dirCreated = await createDirectory(dirPath, mode);\n if (dirCreated !== true) {\n return dirCreated;\n }\n const fileWritten = await writeFile(pathLike, \"\", { mode, flag: \"w\" });\n if (fileWritten !== true) {\n return fileWritten;\n }\n return true;\n }\n }\n if (status.isDirectory()) {\n return await writeFile(pathLike, \"\", { mode, flag: \"w\" });\n } else {\n try {\n await readdir(dirPath);\n return undefined;\n } catch (error) {\n return error;\n }\n }\n}\n","import { access } from \"node:fs/promises\";\n\n/**\n * @name accessWrapper\n * @description Asynchronously tests a user's permissions for the file specified by path.\n * @since 0.0.1\n * @async\n * @param {number} mode\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function accessWrapper(mode, path) {\n try {\n await access(path, mode);\n return true;\n } catch (error) {\n return error;\n }\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name dirIsReadable\n * @description Directory is visible to the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsReadable(pathToDir) {\n return accessWrapper(constants.R_OK, pathToDir);\n}\n","// keep updated https://github.com/sindresorhus/junk\n\nconst ignoreList = [\n // # All\n \"^npm-debug\\\\.log$\", // Error log for npm\n \"^\\\\..*\\\\.swp$\", // Swap file for vim state\n\n // # macOS\n \"^\\\\.DS_Store$\", // Stores custom folder attributes\n \"^\\\\.AppleDouble$\", // Stores additional file resources\n \"^\\\\.LSOverride$\", // Contains the absolute path to the app to be used\n \"^Icon\\\\r$\", // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop\n \"^\\\\._.*\", // Thumbnail\n \"^\\\\.Spotlight-V100(?:$|\\\\/)\", // Directory that might appear on external disk\n \"\\\\.Trashes\", // File that might appear on external disk\n \"^__MACOSX$\", // Resource fork\n\n // # Linux\n \"~$\", // Backup file\n\n // # Windows\n \"^Thumbs\\\\.db$\", // Image file cache\n \"^ehthumbs\\\\.db$\", // Folder config file\n \"^Desktop\\\\.ini$\", // Stores custom folder attributes\n \"@eaDir$\", // Synology Diskstation \"hidden\" folder where the server stores thumbnails\n \"^\\\\$RECYCLE.BIN$\", // Special folder with columns like Date deleted and Original location\n \"^System Volume Information$\",\n];\n\nexport const junkRegex = new RegExp(ignoreList.join(\"|\"));\n\n/**\n * @name isSystemJunk\n * @description Returns true if filename matches a system junk file.\n * @param {string} [fileName]\n * @returns {boolean}\n * @since 0.2.0\n */\nexport function isSystemJunk(fileName) {\n return junkRegex.test(fileName);\n}\n","import { isSystemJunk } from \"./is-system-junk.js\";\n\n/**\n * @name isNotSystemJunk\n * @description Returns true if filename matches a system junk file.\n * @param {string} [fileName]\n * @returns {boolean}\n * @since 0.2.0\n */\nexport function isNotSystemJunk(fileName) {\n return !isSystemJunk(fileName);\n}\n","import { readdir } from \"node:fs/promises\";\n\nimport { isNotSystemJunk } from \"./is-not-system-junk.js\";\n\n/**\n * @name listContents\n * @description Lists files and directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean} [ignoreJunk=true]\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\nexport async function listContents(pathToDir, ignoreJunk = true) {\n try {\n const contents = await readdir(pathToDir);\n if (ignoreJunk) {\n return contents.filter(isNotSystemJunk);\n }\n return contents;\n } catch (error) {\n return error;\n }\n}\n","import { errorExtractOptions } from \"../error/errorExtractOptions.js\";\nimport { dirIsReadable } from \"./dirIsReadable.js\";\nimport { listContents } from \"../list/contents.js\";\n\nconst EXCLUDE = [\n // macOS\n \".AppleDB\",\n \".AppleDesktop\",\n \".AppleDouble\",\n \".DS_Store\",\n \".DocumentRevisions-V100\",\n \".LSOverride\",\n \".Spotlight-V100\",\n \".TemporaryItems\",\n \".Trashes\",\n \".VolumeIcon.icns\",\n // \"._*\",\n \".apdisk\",\n \".com.apple.timemachine.donotpresent\",\n \".fseventsd\",\n \"Network Trash Folder\",\n \"Temporary Items\",\n // Windows\n \"$RECYCLE.BIN/\",\n // \"*.cab\",\n // \"*.lnk\",\n // \"*.msi\",\n // \"*.msix\",\n // \"*.msm\",\n // \"*.msp\",\n // \"*.stackdump\",\n \"Desktop.ini\",\n \"Thumbs.db\",\n \"Thumbs.db:encryptable\",\n \"desktop.ini\",\n \"ehthumbs.db\",\n \"ehthumbs_vista.db\",\n // Linux\n // \"*~\",\n // \".Trash-*\",\n \".directory\",\n // \".fuse_hidden*\",\n // \".nfs*\",\n];\n\n/**\n * @name isEmptyContent\n * @param {Array.} listOfDirsAndFiles\n * @returns {boolean}\n */\nfunction isEmptyContent(listOfDirsAndFiles) {\n const content = new Set(listOfDirsAndFiles);\n listOfDirsAndFiles.length = 0;\n content.forEach((dirOrFileName) => {\n for (const nameToExclude of EXCLUDE) {\n if (!dirOrFileName) {\n continue;\n }\n if (dirOrFileName === nameToExclude || dirOrFileName.match(RegExp(nameToExclude))) {\n content.delete(dirOrFileName);\n }\n }\n });\n return content.size === 0;\n}\n\n/**\n * @name dirIsEmpty\n * @description Check if a directory is empty\n * @since 0.1.33\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean=} excludeSystemFiles\n * @returns {Promise}\n * @throws {Error} If path is not a dir or is not readable.\n */\nexport async function dirIsEmpty(pathToDir, excludeSystemFiles = true) {\n const isReadableOrError = await dirIsReadable(pathToDir);\n if (isReadableOrError !== true) {\n throw new Error(isReadableOrError.message, errorExtractOptions(isReadableOrError));\n }\n let listOfDirsAndFiles = await listContents(pathToDir);\n if (listOfDirsAndFiles instanceof Error) {\n throw listOfDirsAndFiles;\n }\n if (listOfDirsAndFiles.length === 0) {\n return true;\n }\n if (!excludeSystemFiles) {\n return false;\n }\n return isEmptyContent(listOfDirsAndFiles);\n}\n","/**\n * @name errorExtractOptions\n * @param {Error} error\n * @returns {{ cause: Error } | { cause: { code?: string, values?: any[] | { [key: string]: any } }}}\n */\nexport function errorExtractOptions(error) {\n if (!(error instanceof Error)) {\n return { cause: error };\n }\n if (\"code\" in error && \"errno\" in error && \"path\" in error && \"syscall\" in error) {\n return {\n cause: {\n code: error.code,\n values: {\n errno: error.errno,\n path: error.path,\n syscall: error.syscall,\n },\n },\n };\n }\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name dirIsExecutable\n * @description Directory can be executed by the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsExecutable(pathToDir) {\n return accessWrapper(constants.X_OK, pathToDir);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name dirIsVisible\n * @description Directory is visible to the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsVisible(pathToDir) {\n return accessWrapper(constants.F_OK, pathToDir);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name dirIsWritable\n * @description Directory can be written by the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsWritable(pathToDir) {\n return accessWrapper(constants.W_OK, pathToDir);\n}\n","import { createHash, getHashes } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\n\n/**\n * @name hash\n * @description Calculate hash.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {string} algorithm\n * @returns {Promise}\n * @throws {TypeError} If algorithm is not supported.\n */\nexport async function hash(pathToFile, algorithm) {\n if (!getHashes().includes(algorithm)) {\n throw new TypeError(`Digest algorithm [${algorithm}] is not supported.`);\n }\n return createHash(algorithm)\n .update(await readFile(pathToFile))\n .digest(\"hex\");\n}\n","import { readFile } from \"node:fs/promises\";\n\nfunction crc32(text) {\n let chars = [];\n let actual;\n for (let current = 0; current < 256; current++) {\n actual = current;\n for (let f = 0; f < 8; f++) {\n actual = 1 & actual ? 3988292384 ^ (actual >>> 1) : actual >>> 1;\n }\n chars[current] = actual;\n }\n let number = -1;\n let index = 0;\n for (; index < text.length; index++) {\n number = (number >>> 8) ^ chars[255 & (number ^ text.charCodeAt(index))];\n }\n return (-1 ^ number) >>> 0;\n}\n\n/**\n * @name hashCrc32\n * @description CRC32.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashCrc32(pathToFile) {\n return crc32((await readFile(pathToFile)).toString(\"binary\")).toString(16);\n}\n","import { hash } from \"./hash.js\";\n\n/**\n * @name hashMd5\n * @description MD5.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashMd5(pathToFile) {\n return hash(pathToFile, \"md5\");\n}\n","import { hash } from \"./hash.js\";\n\n/**\n * @name hashSha1\n * @description SHA-1.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha1(pathToFile) {\n return hash(pathToFile, \"sha1\");\n}\n","import { hash } from \"./hash.js\";\n\n/**\n * @name hashSha256\n * @description SHA-256.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha256(pathToFile) {\n return hash(pathToFile, \"sha256\");\n}\n","import { hash } from \"./hash.js\";\n\n/**\n * @name hashSha512\n * @description SHA-512.\n * @since 0.2.6\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha512(pathToFile) {\n return hash(pathToFile, \"sha512\");\n}\n","import { stat } from \"node:fs/promises\";\n\n/**\n * @name size\n * @description File size in bytes.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {boolean=} [asString=false]\n * @returns {Promise}\n */\nexport async function size(pathToFile, asString = false) {\n const fileStats = await stat(pathToFile);\n if (!asString) {\n return fileStats.size;\n }\n return fileStats.size.toLocaleString(\"en\").replace(/,/g, \"_\");\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name fileIsExecutable\n * @description File can be executed by the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsExecutable(pathToFile) {\n return accessWrapper(constants.X_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name fileIsReadable\n * @description File is visible to the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsReadable(pathToFile) {\n return accessWrapper(constants.R_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name fileIsVisible\n * @description File is visible to the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsVisible(pathToFile) {\n return accessWrapper(constants.F_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name fileIsWritable\n * @description File can be written by the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsWritable(pathToFile) {\n return accessWrapper(constants.W_OK, pathToFile);\n}\n","import { truncate } from \"node:fs/promises\";\n\n/**\n * @name fileTruncate\n * @description Truncate a file to a specified length\n * @since 0.0.6\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {number=} length\n * @returns {Promise}\n */\nexport async function fileTruncate(pathToFile, length = 0) {\n try {\n await truncate(pathToFile, length);\n return true;\n } catch (error) {\n return error;\n }\n}\n","import { join, normalize } from \"node:path\";\n\n/**\n * @name pathFrom\n * @description Join all arguments together and normalize the resulting path.\n * @since 0.1.3\n * @param {string|Array.} paths\n * @param {...string} morePaths\n * @returns {string}\n */\nexport function pathFrom(paths, ...morePaths) {\n let routes;\n if (Array.isArray(paths)) {\n routes = paths.map((path) => path.toString());\n } else {\n routes = [paths.toString()];\n }\n if (morePaths.length) {\n routes = routes.concat(morePaths.map((path) => path.toString()));\n }\n return normalize(join(...routes));\n}\n","import { getStatus } from \"../status/getStatus.js\";\nimport { listContents } from \"./contents.js\";\nimport { pathFrom } from \"../path/pathFrom.js\";\n\n/**\n * @name listDirectories\n * @description Lists directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\nexport async function listDirectories(pathToDir) {\n const contents = await listContents(pathToDir);\n if (!Array.isArray(contents)) {\n return contents;\n }\n const directories = await Promise.all(\n contents.map(async (content) => {\n const contentPath = pathFrom(pathToDir, content);\n const [status, error] = await getStatus(contentPath);\n if (error) {\n return undefined;\n }\n if (!status.isDirectory()) {\n return undefined;\n }\n return content;\n }),\n );\n return directories.filter((content) => content);\n}\n","import { getStatus } from \"../status/getStatus.js\";\nimport { listContents } from \"./contents.js\";\nimport { pathFrom } from \"../path/pathFrom.js\";\n\n/**\n * @name listFiles\n * @description Lists files in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\nexport async function listFiles(pathToDir) {\n const contents = await listContents(pathToDir);\n if (!Array.isArray(contents)) {\n return contents;\n }\n const files = await Promise.all(\n contents.map(async (content) => {\n const contentPath = pathFrom(pathToDir, content);\n const [status, error] = await getStatus(contentPath);\n if (error) {\n return undefined;\n }\n if (status.isDirectory()) {\n return undefined;\n }\n return content;\n }),\n );\n return files.filter((content) => content);\n}\n","import { rename } from \"node:fs/promises\";\n\n/**\n * @name move\n * @description Change the name or location of a file or directory.\n * @since 0.1.29\n * @param {string} pathFrom\n * @param {string} pathTo\n * @returns {Promise}\n */\nexport async function move(pathFrom, pathTo) {\n try {\n await rename(pathFrom, pathTo);\n return true;\n } catch (error) {\n return error;\n }\n}\n","import os from \"os\";\n\nconst HOME_DIRECTORY = os.homedir();\n\n/**\n * @description deConvert a tilde path to an absolute path: ~/projects β†’ /Users/anon/projects\n * @param {string} pathWithTilde\n * @returns {string}\n */\nexport function absolutePath(pathWithTilde) {\n if (HOME_DIRECTORY) {\n return String(pathWithTilde).replace(/^~(?=$|\\/|\\\\)/, HOME_DIRECTORY);\n }\n return String(pathWithTilde);\n}\n","import { resolve } from \"node:path\";\n\nimport { absolutePath } from \"./absolutePath.js\";\n\n/**\n * @name absolutePathFrom\n * @description Join all arguments together and normalize the resulting path.\n * Creates absolute path from right to left until an absolute path is constructed.\n * @since 0.1.5\n * @param {string|Array.} paths\n * @param {...string} morePaths\n * @returns {string}\n */\nexport function absolutePathFrom(paths, ...morePaths) {\n let routes;\n if (Array.isArray(paths)) {\n routes = paths.map((path) => path.toString());\n } else {\n routes = [paths.toString()];\n }\n if (morePaths.length) {\n routes = routes.concat(morePaths.map((path) => path.toString()));\n }\n return absolutePath(resolve(...routes));\n}\n","import { extname } from \"node:path\";\n\n/**\n * @name fileExtension\n * @description Get file extension.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileExtension(path) {\n return extname(path).substring(1);\n}\n","import { parse } from \"node:path\";\n\n/**\n * @name fileName\n * @description Return the file name without extension.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileName(path) {\n return parse(path).name;\n}\n","import { basename } from \"node:path\";\n\n/**\n * @name fileNameExt\n * @description Return the last portion of a path.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileNameExt(path) {\n return basename(path);\n}\n","import { dirname } from \"node:path\";\n\n/**\n * @name filePath\n * @description Return the directory name of a path.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function filePath(path) {\n return dirname(path);\n}\n","import { readFile } from \"node:fs/promises\";\n\n/**\n * @name readFileToBase64\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.21\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToBase64(pathLike) {\n try {\n const result = await readFile(pathLike, \"base64\");\n return result.toString();\n } catch (error) {\n return error;\n }\n}\n","import { readFile } from \"node:fs/promises\";\n\n/**\n * @name readFileToBuffer\n * @description Asynchronously reads the entire contents of a file into buffer.\n * @since 0.1.19\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToBuffer(pathLike) {\n try {\n const result = await readFile(pathLike, \"binary\");\n return Buffer.from(result);\n } catch (error) {\n return error;\n }\n}\n","import { readFile } from \"node:fs/promises\";\n\nimport { absolutePath } from \"../path/absolutePath.js\";\n\n/**\n * @name readFileToString\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.7\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToString(pathLike) {\n try {\n const result = await readFile(absolutePath(pathLike), \"utf8\");\n return result.toString();\n } catch (error) {\n return error;\n }\n}\n","import fs from \"fs\";\nimport assert from \"node:assert\";\nimport { join } from \"node:path\";\n\nconst IS_WINDOWS = process.platform === \"win32\";\n\n/**\n * @param {object} options\n */\nfunction defaults(options) {\n const methods = [\"unlink\", \"chmod\", \"stat\", \"lstat\", \"rmdir\", \"readdir\"];\n methods.forEach((method) => {\n options[method] = options[method] || fs[method];\n });\n options.maxBusyTries = options.maxBusyTries || 3;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction rimraf(pathLike, options, callback) {\n let busyTries = 0;\n let localCallback = callback;\n let localOptions = options;\n if (typeof localOptions === \"function\") {\n localCallback = localOptions;\n localOptions = {};\n }\n assert(pathLike, \"remove(): missing path\");\n assert.strictEqual(typeof pathLike, \"string\", \"remove(): path should be a string\");\n assert.strictEqual(typeof localCallback, \"function\", \"remove(): callback function required\");\n assert(localOptions, \"remove(): invalid options argument provided\");\n assert.strictEqual(typeof localOptions, \"object\", \"remove(): options should be object\");\n defaults(localOptions);\n rimraf_(pathLike, localOptions, function callbackRimraf(error) {\n if (error) {\n if (\n (error.code === \"EBUSY\" || error.code === \"ENOTEMPTY\" || error.code === \"EPERM\") &&\n busyTries < localOptions.maxBusyTries\n ) {\n busyTries++;\n const time = busyTries * 100;\n setTimeout(() => rimraf_(pathLike, localOptions, callbackRimraf), time);\n return;\n }\n if (error.code === \"ENOENT\") {\n localCallback(null);\n return;\n }\n }\n localCallback(error);\n });\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction rimraf_(pathLike, options, callback) {\n assert(pathLike);\n assert(options);\n assert(typeof callback === \"function\");\n options.lstat(pathLike, (error, stats) => {\n if (error && error.code === \"ENOENT\") {\n return callback(null);\n }\n if (error && error.code === \"EPERM\" && IS_WINDOWS) {\n return fixWinEPERM(pathLike, options, error, callback);\n }\n if (stats && stats.isDirectory()) {\n return rmdir(pathLike, options, error, callback);\n }\n options.unlink(pathLike, (error) => {\n if (error) {\n if (error.code === \"ENOENT\") {\n return callback(null);\n }\n if (error.code === \"EPERM\") {\n if (IS_WINDOWS) {\n return fixWinEPERM(pathLike, options, error, callback);\n } else {\n return rmdir(pathLike, options, error, callback);\n }\n }\n if (error.code === \"EISDIR\") {\n return rmdir(pathLike, options, error, callback);\n }\n }\n return callback(error);\n });\n });\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Error|null} error\n * @param {Function=} callback\n * @returns {null}\n */\nfunction fixWinEPERM(pathLike, options, error, callback) {\n assert(pathLike);\n assert(options);\n assert(typeof callback === \"function\");\n if (error) {\n assert(error instanceof Error);\n }\n options.chmod(pathLike, 0o666, (errorChMod) => {\n if (errorChMod) {\n if (errorChMod.code === \"ENOENT\") {\n callback(null);\n } else {\n callback(error);\n }\n } else {\n options.stat(pathLike, (errorStat, stats) => {\n if (errorStat) {\n if (errorStat.code === \"ENOENT\") {\n callback(null);\n } else {\n callback(error);\n }\n } else if (stats.isDirectory()) {\n rmdir(pathLike, options, error, callback);\n } else {\n options.unlink(pathLike, callback);\n }\n });\n }\n });\n return null;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Error|null} originalError\n * @param {Function=} callback\n * @returns {null}\n */\nfunction rmdir(pathLike, options, originalError, callback) {\n assert(pathLike);\n assert(options);\n if (originalError) {\n assert(originalError instanceof Error);\n }\n assert(typeof callback === \"function\");\n options.rmdir(pathLike, (error) => {\n if (error && (error.code === \"ENOTEMPTY\" || error.code === \"EEXIST\" || error.code === \"EPERM\")) {\n removeSubPath(pathLike, options, callback);\n } else if (error && error.code === \"ENOTDIR\") {\n callback(originalError);\n } else {\n callback(error);\n }\n });\n return null;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction removeSubPath(pathLike, options, callback) {\n assert(pathLike);\n assert(options);\n assert(typeof callback === \"function\");\n options.readdir(pathLike, (error, files) => {\n if (error) {\n return callback(error);\n }\n let count = files.length;\n let errState;\n if (count === 0) {\n return options.rmdir(pathLike, callback);\n }\n files.forEach((filePath) => {\n rimraf(join(pathLike, filePath), options, (error) => {\n if (errState) {\n return;\n }\n if (error) {\n callback((errState = error));\n return;\n }\n --count;\n if (count === 0) {\n options.rmdir(pathLike, callback);\n }\n });\n });\n });\n}\n\n/**\n * @name remove\n * @description Removes a file or directory.\n * @since 0.1.1\n * @async\n * @param {string} pathLike\n * @returns {Promise}\n */\nexport async function remove(pathLike) {\n return new Promise((resolve) => {\n rimraf(pathLike, {}, (error) => {\n if (error) {\n resolve(error);\n } else {\n resolve();\n }\n });\n });\n}\n","import { remove } from \"./remove.js\";\n\n/**\n * @name removeNonBlocking\n * @description Non-blocking remove of a file or directory.\n * @since 0.1.18\n * @param {string|Buffer|URL} pathLike\n * @returns {void}\n */\nexport function removeNonBlocking(pathLike) {\n remove(pathLike)\n .then(() => undefined)\n .catch(() => undefined); // don't put it into next tick\n}\n","import { rm } from \"node:fs/promises\";\n\n/**\n * @name removeSilent\n * @description Removes files and directories (modeled on the standard POSIX rm utility).\n * @summary Minimum Node version 14.14.0\n * @since 0.1.36\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {object=} options\n * @returns {Promise}\n */\nexport async function removeSilent(pathLike, options) {\n try {\n await rm(pathLike, {\n force: true,\n recursive: true,\n ...options,\n });\n } catch (__error) {\n //\n }\n}\n","import { lstat } from \"node:fs/promises\";\n\n/**\n * @name getLinkStatus\n * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to.\n * @url http://man7.org/linux/man-pages/man2/lstat.2.html\n * @since 1.1.0\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise>}\n */\nexport async function getLinkStatus(path) {\n try {\n return [await lstat(path)];\n } catch (error) {\n return [undefined, error];\n }\n}\n","import { getStatus } from \"./getStatus.js\";\n\n/**\n * @name isDirExists\n * @description Get directory status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isDirExists(path) {\n const [status, error] = await getStatus(path);\n if (error) {\n return false;\n }\n return status.isDirectory();\n}\n","import { getStatus } from \"./getStatus.js\";\n\n/**\n * @name isFileExists\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isFileExists(path) {\n const [status, error] = await getStatus(path);\n if (error) {\n return false;\n }\n return status.isFile();\n}\n","import { getStatus } from \"./getStatus.js\";\n\n/**\n * @name isPathExists\n * @description Get path status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isPathExists(path) {\n const [status] = await getStatus(path);\n return Boolean(status);\n}\n","import { createFile } from \"../create/createFile.js\";\nimport { isFileExists } from \"../status/isFileExists.js\";\nimport { readFileToString } from \"../read/readFileToString.js\";\nimport { writeFile } from \"./writeFile.js\";\n\n/**\n * @name writeFileTail\n * @description Asynchronously writes data to the end of a file.\n * @since 1.0.1\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\nexport async function writeFileTail(filePath, data, options) {\n const isFileExist = await isFileExists(filePath);\n if (isFileExist === false) {\n const isFileCreatedOrError = await createFile(filePath);\n if (isFileCreatedOrError !== true) {\n return isFileCreatedOrError;\n }\n }\n const contentOrError = await readFileToString(filePath);\n if (contentOrError instanceof Error) {\n return contentOrError;\n }\n return new Promise((resolve, reject) => {\n setTimeout(() => {\n writeFile(filePath, `${String(contentOrError)}${String(data)}`, options)\n .then(() => {\n resolve(true);\n })\n .catch((error) => {\n reject(error);\n });\n }, 1);\n });\n}\n","import { writeFile } from \"./writeFile.js\";\n\n/**\n * @name objectKeys\n * @param {object} object\n * @returns {Array.}\n */\nfunction objectKeys(object) {\n return Object.keys(object).sort((alpha, beta) => alpha.localeCompare(beta));\n}\n\n/**\n * name isObjectLike\n * @param {*} value\n * @returns {boolean}\n */\nfunction isObjectLike(value) {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\n/**\n * @name collectionSortKeys\n * @param {*} value\n * @param {boolean=} [isDeep=true]\n * @returns {*}\n */\nfunction collectionSortKeys(value, isDeep = true) {\n if (!isObjectLike(value)) {\n if (Array.isArray(value)) {\n return value.map((arrayValue) => collectionSortKeys(arrayValue, isDeep));\n }\n return value;\n }\n const keys = objectKeys(value);\n if (!keys.length) {\n return value;\n }\n return keys.reduce((sorted, key) => {\n if (isDeep && isObjectLike(value[key])) {\n sorted[key] = collectionSortKeys(value[key], isDeep);\n } else if (isDeep && Array.isArray(value[key])) {\n sorted[key] = collectionSortKeys(value[key], isDeep);\n } else {\n sorted[key] = value[key];\n }\n return sorted;\n }, {});\n}\n\n/**\n * @name writeJSON\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.1.25\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {*} data\n * @param {*|null|string=} options\n * @param {{sort: boolean, space: number|string}=} configuration\n * @returns {Promise}\n */\nexport async function writeJSON(filePath, data, options, configuration) {\n let json;\n let stringify = data;\n try {\n if (configuration) {\n if (configuration.sort) {\n if (isObjectLike(data)) {\n stringify = collectionSortKeys(JSON.parse(JSON.stringify(data)));\n } else if (Array.isArray(data)) {\n stringify = JSON.parse(JSON.stringify(data));\n } else {\n stringify = data;\n }\n }\n if (configuration.space) {\n json = JSON.stringify(stringify, null, configuration.space);\n }\n } else {\n json = JSON.stringify(stringify);\n }\n } catch (error) {\n return error;\n }\n return writeFile(filePath, json, options);\n}\n","import { absolutePathFrom } from \"./path/absolutePathFrom.js\";\n\nimport { createDirectory } from \"./create/createDirectory.js\";\nimport { createFile } from \"./create/createFile.js\";\n\nimport { dirIsExecutable } from \"./dir/dirIsExecutable.js\";\nimport { dirIsReadable } from \"./dir/dirIsReadable.js\";\nimport { dirIsVisible } from \"./dir/dirIsVisible.js\";\nimport { dirIsWritable } from \"./dir/dirIsWritable.js\";\nimport { dirIsEmpty } from \"./dir/dirIsEmpty.js\";\n\nimport { fileExtension } from \"./path/fileExtension.js\";\nimport { fileIsExecutable } from \"./file/fileIsExecutable.js\";\nimport { fileIsReadable } from \"./file/fileIsReadable.js\";\nimport { fileIsVisible } from \"./file/fileIsVisible.js\";\nimport { fileIsWritable } from \"./file/fileIsWritable.js\";\nimport { fileName } from \"./path/fileName.js\";\nimport { fileNameExt } from \"./path/fileNameExt.js\";\nimport { filePath } from \"./path/filePath.js\";\nimport { fileTruncate } from \"./file/fileTruncate.js\";\n\nimport { listContents } from \"./list/contents.js\";\nimport { listDirectories } from \"./list/directories.js\";\nimport { listFiles } from \"./list/files.js\";\n\nimport { getLinkStatus } from \"./status/getLinkStatus.js\";\nimport { getStatus } from \"./status/getStatus.js\";\n\nimport { isDirExists } from \"./status/isDirExists.js\";\nimport { isFileExists } from \"./status/isFileExists.js\";\nimport { isPathExists } from \"./status/isPathExists.js\";\n\nimport { move } from \"./move/move.js\";\n\nimport { pathFrom } from \"./path/pathFrom.js\";\n\nimport { readFileToBase64 } from \"./read/readFileToBase64.js\";\nimport { readFileToBuffer } from \"./read/readFileToBuffer.js\";\nimport { readFileToString } from \"./read/readFileToString.js\";\nimport { remove } from \"./remove/remove.js\";\nimport { removeNonBlocking } from \"./remove/removeNonBlocking.js\";\nimport { removeSilent } from \"./remove/removeSilent.js\";\n\nimport { writeFile } from \"./write/writeFile.js\";\nimport { writeFileTail } from \"./write/writeFileTail.js\";\nimport { writeJSON } from \"./write/writeJSON.js\";\n\nimport { hash } from \"./info/hash.js\";\nimport { hashCrc32 } from \"./info/hash-crc32.js\";\nimport { hashMd5 } from \"./info/hash-md5.js\";\nimport { hashSha1 } from \"./info/hash-sha1.js\";\nimport { hashSha256 } from \"./info/hash-sha256.js\";\nimport { hashSha512 } from \"./info/hash-sha512.js\";\n\nimport { size } from \"./info/size.js\";\n\nexport class HileSystemLocal {\n /**\n * @name absolutePathFrom\n * @description Join all arguments together and normalize the resulting path.\n * reates absolute path from right to left until an absolute path is constructed.\n * @since 0.1.5\n * @public\n * @param {string|Array.} paths\n * @param {...string} morePaths\n * @returns {string}\n */\n absolutePathFrom = absolutePathFrom;\n /**\n * @name createDirectory\n * @description Asynchronous create a directory.\n * @since 0.0.10\n * @async\n * @public\n * @param {string|Buffer|URL} dirPath\n * @param {number|string=} mode\n * @param {boolean=} recursive\n * @returns {Promise}\n */\n createDirectory = createDirectory;\n /**\n * @name createFile\n * @description Asynchronous create a file.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} pathLike\n * @param {number|string=} mode\n * @returns {Promise}\n */\n createFile = createFile;\n /**\n * @name dirIsExecutable\n * @description Directory can be executed by the calling process\n * @since 0.0.5\n * @async\n * @public\n * @param {string} pathToDir\n * @returns {Promise}\n */\n dirIsExecutable = dirIsExecutable;\n /**\n * @name dirIsReadable\n * @description Directory is visible to the calling process\n * @since 0.0.1\n * @async\n * @public\n * @param {string} pathToDir\n * @returns {Promise}\n */\n dirIsReadable = dirIsReadable;\n /**\n * @name dirIsVisible\n * @description Directory is visible to the calling process\n * @since 0.0.5\n * @async\n * @public\n * @param {string} pathToDir\n * @returns {Promise}\n */\n dirIsVisible = dirIsVisible;\n /**\n * @name dirIsWritable\n * @description Directory can be written by the calling process\n * @since 0.0.1\n * @async\n * @public\n * @param {string} pathToDir\n * @returns {Promise}\n */\n dirIsWritable = dirIsWritable;\n /**\n * @name dirIsEmpty\n * @description Check if a directory is empty\n * @since 0.1.33\n * @async\n * @public\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean=} excludeSystemFiles\n * @returns {Promise}\n * @throws {Error} If path is not a dir or is not readable.\n */\n dirIsEmpty = dirIsEmpty;\n /**\n * @name getLinkStatus\n * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to.\n * @url http://man7.org/linux/man-pages/man2/lstat.2.html\n * @since 1.1.0\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise>}\n */\n getLinkStatus = getLinkStatus;\n /**\n * @name getStatus\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} path\n * @returns {Promise>}\n */\n getStatus = getStatus;\n /**\n * @name isDirExists\n * @description Get directory status.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\n isDirExists = isDirExists;\n /**\n * @name isFileExists\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\n isFileExists = isFileExists;\n /**\n * @name isPathExists\n * @description Get path status.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\n isPathExists = isPathExists;\n /**\n * @name fileExtension\n * @description Get file extension.\n * @since 0.1.1\n * @public\n * @param {string} path\n * @returns {string}\n */\n fileExtension = fileExtension;\n /**\n * @name fileName\n * @description Return the file name without extension.\n * @since 0.1.1\n * @public\n * @param {string} path\n * @returns {string}\n */\n fileName = fileName;\n /**\n * @name fileNameExt\n * @description Return the last portion of a path.\n * @since 0.1.1\n * @public\n * @param {string} path\n * @returns {string}\n */\n fileNameExt = fileNameExt;\n /**\n * @name filePath\n * @description Return the directory name of a path.\n * @since 0.1.1\n * @public\n * @param {string} path\n * @returns {string}\n */\n filePath = filePath;\n /**\n * @name fileIsExecutable\n * @description File can be executed by the calling process\n * @since 0.0.5\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n fileIsExecutable = fileIsExecutable;\n /**\n * @name fileIsReadable\n * @description File is visible to the calling process\n * @since 0.0.1\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n fileIsReadable = fileIsReadable;\n /**\n * @name fileIsVisible\n * @description File is visible to the calling process\n * @since 0.0.5\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n fileIsVisible = fileIsVisible;\n /**\n * @name fileIsWritable\n * @description File can be written by the calling process\n * @since 0.0.1\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n fileIsWritable = fileIsWritable;\n /**\n * @name fileTruncate\n * @description Truncate a file to a specified length\n * @since 0.0.6\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @param {number=} length\n * @returns {Promise}\n */\n fileTruncate = fileTruncate;\n /**\n * @name hash\n * @description Calculate hash.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @param {string} algorithm\n * @returns {Promise}\n * @throws {TypeError} If algorithm is not supported.\n */\n hash = hash;\n /**\n * @name hashCrc32\n * @description CRC32.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashCrc32 = hashCrc32;\n /**\n * @name hashMd5\n * @description MD5.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashMd5 = hashMd5;\n /**\n * @name hashSha1\n * @description SHA-1.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashSha1 = hashSha1;\n /**\n * @name hashSha256\n * @description SHA-256.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashSha256 = hashSha256;\n /**\n * @name hashSha512\n * @description SHA-512.\n * @since 0.2.6\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashSha512 = hashSha512;\n /**\n * @name listContents\n * @description Lists files and directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\n listContents = listContents;\n /**\n * @name listDirectories\n * @description Lists directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\n listDirectories = listDirectories;\n /**\n * @name listFiles\n * @description Lists files in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\n listFiles = listFiles;\n /**\n * @name move\n * @description Change the name or location of a file or directory.\n * @since 0.1.29\n * @public\n * @param {string} pathFrom\n * @param {string} pathTo\n * @returns {Promise}\n */\n move = move;\n /**\n * @name pathFrom\n * @description Join all arguments together and normalize the resulting path.\n * @since 0.1.3\n * @public\n * @param {string|Array.} paths\n * @param {...string} morePaths\n * @returns {string}\n */\n pathFrom = pathFrom;\n /**\n * @name readFileToBase64\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.21\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\n readFileToBase64 = readFileToBase64;\n /**\n * @name readFileToBuffer\n * @description Asynchronously reads the entire contents of a file into buffer.\n * @since 0.1.19\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\n readFileToBuffer = readFileToBuffer;\n /**\n * @name readFileToString\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.7\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\n readFileToString = readFileToString;\n /**\n * @name remove\n * @description Removes a file or directory.\n * @since 0.1.1\n * @async\n * @public\n * @param {string} pathLike\n * @returns {Promise}\n */\n remove = remove;\n /**\n * @name removeNonBlocking\n * @description Non-blocking remove of a file or directory.\n * @since 0.1.18\n * @public\n * @param {string} pathLike\n * @returns {void}\n */\n removeNonBlocking = removeNonBlocking;\n /**\n * @name removeSilent\n * @description Removes files and directories (modeled on the standard POSIX rm utility).\n * @summary Minimum Node version 14.14.0\n * @since 0.1.36\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {object=} options\n * @returns {Promise}\n */\n removeSilent = removeSilent;\n /**\n * @name size\n * @description File size in bytes.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @param {boolean=} [asString=false]\n * @returns {Promise}\n */\n size = size;\n /**\n * @name writeFile\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.0.10\n * @async\n * @public\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\n writeFile = writeFile;\n /**\n * @name writeFileTail\n * @description Asynchronously writes data to the end of a file.\n * @since 1.0.1\n * @async\n * @public\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\n writeFileTail = writeFileTail;\n /**\n * @name writeJSON\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.1.25\n * @async\n * @public\n * @param {string|Buffer|URL} filePath\n * @param {*} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\n writeJSON = writeJSON;\n}\n"],"names":["async","createDirectory","dirPath","mode","recursive","mkdir","error","getStatus","path","stat","undefined","writeFile","filePath","data","options","writeFileNative","createFile","pathLike","status","isFile","dirname","code","dirCreated","fileWritten","flag","isDirectory","readdir","accessWrapper","access","dirIsReadable","pathToDir","constants","R_OK","junkRegex","RegExp","join","isNotSystemJunk","fileName","isSystemJunk","test","listContents","ignoreJunk","contents","filter","EXCLUDE","dirIsEmpty","excludeSystemFiles","isReadableOrError","Error","message","errorExtractOptions","cause","values","errno","syscall","listOfDirsAndFiles","length","isEmptyContent","content","Set","forEach","dirOrFileName","nameToExclude","match","delete","size","dirIsExecutable","X_OK","dirIsVisible","F_OK","dirIsWritable","W_OK","hash","pathToFile","algorithm","getHashes","includes","TypeError","createHash","update","readFile","digest","hashCrc32","crc32","text","actual","chars","current","f","number","index","charCodeAt","toString","hashMd5","hashSha1","hashSha256","hashSha512","asString","fileStats","toLocaleString","replace","fileIsExecutable","fileIsReadable","fileIsVisible","fileIsWritable","fileTruncate","truncate","pathFrom","paths","morePaths","routes","Array","isArray","map","concat","normalize","listDirectories","Promise","all","contentPath","listFiles","move","pathTo","rename","HOME_DIRECTORY","os","homedir","absolutePath","pathWithTilde","String","absolutePathFrom","resolve","fileExtension","extname","substring","parse","name","fileNameExt","basename","readFileToBase64","readFileToBuffer","result","Buffer","from","readFileToString","IS_WINDOWS","process","platform","rimraf","callback","busyTries","localCallback","localOptions","assert","strictEqual","defaults","method","fs","maxBusyTries","rimraf_","callbackRimraf","setTimeout","lstat","stats","fixWinEPERM","rmdir","unlink","chmod","errorChMod","errorStat","originalError","removeSubPath","files","errState","count","remove","removeNonBlocking","then","catch","removeSilent","rm","force","__error","getLinkStatus","isDirExists","isFileExists","isPathExists","Boolean","writeFileTail","isFileCreatedOrError","contentOrError","reject","isObjectLike","value","collectionSortKeys","isDeep","arrayValue","keys","objectKeys","object","Object","sort","alpha","beta","localeCompare","reduce","sorted","key","writeJSON","configuration","json","stringify","JSON","space","HileSystemLocal","constructor","_defineProperty"],"mappings":"2WAYOA,eAAeC,gBAAgBC,EAASC,EAAO,OAAQC,GAAY,GACxE,IAEE,aADMC,QAAMH,EAAS,CAAEC,KAAAA,EAAMC,UAAAA,KACtB,EACP,MAAOE,GACP,OAAOA,GCPJN,eAAeO,UAAUC,GAC9B,IACE,MAAO,OAAOC,OAAKD,IACnB,MAAOF,GACP,MAAO,MAACI,EAAWJ,ICWhBN,eAAeW,U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,KAChDkG,MAAMC,QAAQnG,GACXuM,KAAK7E,MAAM6E,KAAKD,UAAUtM,IAE1BA,GAGZoM,EAAcI,QAChBH,EAAOE,KAAKD,UAAUA,EAAW,KAAMF,EAAcI,SAGvDH,EAAOE,KAAKD,UAAUA,GAExB,MAAO7M,GACP,OAAOA,EAET,OAAOK,UAAUC,EAAUsM,EAAMpM,6gBC3B5B,MAAMwM,gBAAgBC,cAAAC,wCAWRtF,kBAAgBsF,uCAYjBvN,iBAAeuN,kCAWpBxM,YAAUwM,uCAULtJ,iBAAesJ,qCAUjB3L,eAAa2L,oCAUdpJ,cAAYoJ,qCAUXlJ,eAAakJ,kCAYhB3K,YAAU2K,qCAUPjC,eAAaiC,iCAUjBjN,WAASiN,mCAUPhC,aAAWgC,oCAUV/B,cAAY+B,oCAUZ9B,cAAY8B,qCASXpF,eAAaoF,gCASlBnL,UAAQmL,mCASL/E,aAAW+E,gCASd5M,UAAQ4M,wCAUAnH,kBAAgBmH,sCAUlBlH,gBAAckH,qCAUfjH,eAAaiH,sCAUZhH,gBAAcgH,oCAWhB/G,cAAY+G,4BAYpBhJ,MAAIgJ,iCAUCtI,WAASsI,+BAUX3H,SAAO2H,gCAUN1H,UAAQ0H,kCAUNzH,YAAUyH,kCAUVxH,YAAUwH,oCASRhL,cAAYgL,uCASTpG,iBAAeoG,iCASrBhG,WAASgG,4BAUd/F,MAAI+F,gCAUA7G,UAAQ6G,wCASA7E,kBAAgB6E,wCAShB5E,kBAAgB4E,wCAShBxE,kBAAgBwE,8BAU1BzC,QAAMyC,yCASKxC,mBAAiBwC,oCAWtBrC,cAAYqC,4BAWpBvJ,MAAIuJ,iCAYC7M,WAAS6M,qCAYL5B,eAAa4B,iCAYjBR"} \ No newline at end of file +{"version":3,"file":"index.mjs","sources":["../src/core/create/create-directory.ts","../src/core/status/get-status.ts","../src/core/write/write-file.ts","../src/core/create/create-file.ts","../src/core/error/error-extract-options.ts","../src/core/access/wrapper.ts","../src/core/dir/dir-is-readable.ts","../src/core/list/is-system-junk.ts","../src/core/list/is-not-system-junk.ts","../src/core/list/contents.ts","../src/core/dir/dir-is-empty.ts","../src/core/dir/dir-is-executable.ts","../src/core/dir/dir-is-visible.ts","../src/core/dir/dir-is-writable.ts","../src/core/info/hash.ts","../src/core/info/hash-crc32.ts","../src/core/info/hash-md5.ts","../src/core/info/hash-sha1.ts","../src/core/info/hash-sha256.ts","../src/core/info/hash-sha512.ts","../src/core/info/hash-multi.ts","../src/core/info/size.ts","../src/core/file/file-is-executable.ts","../src/core/file/file-is-readable.ts","../src/core/file/file-is-visible.ts","../src/core/file/file-is-writable.ts","../src/core/file/file-truncate.ts","../src/core/path/path-from.ts","../src/core/list/directories.ts","../src/core/list/files.ts","../src/core/move/move.ts","../src/core/path/absolute-path.ts","../src/core/path/absolute-path-from.ts","../src/core/path/file-extension.ts","../src/core/path/file-name.ts","../src/core/path/file-name-ext.ts","../src/core/path/file-path.ts","../src/core/read/read-file-to-base64.ts","../src/core/read/read-file-to-buffer.ts","../src/core/read/read-file-to-string.ts","../src/core/remove/remove.ts","../src/core/remove/remove-non-blocking.ts","../src/core/remove/remove-silent.ts","../src/core/status/get-link-status.ts","../src/core/status/is-dir-exists.ts","../src/core/status/is-file-exists.ts","../src/core/status/is-path-exists.ts","../src/core/write/write-file-tail.ts","../src/core/write/write-json.ts","../src/core/hile-system-local.ts"],"sourcesContent":["import { mkdir } from \"node:fs/promises\";\n\n/**\n * @name createDirectory\n * @description Asynchronous create a directory.\n * @since 0.0.10\n * @async\n * @param {string|Buffer|URL} dirPath\n * @param {number|string=} mode\n * @param {boolean=} recursive\n * @returns {Promise}\n */\nexport async function createDirectory(\n\t//\n\tdirPath: string | Buffer | URL,\n\tmode: (number | string) | undefined = \"0777\",\n\trecursive: boolean | undefined = true,\n): Promise {\n\ttry {\n\t\tawait mkdir(dirPath, { mode, recursive });\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { stat } from \"node:fs/promises\";\n\n/**\n * @name getStatus\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise<[import(\"node:fs\").Stats|undefined, Error|undefined]>}\n */\nexport async function getStatus(\n\tpath: string | Buffer | URL,\n): Promise<[import(\"node:fs\").Stats | undefined, Error | undefined]> {\n\ttry {\n\t\treturn [await stat(path), undefined];\n\t} catch (error: unknown) {\n\t\treturn [undefined, error as Error];\n\t}\n}\n","import { writeFile as writeFileNative } from \"node:fs/promises\";\n\n/**\n * @name writeFile\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.0.10\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n * @example\n * const controller = new AbortController();\n * const { signal } = controller;\n * const data = new Uint8Array(Buffer.from('Hello Node.js'));\n * (async () => {\n * try {\n * await writeFile('message.txt', data, { signal });\n * } catch (error) {\n * // When a request is aborted - error is an AbortError\n * }\n * })();\n * // When the request should be aborted\n * controller.abort();\n */\nexport async function writeFile(\n\tfilePath: string | Buffer | URL,\n\tdata: any,\n\toptions: any | null | string = null,\n): Promise {\n\ttry {\n\t\tawait writeFileNative(filePath, data, options);\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { dirname } from \"node:path\";\nimport { readdir } from \"node:fs/promises\";\n\nimport { createDirectory } from \"./create-directory\";\nimport { getStatus } from \"../status/get-status\";\nimport { writeFile } from \"../write/write-file\";\n\n/**\n * @name createFile\n * @description Asynchronous create a file.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {number|string=} mode\n * @returns {Promise}\n */\nexport async function createFile(\n\tpathLike: string | Buffer | URL,\n\tmode: string = \"0777\",\n): Promise {\n\tconst [status, error] = await getStatus(pathLike);\n\tif (!error && (status as import(\"node:fs\").Stats).isFile()) {\n\t\treturn true;\n\t}\n\tconst dirPath = dirname(pathLike as string);\n\tif (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\tconst dirCreated = await createDirectory(dirPath, mode);\n\t\t\tif (dirCreated !== true) {\n\t\t\t\treturn dirCreated;\n\t\t\t}\n\t\t\tconst fileWritten = await writeFile(pathLike, \"\", { mode, flag: \"w\" });\n\t\t\tif (fileWritten !== true) {\n\t\t\t\treturn fileWritten;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t}\n\tif ((status as import(\"node:fs\").Stats).isDirectory()) {\n\t\treturn await writeFile(pathLike, \"\", { mode, flag: \"w\" });\n\t} else {\n\t\ttry {\n\t\t\tawait readdir(dirPath);\n\t\t\treturn undefined;\n\t\t} catch (error: unknown) {\n\t\t\treturn error as Error;\n\t\t}\n\t}\n}\n","/**\n * @name errorExtractOptions\n * @param {Error} error\n * @returns {{ cause: Error } | { cause: { code?: string, values?: any[] | { [key: string]: any } }}}\n */\nexport function errorExtractOptions(\n\terror: any,\n): { cause: Error } | { cause: { code?: string; values?: any[] | { [key: string]: any } } } {\n\tif (!(error instanceof Error)) {\n\t\treturn { cause: error };\n\t}\n\tif (\"code\" in error && \"errno\" in error && \"path\" in error && \"syscall\" in error) {\n\t\treturn {\n\t\t\tcause: {\n\t\t\t\tcode: (error as NodeJS.ErrnoException).code as string,\n\t\t\t\tvalues: {\n\t\t\t\t\terrno: error.errno,\n\t\t\t\t\tpath: error.path,\n\t\t\t\t\tsyscall: error.syscall,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\treturn { cause: error };\n}\n","import { access } from \"node:fs/promises\";\n\n/**\n * @name accessWrapper\n * @description Asynchronously tests a user's permissions for the file specified by path.\n * @since 0.0.1\n * @async\n * @param {number} mode\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function accessWrapper(mode: number, path: string | Buffer | URL): Promise {\n\ttry {\n\t\tawait access(path, mode);\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name dirIsReadable\n * @description Directory is visible to the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsReadable(pathToDir: string | Buffer | URL): Promise {\n\tif (process?.permission?.has(\"fs.read\") !== undefined) {\n\t\tconst isWritable = process.permission?.has(\"fs.read\", pathToDir as string);\n\t\tif (isWritable !== undefined) {\n\t\t\treturn isWritable;\n\t\t}\n\t}\n\treturn accessWrapper(constants.R_OK, pathToDir);\n}\n","// keep updated https://github.com/sindresorhus/junk\n\nconst ignoreList = [\n\t// # All\n\t\"^npm-debug\\\\.log$\", // Error log for npm\n\t\"^\\\\..*\\\\.swp$\", // Swap file for vim state\n\n\t// # macOS\n\t\"^\\\\.DS_Store$\", // Stores custom folder attributes\n\t\"^\\\\.AppleDouble$\", // Stores additional file resources\n\t\"^\\\\.LSOverride$\", // Contains the absolute path to the app to be used\n\t\"^Icon\\\\r$\", // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop\n\t\"^\\\\._.*\", // Thumbnail\n\t\"^\\\\.Spotlight-V100(?:$|\\\\/)\", // Directory that might appear on external disk\n\t\"\\\\.Trashes\", // File that might appear on external disk\n\t\"^__MACOSX$\", // Resource fork\n\n\t// # Linux\n\t\"~$\", // Backup file\n\n\t// # Windows\n\t\"^Thumbs\\\\.db$\", // Image file cache\n\t\"^ehthumbs\\\\.db$\", // Folder config file\n\t\"^Desktop\\\\.ini$\", // Stores custom folder attributes\n\t\"@eaDir$\", // Synology Diskstation \"hidden\" folder where the server stores thumbnails\n\t\"^\\\\$RECYCLE.BIN$\", // Special folder with columns like Date deleted and Original location\n\t\"^System Volume Information$\",\n];\n\nexport const junkRegex = new RegExp(ignoreList.join(\"|\"));\n\n/**\n * @name isSystemJunk\n * @description Returns true if filename matches a system junk file.\n * @param {string} [fileName]\n * @returns {boolean}\n * @since 0.2.0\n */\nexport function isSystemJunk(fileName: string): boolean {\n\treturn junkRegex.test(fileName);\n}\n","import { isSystemJunk } from \"./is-system-junk\";\n\n/**\n * @name isNotSystemJunk\n * @description Returns true if filename matches a system junk file.\n * @param {string} [fileName]\n * @returns {boolean}\n * @since 0.2.0\n */\nexport function isNotSystemJunk(fileName: string): boolean {\n\treturn !isSystemJunk(fileName);\n}\n","import { readdir } from \"node:fs/promises\";\n\nimport { isNotSystemJunk } from \"./is-not-system-junk\";\n\n/**\n * @name listContents\n * @description Lists files and directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean} [ignoreJunk=true]\n * @returns {Promise}\n */\nexport async function listContents(pathToDir: string | Buffer | URL, ignoreJunk = true): Promise {\n\ttry {\n\t\tconst contents = await readdir(pathToDir);\n\t\tif (ignoreJunk) {\n\t\t\treturn contents.filter(isNotSystemJunk);\n\t\t}\n\t\treturn contents;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { errorExtractOptions } from \"../error/error-extract-options\";\nimport { dirIsReadable } from \"./dir-is-readable\";\nimport { listContents } from \"../list/contents\";\n\nconst EXCLUDE = [\n\t// macOS\n\t\".AppleDB\",\n\t\".AppleDesktop\",\n\t\".AppleDouble\",\n\t\".DS_Store\",\n\t\".DocumentRevisions-V100\",\n\t\".LSOverride\",\n\t\".Spotlight-V100\",\n\t\".TemporaryItems\",\n\t\".Trashes\",\n\t\".VolumeIcon.icns\",\n\t// \"._*\",\n\t\".apdisk\",\n\t\".com.apple.timemachine.donotpresent\",\n\t\".fseventsd\",\n\t\"Network Trash Folder\",\n\t\"Temporary Items\",\n\t// Windows\n\t\"$RECYCLE.BIN/\",\n\t// \"*.cab\",\n\t// \"*.lnk\",\n\t// \"*.msi\",\n\t// \"*.msix\",\n\t// \"*.msm\",\n\t// \"*.msp\",\n\t// \"*.stackdump\",\n\t\"Desktop.ini\",\n\t\"Thumbs.db\",\n\t\"Thumbs.db:encryptable\",\n\t\"desktop.ini\",\n\t\"ehthumbs.db\",\n\t\"ehthumbs_vista.db\",\n\t// Linux\n\t// \"*~\",\n\t// \".Trash-*\",\n\t\".directory\",\n\t// \".fuse_hidden*\",\n\t// \".nfs*\",\n];\n\n/**\n * @name isEmptyContent\n * @param {string[]} listOfDirsAndFiles\n * @returns {boolean}\n */\nfunction isEmptyContent(listOfDirsAndFiles: string[]): boolean {\n\tconst content = new Set(listOfDirsAndFiles);\n\tlistOfDirsAndFiles.length = 0;\n\tcontent.forEach((dirOrFileName: string) => {\n\t\tfor (const nameToExclude of EXCLUDE) {\n\t\t\tif (!dirOrFileName) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (dirOrFileName === nameToExclude || dirOrFileName.match(RegExp(nameToExclude))) {\n\t\t\t\tcontent.delete(dirOrFileName);\n\t\t\t}\n\t\t}\n\t});\n\treturn content.size === 0;\n}\n\n/**\n * @name dirIsEmpty\n * @description Check if a directory is empty\n * @since 0.1.33\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean=} excludeSystemFiles\n * @returns {Promise}\n * @throws {Error} If path is not a dir or is not readable.\n */\nexport async function dirIsEmpty(\n\tpathToDir: string | Buffer | URL,\n\texcludeSystemFiles: boolean = true,\n): Promise {\n\tconst isReadableOrError = await dirIsReadable(pathToDir);\n\tif (isReadableOrError !== true) {\n\t\tthrow new Error((isReadableOrError as Error).message, errorExtractOptions(isReadableOrError));\n\t}\n\tlet listOfDirsAndFiles = await listContents(pathToDir);\n\tif (listOfDirsAndFiles instanceof Error) {\n\t\tthrow listOfDirsAndFiles;\n\t}\n\tif ((listOfDirsAndFiles as string[]).length === 0) {\n\t\treturn true;\n\t}\n\tif (!excludeSystemFiles) {\n\t\treturn false;\n\t}\n\treturn isEmptyContent(listOfDirsAndFiles as string[]);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name dirIsExecutable\n * @description Directory can be executed by the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsExecutable(pathToDir: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.X_OK, pathToDir);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name dirIsVisible\n * @description Directory is visible to the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsVisible(pathToDir: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.F_OK, pathToDir);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name dirIsWritable\n * @description Directory can be written by the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsWritable(pathToDir: string | Buffer | URL): Promise {\n\tif (process?.permission?.has(\"fs.write\") !== undefined) {\n\t\tconst isWritable = process.permission?.has(\"fs.write\", pathToDir as string);\n\t\tif (isWritable !== undefined) {\n\t\t\treturn isWritable;\n\t\t}\n\t}\n\treturn accessWrapper(constants.W_OK, pathToDir);\n}\n","import { createHash, getHashes } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\n\n/**\n * @name hash\n * @description Calculate hash.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {string} algorithm\n * @returns {Promise}\n * @throws {TypeError} If algorithm is not supported.\n */\nexport async function hash(pathToFile: string | Buffer | URL, algorithm: string): Promise {\n\tif (!getHashes().includes(algorithm)) {\n\t\tthrow new TypeError(`Digest algorithm [${algorithm}] is not supported.`);\n\t}\n\treturn createHash(algorithm)\n\t\t.update(await readFile(pathToFile))\n\t\t.digest(\"hex\");\n}\n","import { readFile } from \"node:fs/promises\";\n\nfunction crc32(text: string): number {\n\tlet chars = [];\n\tlet actual;\n\tfor (let current = 0; current < 256; current++) {\n\t\tactual = current;\n\t\tfor (let f = 0; f < 8; f++) {\n\t\t\tactual = 1 & actual ? 3988292384 ^ (actual >>> 1) : actual >>> 1;\n\t\t}\n\t\tchars[current] = actual;\n\t}\n\tlet number = -1;\n\tlet index = 0;\n\tfor (; index < text.length; index++) {\n\t\t// @ts-ignore\n\t\tnumber = (number >>> 8) ^ chars[255 & (number ^ text.charCodeAt(index))];\n\t}\n\treturn (-1 ^ number) >>> 0;\n}\n\n/**\n * @name hashCrc32\n * @description CRC32.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashCrc32(pathToFile: string | Buffer | URL): Promise {\n\treturn crc32((await readFile(pathToFile)).toString(\"binary\")).toString(16);\n}\n","import { hash } from \"./hash\";\n\n/**\n * @name hashMd5\n * @description MD5.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashMd5(pathToFile: string | Buffer | URL): Promise {\n\treturn hash(pathToFile, \"md5\");\n}\n","import { hash } from \"./hash\";\n\n/**\n * @name hashSha1\n * @description SHA-1.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha1(pathToFile: string | Buffer | URL): Promise {\n\treturn hash(pathToFile, \"sha1\");\n}\n","import { hash } from \"./hash\";\n\n/**\n * @name hashSha256\n * @description SHA-256.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha256(pathToFile: string | Buffer | URL): Promise {\n\treturn hash(pathToFile, \"sha256\");\n}\n","import { hash } from \"./hash\";\n\n/**\n * @name hashSha512\n * @description SHA-512.\n * @since 0.2.6\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha512(pathToFile: string | Buffer | URL): Promise {\n\treturn hash(pathToFile, \"sha512\");\n}\n","import { hashCrc32 } from \"./hash-crc32\";\nimport { hashMd5 } from \"./hash-md5\";\nimport { hashSha1 } from \"./hash-sha1\";\nimport { hashSha256 } from \"./hash-sha256\";\nimport { hashSha512 } from \"./hash-sha512\";\n\n/**\n * @name hashMulti\n * @description Calculates multiple hashes.\n * @summary The objective of the \"hashMulti\" function is to calculate multiple hashes (CRC32, MD5, SHA-1, SHA-256, and SHA-512) for a given file path and return them as an object.\n * @since 1.1.1\n * @async\n * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed.\n * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>}\n * @throws {Error|TypeError}\n */\nexport async function hashMulti(\n\tpathToFile: string | Buffer | URL,\n): Promise<{ crc32: string; md5: string; sha1: string; sha256: string; sha512: string }> {\n\treturn await Promise.all([\n\t\thashCrc32(pathToFile) as Promise,\n\t\thashMd5(pathToFile) as Promise,\n\t\thashSha1(pathToFile) as Promise,\n\t\thashSha256(pathToFile) as Promise,\n\t\thashSha512(pathToFile) as Promise,\n\t]).then(\n\t\t([\n\t\t\t//\n\t\t\tcrc32,\n\t\t\tmd5,\n\t\t\tsha1,\n\t\t\tsha256,\n\t\t\tsha512,\n\t\t]) => ({ crc32, md5, sha1, sha256, sha512 }),\n\t);\n}\n","import { stat } from \"node:fs/promises\";\n\n/**\n * @name size\n * @description File size in bytes.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {boolean=} [asString=false]\n * @returns {Promise}\n */\nexport async function size(\n\tpathToFile: string | Buffer | URL,\n\tasString: boolean = false,\n): Promise {\n\tconst fileStats = await stat(pathToFile);\n\tif (!asString) {\n\t\treturn fileStats.size;\n\t}\n\treturn fileStats.size.toLocaleString(\"en\").replace(/,/g, \"_\");\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name fileIsExecutable\n * @description File can be executed by the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsExecutable(pathToFile: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.X_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name fileIsReadable\n * @description File is visible to the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsReadable(pathToFile: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.R_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name fileIsVisible\n * @description File is visible to the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsVisible(pathToFile: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.F_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name fileIsWritable\n * @description File can be written by the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsWritable(pathToFile: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.W_OK, pathToFile);\n}\n","import { truncate } from \"node:fs/promises\";\n\n/**\n * @name fileTruncate\n * @description Truncate a file to a specified length\n * @since 0.0.6\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {number=} length\n * @returns {Promise}\n */\nexport async function fileTruncate(pathToFile: string | Buffer | URL, length: number = 0): Promise {\n\ttry {\n\t\tawait truncate(pathToFile, length);\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { join, normalize } from \"node:path\";\n\n/**\n * @name pathFrom\n * @description Join all arguments together and normalize the resulting path.\n * @since 0.1.3\n * @param {string|Buffer|URL|string[]|Buffer[]|URL[]} paths\n * @param {...string} morePaths\n * @returns {string}\n */\nexport function pathFrom(paths: string | Buffer | URL | string[] | Buffer[] | URL[], ...morePaths: string[]): string {\n\tlet routes;\n\tif (Array.isArray(paths)) {\n\t\troutes = paths.map((path) => path.toString());\n\t} else {\n\t\troutes = [paths.toString()];\n\t}\n\tif (morePaths.length) {\n\t\troutes = routes.concat(morePaths.map((path) => path.toString()));\n\t}\n\treturn normalize(join(...routes));\n}\n","import { getStatus } from \"../status/get-status\";\nimport { listContents } from \"./contents\";\nimport { pathFrom } from \"../path/path-from\";\n\n/**\n * @name listDirectories\n * @description Lists directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function listDirectories(pathToDir: string | Buffer | URL): Promise {\n\tconst contents = await listContents(pathToDir);\n\tif (!Array.isArray(contents)) {\n\t\treturn contents;\n\t}\n\tconst directories = await Promise.all(\n\t\tcontents.map(async (content) => {\n\t\t\tconst contentPath = pathFrom(pathToDir, content);\n\t\t\tconst [status, error] = await getStatus(contentPath);\n\t\t\tif (error) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (!(status as import(\"node:fs\").Stats).isDirectory()) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn content;\n\t\t}),\n\t);\n\treturn directories.filter((content) => content) as string[];\n}\n","import { getStatus } from \"../status/get-status\";\nimport { listContents } from \"./contents\";\nimport { pathFrom } from \"../path/path-from\";\n\n/**\n * @name listFiles\n * @description Lists files in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function listFiles(pathToDir: string | Buffer | URL): Promise {\n\tconst contents = await listContents(pathToDir);\n\tif (!Array.isArray(contents)) {\n\t\treturn contents;\n\t}\n\tconst files = await Promise.all(\n\t\tcontents.map(async (content) => {\n\t\t\tconst contentPath = pathFrom(pathToDir, content);\n\t\t\tconst [status, error] = await getStatus(contentPath);\n\t\t\tif (error) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif ((status as import(\"node:fs\").Stats).isDirectory()) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn content;\n\t\t}),\n\t);\n\treturn files.filter((content) => content) as string[];\n}\n","import { rename } from \"node:fs/promises\";\n\n/**\n * @name move\n * @description Change the name or location of a file or directory.\n * @since 0.1.29\n * @param {string} pathFrom\n * @param {string} pathTo\n * @returns {Promise}\n */\nexport async function move(pathFrom: string, pathTo: string): Promise {\n\ttry {\n\t\tawait rename(pathFrom, pathTo);\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { homedir } from \"node:os\";\n\nconst HOME_DIRECTORY = homedir();\n\n/**\n * @description deConvert a tilde path to an absolute path: ~/projects β†’ /Users/anon/projects\n * @param {string} pathWithTilde\n * @returns {string}\n */\nexport function absolutePath(pathWithTilde: string): string {\n\tif (HOME_DIRECTORY) {\n\t\treturn String(pathWithTilde).replace(/^~(?=$|\\/|\\\\)/, HOME_DIRECTORY);\n\t}\n\treturn String(pathWithTilde);\n}\n","import { resolve } from \"node:path\";\n\nimport { absolutePath } from \"./absolute-path\";\n\n/**\n * @name absolutePathFrom\n * @description Join all arguments together and normalize the resulting path.\n * Creates absolute path from right to left until an absolute path is constructed.\n * @since 0.1.5\n * @param {string|string[]} paths\n * @param {...string} morePaths\n * @returns {string}\n */\nexport function absolutePathFrom(paths: string | string[], ...morePaths: string[]): string {\n\tlet routes: string[];\n\tif (Array.isArray(paths)) {\n\t\troutes = paths.map((path) => path.toString());\n\t} else {\n\t\troutes = [paths.toString()];\n\t}\n\tif (morePaths.length) {\n\t\troutes = routes.concat(morePaths.map((path) => path.toString()));\n\t}\n\treturn absolutePath(resolve(...routes));\n}\n","import { extname } from \"node:path\";\n\n/**\n * @name fileExtension\n * @description Get file extension.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileExtension(path: string): string {\n\treturn extname(path).substring(1);\n}\n","import { parse } from \"node:path\";\n\n/**\n * @name fileName\n * @description Return the file name without extension.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileName(path: string): string {\n\treturn parse(path).name;\n}\n","import { basename } from \"node:path\";\n\n/**\n * @name fileNameExt\n * @description Return the last portion of a path.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileNameExt(path: string): string {\n\treturn basename(path);\n}\n","import { dirname } from \"node:path\";\n\n/**\n * @name filePath\n * @description Return the directory name of a path.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function filePath(path: string): string {\n\treturn dirname(path);\n}\n","import { readFile } from \"node:fs/promises\";\n\n/**\n * @name readFileToBase64\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.21\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToBase64(pathLike: string | Buffer | URL): Promise {\n\ttry {\n\t\tconst result = await readFile(pathLike, \"base64\");\n\t\treturn result.toString();\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { readFile } from \"node:fs/promises\";\n\n/**\n * @name readFileToBuffer\n * @description Asynchronously reads the entire contents of a file into buffer.\n * @since 0.1.19\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToBuffer(pathLike: string | Buffer | URL): Promise {\n\ttry {\n\t\tconst result = await readFile(pathLike, \"binary\");\n\t\treturn Buffer.from(result);\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { readFile } from \"node:fs/promises\";\n\nimport { absolutePath } from \"../path/absolute-path\";\n\n/**\n * @name readFileToString\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.7\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToString(pathLike: string | Buffer | URL): Promise {\n\ttry {\n\t\tconst result = await readFile(absolutePath(pathLike as string), \"utf8\");\n\t\treturn result.toString();\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","// @ts-ignore\nimport fs from \"node:fs\";\n// @ts-ignore\nimport assert from \"node:assert\";\nimport { join } from \"node:path\";\n\nconst IS_WINDOWS = process.platform === \"win32\";\n\n/**\n * @param {object} options\n */\nfunction defaults(options: any) {\n\tconst methods = [\"unlink\", \"chmod\", \"stat\", \"lstat\", \"rmdir\", \"readdir\"];\n\tmethods.forEach((method) => {\n\t\toptions[method] = options[method] || fs[method];\n\t});\n\toptions.maxBusyTries = options.maxBusyTries || 3;\n}\n\n/**\n * @param {string | Buffer | URL} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction rimraf(\n\tpathLike: string | Buffer | URL,\n\toptions: any,\n\tcallback: (error: NodeJS.ErrnoException | null) => void,\n): void {\n\tlet busyTries = 0;\n\tlet localCallback = callback;\n\tlet localOptions = options;\n\tif (typeof localOptions === \"function\") {\n\t\tlocalCallback = localOptions;\n\t\tlocalOptions = {};\n\t}\n\tassert(pathLike, \"remove(): missing path\");\n\t// assert.strictEqual(typeof pathLike, \"string\", \"remove(): path should be a string\");\n\t// assert.strictEqual(typeof localCallback, \"function\", \"remove(): callback function required\");\n\tassert(localOptions, \"remove(): invalid options argument provided\");\n\t// assert.strictEqual(typeof localOptions, \"object\", \"remove(): options should be an object?\");\n\tdefaults(localOptions);\n\trimraf_(pathLike as string, localOptions, function callbackRimraf(error: NodeJS.ErrnoException | null) {\n\t\tif (error) {\n\t\t\tif (\n\t\t\t\t(error.code === \"EBUSY\" || error.code === \"ENOTEMPTY\" || error.code === \"EPERM\") &&\n\t\t\t\tbusyTries < localOptions.maxBusyTries\n\t\t\t) {\n\t\t\t\tbusyTries++;\n\t\t\t\tconst time = busyTries * 100;\n\t\t\t\tsetTimeout(() => rimraf_(pathLike as string, localOptions, callbackRimraf), time);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\tlocalCallback(null);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tlocalCallback(error);\n\t});\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction rimraf_(pathLike: string, options: any, callback: (error: NodeJS.ErrnoException | null) => void): void {\n\tassert(pathLike);\n\tassert(options);\n\tassert(typeof callback === \"function\");\n\toptions.lstat(pathLike, (error: NodeJS.ErrnoException | null, stats: fs.Stats | fs.BigIntStats | undefined) => {\n\t\tif (error && error.code === \"ENOENT\") {\n\t\t\treturn callback(null);\n\t\t}\n\t\tif (error && error.code === \"EPERM\" && IS_WINDOWS) {\n\t\t\treturn fixWinEPERM(pathLike, options, error, callback);\n\t\t}\n\t\tif (stats && stats.isDirectory()) {\n\t\t\treturn rmdir(pathLike, options, error as NodeJS.ErrnoException, callback);\n\t\t}\n\t\toptions.unlink(pathLike, (error: NodeJS.ErrnoException | null): void | any => {\n\t\t\tif (error) {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn callback(null);\n\t\t\t\t}\n\t\t\t\tif (error.code === \"EPERM\") {\n\t\t\t\t\tif (IS_WINDOWS) {\n\t\t\t\t\t\treturn fixWinEPERM(pathLike, options, error, callback);\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn rmdir(pathLike, options, error, callback);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (error.code === \"EISDIR\") {\n\t\t\t\t\treturn rmdir(pathLike, options, error, callback);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn callback(error);\n\t\t});\n\t});\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Error|null} error\n * @param {Function=} callback\n * @returns {null}\n */\nfunction fixWinEPERM(\n\tpathLike: string,\n\toptions: any,\n\terror: NodeJS.ErrnoException | null,\n\tcallback: (error: NodeJS.ErrnoException | null) => void,\n): null {\n\tassert(pathLike);\n\tassert(options);\n\tassert(typeof callback === \"function\");\n\tif (error) {\n\t\tassert(error instanceof Error);\n\t}\n\toptions.chmod(pathLike, 0o666, (errorChMod: NodeJS.ErrnoException | null): void => {\n\t\tif (errorChMod) {\n\t\t\tif (errorChMod.code === \"ENOENT\") {\n\t\t\t\tcallback(null);\n\t\t\t} else {\n\t\t\t\tcallback(error);\n\t\t\t}\n\t\t} else {\n\t\t\toptions.stat(\n\t\t\t\tpathLike,\n\t\t\t\t(errorStat: NodeJS.ErrnoException | null, stats: fs.Stats | fs.BigIntStats | undefined) => {\n\t\t\t\t\tif (errorStat) {\n\t\t\t\t\t\tif (errorStat.code === \"ENOENT\") {\n\t\t\t\t\t\t\tcallback(null);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcallback(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (stats.isDirectory()) {\n\t\t\t\t\t\trmdir(pathLike, options, error as NodeJS.ErrnoException, callback);\n\t\t\t\t\t} else {\n\t\t\t\t\t\toptions.unlink(pathLike, callback);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t});\n\treturn null;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Error|null} originalError\n * @param {Function=} callback\n * @returns {null}\n */\nfunction rmdir(\n\tpathLike: string,\n\toptions: any,\n\toriginalError: NodeJS.ErrnoException,\n\tcallback: (error: NodeJS.ErrnoException | null) => void,\n) {\n\tassert(pathLike);\n\tassert(options);\n\tif (originalError) {\n\t\tassert(originalError instanceof Error);\n\t}\n\tassert(typeof callback === \"function\");\n\toptions.rmdir(pathLike, (error: NodeJS.ErrnoException): void => {\n\t\tif (error && (error.code === \"ENOTEMPTY\" || error.code === \"EEXIST\" || error.code === \"EPERM\")) {\n\t\t\tremoveSubPath(pathLike, options, callback);\n\t\t} else if (error && error.code === \"ENOTDIR\") {\n\t\t\tcallback(originalError);\n\t\t} else {\n\t\t\tcallback(error);\n\t\t}\n\t});\n\treturn null;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction removeSubPath(pathLike: string, options: any, callback: (error: NodeJS.ErrnoException | null) => void): void {\n\tassert(pathLike);\n\tassert(options);\n\tassert(typeof callback === \"function\");\n\toptions.readdir(pathLike, (error: Error | null, files: string[] | Buffer[] | fs.Dirent[]) => {\n\t\tif (error) {\n\t\t\treturn callback(error);\n\t\t}\n\t\tlet count = files.length;\n\t\tlet errState: Error | null = null;\n\t\tif (count === 0) {\n\t\t\treturn options.rmdir(pathLike, callback);\n\t\t}\n\t\tfiles.forEach((filePath: string): void => {\n\t\t\trimraf(join(pathLike, filePath), options, (error): void => {\n\t\t\t\tif (errState) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (error) {\n\t\t\t\t\tcallback((errState = error));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t--count;\n\t\t\t\tif (count === 0) {\n\t\t\t\t\toptions.rmdir(pathLike, callback);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t});\n}\n\n/**\n * @name remove\n * @description Removes a file or directory.\n * @since 0.1.1\n * @async\n * @param {string | Buffer | URL} pathLike\n * @returns {Promise}\n */\nexport async function remove(pathLike: string | Buffer | URL): Promise {\n\treturn new Promise((resolve) => {\n\t\trimraf(pathLike, {}, (error: unknown) => {\n\t\t\tif (error) {\n\t\t\t\tresolve(error as Error);\n\t\t\t} else {\n\t\t\t\tresolve(true);\n\t\t\t}\n\t\t});\n\t});\n}\n","import { remove } from \"./remove\";\n\n/**\n * @name removeNonBlocking\n * @description Non-blocking remove of a file or directory.\n * @since 0.1.18\n * @param {string|Buffer|URL} pathLike\n * @returns {void}\n */\nexport function removeNonBlocking(pathLike: string | Buffer | URL): void {\n\tremove(pathLike)\n\t\t.then(() => undefined)\n\t\t.catch(() => undefined); // don't put it into next tick\n}\n","import { rm } from \"node:fs/promises\";\n\nimport type { RmOptions } from \"node:fs\";\n\n/**\n * @name removeSilent\n * @description Removes files and directories (modeled on the standard POSIX rm utility).\n * @summary Minimum Node version 14.14.0\n * @since 0.1.36\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {RmOptions=} options\n * @returns {Promise}\n */\nexport async function removeSilent(pathLike: string | Buffer | URL, options: RmOptions): Promise {\n\ttry {\n\t\tawait rm(pathLike, {\n\t\t\tforce: true,\n\t\t\trecursive: true,\n\t\t\t...options,\n\t\t});\n\t} catch (__error) {\n\t\t//\n\t}\n}\n","import { lstat } from \"node:fs/promises\";\n\n/**\n * @name getLinkStatus\n * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to.\n * @url http://man7.org/linux/man-pages/man2/lstat.2.html\n * @since 1.1.0\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise<[import(\"node:fs\").Stats|undefined, Error|undefined]>}\n */\nexport async function getLinkStatus(\n\tpath: string | Buffer | URL,\n): Promise<[import(\"node:fs\").Stats | undefined, Error | undefined]> {\n\ttry {\n\t\treturn [await lstat(path), undefined];\n\t} catch (error: unknown) {\n\t\treturn [undefined, error as Error];\n\t}\n}\n","import { getStatus } from \"./get-status\";\n\n/**\n * @name isDirExists\n * @description Get directory status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isDirExists(path: string | Buffer | URL): Promise {\n\tconst [status, error] = await getStatus(path);\n\tif (error) {\n\t\treturn false;\n\t}\n\treturn (status as import(\"node:fs\").Stats).isDirectory();\n}\n","import { getStatus } from \"./get-status\";\n\n/**\n * @name isFileExists\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isFileExists(path: string | Buffer | URL): Promise {\n\tconst [status, error] = await getStatus(path);\n\tif (error) {\n\t\treturn false;\n\t}\n\treturn (status as import(\"node:fs\").Stats).isFile();\n}\n","import { getStatus } from \"./get-status\";\n\n/**\n * @name isPathExists\n * @description Get path status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isPathExists(path: string | Buffer | URL): Promise {\n\tconst [status] = await getStatus(path);\n\treturn Boolean(status);\n}\n","import { createFile } from \"../create/create-file\";\nimport { isFileExists } from \"../status/is-file-exists\";\nimport { readFileToString } from \"../read/read-file-to-string\";\nimport { writeFile } from \"./write-file\";\n\n/**\n * @name writeFileTail\n * @description Asynchronously writes data to the end of a file.\n * @since 1.0.1\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\nexport async function writeFileTail(\n\tfilePath: string | Buffer | URL,\n\tdata: any,\n\toptions: any | null | string = null,\n): Promise {\n\tconst isFileExist = await isFileExists(filePath);\n\tif (!isFileExist) {\n\t\tconst isFileCreatedOrError = await createFile(filePath);\n\t\tif (isFileCreatedOrError !== true) {\n\t\t\treturn isFileCreatedOrError as Error;\n\t\t}\n\t}\n\tconst contentOrError = await readFileToString(filePath);\n\tif (contentOrError instanceof Error) {\n\t\treturn contentOrError;\n\t}\n\treturn new Promise((resolve, reject) => {\n\t\tsetTimeout(() => {\n\t\t\twriteFile(filePath, `${String(contentOrError)}${String(data)}`, options)\n\t\t\t\t.then(() => {\n\t\t\t\t\tresolve(true);\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\treject(error);\n\t\t\t\t});\n\t\t}, 1);\n\t});\n}\n","import { writeFile } from \"./write-file\";\n\n/**\n * @name objectKeys\n * @param {object} object\n * @returns {string[]}\n */\nfunction objectKeys(object: object) {\n\treturn Object.keys(object).sort((alpha, beta) => alpha.localeCompare(beta));\n}\n\n/**\n * name isObjectLike\n * @param {*} value\n * @returns {boolean}\n */\nfunction isObjectLike(value: any) {\n\treturn value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\n/**\n * @name collectionSortKeys\n * @param {*} value\n * @param {boolean=} [isDeep=true]\n * @returns {Record|any[]}\n */\nfunction collectionSortKeys(value: any, isDeep = true): Record | any[] {\n\tif (!isObjectLike(value)) {\n\t\tif (Array.isArray(value)) {\n\t\t\treturn value.map((arrayValue) => collectionSortKeys(arrayValue, isDeep));\n\t\t}\n\t\treturn value;\n\t}\n\tconst keys = objectKeys(value);\n\tif (!keys.length) {\n\t\treturn value;\n\t}\n\treturn keys.reduce((sorted: Record, key) => {\n\t\tif (isDeep && isObjectLike(value[key])) {\n\t\t\tsorted[key] = collectionSortKeys(value[key], isDeep);\n\t\t} else if (isDeep && Array.isArray(value[key])) {\n\t\t\tsorted[key] = collectionSortKeys(value[key], isDeep);\n\t\t} else {\n\t\t\tsorted[key] = value[key];\n\t\t}\n\t\treturn sorted;\n\t}, {});\n}\n\n/**\n * @name writeJson\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.1.25\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {*} data\n * @param {*|null|string=} options\n * @param {{sort: boolean, space: number|string}=} configuration\n * @returns {Promise}\n */\nexport async function writeJson(\n\tfilePath: string | Buffer | URL,\n\tdata: any,\n\toptions: any | null | string = null,\n\tconfiguration: { sort: boolean; space: number | string } | undefined,\n): Promise {\n\tlet json;\n\tlet stringify = data;\n\ttry {\n\t\tif (configuration) {\n\t\t\tif (configuration.sort) {\n\t\t\t\tif (isObjectLike(data)) {\n\t\t\t\t\tstringify = collectionSortKeys(JSON.parse(JSON.stringify(data)));\n\t\t\t\t} else if (Array.isArray(data)) {\n\t\t\t\t\tstringify = JSON.parse(JSON.stringify(data));\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (configuration.space) {\n\t\t\t\tjson = JSON.stringify(stringify, null, configuration.space);\n\t\t\t}\n\t\t} else {\n\t\t\tjson = JSON.stringify(stringify);\n\t\t}\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n\treturn writeFile(filePath, json, options);\n}\n","import { absolutePathFrom } from \"./path/absolute-path-from\";\n\nimport { createDirectory } from \"./create/create-directory\";\nimport { createFile } from \"./create/create-file\";\n\nimport { dirIsExecutable } from \"./dir/dir-is-executable\";\nimport { dirIsReadable } from \"./dir/dir-is-readable\";\nimport { dirIsVisible } from \"./dir/dir-is-visible\";\nimport { dirIsWritable } from \"./dir/dir-is-writable\";\nimport { dirIsEmpty } from \"./dir/dir-is-empty\";\n\nimport { fileExtension } from \"./path/file-extension\";\nimport { fileIsExecutable } from \"./file/file-is-executable\";\nimport { fileIsReadable } from \"./file/file-is-readable\";\nimport { fileIsVisible } from \"./file/file-is-visible\";\nimport { fileIsWritable } from \"./file/file-is-writable\";\nimport { fileName } from \"./path/file-name\";\nimport { fileNameExt } from \"./path/file-name-ext\";\nimport { filePath } from \"./path/file-path\";\nimport { fileTruncate } from \"./file/file-truncate\";\n\nimport { listContents } from \"./list/contents\";\nimport { listDirectories } from \"./list/directories\";\nimport { listFiles } from \"./list/files\";\n\nimport { getLinkStatus } from \"./status/get-link-status\";\nimport { getStatus } from \"./status/get-status\";\n\nimport { isDirExists } from \"./status/is-dir-exists\";\nimport { isFileExists } from \"./status/is-file-exists\";\nimport { isPathExists } from \"./status/is-path-exists\";\n\nimport { move } from \"./move/move\";\n\nimport { pathFrom } from \"./path/path-from\";\n\nimport { readFileToBase64 } from \"./read/read-file-to-base64\";\nimport { readFileToBuffer } from \"./read/read-file-to-buffer\";\nimport { readFileToString } from \"./read/read-file-to-string\";\nimport { remove } from \"./remove/remove\";\nimport { removeNonBlocking } from \"./remove/remove-non-blocking\";\nimport { removeSilent } from \"./remove/remove-silent\";\n\nimport { writeFile } from \"./write/write-file\";\nimport { writeFileTail } from \"./write/write-file-tail\";\nimport { writeJson } from \"./write/write-json\";\n\nimport { hash } from \"./info/hash\";\nimport { hashCrc32 } from \"./info/hash-crc32\";\nimport { hashMd5 } from \"./info/hash-md5\";\nimport { hashMulti } from \"./info/hash-multi\";\nimport { hashSha1 } from \"./info/hash-sha1\";\nimport { hashSha256 } from \"./info/hash-sha256\";\nimport { hashSha512 } from \"./info/hash-sha512\";\n\nimport { size } from \"./info/size\";\n\nexport class HileSystemLocal {\n\t/**\n\t * @name absolutePathFrom\n\t * @description Join all arguments together and normalize the resulting path.\n\t * Creates absolute path from right to left until an absolute path is constructed.\n\t * @since 0.1.5\n\t * @public\n\t * @param {string|string[]} paths\n\t * @param {...string} morePaths\n\t * @returns {string}\n\t */\n\tabsolutePathFrom = absolutePathFrom;\n\t/**\n\t * @name createDirectory\n\t * @description Asynchronous create a directory.\n\t * @since 0.0.10\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} dirPath\n\t * @param {number|string=} mode\n\t * @param {boolean=} recursive\n\t * @returns {Promise}\n\t */\n\tcreateDirectory = createDirectory;\n\t/**\n\t * @name createFile\n\t * @description Asynchronous create a file.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathLike\n\t * @param {number|string=} mode\n\t * @returns {Promise}\n\t */\n\tcreateFile = createFile;\n\t/**\n\t * @name dirIsExecutable\n\t * @description Directory can be executed by the calling process\n\t * @since 0.0.5\n\t * @async\n\t * @public\n\t * @param {string} pathToDir\n\t * @returns {Promise}\n\t */\n\tdirIsExecutable = dirIsExecutable;\n\t/**\n\t * @name dirIsReadable\n\t * @description Directory is visible to the calling process\n\t * @since 0.0.1\n\t * @async\n\t * @public\n\t * @param {string} pathToDir\n\t * @returns {Promise}\n\t */\n\tdirIsReadable = dirIsReadable;\n\t/**\n\t * @name dirIsVisible\n\t * @description Directory is visible to the calling process\n\t * @since 0.0.5\n\t * @async\n\t * @public\n\t * @param {string} pathToDir\n\t * @returns {Promise}\n\t */\n\tdirIsVisible = dirIsVisible;\n\t/**\n\t * @name dirIsWritable\n\t * @description Directory can be written by the calling process\n\t * @since 0.0.1\n\t * @async\n\t * @public\n\t * @param {string} pathToDir\n\t * @returns {Promise}\n\t */\n\tdirIsWritable = dirIsWritable;\n\t/**\n\t * @name dirIsEmpty\n\t * @description Check if a directory is empty\n\t * @since 0.1.33\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToDir\n\t * @param {boolean=} excludeSystemFiles\n\t * @returns {Promise}\n\t * @throws {Error} If path is not a dir or is not readable.\n\t */\n\tdirIsEmpty = dirIsEmpty;\n\t/**\n\t * @name getLinkStatus\n\t * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to.\n\t * @url http://man7.org/linux/man-pages/man2/lstat.2.html\n\t * @since 1.1.0\n\t * @async\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise>}\n\t */\n\tgetLinkStatus = getLinkStatus;\n\t/**\n\t * @name getStatus\n\t * @description Get file status.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise>}\n\t */\n\tgetStatus = getStatus;\n\t/**\n\t * @name isDirExists\n\t * @description Get directory status.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise}\n\t */\n\tisDirExists = isDirExists;\n\t/**\n\t * @name isFileExists\n\t * @description Get file status.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise}\n\t */\n\tisFileExists = isFileExists;\n\t/**\n\t * @name isPathExists\n\t * @description Get path status.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise}\n\t */\n\tisPathExists = isPathExists;\n\t/**\n\t * @name fileExtension\n\t * @description Get file extension.\n\t * @since 0.1.1\n\t * @public\n\t * @param {string} path\n\t * @returns {string}\n\t */\n\tfileExtension = fileExtension;\n\t/**\n\t * @name fileName\n\t * @description Return the file name without extension.\n\t * @since 0.1.1\n\t * @public\n\t * @param {string} path\n\t * @returns {string}\n\t */\n\tfileName = fileName;\n\t/**\n\t * @name fileNameExt\n\t * @description Return the last portion of a path.\n\t * @since 0.1.1\n\t * @public\n\t * @param {string} path\n\t * @returns {string}\n\t */\n\tfileNameExt = fileNameExt;\n\t/**\n\t * @name filePath\n\t * @description Return the directory name of a path.\n\t * @since 0.1.1\n\t * @public\n\t * @param {string} path\n\t * @returns {string}\n\t */\n\tfilePath = filePath;\n\t/**\n\t * @name fileIsExecutable\n\t * @description File can be executed by the calling process\n\t * @since 0.0.5\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\tfileIsExecutable = fileIsExecutable;\n\t/**\n\t * @name fileIsReadable\n\t * @description File is visible to the calling process\n\t * @since 0.0.1\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\tfileIsReadable = fileIsReadable;\n\t/**\n\t * @name fileIsVisible\n\t * @description File is visible to the calling process\n\t * @since 0.0.5\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\tfileIsVisible = fileIsVisible;\n\t/**\n\t * @name fileIsWritable\n\t * @description File can be written by the calling process\n\t * @since 0.0.1\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\tfileIsWritable = fileIsWritable;\n\t/**\n\t * @name fileTruncate\n\t * @description Truncate a file to a specified length\n\t * @since 0.0.6\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @param {number=} length\n\t * @returns {Promise}\n\t */\n\tfileTruncate = fileTruncate;\n\t/**\n\t * @name hash\n\t * @description Calculate hash.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @param {string} algorithm\n\t * @returns {Promise}\n\t * @throws {TypeError} If algorithm is not supported.\n\t */\n\thash = hash;\n\t/**\n\t * @name hashCrc32\n\t * @description CRC32.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashCrc32 = hashCrc32;\n\t/**\n\t * @name hashMd5\n\t * @description MD5.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashMd5 = hashMd5;\n\t/**\n\t * @name hashMulti\n\t * @description Calculates multiple hashes.\n\t * @since 1.1.1\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed.\n\t * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>}\n\t * @throws {Error|TypeError}\n\t */\n\thashMulti = hashMulti;\n\t/**\n\t * @name hashSha1\n\t * @description SHA-1.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashSha1 = hashSha1;\n\t/**\n\t * @name hashSha256\n\t * @description SHA-256.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashSha256 = hashSha256;\n\t/**\n\t * @name hashSha512\n\t * @description SHA-512.\n\t * @since 0.2.6\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashSha512 = hashSha512;\n\t/**\n\t * @name listContents\n\t * @description Lists files and directories in path\n\t * @since 0.1.32\n\t * @async\n\t * @param {string|Buffer|URL} pathToDir\n\t * @returns {Promise}\n\t */\n\tlistContents = listContents;\n\t/**\n\t * @name listDirectories\n\t * @description Lists directories in path\n\t * @since 0.1.32\n\t * @async\n\t * @param {string|Buffer|URL} pathToDir\n\t * @returns {Promise}\n\t */\n\tlistDirectories = listDirectories;\n\t/**\n\t * @name listFiles\n\t * @description Lists files in path\n\t * @since 0.1.32\n\t * @async\n\t * @param {string|Buffer|URL} pathToDir\n\t * @returns {Promise}\n\t */\n\tlistFiles = listFiles;\n\t/**\n\t * @name move\n\t * @description Change the name or location of a file or directory.\n\t * @since 0.1.29\n\t * @public\n\t * @param {string} pathFrom\n\t * @param {string} pathTo\n\t * @returns {Promise}\n\t */\n\tmove = move;\n\t/**\n\t * @name pathFrom\n\t * @description Join all arguments together and normalize the resulting path.\n\t * @since 0.1.3\n\t * @public\n\t * @param {string|string[]} paths\n\t * @param {...string} morePaths\n\t * @returns {string}\n\t */\n\tpathFrom = pathFrom;\n\t/**\n\t * @name readFileToBase64\n\t * @description Asynchronously reads the entire contents of a file into string.\n\t * @since 0.1.21\n\t * @async\n\t * @param {string|Buffer|URL} pathLike\n\t * @returns {Promise}\n\t */\n\treadFileToBase64 = readFileToBase64;\n\t/**\n\t * @name readFileToBuffer\n\t * @description Asynchronously reads the entire contents of a file into buffer.\n\t * @since 0.1.19\n\t * @async\n\t * @param {string|Buffer|URL} pathLike\n\t * @returns {Promise}\n\t */\n\treadFileToBuffer = readFileToBuffer;\n\t/**\n\t * @name readFileToString\n\t * @description Asynchronously reads the entire contents of a file into string.\n\t * @since 0.1.7\n\t * @async\n\t * @param {string|Buffer|URL} pathLike\n\t * @returns {Promise}\n\t */\n\treadFileToString = readFileToString;\n\t/**\n\t * @name remove\n\t * @description Removes a file or directory.\n\t * @since 0.1.1\n\t * @async\n\t * @public\n\t * @param {string} pathLike\n\t * @returns {Promise}\n\t */\n\tremove = remove;\n\t/**\n\t * @name removeNonBlocking\n\t * @description Non-blocking remove of a file or directory.\n\t * @since 0.1.18\n\t * @public\n\t * @param {string} pathLike\n\t * @returns {void}\n\t */\n\tremoveNonBlocking = removeNonBlocking;\n\t/**\n\t * @name removeSilent\n\t * @description Removes files and directories (modeled on the standard POSIX rm utility).\n\t * @summary Minimum Node version 14.14.0\n\t * @since 0.1.36\n\t * @async\n\t * @param {string|Buffer|URL} pathLike\n\t * @param {object=} options\n\t * @returns {Promise}\n\t */\n\tremoveSilent = removeSilent;\n\t/**\n\t * @name size\n\t * @description File size in bytes.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @param {boolean=} [asString=false]\n\t * @returns {Promise}\n\t */\n\tsize = size;\n\t/**\n\t * @name writeFile\n\t * @description Asynchronously writes data to a file, replacing the file if it already exists.\n\t * @since 0.0.10\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} filePath\n\t * @param {string} data\n\t * @param {*|null|string=} options\n\t * @returns {Promise}\n\t */\n\twriteFile = writeFile;\n\t/**\n\t * @name writeFileTail\n\t * @description Asynchronously writes data to the end of a file.\n\t * @since 1.0.1\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} filePath\n\t * @param {string} data\n\t * @param {*|null|string=} options\n\t * @returns {Promise}\n\t */\n\twriteFileTail = writeFileTail;\n\t/**\n\t * @name writeJson\n\t * @description Asynchronously writes data to a file, replacing the file if it already exists.\n\t * @since 0.1.25\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} filePath\n\t * @param {*} data\n\t * @param {*|null|string=} options\n\t * @returns {Promise}\n\t */\n\twriteJson = writeJson;\n}\n"],"names":["createDirectory","dirPath","mode","recursive","mkdir","error","getStatus","path","stat","writeFile","filePath","data","options","writeFileNative","createFile","pathLike","status","dirname","dirCreated","fileWritten","readdir","errorExtractOptions","accessWrapper","access","dirIsReadable","pathToDir","_a","isWritable","_b","constants","ignoreList","junkRegex","isSystemJunk","fileName","isNotSystemJunk","listContents","ignoreJunk","contents","EXCLUDE","isEmptyContent","listOfDirsAndFiles","content","dirOrFileName","nameToExclude","dirIsEmpty","excludeSystemFiles","isReadableOrError","dirIsExecutable","dirIsVisible","dirIsWritable","hash","pathToFile","algorithm","getHashes","createHash","readFile","crc32","text","chars","actual","current","f","number","index","hashCrc32","hashMd5","hashSha1","hashSha256","hashSha512","hashMulti","md5","sha1","sha256","sha512","size","asString","fileStats","fileIsExecutable","fileIsReadable","fileIsVisible","fileIsWritable","fileTruncate","length","truncate","pathFrom","paths","morePaths","routes","normalize","join","listDirectories","contentPath","listFiles","move","pathTo","rename","HOME_DIRECTORY","homedir","absolutePath","pathWithTilde","absolutePathFrom","resolve","fileExtension","extname","parse","fileNameExt","basename","readFileToBase64","readFileToBuffer","result","readFileToString","IS_WINDOWS","defaults","method","fs","rimraf","callback","busyTries","localCallback","localOptions","assert","rimraf_","callbackRimraf","time","stats","fixWinEPERM","rmdir","errorChMod","errorStat","originalError","removeSubPath","files","count","errState","remove","removeNonBlocking","removeSilent","rm","getLinkStatus","lstat","isDirExists","isFileExists","isPathExists","writeFileTail","isFileCreatedOrError","contentOrError","reject","objectKeys","object","alpha","beta","isObjectLike","value","collectionSortKeys","isDeep","arrayValue","keys","sorted","key","writeJson","configuration","json","stringify","HileSystemLocal"],"mappings":";;;;;;AAYA,eAAsBA,EAErBC,GACAC,IAAsC,QACtCC,IAAiC,IACN;AACvB,MAAA;AACH,iBAAMC,EAAMH,GAAS,EAAE,MAAAC,GAAM,WAAAC,EAAW,CAAA,GACjC;AAAA,WACCE,GAAgB;AACjB,WAAAA;AAAA,EACR;AACD;ACdA,eAAsBC,EACrBC,GACoE;AAChE,MAAA;AACH,WAAO,CAAC,MAAMC,EAAKD,CAAI,GAAG,MAAS;AAAA,WAC3BF,GAAgB;AACjB,WAAA,CAAC,QAAWA,CAAc;AAAA,EAClC;AACD;ACOA,eAAsBI,EACrBC,GACAC,GACAC,IAA+B,MACJ;AACvB,MAAA;AACG,iBAAAC,EAAgBH,GAAUC,GAAMC,CAAO,GACtC;AAAA,WACCP,GAAgB;AACjB,WAAAA;AAAA,EACR;AACD;ACpBsB,eAAAS,EACrBC,GACAb,IAAe,QACwB;AACvC,QAAM,CAACc,GAAQX,CAAK,IAAI,MAAMC,EAAUS,CAAQ;AAChD,MAAI,CAACV,KAAUW,EAAmC;AAC1C,WAAA;AAEF,QAAAf,IAAUgB,EAAQF,CAAkB;AAC1C,MAAIV,KACEA,EAAgC,SAAS,UAAU;AACvD,UAAMa,IAAa,MAAMlB,EAAgBC,GAASC,CAAI;AACtD,QAAIgB,MAAe;AACX,aAAAA;AAEF,UAAAC,IAAc,MAAMV,EAAUM,GAAU,IAAI,EAAE,MAAAb,GAAM,MAAM,IAAA,CAAK;AACrE,WAAIiB,MAAgB,KACZA,IAED;AAAA,EACR;AAEI,MAAAH,EAAmC;AAChC,WAAA,MAAMP,EAAUM,GAAU,IAAI,EAAE,MAAAb,GAAM,MAAM,KAAK;AAEpD,MAAA;AACH,UAAMkB,EAAQnB,CAAO;AACd;AAAA,WACCI,GAAgB;AACjBA,WAAAA;AAAAA,EACR;AAEF;AC3CO,SAASgB,GACfhB,GAC2F;AACvF,SAAEA,aAAiB,QAGnB,UAAU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AC9BO,MAAMuJ,GAAgB;AAAA,EAAtB,cAAA;AAWa,SAAA,mBAAA/D,IAYD,KAAA,kBAAApG,GAWL,KAAA,aAAAc,GAUK,KAAA,kBAAAiC,IAUF,KAAA,gBAAAvB,GAUD,KAAA,eAAAwB,IAUC,KAAA,gBAAAC,IAYH,KAAA,aAAAL,IAUG,KAAA,gBAAA8F,IAUJ,KAAA,YAAApI,GAUE,KAAA,cAAAsI,IAUC,KAAA,eAAAC,GAUA,KAAA,eAAAC,IASC,KAAA,gBAAAxC,IASL,KAAA,WAAArE,IASG,KAAA,cAAAwE,IASH,KAAA,WAAA/F,IAUQ,KAAA,mBAAAmE,IAUF,KAAA,iBAAAC,IAUD,KAAA,gBAAAC,IAUC,KAAA,iBAAAC,IAWF,KAAA,eAAAC,IAYR,KAAA,OAAA/B,GAUK,KAAA,YAAAc,GAUF,KAAA,UAAAC,GAWE,KAAA,YAAAI,IAUD,KAAA,WAAAH,GAUE,KAAA,aAAAC,GAUA,KAAA,aAAAC,GASE,KAAA,eAAAjC,GASG,KAAA,kBAAAuD,IASN,KAAA,YAAAE,IAUL,KAAA,OAAAC,IAUI,KAAA,WAAAT,GASQ,KAAA,mBAAAuB,IASA,KAAA,mBAAAC,IASA,KAAA,mBAAAE,GAUV,KAAA,SAAAwB,GASW,KAAA,oBAAAC,IAWL,KAAA,eAAAC,IAWR,KAAA,OAAA9D,IAYK,KAAA,YAAAjE,GAYI,KAAA,gBAAAsI,IAYJ,KAAA,YAAAgB;AAAA,EAAA;AACb;"} \ No newline at end of file diff --git a/dist/index.mjs b/dist/index.mjs index b259a9c..a144b89 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -1,2 +1,559 @@ -import{mkdir as e,stat as t,writeFile as r,readdir as i,access as n,readFile as s,truncate as a,rename as o,rm as c,lstat as l}from"node:fs/promises";import{dirname as u,normalize as f,join as h,resolve as y,extname as d,parse as p,basename as m}from"node:path";import{constants as E}from"node:fs";import{getHashes as S,createHash as b}from"node:crypto";import P from"os";import g from"fs";import w from"node:assert";async function createDirectory(t,r="0777",i=!0){try{return await e(t,{mode:r,recursive:i}),!0}catch(e){return e}}async function getStatus(e){try{return[await t(e)]}catch(e){return[void 0,e]}}async function writeFile(e,t,i){try{return await r(e,t,i),!0}catch(e){return e}}async function createFile(e,t="0777"){const[r,n]=await getStatus(e);if(!n&&r.isFile())return!0;const s=u(e);if(n&&"ENOENT"===n.code){const r=await createDirectory(s,t);if(!0!==r)return r;const i=await writeFile(e,"",{mode:t,flag:"w"});return!0===i||i}if(r.isDirectory())return await writeFile(e,"",{mode:t,flag:"w"});try{return void await i(s)}catch(n){return n}}async function accessWrapper(e,t){try{return await n(t,e),!0}catch(e){return e}}async function dirIsReadable(e){return accessWrapper(E.R_OK,e)}const _=new RegExp(["^npm-debug\\.log$","^\\..*\\.swp$","^\\.DS_Store$","^\\.AppleDouble$","^\\.LSOverride$","^Icon\\r$","^\\._.*","^\\.Spotlight-V100(?:$|\\/)","\\.Trashes","^__MACOSX$","~$","^Thumbs\\.db$","^ehthumbs\\.db$","^Desktop\\.ini$","@eaDir$","^\\$RECYCLE.BIN$","^System Volume Information$"].join("|"));function isNotSystemJunk(e){return!function isSystemJunk(e){return _.test(e)}(e)}async function listContents(e,t=!0){try{const r=await i(e);return t?r.filter(isNotSystemJunk):r}catch(e){return e}}const F=[".AppleDB",".AppleDesktop",".AppleDouble",".DS_Store",".DocumentRevisions-V100",".LSOverride",".Spotlight-V100",".TemporaryItems",".Trashes",".VolumeIcon.icns",".apdisk",".com.apple.timemachine.donotpresent",".fseventsd","Network Trash Folder","Temporary Items","$RECYCLE.BIN/","Desktop.ini","Thumbs.db","Thumbs.db:encryptable","desktop.ini","ehthumbs.db","ehthumbs_vista.db",".directory"];async function dirIsEmpty(e,t=!0){const r=await dirIsReadable(e);if(!0!==r)throw new Error(r.message,function errorExtractOptions(e){return e instanceof Error?"code"in e&&"errno"in e&&"path"in e&&"syscall"in e?{cause:{code:e.code,values:{errno:e.errno,path:e.path,syscall:e.syscall}}}:void 0:{cause:e}}(r));let i=await listContents(e);if(i instanceof Error)throw i;return 0===i.length||!!t&&function isEmptyContent(e){const t=new Set(e);return e.length=0,t.forEach(e=>{for(const r of F)e&&(e===r||e.match(RegExp(r)))&&t.delete(e)}),0===t.size}(i)}async function dirIsExecutable(e){return accessWrapper(E.X_OK,e)}async function dirIsVisible(e){return accessWrapper(E.F_OK,e)}async function dirIsWritable(e){return accessWrapper(E.W_OK,e)}async function hash(e,t){if(!S().includes(t))throw new TypeError(`Digest algorithm [${t}] is not supported.`);return b(t).update(await s(e)).digest("hex")}async function hashCrc32(e){return function crc32(e){let t,r=[];for(let e=0;e<256;e++){t=e;for(let e=0;e<8;e++)t=1&t?3988292384^t>>>1:t>>>1;r[e]=t}let i=-1,n=0;for(;n>>8^r[255&(i^e.charCodeAt(n))];return(-1^i)>>>0}((await s(e)).toString("binary")).toString(16)}async function hashMd5(e){return hash(e,"md5")}async function hashSha1(e){return hash(e,"sha1")}async function hashSha256(e){return hash(e,"sha256")}async function hashSha512(e){return hash(e,"sha512")}async function size(e,r=!1){const i=await t(e);return r?i.size.toLocaleString("en").replace(/,/g,"_"):i.size}async function fileIsExecutable(e){return accessWrapper(E.X_OK,e)}async function fileIsReadable(e){return accessWrapper(E.R_OK,e)}async function fileIsVisible(e){return accessWrapper(E.F_OK,e)}async function fileIsWritable(e){return accessWrapper(E.W_OK,e)}async function fileTruncate(e,t=0){try{return await a(e,t),!0}catch(e){return e}}function pathFrom(e,...t){let r;return r=Array.isArray(e)?e.map(e=>e.toString()):[e.toString()],t.length&&(r=r.concat(t.map(e=>e.toString()))),f(h(...r))}async function listDirectories(e){const t=await listContents(e);if(!Array.isArray(t))return t;return(await Promise.all(t.map(async t=>{const r=pathFrom(e,t),[i,n]=await getStatus(r);if(!n&&i.isDirectory())return t}))).filter(e=>e)}async function listFiles(e){const t=await listContents(e);if(!Array.isArray(t))return t;return(await Promise.all(t.map(async t=>{const r=pathFrom(e,t),[i,n]=await getStatus(r);if(!n&&!i.isDirectory())return t}))).filter(e=>e)}async function move(e,t){try{return await o(e,t),!0}catch(e){return e}}const v=P.homedir();function absolutePath(e){return v?String(e).replace(/^~(?=$|\/|\\)/,v):String(e)}function absolutePathFrom(e,...t){let r;return r=Array.isArray(e)?e.map(e=>e.toString()):[e.toString()],t.length&&(r=r.concat(t.map(e=>e.toString()))),absolutePath(y(...r))}function fileExtension(e){return d(e).substring(1)}function fileName(e){return p(e).name}function fileNameExt(e){return m(e)}function filePath(e){return u(e)}async function readFileToBase64(e){try{return(await s(e,"base64")).toString()}catch(e){return e}}async function readFileToBuffer(e){try{const t=await s(e,"binary");return Buffer.from(t)}catch(e){return e}}async function readFileToString(e){try{return(await s(absolutePath(e),"utf8")).toString()}catch(e){return e}}const I="win32"===process.platform;function rimraf(e,t,r){let i=0,n=r,s=t;"function"==typeof s&&(n=s,s={}),w(e,"remove(): missing path"),w.strictEqual(typeof e,"string","remove(): path should be a string"),w.strictEqual(typeof n,"function","remove(): callback function required"),w(s,"remove(): invalid options argument provided"),w.strictEqual(typeof s,"object","remove(): options should be object"),function defaults(e){["unlink","chmod","stat","lstat","rmdir","readdir"].forEach(t=>{e[t]=e[t]||g[t]}),e.maxBusyTries=e.maxBusyTries||3}(s),rimraf_(e,s,(function callbackRimraf(t){if(t){if(("EBUSY"===t.code||"ENOTEMPTY"===t.code||"EPERM"===t.code)&&irimraf_(e,s,callbackRimraf),100*i)}if("ENOENT"===t.code)return void n(null)}n(t)}))}function rimraf_(e,t,r){w(e),w(t),w("function"==typeof r),t.lstat(e,(i,n)=>i&&"ENOENT"===i.code?r(null):i&&"EPERM"===i.code&&I?fixWinEPERM(e,t,i,r):n&&n.isDirectory()?rmdir(e,t,i,r):void t.unlink(e,i=>{if(i){if("ENOENT"===i.code)return r(null);if("EPERM"===i.code)return I?fixWinEPERM(e,t,i,r):rmdir(e,t,i,r);if("EISDIR"===i.code)return rmdir(e,t,i,r)}return r(i)}))}function fixWinEPERM(e,t,r,i){return w(e),w(t),w("function"==typeof i),r&&w(r instanceof Error),t.chmod(e,438,n=>{n?"ENOENT"===n.code?i(null):i(r):t.stat(e,(n,s)=>{n?"ENOENT"===n.code?i(null):i(r):s.isDirectory()?rmdir(e,t,r,i):t.unlink(e,i)})}),null}function rmdir(e,t,r,i){return w(e),w(t),r&&w(r instanceof Error),w("function"==typeof i),t.rmdir(e,n=>{!n||"ENOTEMPTY"!==n.code&&"EEXIST"!==n.code&&"EPERM"!==n.code?n&&"ENOTDIR"===n.code?i(r):i(n):function removeSubPath(e,t,r){w(e),w(t),w("function"==typeof r),t.readdir(e,(i,n)=>{if(i)return r(i);let s,a=n.length;if(0===a)return t.rmdir(e,r);n.forEach(i=>{rimraf(h(e,i),t,i=>{s||(i?r(s=i):(--a,0===a&&t.rmdir(e,r)))})})})}(e,t,i)}),null}async function remove(e){return new Promise(t=>{rimraf(e,{},e=>{e?t(e):t()})})}function removeNonBlocking(e){remove(e).then(()=>{}).catch(()=>{})}async function removeSilent(e,t){try{await c(e,{force:!0,recursive:!0,...t})}catch(e){}}async function getLinkStatus(e){try{return[await l(e)]}catch(e){return[void 0,e]}}async function isDirExists(e){const[t,r]=await getStatus(e);return!r&&t.isDirectory()}async function isFileExists(e){const[t,r]=await getStatus(e);return!r&&t.isFile()}async function isPathExists(e){const[t]=await getStatus(e);return Boolean(t)}async function writeFileTail(e,t,r){if(!1===await isFileExists(e)){const t=await createFile(e);if(!0!==t)return t}const i=await readFileToString(e);return i instanceof Error?i:new Promise((n,s)=>{setTimeout(()=>{writeFile(e,`${String(i)}${String(t)}`,r).then(()=>{n(!0)}).catch(e=>{s(e)})},1)})}function isObjectLike(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function collectionSortKeys(e,t=!0){if(!isObjectLike(e))return Array.isArray(e)?e.map(e=>collectionSortKeys(e,t)):e;const r=function objectKeys(e){return Object.keys(e).sort((e,t)=>e.localeCompare(t))}(e);return r.length?r.reduce((r,i)=>(t&&isObjectLike(e[i])||t&&Array.isArray(e[i])?r[i]=collectionSortKeys(e[i],t):r[i]=e[i],r),{}):e}async function writeJSON(e,t,r,i){let n,s=t;try{i?(i.sort&&(s=isObjectLike(t)?collectionSortKeys(JSON.parse(JSON.stringify(t))):Array.isArray(t)?JSON.parse(JSON.stringify(t)):t),i.space&&(n=JSON.stringify(s,null,i.space))):n=JSON.stringify(s)}catch(e){return e}return writeFile(e,n,r)}function _defineProperty(e,t,r){return(t=function _toPropertyKey(e){var t=function _toPrimitive(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class HileSystemLocal{constructor(){_defineProperty(this,"absolutePathFrom",absolutePathFrom),_defineProperty(this,"createDirectory",createDirectory),_defineProperty(this,"createFile",createFile),_defineProperty(this,"dirIsExecutable",dirIsExecutable),_defineProperty(this,"dirIsReadable",dirIsReadable),_defineProperty(this,"dirIsVisible",dirIsVisible),_defineProperty(this,"dirIsWritable",dirIsWritable),_defineProperty(this,"dirIsEmpty",dirIsEmpty),_defineProperty(this,"getLinkStatus",getLinkStatus),_defineProperty(this,"getStatus",getStatus),_defineProperty(this,"isDirExists",isDirExists),_defineProperty(this,"isFileExists",isFileExists),_defineProperty(this,"isPathExists",isPathExists),_defineProperty(this,"fileExtension",fileExtension),_defineProperty(this,"fileName",fileName),_defineProperty(this,"fileNameExt",fileNameExt),_defineProperty(this,"filePath",filePath),_defineProperty(this,"fileIsExecutable",fileIsExecutable),_defineProperty(this,"fileIsReadable",fileIsReadable),_defineProperty(this,"fileIsVisible",fileIsVisible),_defineProperty(this,"fileIsWritable",fileIsWritable),_defineProperty(this,"fileTruncate",fileTruncate),_defineProperty(this,"hash",hash),_defineProperty(this,"hashCrc32",hashCrc32),_defineProperty(this,"hashMd5",hashMd5),_defineProperty(this,"hashSha1",hashSha1),_defineProperty(this,"hashSha256",hashSha256),_defineProperty(this,"hashSha512",hashSha512),_defineProperty(this,"listContents",listContents),_defineProperty(this,"listDirectories",listDirectories),_defineProperty(this,"listFiles",listFiles),_defineProperty(this,"move",move),_defineProperty(this,"pathFrom",pathFrom),_defineProperty(this,"readFileToBase64",readFileToBase64),_defineProperty(this,"readFileToBuffer",readFileToBuffer),_defineProperty(this,"readFileToString",readFileToString),_defineProperty(this,"remove",remove),_defineProperty(this,"removeNonBlocking",removeNonBlocking),_defineProperty(this,"removeSilent",removeSilent),_defineProperty(this,"size",size),_defineProperty(this,"writeFile",writeFile),_defineProperty(this,"writeFileTail",writeFileTail),_defineProperty(this,"writeJSON",writeJSON)}}export{HileSystemLocal,absolutePathFrom,createDirectory,createFile,dirIsEmpty,dirIsExecutable,dirIsReadable,dirIsVisible,dirIsWritable,fileExtension,fileIsExecutable,fileIsReadable,fileIsVisible,fileIsWritable,fileName,fileNameExt,filePath,fileTruncate,getLinkStatus,getStatus,hash,hashCrc32,hashMd5,hashSha1,hashSha256,hashSha512,isDirExists,isFileExists,isPathExists,listContents,listDirectories,listFiles,move,pathFrom,readFileToBase64,readFileToBuffer,readFileToString,remove,removeNonBlocking,removeSilent,size,writeFile,writeFileTail,writeJSON}; +import { mkdir as j, stat as x, writeFile as z, readdir as F, access as Y, readFile as y, truncate as X, rename as H, rm as U, lstat as q } from "node:fs/promises"; +import { dirname as v, normalize as G, join as R, resolve as Q, extname as Z, parse as L, basename as k } from "node:path"; +import tt, { constants as a } from "node:fs"; +import { getHashes as et, createHash as rt } from "node:crypto"; +import { homedir as nt } from "node:os"; +import c from "node:assert"; +async function p(t, e = "0777", r = !0) { + try { + return await j(t, { mode: e, recursive: r }), !0; + } catch (n) { + return n; + } +} +async function l(t) { + try { + return [await x(t), void 0]; + } catch (e) { + return [void 0, e]; + } +} +async function h(t, e, r = null) { + try { + return await z(t, e, r), !0; + } catch (n) { + return n; + } +} +async function A(t, e = "0777") { + const [r, n] = await l(t); + if (!n && r.isFile()) + return !0; + const i = v(t); + if (n && n.code === "ENOENT") { + const s = await p(i, e); + if (s !== !0) + return s; + const u = await h(t, "", { mode: e, flag: "w" }); + return u !== !0 ? u : !0; + } + if (r.isDirectory()) + return await h(t, "", { mode: e, flag: "w" }); + try { + await F(i); + return; + } catch (s) { + return s; + } +} +function it(t) { + return t instanceof Error ? "code" in t && "errno" in t && "path" in t && "syscall" in t ? { + cause: { + code: t.code, + values: { + errno: t.errno, + path: t.path, + syscall: t.syscall + } + } + } : { cause: t } : { cause: t }; +} +async function f(t, e) { + try { + return await Y(e, t), !0; + } catch (r) { + return r; + } +} +async function $(t) { + var e, r; + if (((e = process == null ? void 0 : process.permission) == null ? void 0 : e.has("fs.read")) !== void 0) { + const n = (r = process.permission) == null ? void 0 : r.has("fs.read", t); + if (n !== void 0) + return n; + } + return f(a.R_OK, t); +} +const st = [ + // # All + "^npm-debug\\.log$", + // Error log for npm + "^\\..*\\.swp$", + // Swap file for vim state + // # macOS + "^\\.DS_Store$", + // Stores custom folder attributes + "^\\.AppleDouble$", + // Stores additional file resources + "^\\.LSOverride$", + // Contains the absolute path to the app to be used + "^Icon\\r$", + // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop + "^\\._.*", + // Thumbnail + "^\\.Spotlight-V100(?:$|\\/)", + // Directory that might appear on external disk + "\\.Trashes", + // File that might appear on external disk + "^__MACOSX$", + // Resource fork + // # Linux + "~$", + // Backup file + // # Windows + "^Thumbs\\.db$", + // Image file cache + "^ehthumbs\\.db$", + // Folder config file + "^Desktop\\.ini$", + // Stores custom folder attributes + "@eaDir$", + // Synology Diskstation "hidden" folder where the server stores thumbnails + "^\\$RECYCLE.BIN$", + // Special folder with columns like Date deleted and Original location + "^System Volume Information$" +], ut = new RegExp(st.join("|")); +function ct(t) { + return ut.test(t); +} +function ot(t) { + return !ct(t); +} +async function S(t, e = !0) { + try { + const r = await F(t); + return e ? r.filter(ot) : r; + } catch (r) { + return r; + } +} +const at = [ + // macOS + ".AppleDB", + ".AppleDesktop", + ".AppleDouble", + ".DS_Store", + ".DocumentRevisions-V100", + ".LSOverride", + ".Spotlight-V100", + ".TemporaryItems", + ".Trashes", + ".VolumeIcon.icns", + // "._*", + ".apdisk", + ".com.apple.timemachine.donotpresent", + ".fseventsd", + "Network Trash Folder", + "Temporary Items", + // Windows + "$RECYCLE.BIN/", + // "*.cab", + // "*.lnk", + // "*.msi", + // "*.msix", + // "*.msm", + // "*.msp", + // "*.stackdump", + "Desktop.ini", + "Thumbs.db", + "Thumbs.db:encryptable", + "desktop.ini", + "ehthumbs.db", + "ehthumbs_vista.db", + // Linux + // "*~", + // ".Trash-*", + ".directory" + // ".fuse_hidden*", + // ".nfs*", +]; +function ft(t) { + const e = new Set(t); + return t.length = 0, e.forEach((r) => { + for (const n of at) + r && (r === n || r.match(RegExp(n))) && e.delete(r); + }), e.size === 0; +} +async function lt(t, e = !0) { + const r = await $(t); + if (r !== !0) + throw new Error(r.message, it(r)); + let n = await S(t); + if (n instanceof Error) + throw n; + return n.length === 0 ? !0 : e ? ft(n) : !1; +} +async function ht(t) { + return f(a.X_OK, t); +} +async function yt(t) { + return f(a.F_OK, t); +} +async function mt(t) { + var e, r; + if (((e = process == null ? void 0 : process.permission) == null ? void 0 : e.has("fs.write")) !== void 0) { + const n = (r = process.permission) == null ? void 0 : r.has("fs.write", t); + if (n !== void 0) + return n; + } + return f(a.W_OK, t); +} +async function m(t, e) { + if (!et().includes(e)) + throw new TypeError(`Digest algorithm [${e}] is not supported.`); + return rt(e).update(await y(t)).digest("hex"); +} +function dt(t) { + let e = [], r; + for (let s = 0; s < 256; s++) { + r = s; + for (let u = 0; u < 8; u++) + r = 1 & r ? 3988292384 ^ r >>> 1 : r >>> 1; + e[s] = r; + } + let n = -1, i = 0; + for (; i < t.length; i++) + n = n >>> 8 ^ e[255 & (n ^ t.charCodeAt(i))]; + return (-1 ^ n) >>> 0; +} +async function _(t) { + return dt((await y(t)).toString("binary")).toString(16); +} +async function D(t) { + return m(t, "md5"); +} +async function P(t) { + return m(t, "sha1"); +} +async function C(t) { + return m(t, "sha256"); +} +async function B(t) { + return m(t, "sha512"); +} +async function Et(t) { + return await Promise.all([ + _(t), + D(t), + P(t), + C(t), + B(t) + ]).then( + ([ + // + e, + r, + n, + i, + s + ]) => ({ crc32: e, md5: r, sha1: n, sha256: i, sha512: s }) + ); +} +async function wt(t, e = !1) { + const r = await x(t); + return e ? r.size.toLocaleString("en").replace(/,/g, "_") : r.size; +} +async function St(t) { + return f(a.X_OK, t); +} +async function gt(t) { + return f(a.R_OK, t); +} +async function Ot(t) { + return f(a.F_OK, t); +} +async function It(t) { + return f(a.W_OK, t); +} +async function bt(t, e = 0) { + try { + return await X(t, e), !0; + } catch (r) { + return r; + } +} +function O(t, ...e) { + let r; + return Array.isArray(t) ? r = t.map((n) => n.toString()) : r = [t.toString()], e.length && (r = r.concat(e.map((n) => n.toString()))), G(R(...r)); +} +async function Nt(t) { + const e = await S(t); + return Array.isArray(e) ? (await Promise.all( + e.map(async (n) => { + const i = O(t, n), [s, u] = await l(i); + if (!u && s.isDirectory()) + return n; + }) + )).filter((n) => n) : e; +} +async function Tt(t) { + const e = await S(t); + return Array.isArray(e) ? (await Promise.all( + e.map(async (n) => { + const i = O(t, n), [s, u] = await l(i); + if (!u && !s.isDirectory()) + return n; + }) + )).filter((n) => n) : e; +} +async function xt(t, e) { + try { + return await H(t, e), !0; + } catch (r) { + return r; + } +} +const I = nt(); +function M(t) { + return I ? String(t).replace(/^~(?=$|\/|\\)/, I) : String(t); +} +function Ft(t, ...e) { + let r; + return Array.isArray(t) ? r = t.map((n) => n.toString()) : r = [t.toString()], e.length && (r = r.concat(e.map((n) => n.toString()))), M(Q(...r)); +} +function vt(t) { + return Z(t).substring(1); +} +function Rt(t) { + return L(t).name; +} +function pt(t) { + return k(t); +} +function At(t) { + return v(t); +} +async function $t(t) { + try { + return (await y(t, "base64")).toString(); + } catch (e) { + return e; + } +} +async function _t(t) { + try { + const e = await y(t, "binary"); + return Buffer.from(e); + } catch (e) { + return e; + } +} +async function W(t) { + try { + return (await y(M(t), "utf8")).toString(); + } catch (e) { + return e; + } +} +const b = process.platform === "win32"; +function Dt(t) { + ["unlink", "chmod", "stat", "lstat", "rmdir", "readdir"].forEach((r) => { + t[r] = t[r] || tt[r]; + }), t.maxBusyTries = t.maxBusyTries || 3; +} +function J(t, e, r) { + let n = 0, i = r, s = e; + typeof s == "function" && (i = s, s = {}), c(t, "remove(): missing path"), c(s, "remove(): invalid options argument provided"), Dt(s), N(t, s, function u(o) { + if (o) { + if ((o.code === "EBUSY" || o.code === "ENOTEMPTY" || o.code === "EPERM") && n < s.maxBusyTries) { + n++; + const d = n * 100; + setTimeout(() => N(t, s, u), d); + return; + } + if (o.code === "ENOENT") { + i(null); + return; + } + } + i(o); + }); +} +function N(t, e, r) { + c(t), c(e), c(typeof r == "function"), e.lstat(t, (n, i) => { + if (n && n.code === "ENOENT") + return r(null); + if (n && n.code === "EPERM" && b) + return T(t, e, n, r); + if (i && i.isDirectory()) + return E(t, e, n, r); + e.unlink(t, (s) => { + if (s) { + if (s.code === "ENOENT") + return r(null); + if (s.code === "EPERM") + return b ? T(t, e, s, r) : E(t, e, s, r); + if (s.code === "EISDIR") + return E(t, e, s, r); + } + return r(s); + }); + }); +} +function T(t, e, r, n) { + return c(t), c(e), c(typeof n == "function"), r && c(r instanceof Error), e.chmod(t, 438, (i) => { + i ? i.code === "ENOENT" ? n(null) : n(r) : e.stat( + t, + (s, u) => { + s ? s.code === "ENOENT" ? n(null) : n(r) : u.isDirectory() ? E(t, e, r, n) : e.unlink(t, n); + } + ); + }), null; +} +function E(t, e, r, n) { + return c(t), c(e), r && c(r instanceof Error), c(typeof n == "function"), e.rmdir(t, (i) => { + i && (i.code === "ENOTEMPTY" || i.code === "EEXIST" || i.code === "EPERM") ? Pt(t, e, n) : i && i.code === "ENOTDIR" ? n(r) : n(i); + }), null; +} +function Pt(t, e, r) { + c(t), c(e), c(typeof r == "function"), e.readdir(t, (n, i) => { + if (n) + return r(n); + let s = i.length, u = null; + if (s === 0) + return e.rmdir(t, r); + i.forEach((o) => { + J(R(t, o), e, (d) => { + if (!u) { + if (d) { + r(u = d); + return; + } + --s, s === 0 && e.rmdir(t, r); + } + }); + }); + }); +} +async function K(t) { + return new Promise((e) => { + J(t, {}, (r) => { + e(r || !0); + }); + }); +} +function Ct(t) { + K(t).then(() => { + }).catch(() => { + }); +} +async function Bt(t, e) { + try { + await U(t, { + force: !0, + recursive: !0, + ...e + }); + } catch { + } +} +async function Mt(t) { + try { + return [await q(t), void 0]; + } catch (e) { + return [void 0, e]; + } +} +async function Wt(t) { + const [e, r] = await l(t); + return r ? !1 : e.isDirectory(); +} +async function V(t) { + const [e, r] = await l(t); + return r ? !1 : e.isFile(); +} +async function Jt(t) { + const [e] = await l(t); + return !!e; +} +async function Kt(t, e, r = null) { + if (!await V(t)) { + const s = await A(t); + if (s !== !0) + return s; + } + const i = await W(t); + return i instanceof Error ? i : new Promise((s, u) => { + setTimeout(() => { + h(t, `${String(i)}${String(e)}`, r).then(() => { + s(!0); + }).catch((o) => { + u(o); + }); + }, 1); + }); +} +function Vt(t) { + return Object.keys(t).sort((e, r) => e.localeCompare(r)); +} +function g(t) { + return t !== null && typeof t == "object" && !Array.isArray(t); +} +function w(t, e = !0) { + if (!g(t)) + return Array.isArray(t) ? t.map((n) => w(n, e)) : t; + const r = Vt(t); + return r.length ? r.reduce((n, i) => (e && g(t[i]) || e && Array.isArray(t[i]) ? n[i] = w(t[i], e) : n[i] = t[i], n), {}) : t; +} +async function jt(t, e, r = null, n) { + let i, s = e; + try { + n ? (n.sort && (g(e) ? s = w(JSON.parse(JSON.stringify(e))) : Array.isArray(e) && (s = JSON.parse(JSON.stringify(e)))), n.space && (i = JSON.stringify(s, null, n.space))) : i = JSON.stringify(s); + } catch (u) { + return u; + } + return h(t, i, r); +} +class Gt { + constructor() { + this.absolutePathFrom = Ft, this.createDirectory = p, this.createFile = A, this.dirIsExecutable = ht, this.dirIsReadable = $, this.dirIsVisible = yt, this.dirIsWritable = mt, this.dirIsEmpty = lt, this.getLinkStatus = Mt, this.getStatus = l, this.isDirExists = Wt, this.isFileExists = V, this.isPathExists = Jt, this.fileExtension = vt, this.fileName = Rt, this.fileNameExt = pt, this.filePath = At, this.fileIsExecutable = St, this.fileIsReadable = gt, this.fileIsVisible = Ot, this.fileIsWritable = It, this.fileTruncate = bt, this.hash = m, this.hashCrc32 = _, this.hashMd5 = D, this.hashMulti = Et, this.hashSha1 = P, this.hashSha256 = C, this.hashSha512 = B, this.listContents = S, this.listDirectories = Nt, this.listFiles = Tt, this.move = xt, this.pathFrom = O, this.readFileToBase64 = $t, this.readFileToBuffer = _t, this.readFileToString = W, this.remove = K, this.removeNonBlocking = Ct, this.removeSilent = Bt, this.size = wt, this.writeFile = h, this.writeFileTail = Kt, this.writeJson = jt; + } +} +export { + Gt as HileSystemLocal, + Ft as absolutePathFrom, + p as createDirectory, + A as createFile, + lt as dirIsEmpty, + ht as dirIsExecutable, + $ as dirIsReadable, + yt as dirIsVisible, + mt as dirIsWritable, + vt as fileExtension, + St as fileIsExecutable, + gt as fileIsReadable, + Ot as fileIsVisible, + It as fileIsWritable, + Rt as fileName, + pt as fileNameExt, + At as filePath, + bt as fileTruncate, + Mt as getLinkStatus, + l as getStatus, + m as hash, + _ as hashCrc32, + D as hashMd5, + Et as hashMulti, + P as hashSha1, + C as hashSha256, + B as hashSha512, + Wt as isDirExists, + V as isFileExists, + Jt as isPathExists, + S as listContents, + Nt as listDirectories, + Tt as listFiles, + xt as move, + O as pathFrom, + $t as readFileToBase64, + _t as readFileToBuffer, + W as readFileToString, + K as remove, + Ct as removeNonBlocking, + Bt as removeSilent, + wt as size, + h as writeFile, + Kt as writeFileTail, + jt as writeJson +}; //# sourceMappingURL=index.mjs.map diff --git a/dist/index.mjs.map b/dist/index.mjs.map index f4c492a..99faf21 100644 --- a/dist/index.mjs.map +++ b/dist/index.mjs.map @@ -1 +1 @@ -{"version":3,"file":"index.mjs","sources":["../src/core/create/createDirectory.js","../src/core/status/getStatus.js","../src/core/write/writeFile.js","../src/core/create/createFile.js","../src/core/access/wrapper.js","../src/core/dir/dirIsReadable.js","../src/core/list/is-system-junk.js","../src/core/list/is-not-system-junk.js","../src/core/list/contents.js","../src/core/dir/dirIsEmpty.js","../src/core/error/errorExtractOptions.js","../src/core/dir/dirIsExecutable.js","../src/core/dir/dirIsVisible.js","../src/core/dir/dirIsWritable.js","../src/core/info/hash.js","../src/core/info/hash-crc32.js","../src/core/info/hash-md5.js","../src/core/info/hash-sha1.js","../src/core/info/hash-sha256.js","../src/core/info/hash-sha512.js","../src/core/info/size.js","../src/core/file/fileIsExecutable.js","../src/core/file/fileIsReadable.js","../src/core/file/fileIsVisible.js","../src/core/file/fileIsWritable.js","../src/core/file/fileTruncate.js","../src/core/path/pathFrom.js","../src/core/list/directories.js","../src/core/list/files.js","../src/core/move/move.js","../src/core/path/absolutePath.js","../src/core/path/absolutePathFrom.js","../src/core/path/fileExtension.js","../src/core/path/fileName.js","../src/core/path/fileNameExt.js","../src/core/path/filePath.js","../src/core/read/readFileToBase64.js","../src/core/read/readFileToBuffer.js","../src/core/read/readFileToString.js","../src/core/remove/remove.js","../src/core/remove/removeNonBlocking.js","../src/core/remove/removeSilent.js","../src/core/status/getLinkStatus.js","../src/core/status/isDirExists.js","../src/core/status/isFileExists.js","../src/core/status/isPathExists.js","../src/core/write/writeFileTail.js","../src/core/write/writeJSON.js","../src/core/HileSystemLocal.js"],"sourcesContent":["import { mkdir } from \"node:fs/promises\";\n\n/**\n * @name createDirectory\n * @description Asynchronous create a directory.\n * @since 0.0.10\n * @async\n * @param {string|Buffer|URL} dirPath\n * @param {number|string=} mode\n * @param {boolean=} recursive\n * @returns {Promise}\n */\nexport async function createDirectory(dirPath, mode = \"0777\", recursive = true) {\n try {\n await mkdir(dirPath, { mode, recursive });\n return true;\n } catch (error) {\n return error;\n }\n}\n","import { stat } from \"node:fs/promises\";\n\n/**\n * @name getStatus\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise>}\n */\nexport async function getStatus(path) {\n try {\n return [await stat(path)];\n } catch (error) {\n return [undefined, error];\n }\n}\n","import { writeFile as writeFileNative } from \"node:fs/promises\";\n\n/**\n * @name writeFile\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.0.10\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n * @example\n * const controller = new AbortController();\n * const { signal } = controller;\n * const data = new Uint8Array(Buffer.from('Hello Node.js'));\n * (async () => {\n * try {\n * await writeFile('message.txt', data, { signal });\n * } catch (error) {\n * // When a request is aborted - error is an AbortError\n * }\n * })();\n * // When the request should be aborted\n * controller.abort();\n */\nexport async function writeFile(filePath, data, options) {\n try {\n await writeFileNative(filePath, data, options);\n return true;\n } catch (error) {\n return error;\n }\n}\n","import { dirname } from \"node:path\";\nimport { readdir } from \"node:fs/promises\";\n\nimport { createDirectory } from \"./createDirectory.js\";\nimport { getStatus } from \"../status/getStatus.js\";\nimport { writeFile } from \"../write/writeFile.js\";\n\n/**\n * @name createFile\n * @description Asynchronous create a file.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {number|string=} mode\n * @returns {Promise}\n */\nexport async function createFile(pathLike, mode = \"0777\") {\n const [status, error] = await getStatus(pathLike);\n if (!error && status.isFile()) {\n return true;\n }\n const dirPath = dirname(pathLike);\n if (error) {\n if (error.code === \"ENOENT\") {\n const dirCreated = await createDirectory(dirPath, mode);\n if (dirCreated !== true) {\n return dirCreated;\n }\n const fileWritten = await writeFile(pathLike, \"\", { mode, flag: \"w\" });\n if (fileWritten !== true) {\n return fileWritten;\n }\n return true;\n }\n }\n if (status.isDirectory()) {\n return await writeFile(pathLike, \"\", { mode, flag: \"w\" });\n } else {\n try {\n await readdir(dirPath);\n return undefined;\n } catch (error) {\n return error;\n }\n }\n}\n","import { access } from \"node:fs/promises\";\n\n/**\n * @name accessWrapper\n * @description Asynchronously tests a user's permissions for the file specified by path.\n * @since 0.0.1\n * @async\n * @param {number} mode\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function accessWrapper(mode, path) {\n try {\n await access(path, mode);\n return true;\n } catch (error) {\n return error;\n }\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name dirIsReadable\n * @description Directory is visible to the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsReadable(pathToDir) {\n return accessWrapper(constants.R_OK, pathToDir);\n}\n","// keep updated https://github.com/sindresorhus/junk\n\nconst ignoreList = [\n // # All\n \"^npm-debug\\\\.log$\", // Error log for npm\n \"^\\\\..*\\\\.swp$\", // Swap file for vim state\n\n // # macOS\n \"^\\\\.DS_Store$\", // Stores custom folder attributes\n \"^\\\\.AppleDouble$\", // Stores additional file resources\n \"^\\\\.LSOverride$\", // Contains the absolute path to the app to be used\n \"^Icon\\\\r$\", // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop\n \"^\\\\._.*\", // Thumbnail\n \"^\\\\.Spotlight-V100(?:$|\\\\/)\", // Directory that might appear on external disk\n \"\\\\.Trashes\", // File that might appear on external disk\n \"^__MACOSX$\", // Resource fork\n\n // # Linux\n \"~$\", // Backup file\n\n // # Windows\n \"^Thumbs\\\\.db$\", // Image file cache\n \"^ehthumbs\\\\.db$\", // Folder config file\n \"^Desktop\\\\.ini$\", // Stores custom folder attributes\n \"@eaDir$\", // Synology Diskstation \"hidden\" folder where the server stores thumbnails\n \"^\\\\$RECYCLE.BIN$\", // Special folder with columns like Date deleted and Original location\n \"^System Volume Information$\",\n];\n\nexport const junkRegex = new RegExp(ignoreList.join(\"|\"));\n\n/**\n * @name isSystemJunk\n * @description Returns true if filename matches a system junk file.\n * @param {string} [fileName]\n * @returns {boolean}\n * @since 0.2.0\n */\nexport function isSystemJunk(fileName) {\n return junkRegex.test(fileName);\n}\n","import { isSystemJunk } from \"./is-system-junk.js\";\n\n/**\n * @name isNotSystemJunk\n * @description Returns true if filename matches a system junk file.\n * @param {string} [fileName]\n * @returns {boolean}\n * @since 0.2.0\n */\nexport function isNotSystemJunk(fileName) {\n return !isSystemJunk(fileName);\n}\n","import { readdir } from \"node:fs/promises\";\n\nimport { isNotSystemJunk } from \"./is-not-system-junk.js\";\n\n/**\n * @name listContents\n * @description Lists files and directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean} [ignoreJunk=true]\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\nexport async function listContents(pathToDir, ignoreJunk = true) {\n try {\n const contents = await readdir(pathToDir);\n if (ignoreJunk) {\n return contents.filter(isNotSystemJunk);\n }\n return contents;\n } catch (error) {\n return error;\n }\n}\n","import { errorExtractOptions } from \"../error/errorExtractOptions.js\";\nimport { dirIsReadable } from \"./dirIsReadable.js\";\nimport { listContents } from \"../list/contents.js\";\n\nconst EXCLUDE = [\n // macOS\n \".AppleDB\",\n \".AppleDesktop\",\n \".AppleDouble\",\n \".DS_Store\",\n \".DocumentRevisions-V100\",\n \".LSOverride\",\n \".Spotlight-V100\",\n \".TemporaryItems\",\n \".Trashes\",\n \".VolumeIcon.icns\",\n // \"._*\",\n \".apdisk\",\n \".com.apple.timemachine.donotpresent\",\n \".fseventsd\",\n \"Network Trash Folder\",\n \"Temporary Items\",\n // Windows\n \"$RECYCLE.BIN/\",\n // \"*.cab\",\n // \"*.lnk\",\n // \"*.msi\",\n // \"*.msix\",\n // \"*.msm\",\n // \"*.msp\",\n // \"*.stackdump\",\n \"Desktop.ini\",\n \"Thumbs.db\",\n \"Thumbs.db:encryptable\",\n \"desktop.ini\",\n \"ehthumbs.db\",\n \"ehthumbs_vista.db\",\n // Linux\n // \"*~\",\n // \".Trash-*\",\n \".directory\",\n // \".fuse_hidden*\",\n // \".nfs*\",\n];\n\n/**\n * @name isEmptyContent\n * @param {Array.} listOfDirsAndFiles\n * @returns {boolean}\n */\nfunction isEmptyContent(listOfDirsAndFiles) {\n const content = new Set(listOfDirsAndFiles);\n listOfDirsAndFiles.length = 0;\n content.forEach((dirOrFileName) => {\n for (const nameToExclude of EXCLUDE) {\n if (!dirOrFileName) {\n continue;\n }\n if (dirOrFileName === nameToExclude || dirOrFileName.match(RegExp(nameToExclude))) {\n content.delete(dirOrFileName);\n }\n }\n });\n return content.size === 0;\n}\n\n/**\n * @name dirIsEmpty\n * @description Check if a directory is empty\n * @since 0.1.33\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean=} excludeSystemFiles\n * @returns {Promise}\n * @throws {Error} If path is not a dir or is not readable.\n */\nexport async function dirIsEmpty(pathToDir, excludeSystemFiles = true) {\n const isReadableOrError = await dirIsReadable(pathToDir);\n if (isReadableOrError !== true) {\n throw new Error(isReadableOrError.message, errorExtractOptions(isReadableOrError));\n }\n let listOfDirsAndFiles = await listContents(pathToDir);\n if (listOfDirsAndFiles instanceof Error) {\n throw listOfDirsAndFiles;\n }\n if (listOfDirsAndFiles.length === 0) {\n return true;\n }\n if (!excludeSystemFiles) {\n return false;\n }\n return isEmptyContent(listOfDirsAndFiles);\n}\n","/**\n * @name errorExtractOptions\n * @param {Error} error\n * @returns {{ cause: Error } | { cause: { code?: string, values?: any[] | { [key: string]: any } }}}\n */\nexport function errorExtractOptions(error) {\n if (!(error instanceof Error)) {\n return { cause: error };\n }\n if (\"code\" in error && \"errno\" in error && \"path\" in error && \"syscall\" in error) {\n return {\n cause: {\n code: error.code,\n values: {\n errno: error.errno,\n path: error.path,\n syscall: error.syscall,\n },\n },\n };\n }\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name dirIsExecutable\n * @description Directory can be executed by the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsExecutable(pathToDir) {\n return accessWrapper(constants.X_OK, pathToDir);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name dirIsVisible\n * @description Directory is visible to the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsVisible(pathToDir) {\n return accessWrapper(constants.F_OK, pathToDir);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name dirIsWritable\n * @description Directory can be written by the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsWritable(pathToDir) {\n return accessWrapper(constants.W_OK, pathToDir);\n}\n","import { createHash, getHashes } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\n\n/**\n * @name hash\n * @description Calculate hash.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {string} algorithm\n * @returns {Promise}\n * @throws {TypeError} If algorithm is not supported.\n */\nexport async function hash(pathToFile, algorithm) {\n if (!getHashes().includes(algorithm)) {\n throw new TypeError(`Digest algorithm [${algorithm}] is not supported.`);\n }\n return createHash(algorithm)\n .update(await readFile(pathToFile))\n .digest(\"hex\");\n}\n","import { readFile } from \"node:fs/promises\";\n\nfunction crc32(text) {\n let chars = [];\n let actual;\n for (let current = 0; current < 256; current++) {\n actual = current;\n for (let f = 0; f < 8; f++) {\n actual = 1 & actual ? 3988292384 ^ (actual >>> 1) : actual >>> 1;\n }\n chars[current] = actual;\n }\n let number = -1;\n let index = 0;\n for (; index < text.length; index++) {\n number = (number >>> 8) ^ chars[255 & (number ^ text.charCodeAt(index))];\n }\n return (-1 ^ number) >>> 0;\n}\n\n/**\n * @name hashCrc32\n * @description CRC32.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashCrc32(pathToFile) {\n return crc32((await readFile(pathToFile)).toString(\"binary\")).toString(16);\n}\n","import { hash } from \"./hash.js\";\n\n/**\n * @name hashMd5\n * @description MD5.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashMd5(pathToFile) {\n return hash(pathToFile, \"md5\");\n}\n","import { hash } from \"./hash.js\";\n\n/**\n * @name hashSha1\n * @description SHA-1.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha1(pathToFile) {\n return hash(pathToFile, \"sha1\");\n}\n","import { hash } from \"./hash.js\";\n\n/**\n * @name hashSha256\n * @description SHA-256.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha256(pathToFile) {\n return hash(pathToFile, \"sha256\");\n}\n","import { hash } from \"./hash.js\";\n\n/**\n * @name hashSha512\n * @description SHA-512.\n * @since 0.2.6\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha512(pathToFile) {\n return hash(pathToFile, \"sha512\");\n}\n","import { stat } from \"node:fs/promises\";\n\n/**\n * @name size\n * @description File size in bytes.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {boolean=} [asString=false]\n * @returns {Promise}\n */\nexport async function size(pathToFile, asString = false) {\n const fileStats = await stat(pathToFile);\n if (!asString) {\n return fileStats.size;\n }\n return fileStats.size.toLocaleString(\"en\").replace(/,/g, \"_\");\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name fileIsExecutable\n * @description File can be executed by the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsExecutable(pathToFile) {\n return accessWrapper(constants.X_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name fileIsReadable\n * @description File is visible to the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsReadable(pathToFile) {\n return accessWrapper(constants.R_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name fileIsVisible\n * @description File is visible to the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsVisible(pathToFile) {\n return accessWrapper(constants.F_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper.js\";\n\n/**\n * @name fileIsWritable\n * @description File can be written by the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsWritable(pathToFile) {\n return accessWrapper(constants.W_OK, pathToFile);\n}\n","import { truncate } from \"node:fs/promises\";\n\n/**\n * @name fileTruncate\n * @description Truncate a file to a specified length\n * @since 0.0.6\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {number=} length\n * @returns {Promise}\n */\nexport async function fileTruncate(pathToFile, length = 0) {\n try {\n await truncate(pathToFile, length);\n return true;\n } catch (error) {\n return error;\n }\n}\n","import { join, normalize } from \"node:path\";\n\n/**\n * @name pathFrom\n * @description Join all arguments together and normalize the resulting path.\n * @since 0.1.3\n * @param {string|Array.} paths\n * @param {...string} morePaths\n * @returns {string}\n */\nexport function pathFrom(paths, ...morePaths) {\n let routes;\n if (Array.isArray(paths)) {\n routes = paths.map((path) => path.toString());\n } else {\n routes = [paths.toString()];\n }\n if (morePaths.length) {\n routes = routes.concat(morePaths.map((path) => path.toString()));\n }\n return normalize(join(...routes));\n}\n","import { getStatus } from \"../status/getStatus.js\";\nimport { listContents } from \"./contents.js\";\nimport { pathFrom } from \"../path/pathFrom.js\";\n\n/**\n * @name listDirectories\n * @description Lists directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\nexport async function listDirectories(pathToDir) {\n const contents = await listContents(pathToDir);\n if (!Array.isArray(contents)) {\n return contents;\n }\n const directories = await Promise.all(\n contents.map(async (content) => {\n const contentPath = pathFrom(pathToDir, content);\n const [status, error] = await getStatus(contentPath);\n if (error) {\n return undefined;\n }\n if (!status.isDirectory()) {\n return undefined;\n }\n return content;\n }),\n );\n return directories.filter((content) => content);\n}\n","import { getStatus } from \"../status/getStatus.js\";\nimport { listContents } from \"./contents.js\";\nimport { pathFrom } from \"../path/pathFrom.js\";\n\n/**\n * @name listFiles\n * @description Lists files in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\nexport async function listFiles(pathToDir) {\n const contents = await listContents(pathToDir);\n if (!Array.isArray(contents)) {\n return contents;\n }\n const files = await Promise.all(\n contents.map(async (content) => {\n const contentPath = pathFrom(pathToDir, content);\n const [status, error] = await getStatus(contentPath);\n if (error) {\n return undefined;\n }\n if (status.isDirectory()) {\n return undefined;\n }\n return content;\n }),\n );\n return files.filter((content) => content);\n}\n","import { rename } from \"node:fs/promises\";\n\n/**\n * @name move\n * @description Change the name or location of a file or directory.\n * @since 0.1.29\n * @param {string} pathFrom\n * @param {string} pathTo\n * @returns {Promise}\n */\nexport async function move(pathFrom, pathTo) {\n try {\n await rename(pathFrom, pathTo);\n return true;\n } catch (error) {\n return error;\n }\n}\n","import os from \"os\";\n\nconst HOME_DIRECTORY = os.homedir();\n\n/**\n * @description deConvert a tilde path to an absolute path: ~/projects β†’ /Users/anon/projects\n * @param {string} pathWithTilde\n * @returns {string}\n */\nexport function absolutePath(pathWithTilde) {\n if (HOME_DIRECTORY) {\n return String(pathWithTilde).replace(/^~(?=$|\\/|\\\\)/, HOME_DIRECTORY);\n }\n return String(pathWithTilde);\n}\n","import { resolve } from \"node:path\";\n\nimport { absolutePath } from \"./absolutePath.js\";\n\n/**\n * @name absolutePathFrom\n * @description Join all arguments together and normalize the resulting path.\n * Creates absolute path from right to left until an absolute path is constructed.\n * @since 0.1.5\n * @param {string|Array.} paths\n * @param {...string} morePaths\n * @returns {string}\n */\nexport function absolutePathFrom(paths, ...morePaths) {\n let routes;\n if (Array.isArray(paths)) {\n routes = paths.map((path) => path.toString());\n } else {\n routes = [paths.toString()];\n }\n if (morePaths.length) {\n routes = routes.concat(morePaths.map((path) => path.toString()));\n }\n return absolutePath(resolve(...routes));\n}\n","import { extname } from \"node:path\";\n\n/**\n * @name fileExtension\n * @description Get file extension.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileExtension(path) {\n return extname(path).substring(1);\n}\n","import { parse } from \"node:path\";\n\n/**\n * @name fileName\n * @description Return the file name without extension.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileName(path) {\n return parse(path).name;\n}\n","import { basename } from \"node:path\";\n\n/**\n * @name fileNameExt\n * @description Return the last portion of a path.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileNameExt(path) {\n return basename(path);\n}\n","import { dirname } from \"node:path\";\n\n/**\n * @name filePath\n * @description Return the directory name of a path.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function filePath(path) {\n return dirname(path);\n}\n","import { readFile } from \"node:fs/promises\";\n\n/**\n * @name readFileToBase64\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.21\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToBase64(pathLike) {\n try {\n const result = await readFile(pathLike, \"base64\");\n return result.toString();\n } catch (error) {\n return error;\n }\n}\n","import { readFile } from \"node:fs/promises\";\n\n/**\n * @name readFileToBuffer\n * @description Asynchronously reads the entire contents of a file into buffer.\n * @since 0.1.19\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToBuffer(pathLike) {\n try {\n const result = await readFile(pathLike, \"binary\");\n return Buffer.from(result);\n } catch (error) {\n return error;\n }\n}\n","import { readFile } from \"node:fs/promises\";\n\nimport { absolutePath } from \"../path/absolutePath.js\";\n\n/**\n * @name readFileToString\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.7\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToString(pathLike) {\n try {\n const result = await readFile(absolutePath(pathLike), \"utf8\");\n return result.toString();\n } catch (error) {\n return error;\n }\n}\n","import fs from \"fs\";\nimport assert from \"node:assert\";\nimport { join } from \"node:path\";\n\nconst IS_WINDOWS = process.platform === \"win32\";\n\n/**\n * @param {object} options\n */\nfunction defaults(options) {\n const methods = [\"unlink\", \"chmod\", \"stat\", \"lstat\", \"rmdir\", \"readdir\"];\n methods.forEach((method) => {\n options[method] = options[method] || fs[method];\n });\n options.maxBusyTries = options.maxBusyTries || 3;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction rimraf(pathLike, options, callback) {\n let busyTries = 0;\n let localCallback = callback;\n let localOptions = options;\n if (typeof localOptions === \"function\") {\n localCallback = localOptions;\n localOptions = {};\n }\n assert(pathLike, \"remove(): missing path\");\n assert.strictEqual(typeof pathLike, \"string\", \"remove(): path should be a string\");\n assert.strictEqual(typeof localCallback, \"function\", \"remove(): callback function required\");\n assert(localOptions, \"remove(): invalid options argument provided\");\n assert.strictEqual(typeof localOptions, \"object\", \"remove(): options should be object\");\n defaults(localOptions);\n rimraf_(pathLike, localOptions, function callbackRimraf(error) {\n if (error) {\n if (\n (error.code === \"EBUSY\" || error.code === \"ENOTEMPTY\" || error.code === \"EPERM\") &&\n busyTries < localOptions.maxBusyTries\n ) {\n busyTries++;\n const time = busyTries * 100;\n setTimeout(() => rimraf_(pathLike, localOptions, callbackRimraf), time);\n return;\n }\n if (error.code === \"ENOENT\") {\n localCallback(null);\n return;\n }\n }\n localCallback(error);\n });\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction rimraf_(pathLike, options, callback) {\n assert(pathLike);\n assert(options);\n assert(typeof callback === \"function\");\n options.lstat(pathLike, (error, stats) => {\n if (error && error.code === \"ENOENT\") {\n return callback(null);\n }\n if (error && error.code === \"EPERM\" && IS_WINDOWS) {\n return fixWinEPERM(pathLike, options, error, callback);\n }\n if (stats && stats.isDirectory()) {\n return rmdir(pathLike, options, error, callback);\n }\n options.unlink(pathLike, (error) => {\n if (error) {\n if (error.code === \"ENOENT\") {\n return callback(null);\n }\n if (error.code === \"EPERM\") {\n if (IS_WINDOWS) {\n return fixWinEPERM(pathLike, options, error, callback);\n } else {\n return rmdir(pathLike, options, error, callback);\n }\n }\n if (error.code === \"EISDIR\") {\n return rmdir(pathLike, options, error, callback);\n }\n }\n return callback(error);\n });\n });\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Error|null} error\n * @param {Function=} callback\n * @returns {null}\n */\nfunction fixWinEPERM(pathLike, options, error, callback) {\n assert(pathLike);\n assert(options);\n assert(typeof callback === \"function\");\n if (error) {\n assert(error instanceof Error);\n }\n options.chmod(pathLike, 0o666, (errorChMod) => {\n if (errorChMod) {\n if (errorChMod.code === \"ENOENT\") {\n callback(null);\n } else {\n callback(error);\n }\n } else {\n options.stat(pathLike, (errorStat, stats) => {\n if (errorStat) {\n if (errorStat.code === \"ENOENT\") {\n callback(null);\n } else {\n callback(error);\n }\n } else if (stats.isDirectory()) {\n rmdir(pathLike, options, error, callback);\n } else {\n options.unlink(pathLike, callback);\n }\n });\n }\n });\n return null;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Error|null} originalError\n * @param {Function=} callback\n * @returns {null}\n */\nfunction rmdir(pathLike, options, originalError, callback) {\n assert(pathLike);\n assert(options);\n if (originalError) {\n assert(originalError instanceof Error);\n }\n assert(typeof callback === \"function\");\n options.rmdir(pathLike, (error) => {\n if (error && (error.code === \"ENOTEMPTY\" || error.code === \"EEXIST\" || error.code === \"EPERM\")) {\n removeSubPath(pathLike, options, callback);\n } else if (error && error.code === \"ENOTDIR\") {\n callback(originalError);\n } else {\n callback(error);\n }\n });\n return null;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction removeSubPath(pathLike, options, callback) {\n assert(pathLike);\n assert(options);\n assert(typeof callback === \"function\");\n options.readdir(pathLike, (error, files) => {\n if (error) {\n return callback(error);\n }\n let count = files.length;\n let errState;\n if (count === 0) {\n return options.rmdir(pathLike, callback);\n }\n files.forEach((filePath) => {\n rimraf(join(pathLike, filePath), options, (error) => {\n if (errState) {\n return;\n }\n if (error) {\n callback((errState = error));\n return;\n }\n --count;\n if (count === 0) {\n options.rmdir(pathLike, callback);\n }\n });\n });\n });\n}\n\n/**\n * @name remove\n * @description Removes a file or directory.\n * @since 0.1.1\n * @async\n * @param {string} pathLike\n * @returns {Promise}\n */\nexport async function remove(pathLike) {\n return new Promise((resolve) => {\n rimraf(pathLike, {}, (error) => {\n if (error) {\n resolve(error);\n } else {\n resolve();\n }\n });\n });\n}\n","import { remove } from \"./remove.js\";\n\n/**\n * @name removeNonBlocking\n * @description Non-blocking remove of a file or directory.\n * @since 0.1.18\n * @param {string|Buffer|URL} pathLike\n * @returns {void}\n */\nexport function removeNonBlocking(pathLike) {\n remove(pathLike)\n .then(() => undefined)\n .catch(() => undefined); // don't put it into next tick\n}\n","import { rm } from \"node:fs/promises\";\n\n/**\n * @name removeSilent\n * @description Removes files and directories (modeled on the standard POSIX rm utility).\n * @summary Minimum Node version 14.14.0\n * @since 0.1.36\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {object=} options\n * @returns {Promise}\n */\nexport async function removeSilent(pathLike, options) {\n try {\n await rm(pathLike, {\n force: true,\n recursive: true,\n ...options,\n });\n } catch (__error) {\n //\n }\n}\n","import { lstat } from \"node:fs/promises\";\n\n/**\n * @name getLinkStatus\n * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to.\n * @url http://man7.org/linux/man-pages/man2/lstat.2.html\n * @since 1.1.0\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise>}\n */\nexport async function getLinkStatus(path) {\n try {\n return [await lstat(path)];\n } catch (error) {\n return [undefined, error];\n }\n}\n","import { getStatus } from \"./getStatus.js\";\n\n/**\n * @name isDirExists\n * @description Get directory status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isDirExists(path) {\n const [status, error] = await getStatus(path);\n if (error) {\n return false;\n }\n return status.isDirectory();\n}\n","import { getStatus } from \"./getStatus.js\";\n\n/**\n * @name isFileExists\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isFileExists(path) {\n const [status, error] = await getStatus(path);\n if (error) {\n return false;\n }\n return status.isFile();\n}\n","import { getStatus } from \"./getStatus.js\";\n\n/**\n * @name isPathExists\n * @description Get path status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isPathExists(path) {\n const [status] = await getStatus(path);\n return Boolean(status);\n}\n","import { createFile } from \"../create/createFile.js\";\nimport { isFileExists } from \"../status/isFileExists.js\";\nimport { readFileToString } from \"../read/readFileToString.js\";\nimport { writeFile } from \"./writeFile.js\";\n\n/**\n * @name writeFileTail\n * @description Asynchronously writes data to the end of a file.\n * @since 1.0.1\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\nexport async function writeFileTail(filePath, data, options) {\n const isFileExist = await isFileExists(filePath);\n if (isFileExist === false) {\n const isFileCreatedOrError = await createFile(filePath);\n if (isFileCreatedOrError !== true) {\n return isFileCreatedOrError;\n }\n }\n const contentOrError = await readFileToString(filePath);\n if (contentOrError instanceof Error) {\n return contentOrError;\n }\n return new Promise((resolve, reject) => {\n setTimeout(() => {\n writeFile(filePath, `${String(contentOrError)}${String(data)}`, options)\n .then(() => {\n resolve(true);\n })\n .catch((error) => {\n reject(error);\n });\n }, 1);\n });\n}\n","import { writeFile } from \"./writeFile.js\";\n\n/**\n * @name objectKeys\n * @param {object} object\n * @returns {Array.}\n */\nfunction objectKeys(object) {\n return Object.keys(object).sort((alpha, beta) => alpha.localeCompare(beta));\n}\n\n/**\n * name isObjectLike\n * @param {*} value\n * @returns {boolean}\n */\nfunction isObjectLike(value) {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\n/**\n * @name collectionSortKeys\n * @param {*} value\n * @param {boolean=} [isDeep=true]\n * @returns {*}\n */\nfunction collectionSortKeys(value, isDeep = true) {\n if (!isObjectLike(value)) {\n if (Array.isArray(value)) {\n return value.map((arrayValue) => collectionSortKeys(arrayValue, isDeep));\n }\n return value;\n }\n const keys = objectKeys(value);\n if (!keys.length) {\n return value;\n }\n return keys.reduce((sorted, key) => {\n if (isDeep && isObjectLike(value[key])) {\n sorted[key] = collectionSortKeys(value[key], isDeep);\n } else if (isDeep && Array.isArray(value[key])) {\n sorted[key] = collectionSortKeys(value[key], isDeep);\n } else {\n sorted[key] = value[key];\n }\n return sorted;\n }, {});\n}\n\n/**\n * @name writeJSON\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.1.25\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {*} data\n * @param {*|null|string=} options\n * @param {{sort: boolean, space: number|string}=} configuration\n * @returns {Promise}\n */\nexport async function writeJSON(filePath, data, options, configuration) {\n let json;\n let stringify = data;\n try {\n if (configuration) {\n if (configuration.sort) {\n if (isObjectLike(data)) {\n stringify = collectionSortKeys(JSON.parse(JSON.stringify(data)));\n } else if (Array.isArray(data)) {\n stringify = JSON.parse(JSON.stringify(data));\n } else {\n stringify = data;\n }\n }\n if (configuration.space) {\n json = JSON.stringify(stringify, null, configuration.space);\n }\n } else {\n json = JSON.stringify(stringify);\n }\n } catch (error) {\n return error;\n }\n return writeFile(filePath, json, options);\n}\n","import { absolutePathFrom } from \"./path/absolutePathFrom.js\";\n\nimport { createDirectory } from \"./create/createDirectory.js\";\nimport { createFile } from \"./create/createFile.js\";\n\nimport { dirIsExecutable } from \"./dir/dirIsExecutable.js\";\nimport { dirIsReadable } from \"./dir/dirIsReadable.js\";\nimport { dirIsVisible } from \"./dir/dirIsVisible.js\";\nimport { dirIsWritable } from \"./dir/dirIsWritable.js\";\nimport { dirIsEmpty } from \"./dir/dirIsEmpty.js\";\n\nimport { fileExtension } from \"./path/fileExtension.js\";\nimport { fileIsExecutable } from \"./file/fileIsExecutable.js\";\nimport { fileIsReadable } from \"./file/fileIsReadable.js\";\nimport { fileIsVisible } from \"./file/fileIsVisible.js\";\nimport { fileIsWritable } from \"./file/fileIsWritable.js\";\nimport { fileName } from \"./path/fileName.js\";\nimport { fileNameExt } from \"./path/fileNameExt.js\";\nimport { filePath } from \"./path/filePath.js\";\nimport { fileTruncate } from \"./file/fileTruncate.js\";\n\nimport { listContents } from \"./list/contents.js\";\nimport { listDirectories } from \"./list/directories.js\";\nimport { listFiles } from \"./list/files.js\";\n\nimport { getLinkStatus } from \"./status/getLinkStatus.js\";\nimport { getStatus } from \"./status/getStatus.js\";\n\nimport { isDirExists } from \"./status/isDirExists.js\";\nimport { isFileExists } from \"./status/isFileExists.js\";\nimport { isPathExists } from \"./status/isPathExists.js\";\n\nimport { move } from \"./move/move.js\";\n\nimport { pathFrom } from \"./path/pathFrom.js\";\n\nimport { readFileToBase64 } from \"./read/readFileToBase64.js\";\nimport { readFileToBuffer } from \"./read/readFileToBuffer.js\";\nimport { readFileToString } from \"./read/readFileToString.js\";\nimport { remove } from \"./remove/remove.js\";\nimport { removeNonBlocking } from \"./remove/removeNonBlocking.js\";\nimport { removeSilent } from \"./remove/removeSilent.js\";\n\nimport { writeFile } from \"./write/writeFile.js\";\nimport { writeFileTail } from \"./write/writeFileTail.js\";\nimport { writeJSON } from \"./write/writeJSON.js\";\n\nimport { hash } from \"./info/hash.js\";\nimport { hashCrc32 } from \"./info/hash-crc32.js\";\nimport { hashMd5 } from \"./info/hash-md5.js\";\nimport { hashSha1 } from \"./info/hash-sha1.js\";\nimport { hashSha256 } from \"./info/hash-sha256.js\";\nimport { hashSha512 } from \"./info/hash-sha512.js\";\n\nimport { size } from \"./info/size.js\";\n\nexport class HileSystemLocal {\n /**\n * @name absolutePathFrom\n * @description Join all arguments together and normalize the resulting path.\n * reates absolute path from right to left until an absolute path is constructed.\n * @since 0.1.5\n * @public\n * @param {string|Array.} paths\n * @param {...string} morePaths\n * @returns {string}\n */\n absolutePathFrom = absolutePathFrom;\n /**\n * @name createDirectory\n * @description Asynchronous create a directory.\n * @since 0.0.10\n * @async\n * @public\n * @param {string|Buffer|URL} dirPath\n * @param {number|string=} mode\n * @param {boolean=} recursive\n * @returns {Promise}\n */\n createDirectory = createDirectory;\n /**\n * @name createFile\n * @description Asynchronous create a file.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} pathLike\n * @param {number|string=} mode\n * @returns {Promise}\n */\n createFile = createFile;\n /**\n * @name dirIsExecutable\n * @description Directory can be executed by the calling process\n * @since 0.0.5\n * @async\n * @public\n * @param {string} pathToDir\n * @returns {Promise}\n */\n dirIsExecutable = dirIsExecutable;\n /**\n * @name dirIsReadable\n * @description Directory is visible to the calling process\n * @since 0.0.1\n * @async\n * @public\n * @param {string} pathToDir\n * @returns {Promise}\n */\n dirIsReadable = dirIsReadable;\n /**\n * @name dirIsVisible\n * @description Directory is visible to the calling process\n * @since 0.0.5\n * @async\n * @public\n * @param {string} pathToDir\n * @returns {Promise}\n */\n dirIsVisible = dirIsVisible;\n /**\n * @name dirIsWritable\n * @description Directory can be written by the calling process\n * @since 0.0.1\n * @async\n * @public\n * @param {string} pathToDir\n * @returns {Promise}\n */\n dirIsWritable = dirIsWritable;\n /**\n * @name dirIsEmpty\n * @description Check if a directory is empty\n * @since 0.1.33\n * @async\n * @public\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean=} excludeSystemFiles\n * @returns {Promise}\n * @throws {Error} If path is not a dir or is not readable.\n */\n dirIsEmpty = dirIsEmpty;\n /**\n * @name getLinkStatus\n * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to.\n * @url http://man7.org/linux/man-pages/man2/lstat.2.html\n * @since 1.1.0\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise>}\n */\n getLinkStatus = getLinkStatus;\n /**\n * @name getStatus\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} path\n * @returns {Promise>}\n */\n getStatus = getStatus;\n /**\n * @name isDirExists\n * @description Get directory status.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\n isDirExists = isDirExists;\n /**\n * @name isFileExists\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\n isFileExists = isFileExists;\n /**\n * @name isPathExists\n * @description Get path status.\n * @since 0.0.11\n * @async\n * @public\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\n isPathExists = isPathExists;\n /**\n * @name fileExtension\n * @description Get file extension.\n * @since 0.1.1\n * @public\n * @param {string} path\n * @returns {string}\n */\n fileExtension = fileExtension;\n /**\n * @name fileName\n * @description Return the file name without extension.\n * @since 0.1.1\n * @public\n * @param {string} path\n * @returns {string}\n */\n fileName = fileName;\n /**\n * @name fileNameExt\n * @description Return the last portion of a path.\n * @since 0.1.1\n * @public\n * @param {string} path\n * @returns {string}\n */\n fileNameExt = fileNameExt;\n /**\n * @name filePath\n * @description Return the directory name of a path.\n * @since 0.1.1\n * @public\n * @param {string} path\n * @returns {string}\n */\n filePath = filePath;\n /**\n * @name fileIsExecutable\n * @description File can be executed by the calling process\n * @since 0.0.5\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n fileIsExecutable = fileIsExecutable;\n /**\n * @name fileIsReadable\n * @description File is visible to the calling process\n * @since 0.0.1\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n fileIsReadable = fileIsReadable;\n /**\n * @name fileIsVisible\n * @description File is visible to the calling process\n * @since 0.0.5\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n fileIsVisible = fileIsVisible;\n /**\n * @name fileIsWritable\n * @description File can be written by the calling process\n * @since 0.0.1\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n fileIsWritable = fileIsWritable;\n /**\n * @name fileTruncate\n * @description Truncate a file to a specified length\n * @since 0.0.6\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @param {number=} length\n * @returns {Promise}\n */\n fileTruncate = fileTruncate;\n /**\n * @name hash\n * @description Calculate hash.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @param {string} algorithm\n * @returns {Promise}\n * @throws {TypeError} If algorithm is not supported.\n */\n hash = hash;\n /**\n * @name hashCrc32\n * @description CRC32.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashCrc32 = hashCrc32;\n /**\n * @name hashMd5\n * @description MD5.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashMd5 = hashMd5;\n /**\n * @name hashSha1\n * @description SHA-1.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashSha1 = hashSha1;\n /**\n * @name hashSha256\n * @description SHA-256.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashSha256 = hashSha256;\n /**\n * @name hashSha512\n * @description SHA-512.\n * @since 0.2.6\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\n hashSha512 = hashSha512;\n /**\n * @name listContents\n * @description Lists files and directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\n listContents = listContents;\n /**\n * @name listDirectories\n * @description Lists directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\n listDirectories = listDirectories;\n /**\n * @name listFiles\n * @description Lists files in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise|Error|{name: string, message: string, stack?: string}>}\n */\n listFiles = listFiles;\n /**\n * @name move\n * @description Change the name or location of a file or directory.\n * @since 0.1.29\n * @public\n * @param {string} pathFrom\n * @param {string} pathTo\n * @returns {Promise}\n */\n move = move;\n /**\n * @name pathFrom\n * @description Join all arguments together and normalize the resulting path.\n * @since 0.1.3\n * @public\n * @param {string|Array.} paths\n * @param {...string} morePaths\n * @returns {string}\n */\n pathFrom = pathFrom;\n /**\n * @name readFileToBase64\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.21\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\n readFileToBase64 = readFileToBase64;\n /**\n * @name readFileToBuffer\n * @description Asynchronously reads the entire contents of a file into buffer.\n * @since 0.1.19\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\n readFileToBuffer = readFileToBuffer;\n /**\n * @name readFileToString\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.7\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\n readFileToString = readFileToString;\n /**\n * @name remove\n * @description Removes a file or directory.\n * @since 0.1.1\n * @async\n * @public\n * @param {string} pathLike\n * @returns {Promise}\n */\n remove = remove;\n /**\n * @name removeNonBlocking\n * @description Non-blocking remove of a file or directory.\n * @since 0.1.18\n * @public\n * @param {string} pathLike\n * @returns {void}\n */\n removeNonBlocking = removeNonBlocking;\n /**\n * @name removeSilent\n * @description Removes files and directories (modeled on the standard POSIX rm utility).\n * @summary Minimum Node version 14.14.0\n * @since 0.1.36\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {object=} options\n * @returns {Promise}\n */\n removeSilent = removeSilent;\n /**\n * @name size\n * @description File size in bytes.\n * @since 0.2.3\n * @async\n * @public\n * @param {string|Buffer|URL} pathToFile\n * @param {boolean=} [asString=false]\n * @returns {Promise}\n */\n size = size;\n /**\n * @name writeFile\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.0.10\n * @async\n * @public\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\n writeFile = writeFile;\n /**\n * @name writeFileTail\n * @description Asynchronously writes data to the end of a file.\n * @since 1.0.1\n * @async\n * @public\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\n writeFileTail = writeFileTail;\n /**\n * @name writeJSON\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.1.25\n * @async\n * @public\n * @param {string|Buffer|URL} filePath\n * @param {*} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\n writeJSON = writeJSON;\n}\n"],"names":["async","createDirectory","dirPath","mode","recursive","mkdir","error","getStatus","path","stat","undefined","writeFile","filePath","data","options","writeFileNative","createFile","pathLike","status","isFile","dirname","code","dirCreated","fileWritten","flag","isDirectory","readdir","accessWrapper","access","dirIsReadable","pathToDir","constants","R_OK","junkRegex","RegExp","join","isNotSystemJunk","fileName","isSystemJunk","test","listContents","ignoreJunk","contents","filter","EXCLUDE","dirIsEmpty","excludeSystemFiles","isReadableOrError","Error","message","errorExtractOptions","cause","values","errno","syscall","listOfDirsAndFiles","length","isEmptyContent","content","Set","forEach","dirOrFileName","nameToExclude","match","delete","size","dirIsExecutable","X_OK","dirIsVisible","F_OK","dirIsWritable","W_OK","hash","pathToFile","algorithm","getHashes","includes","TypeError","createHash","update","readFile","digest","hashCrc32","crc32","text","actual","chars","current","f","number","index","charCodeAt","toString","hashMd5","hashSha1","hashSha256","hashSha512","asString","fileStats","toLocaleString","replace","fileIsExecutable","fileIsReadable","fileIsVisible","fileIsWritable","fileTruncate","truncate","pathFrom","paths","morePaths","routes","Array","isArray","map","concat","normalize","listDirectories","Promise","all","contentPath","listFiles","move","pathTo","rename","HOME_DIRECTORY","os","homedir","absolutePath","pathWithTilde","String","absolutePathFrom","resolve","fileExtension","extname","substring","parse","name","fileNameExt","basename","readFileToBase64","readFileToBuffer","result","Buffer","from","readFileToString","IS_WINDOWS","process","platform","rimraf","callback","busyTries","localCallback","localOptions","assert","strictEqual","defaults","method","fs","maxBusyTries","rimraf_","callbackRimraf","setTimeout","lstat","stats","fixWinEPERM","rmdir","unlink","chmod","errorChMod","errorStat","originalError","removeSubPath","files","errState","count","remove","removeNonBlocking","then","catch","removeSilent","rm","force","__error","getLinkStatus","isDirExists","isFileExists","isPathExists","Boolean","writeFileTail","isFileCreatedOrError","contentOrError","reject","isObjectLike","value","collectionSortKeys","isDeep","arrayValue","keys","objectKeys","object","Object","sort","alpha","beta","localeCompare","reduce","sorted","key","writeJSON","configuration","json","stringify","JSON","space","HileSystemLocal","constructor","_defineProperty"],"mappings":"iaAYOA,eAAeC,gBAAgBC,EAASC,EAAO,OAAQC,GAAY,GACxE,IAEE,aADMC,EAAMH,EAAS,CAAEC,KAAAA,EAAMC,UAAAA,KACtB,EACP,MAAOE,GACP,OAAOA,GCPJN,eAAeO,UAAUC,GAC9B,IACE,MAAO,OAAOC,EAAKD,IACnB,MAAOF,GACP,MAAO,MAACI,EAAWJ,ICWhBN,eAAeW,UAAUC,EAAUC,EAAMC,GAC9C,IAEE,aADMC,EAAgBH,EAAUC,EAAMC,IAC/B,EACP,MAAOR,GACP,OAAOA,GCdJN,eAAegB,WAAWC,EAAUd,EAAO,QAChD,MAAOe,EAAQZ,SAAeC,UAAUU,G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A,GAExB,MAAO7M,GACP,OAAOA,EAET,OAAOK,UAAUC,EAAUsM,EAAMpM,qfC3B5B,MAAMwM,gBAAgBC,cAAAC,wCAWRtF,kBAAgBsF,uCAYjBvN,iBAAeuN,kCAWpBxM,YAAUwM,uCAULtJ,iBAAesJ,qCAUjB3L,eAAa2L,oCAUdpJ,cAAYoJ,qCAUXlJ,eAAakJ,kCAYhB3K,YAAU2K,qCAUPjC,eAAaiC,iCAUjBjN,WAASiN,mCAUPhC,aAAWgC,oCAUV/B,cAAY+B,oCAUZ9B,cAAY8B,qCASXpF,eAAaoF,gCASlBnL,UAAQmL,mCASL/E,aAAW+E,gCASd5M,UAAQ4M,wCAUAnH,kBAAgBmH,sCAUlBlH,gBAAckH,qCAUfjH,eAAaiH,sCAUZhH,gBAAcgH,oCAWhB/G,cAAY+G,4BAYpBhJ,MAAIgJ,iCAUCtI,WAASsI,+BAUX3H,SAAO2H,gCAUN1H,UAAQ0H,kCAUNzH,YAAUyH,kCAUVxH,YAAUwH,oCASRhL,cAAYgL,uCASTpG,iBAAeoG,iCASrBhG,WAASgG,4BAUd/F,MAAI+F,gCAUA7G,UAAQ6G,wCASA7E,kBAAgB6E,wCAShB5E,kBAAgB4E,wCAShBxE,kBAAgBwE,8BAU1BzC,QAAMyC,yCASKxC,mBAAiBwC,oCAWtBrC,cAAYqC,4BAWpBvJ,MAAIuJ,iCAYC7M,WAAS6M,qCAYL5B,eAAa4B,iCAYjBR"} \ No newline at end of file +{"version":3,"file":"index.mjs","sources":["../src/core/create/create-directory.ts","../src/core/status/get-status.ts","../src/core/write/write-file.ts","../src/core/create/create-file.ts","../src/core/error/error-extract-options.ts","../src/core/access/wrapper.ts","../src/core/dir/dir-is-readable.ts","../src/core/list/is-system-junk.ts","../src/core/list/is-not-system-junk.ts","../src/core/list/contents.ts","../src/core/dir/dir-is-empty.ts","../src/core/dir/dir-is-executable.ts","../src/core/dir/dir-is-visible.ts","../src/core/dir/dir-is-writable.ts","../src/core/info/hash.ts","../src/core/info/hash-crc32.ts","../src/core/info/hash-md5.ts","../src/core/info/hash-sha1.ts","../src/core/info/hash-sha256.ts","../src/core/info/hash-sha512.ts","../src/core/info/hash-multi.ts","../src/core/info/size.ts","../src/core/file/file-is-executable.ts","../src/core/file/file-is-readable.ts","../src/core/file/file-is-visible.ts","../src/core/file/file-is-writable.ts","../src/core/file/file-truncate.ts","../src/core/path/path-from.ts","../src/core/list/directories.ts","../src/core/list/files.ts","../src/core/move/move.ts","../src/core/path/absolute-path.ts","../src/core/path/absolute-path-from.ts","../src/core/path/file-extension.ts","../src/core/path/file-name.ts","../src/core/path/file-name-ext.ts","../src/core/path/file-path.ts","../src/core/read/read-file-to-base64.ts","../src/core/read/read-file-to-buffer.ts","../src/core/read/read-file-to-string.ts","../src/core/remove/remove.ts","../src/core/remove/remove-non-blocking.ts","../src/core/remove/remove-silent.ts","../src/core/status/get-link-status.ts","../src/core/status/is-dir-exists.ts","../src/core/status/is-file-exists.ts","../src/core/status/is-path-exists.ts","../src/core/write/write-file-tail.ts","../src/core/write/write-json.ts","../src/core/hile-system-local.ts"],"sourcesContent":["import { mkdir } from \"node:fs/promises\";\n\n/**\n * @name createDirectory\n * @description Asynchronous create a directory.\n * @since 0.0.10\n * @async\n * @param {string|Buffer|URL} dirPath\n * @param {number|string=} mode\n * @param {boolean=} recursive\n * @returns {Promise}\n */\nexport async function createDirectory(\n\t//\n\tdirPath: string | Buffer | URL,\n\tmode: (number | string) | undefined = \"0777\",\n\trecursive: boolean | undefined = true,\n): Promise {\n\ttry {\n\t\tawait mkdir(dirPath, { mode, recursive });\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { stat } from \"node:fs/promises\";\n\n/**\n * @name getStatus\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise<[import(\"node:fs\").Stats|undefined, Error|undefined]>}\n */\nexport async function getStatus(\n\tpath: string | Buffer | URL,\n): Promise<[import(\"node:fs\").Stats | undefined, Error | undefined]> {\n\ttry {\n\t\treturn [await stat(path), undefined];\n\t} catch (error: unknown) {\n\t\treturn [undefined, error as Error];\n\t}\n}\n","import { writeFile as writeFileNative } from \"node:fs/promises\";\n\n/**\n * @name writeFile\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.0.10\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n * @example\n * const controller = new AbortController();\n * const { signal } = controller;\n * const data = new Uint8Array(Buffer.from('Hello Node.js'));\n * (async () => {\n * try {\n * await writeFile('message.txt', data, { signal });\n * } catch (error) {\n * // When a request is aborted - error is an AbortError\n * }\n * })();\n * // When the request should be aborted\n * controller.abort();\n */\nexport async function writeFile(\n\tfilePath: string | Buffer | URL,\n\tdata: any,\n\toptions: any | null | string = null,\n): Promise {\n\ttry {\n\t\tawait writeFileNative(filePath, data, options);\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { dirname } from \"node:path\";\nimport { readdir } from \"node:fs/promises\";\n\nimport { createDirectory } from \"./create-directory\";\nimport { getStatus } from \"../status/get-status\";\nimport { writeFile } from \"../write/write-file\";\n\n/**\n * @name createFile\n * @description Asynchronous create a file.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {number|string=} mode\n * @returns {Promise}\n */\nexport async function createFile(\n\tpathLike: string | Buffer | URL,\n\tmode: string = \"0777\",\n): Promise {\n\tconst [status, error] = await getStatus(pathLike);\n\tif (!error && (status as import(\"node:fs\").Stats).isFile()) {\n\t\treturn true;\n\t}\n\tconst dirPath = dirname(pathLike as string);\n\tif (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\tconst dirCreated = await createDirectory(dirPath, mode);\n\t\t\tif (dirCreated !== true) {\n\t\t\t\treturn dirCreated;\n\t\t\t}\n\t\t\tconst fileWritten = await writeFile(pathLike, \"\", { mode, flag: \"w\" });\n\t\t\tif (fileWritten !== true) {\n\t\t\t\treturn fileWritten;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t}\n\tif ((status as import(\"node:fs\").Stats).isDirectory()) {\n\t\treturn await writeFile(pathLike, \"\", { mode, flag: \"w\" });\n\t} else {\n\t\ttry {\n\t\t\tawait readdir(dirPath);\n\t\t\treturn undefined;\n\t\t} catch (error: unknown) {\n\t\t\treturn error as Error;\n\t\t}\n\t}\n}\n","/**\n * @name errorExtractOptions\n * @param {Error} error\n * @returns {{ cause: Error } | { cause: { code?: string, values?: any[] | { [key: string]: any } }}}\n */\nexport function errorExtractOptions(\n\terror: any,\n): { cause: Error } | { cause: { code?: string; values?: any[] | { [key: string]: any } } } {\n\tif (!(error instanceof Error)) {\n\t\treturn { cause: error };\n\t}\n\tif (\"code\" in error && \"errno\" in error && \"path\" in error && \"syscall\" in error) {\n\t\treturn {\n\t\t\tcause: {\n\t\t\t\tcode: (error as NodeJS.ErrnoException).code as string,\n\t\t\t\tvalues: {\n\t\t\t\t\terrno: error.errno,\n\t\t\t\t\tpath: error.path,\n\t\t\t\t\tsyscall: error.syscall,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\treturn { cause: error };\n}\n","import { access } from \"node:fs/promises\";\n\n/**\n * @name accessWrapper\n * @description Asynchronously tests a user's permissions for the file specified by path.\n * @since 0.0.1\n * @async\n * @param {number} mode\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function accessWrapper(mode: number, path: string | Buffer | URL): Promise {\n\ttry {\n\t\tawait access(path, mode);\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name dirIsReadable\n * @description Directory is visible to the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsReadable(pathToDir: string | Buffer | URL): Promise {\n\tif (process?.permission?.has(\"fs.read\") !== undefined) {\n\t\tconst isWritable = process.permission?.has(\"fs.read\", pathToDir as string);\n\t\tif (isWritable !== undefined) {\n\t\t\treturn isWritable;\n\t\t}\n\t}\n\treturn accessWrapper(constants.R_OK, pathToDir);\n}\n","// keep updated https://github.com/sindresorhus/junk\n\nconst ignoreList = [\n\t// # All\n\t\"^npm-debug\\\\.log$\", // Error log for npm\n\t\"^\\\\..*\\\\.swp$\", // Swap file for vim state\n\n\t// # macOS\n\t\"^\\\\.DS_Store$\", // Stores custom folder attributes\n\t\"^\\\\.AppleDouble$\", // Stores additional file resources\n\t\"^\\\\.LSOverride$\", // Contains the absolute path to the app to be used\n\t\"^Icon\\\\r$\", // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop\n\t\"^\\\\._.*\", // Thumbnail\n\t\"^\\\\.Spotlight-V100(?:$|\\\\/)\", // Directory that might appear on external disk\n\t\"\\\\.Trashes\", // File that might appear on external disk\n\t\"^__MACOSX$\", // Resource fork\n\n\t// # Linux\n\t\"~$\", // Backup file\n\n\t// # Windows\n\t\"^Thumbs\\\\.db$\", // Image file cache\n\t\"^ehthumbs\\\\.db$\", // Folder config file\n\t\"^Desktop\\\\.ini$\", // Stores custom folder attributes\n\t\"@eaDir$\", // Synology Diskstation \"hidden\" folder where the server stores thumbnails\n\t\"^\\\\$RECYCLE.BIN$\", // Special folder with columns like Date deleted and Original location\n\t\"^System Volume Information$\",\n];\n\nexport const junkRegex = new RegExp(ignoreList.join(\"|\"));\n\n/**\n * @name isSystemJunk\n * @description Returns true if filename matches a system junk file.\n * @param {string} [fileName]\n * @returns {boolean}\n * @since 0.2.0\n */\nexport function isSystemJunk(fileName: string): boolean {\n\treturn junkRegex.test(fileName);\n}\n","import { isSystemJunk } from \"./is-system-junk\";\n\n/**\n * @name isNotSystemJunk\n * @description Returns true if filename matches a system junk file.\n * @param {string} [fileName]\n * @returns {boolean}\n * @since 0.2.0\n */\nexport function isNotSystemJunk(fileName: string): boolean {\n\treturn !isSystemJunk(fileName);\n}\n","import { readdir } from \"node:fs/promises\";\n\nimport { isNotSystemJunk } from \"./is-not-system-junk\";\n\n/**\n * @name listContents\n * @description Lists files and directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean} [ignoreJunk=true]\n * @returns {Promise}\n */\nexport async function listContents(pathToDir: string | Buffer | URL, ignoreJunk = true): Promise {\n\ttry {\n\t\tconst contents = await readdir(pathToDir);\n\t\tif (ignoreJunk) {\n\t\t\treturn contents.filter(isNotSystemJunk);\n\t\t}\n\t\treturn contents;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { errorExtractOptions } from \"../error/error-extract-options\";\nimport { dirIsReadable } from \"./dir-is-readable\";\nimport { listContents } from \"../list/contents\";\n\nconst EXCLUDE = [\n\t// macOS\n\t\".AppleDB\",\n\t\".AppleDesktop\",\n\t\".AppleDouble\",\n\t\".DS_Store\",\n\t\".DocumentRevisions-V100\",\n\t\".LSOverride\",\n\t\".Spotlight-V100\",\n\t\".TemporaryItems\",\n\t\".Trashes\",\n\t\".VolumeIcon.icns\",\n\t// \"._*\",\n\t\".apdisk\",\n\t\".com.apple.timemachine.donotpresent\",\n\t\".fseventsd\",\n\t\"Network Trash Folder\",\n\t\"Temporary Items\",\n\t// Windows\n\t\"$RECYCLE.BIN/\",\n\t// \"*.cab\",\n\t// \"*.lnk\",\n\t// \"*.msi\",\n\t// \"*.msix\",\n\t// \"*.msm\",\n\t// \"*.msp\",\n\t// \"*.stackdump\",\n\t\"Desktop.ini\",\n\t\"Thumbs.db\",\n\t\"Thumbs.db:encryptable\",\n\t\"desktop.ini\",\n\t\"ehthumbs.db\",\n\t\"ehthumbs_vista.db\",\n\t// Linux\n\t// \"*~\",\n\t// \".Trash-*\",\n\t\".directory\",\n\t// \".fuse_hidden*\",\n\t// \".nfs*\",\n];\n\n/**\n * @name isEmptyContent\n * @param {string[]} listOfDirsAndFiles\n * @returns {boolean}\n */\nfunction isEmptyContent(listOfDirsAndFiles: string[]): boolean {\n\tconst content = new Set(listOfDirsAndFiles);\n\tlistOfDirsAndFiles.length = 0;\n\tcontent.forEach((dirOrFileName: string) => {\n\t\tfor (const nameToExclude of EXCLUDE) {\n\t\t\tif (!dirOrFileName) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (dirOrFileName === nameToExclude || dirOrFileName.match(RegExp(nameToExclude))) {\n\t\t\t\tcontent.delete(dirOrFileName);\n\t\t\t}\n\t\t}\n\t});\n\treturn content.size === 0;\n}\n\n/**\n * @name dirIsEmpty\n * @description Check if a directory is empty\n * @since 0.1.33\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @param {boolean=} excludeSystemFiles\n * @returns {Promise}\n * @throws {Error} If path is not a dir or is not readable.\n */\nexport async function dirIsEmpty(\n\tpathToDir: string | Buffer | URL,\n\texcludeSystemFiles: boolean = true,\n): Promise {\n\tconst isReadableOrError = await dirIsReadable(pathToDir);\n\tif (isReadableOrError !== true) {\n\t\tthrow new Error((isReadableOrError as Error).message, errorExtractOptions(isReadableOrError));\n\t}\n\tlet listOfDirsAndFiles = await listContents(pathToDir);\n\tif (listOfDirsAndFiles instanceof Error) {\n\t\tthrow listOfDirsAndFiles;\n\t}\n\tif ((listOfDirsAndFiles as string[]).length === 0) {\n\t\treturn true;\n\t}\n\tif (!excludeSystemFiles) {\n\t\treturn false;\n\t}\n\treturn isEmptyContent(listOfDirsAndFiles as string[]);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name dirIsExecutable\n * @description Directory can be executed by the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsExecutable(pathToDir: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.X_OK, pathToDir);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name dirIsVisible\n * @description Directory is visible to the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsVisible(pathToDir: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.F_OK, pathToDir);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name dirIsWritable\n * @description Directory can be written by the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function dirIsWritable(pathToDir: string | Buffer | URL): Promise {\n\tif (process?.permission?.has(\"fs.write\") !== undefined) {\n\t\tconst isWritable = process.permission?.has(\"fs.write\", pathToDir as string);\n\t\tif (isWritable !== undefined) {\n\t\t\treturn isWritable;\n\t\t}\n\t}\n\treturn accessWrapper(constants.W_OK, pathToDir);\n}\n","import { createHash, getHashes } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\n\n/**\n * @name hash\n * @description Calculate hash.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {string} algorithm\n * @returns {Promise}\n * @throws {TypeError} If algorithm is not supported.\n */\nexport async function hash(pathToFile: string | Buffer | URL, algorithm: string): Promise {\n\tif (!getHashes().includes(algorithm)) {\n\t\tthrow new TypeError(`Digest algorithm [${algorithm}] is not supported.`);\n\t}\n\treturn createHash(algorithm)\n\t\t.update(await readFile(pathToFile))\n\t\t.digest(\"hex\");\n}\n","import { readFile } from \"node:fs/promises\";\n\nfunction crc32(text: string): number {\n\tlet chars = [];\n\tlet actual;\n\tfor (let current = 0; current < 256; current++) {\n\t\tactual = current;\n\t\tfor (let f = 0; f < 8; f++) {\n\t\t\tactual = 1 & actual ? 3988292384 ^ (actual >>> 1) : actual >>> 1;\n\t\t}\n\t\tchars[current] = actual;\n\t}\n\tlet number = -1;\n\tlet index = 0;\n\tfor (; index < text.length; index++) {\n\t\t// @ts-ignore\n\t\tnumber = (number >>> 8) ^ chars[255 & (number ^ text.charCodeAt(index))];\n\t}\n\treturn (-1 ^ number) >>> 0;\n}\n\n/**\n * @name hashCrc32\n * @description CRC32.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashCrc32(pathToFile: string | Buffer | URL): Promise {\n\treturn crc32((await readFile(pathToFile)).toString(\"binary\")).toString(16);\n}\n","import { hash } from \"./hash\";\n\n/**\n * @name hashMd5\n * @description MD5.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashMd5(pathToFile: string | Buffer | URL): Promise {\n\treturn hash(pathToFile, \"md5\");\n}\n","import { hash } from \"./hash\";\n\n/**\n * @name hashSha1\n * @description SHA-1.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha1(pathToFile: string | Buffer | URL): Promise {\n\treturn hash(pathToFile, \"sha1\");\n}\n","import { hash } from \"./hash\";\n\n/**\n * @name hashSha256\n * @description SHA-256.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha256(pathToFile: string | Buffer | URL): Promise {\n\treturn hash(pathToFile, \"sha256\");\n}\n","import { hash } from \"./hash\";\n\n/**\n * @name hashSha512\n * @description SHA-512.\n * @since 0.2.6\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function hashSha512(pathToFile: string | Buffer | URL): Promise {\n\treturn hash(pathToFile, \"sha512\");\n}\n","import { hashCrc32 } from \"./hash-crc32\";\nimport { hashMd5 } from \"./hash-md5\";\nimport { hashSha1 } from \"./hash-sha1\";\nimport { hashSha256 } from \"./hash-sha256\";\nimport { hashSha512 } from \"./hash-sha512\";\n\n/**\n * @name hashMulti\n * @description Calculates multiple hashes.\n * @summary The objective of the \"hashMulti\" function is to calculate multiple hashes (CRC32, MD5, SHA-1, SHA-256, and SHA-512) for a given file path and return them as an object.\n * @since 1.1.1\n * @async\n * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed.\n * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>}\n * @throws {Error|TypeError}\n */\nexport async function hashMulti(\n\tpathToFile: string | Buffer | URL,\n): Promise<{ crc32: string; md5: string; sha1: string; sha256: string; sha512: string }> {\n\treturn await Promise.all([\n\t\thashCrc32(pathToFile) as Promise,\n\t\thashMd5(pathToFile) as Promise,\n\t\thashSha1(pathToFile) as Promise,\n\t\thashSha256(pathToFile) as Promise,\n\t\thashSha512(pathToFile) as Promise,\n\t]).then(\n\t\t([\n\t\t\t//\n\t\t\tcrc32,\n\t\t\tmd5,\n\t\t\tsha1,\n\t\t\tsha256,\n\t\t\tsha512,\n\t\t]) => ({ crc32, md5, sha1, sha256, sha512 }),\n\t);\n}\n","import { stat } from \"node:fs/promises\";\n\n/**\n * @name size\n * @description File size in bytes.\n * @since 0.2.3\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {boolean=} [asString=false]\n * @returns {Promise}\n */\nexport async function size(\n\tpathToFile: string | Buffer | URL,\n\tasString: boolean = false,\n): Promise {\n\tconst fileStats = await stat(pathToFile);\n\tif (!asString) {\n\t\treturn fileStats.size;\n\t}\n\treturn fileStats.size.toLocaleString(\"en\").replace(/,/g, \"_\");\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name fileIsExecutable\n * @description File can be executed by the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsExecutable(pathToFile: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.X_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name fileIsReadable\n * @description File is visible to the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsReadable(pathToFile: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.R_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name fileIsVisible\n * @description File is visible to the calling process\n * @since 0.0.5\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsVisible(pathToFile: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.F_OK, pathToFile);\n}\n","import { constants } from \"node:fs\";\n\nimport { accessWrapper } from \"../access/wrapper\";\n\n/**\n * @name fileIsWritable\n * @description File can be written by the calling process\n * @since 0.0.1\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @returns {Promise}\n */\nexport async function fileIsWritable(pathToFile: string | Buffer | URL): Promise {\n\treturn accessWrapper(constants.W_OK, pathToFile);\n}\n","import { truncate } from \"node:fs/promises\";\n\n/**\n * @name fileTruncate\n * @description Truncate a file to a specified length\n * @since 0.0.6\n * @async\n * @param {string|Buffer|URL} pathToFile\n * @param {number=} length\n * @returns {Promise}\n */\nexport async function fileTruncate(pathToFile: string | Buffer | URL, length: number = 0): Promise {\n\ttry {\n\t\tawait truncate(pathToFile, length);\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { join, normalize } from \"node:path\";\n\n/**\n * @name pathFrom\n * @description Join all arguments together and normalize the resulting path.\n * @since 0.1.3\n * @param {string|Buffer|URL|string[]|Buffer[]|URL[]} paths\n * @param {...string} morePaths\n * @returns {string}\n */\nexport function pathFrom(paths: string | Buffer | URL | string[] | Buffer[] | URL[], ...morePaths: string[]): string {\n\tlet routes;\n\tif (Array.isArray(paths)) {\n\t\troutes = paths.map((path) => path.toString());\n\t} else {\n\t\troutes = [paths.toString()];\n\t}\n\tif (morePaths.length) {\n\t\troutes = routes.concat(morePaths.map((path) => path.toString()));\n\t}\n\treturn normalize(join(...routes));\n}\n","import { getStatus } from \"../status/get-status\";\nimport { listContents } from \"./contents\";\nimport { pathFrom } from \"../path/path-from\";\n\n/**\n * @name listDirectories\n * @description Lists directories in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function listDirectories(pathToDir: string | Buffer | URL): Promise {\n\tconst contents = await listContents(pathToDir);\n\tif (!Array.isArray(contents)) {\n\t\treturn contents;\n\t}\n\tconst directories = await Promise.all(\n\t\tcontents.map(async (content) => {\n\t\t\tconst contentPath = pathFrom(pathToDir, content);\n\t\t\tconst [status, error] = await getStatus(contentPath);\n\t\t\tif (error) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (!(status as import(\"node:fs\").Stats).isDirectory()) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn content;\n\t\t}),\n\t);\n\treturn directories.filter((content) => content) as string[];\n}\n","import { getStatus } from \"../status/get-status\";\nimport { listContents } from \"./contents\";\nimport { pathFrom } from \"../path/path-from\";\n\n/**\n * @name listFiles\n * @description Lists files in path\n * @since 0.1.32\n * @async\n * @param {string|Buffer|URL} pathToDir\n * @returns {Promise}\n */\nexport async function listFiles(pathToDir: string | Buffer | URL): Promise {\n\tconst contents = await listContents(pathToDir);\n\tif (!Array.isArray(contents)) {\n\t\treturn contents;\n\t}\n\tconst files = await Promise.all(\n\t\tcontents.map(async (content) => {\n\t\t\tconst contentPath = pathFrom(pathToDir, content);\n\t\t\tconst [status, error] = await getStatus(contentPath);\n\t\t\tif (error) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif ((status as import(\"node:fs\").Stats).isDirectory()) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn content;\n\t\t}),\n\t);\n\treturn files.filter((content) => content) as string[];\n}\n","import { rename } from \"node:fs/promises\";\n\n/**\n * @name move\n * @description Change the name or location of a file or directory.\n * @since 0.1.29\n * @param {string} pathFrom\n * @param {string} pathTo\n * @returns {Promise}\n */\nexport async function move(pathFrom: string, pathTo: string): Promise {\n\ttry {\n\t\tawait rename(pathFrom, pathTo);\n\t\treturn true;\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { homedir } from \"node:os\";\n\nconst HOME_DIRECTORY = homedir();\n\n/**\n * @description deConvert a tilde path to an absolute path: ~/projects β†’ /Users/anon/projects\n * @param {string} pathWithTilde\n * @returns {string}\n */\nexport function absolutePath(pathWithTilde: string): string {\n\tif (HOME_DIRECTORY) {\n\t\treturn String(pathWithTilde).replace(/^~(?=$|\\/|\\\\)/, HOME_DIRECTORY);\n\t}\n\treturn String(pathWithTilde);\n}\n","import { resolve } from \"node:path\";\n\nimport { absolutePath } from \"./absolute-path\";\n\n/**\n * @name absolutePathFrom\n * @description Join all arguments together and normalize the resulting path.\n * Creates absolute path from right to left until an absolute path is constructed.\n * @since 0.1.5\n * @param {string|string[]} paths\n * @param {...string} morePaths\n * @returns {string}\n */\nexport function absolutePathFrom(paths: string | string[], ...morePaths: string[]): string {\n\tlet routes: string[];\n\tif (Array.isArray(paths)) {\n\t\troutes = paths.map((path) => path.toString());\n\t} else {\n\t\troutes = [paths.toString()];\n\t}\n\tif (morePaths.length) {\n\t\troutes = routes.concat(morePaths.map((path) => path.toString()));\n\t}\n\treturn absolutePath(resolve(...routes));\n}\n","import { extname } from \"node:path\";\n\n/**\n * @name fileExtension\n * @description Get file extension.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileExtension(path: string): string {\n\treturn extname(path).substring(1);\n}\n","import { parse } from \"node:path\";\n\n/**\n * @name fileName\n * @description Return the file name without extension.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileName(path: string): string {\n\treturn parse(path).name;\n}\n","import { basename } from \"node:path\";\n\n/**\n * @name fileNameExt\n * @description Return the last portion of a path.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function fileNameExt(path: string): string {\n\treturn basename(path);\n}\n","import { dirname } from \"node:path\";\n\n/**\n * @name filePath\n * @description Return the directory name of a path.\n * @since 0.1.1\n * @param {string} path\n * @returns {string}\n */\nexport function filePath(path: string): string {\n\treturn dirname(path);\n}\n","import { readFile } from \"node:fs/promises\";\n\n/**\n * @name readFileToBase64\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.21\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToBase64(pathLike: string | Buffer | URL): Promise {\n\ttry {\n\t\tconst result = await readFile(pathLike, \"base64\");\n\t\treturn result.toString();\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { readFile } from \"node:fs/promises\";\n\n/**\n * @name readFileToBuffer\n * @description Asynchronously reads the entire contents of a file into buffer.\n * @since 0.1.19\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToBuffer(pathLike: string | Buffer | URL): Promise {\n\ttry {\n\t\tconst result = await readFile(pathLike, \"binary\");\n\t\treturn Buffer.from(result);\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","import { readFile } from \"node:fs/promises\";\n\nimport { absolutePath } from \"../path/absolute-path\";\n\n/**\n * @name readFileToString\n * @description Asynchronously reads the entire contents of a file into string.\n * @since 0.1.7\n * @async\n * @param {string|Buffer|URL} pathLike\n * @returns {Promise}\n */\nexport async function readFileToString(pathLike: string | Buffer | URL): Promise {\n\ttry {\n\t\tconst result = await readFile(absolutePath(pathLike as string), \"utf8\");\n\t\treturn result.toString();\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n}\n","// @ts-ignore\nimport fs from \"node:fs\";\n// @ts-ignore\nimport assert from \"node:assert\";\nimport { join } from \"node:path\";\n\nconst IS_WINDOWS = process.platform === \"win32\";\n\n/**\n * @param {object} options\n */\nfunction defaults(options: any) {\n\tconst methods = [\"unlink\", \"chmod\", \"stat\", \"lstat\", \"rmdir\", \"readdir\"];\n\tmethods.forEach((method) => {\n\t\toptions[method] = options[method] || fs[method];\n\t});\n\toptions.maxBusyTries = options.maxBusyTries || 3;\n}\n\n/**\n * @param {string | Buffer | URL} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction rimraf(\n\tpathLike: string | Buffer | URL,\n\toptions: any,\n\tcallback: (error: NodeJS.ErrnoException | null) => void,\n): void {\n\tlet busyTries = 0;\n\tlet localCallback = callback;\n\tlet localOptions = options;\n\tif (typeof localOptions === \"function\") {\n\t\tlocalCallback = localOptions;\n\t\tlocalOptions = {};\n\t}\n\tassert(pathLike, \"remove(): missing path\");\n\t// assert.strictEqual(typeof pathLike, \"string\", \"remove(): path should be a string\");\n\t// assert.strictEqual(typeof localCallback, \"function\", \"remove(): callback function required\");\n\tassert(localOptions, \"remove(): invalid options argument provided\");\n\t// assert.strictEqual(typeof localOptions, \"object\", \"remove(): options should be an object?\");\n\tdefaults(localOptions);\n\trimraf_(pathLike as string, localOptions, function callbackRimraf(error: NodeJS.ErrnoException | null) {\n\t\tif (error) {\n\t\t\tif (\n\t\t\t\t(error.code === \"EBUSY\" || error.code === \"ENOTEMPTY\" || error.code === \"EPERM\") &&\n\t\t\t\tbusyTries < localOptions.maxBusyTries\n\t\t\t) {\n\t\t\t\tbusyTries++;\n\t\t\t\tconst time = busyTries * 100;\n\t\t\t\tsetTimeout(() => rimraf_(pathLike as string, localOptions, callbackRimraf), time);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\tlocalCallback(null);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tlocalCallback(error);\n\t});\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction rimraf_(pathLike: string, options: any, callback: (error: NodeJS.ErrnoException | null) => void): void {\n\tassert(pathLike);\n\tassert(options);\n\tassert(typeof callback === \"function\");\n\toptions.lstat(pathLike, (error: NodeJS.ErrnoException | null, stats: fs.Stats | fs.BigIntStats | undefined) => {\n\t\tif (error && error.code === \"ENOENT\") {\n\t\t\treturn callback(null);\n\t\t}\n\t\tif (error && error.code === \"EPERM\" && IS_WINDOWS) {\n\t\t\treturn fixWinEPERM(pathLike, options, error, callback);\n\t\t}\n\t\tif (stats && stats.isDirectory()) {\n\t\t\treturn rmdir(pathLike, options, error as NodeJS.ErrnoException, callback);\n\t\t}\n\t\toptions.unlink(pathLike, (error: NodeJS.ErrnoException | null): void | any => {\n\t\t\tif (error) {\n\t\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\t\treturn callback(null);\n\t\t\t\t}\n\t\t\t\tif (error.code === \"EPERM\") {\n\t\t\t\t\tif (IS_WINDOWS) {\n\t\t\t\t\t\treturn fixWinEPERM(pathLike, options, error, callback);\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn rmdir(pathLike, options, error, callback);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (error.code === \"EISDIR\") {\n\t\t\t\t\treturn rmdir(pathLike, options, error, callback);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn callback(error);\n\t\t});\n\t});\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Error|null} error\n * @param {Function=} callback\n * @returns {null}\n */\nfunction fixWinEPERM(\n\tpathLike: string,\n\toptions: any,\n\terror: NodeJS.ErrnoException | null,\n\tcallback: (error: NodeJS.ErrnoException | null) => void,\n): null {\n\tassert(pathLike);\n\tassert(options);\n\tassert(typeof callback === \"function\");\n\tif (error) {\n\t\tassert(error instanceof Error);\n\t}\n\toptions.chmod(pathLike, 0o666, (errorChMod: NodeJS.ErrnoException | null): void => {\n\t\tif (errorChMod) {\n\t\t\tif (errorChMod.code === \"ENOENT\") {\n\t\t\t\tcallback(null);\n\t\t\t} else {\n\t\t\t\tcallback(error);\n\t\t\t}\n\t\t} else {\n\t\t\toptions.stat(\n\t\t\t\tpathLike,\n\t\t\t\t(errorStat: NodeJS.ErrnoException | null, stats: fs.Stats | fs.BigIntStats | undefined) => {\n\t\t\t\t\tif (errorStat) {\n\t\t\t\t\t\tif (errorStat.code === \"ENOENT\") {\n\t\t\t\t\t\t\tcallback(null);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcallback(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (stats.isDirectory()) {\n\t\t\t\t\t\trmdir(pathLike, options, error as NodeJS.ErrnoException, callback);\n\t\t\t\t\t} else {\n\t\t\t\t\t\toptions.unlink(pathLike, callback);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t});\n\treturn null;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Error|null} originalError\n * @param {Function=} callback\n * @returns {null}\n */\nfunction rmdir(\n\tpathLike: string,\n\toptions: any,\n\toriginalError: NodeJS.ErrnoException,\n\tcallback: (error: NodeJS.ErrnoException | null) => void,\n) {\n\tassert(pathLike);\n\tassert(options);\n\tif (originalError) {\n\t\tassert(originalError instanceof Error);\n\t}\n\tassert(typeof callback === \"function\");\n\toptions.rmdir(pathLike, (error: NodeJS.ErrnoException): void => {\n\t\tif (error && (error.code === \"ENOTEMPTY\" || error.code === \"EEXIST\" || error.code === \"EPERM\")) {\n\t\t\tremoveSubPath(pathLike, options, callback);\n\t\t} else if (error && error.code === \"ENOTDIR\") {\n\t\t\tcallback(originalError);\n\t\t} else {\n\t\t\tcallback(error);\n\t\t}\n\t});\n\treturn null;\n}\n\n/**\n * @param {string} pathLike\n * @param {Function|object=} options\n * @param {Function=} callback\n */\nfunction removeSubPath(pathLike: string, options: any, callback: (error: NodeJS.ErrnoException | null) => void): void {\n\tassert(pathLike);\n\tassert(options);\n\tassert(typeof callback === \"function\");\n\toptions.readdir(pathLike, (error: Error | null, files: string[] | Buffer[] | fs.Dirent[]) => {\n\t\tif (error) {\n\t\t\treturn callback(error);\n\t\t}\n\t\tlet count = files.length;\n\t\tlet errState: Error | null = null;\n\t\tif (count === 0) {\n\t\t\treturn options.rmdir(pathLike, callback);\n\t\t}\n\t\tfiles.forEach((filePath: string): void => {\n\t\t\trimraf(join(pathLike, filePath), options, (error): void => {\n\t\t\t\tif (errState) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (error) {\n\t\t\t\t\tcallback((errState = error));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t--count;\n\t\t\t\tif (count === 0) {\n\t\t\t\t\toptions.rmdir(pathLike, callback);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t});\n}\n\n/**\n * @name remove\n * @description Removes a file or directory.\n * @since 0.1.1\n * @async\n * @param {string | Buffer | URL} pathLike\n * @returns {Promise}\n */\nexport async function remove(pathLike: string | Buffer | URL): Promise {\n\treturn new Promise((resolve) => {\n\t\trimraf(pathLike, {}, (error: unknown) => {\n\t\t\tif (error) {\n\t\t\t\tresolve(error as Error);\n\t\t\t} else {\n\t\t\t\tresolve(true);\n\t\t\t}\n\t\t});\n\t});\n}\n","import { remove } from \"./remove\";\n\n/**\n * @name removeNonBlocking\n * @description Non-blocking remove of a file or directory.\n * @since 0.1.18\n * @param {string|Buffer|URL} pathLike\n * @returns {void}\n */\nexport function removeNonBlocking(pathLike: string | Buffer | URL): void {\n\tremove(pathLike)\n\t\t.then(() => undefined)\n\t\t.catch(() => undefined); // don't put it into next tick\n}\n","import { rm } from \"node:fs/promises\";\n\nimport type { RmOptions } from \"node:fs\";\n\n/**\n * @name removeSilent\n * @description Removes files and directories (modeled on the standard POSIX rm utility).\n * @summary Minimum Node version 14.14.0\n * @since 0.1.36\n * @async\n * @param {string|Buffer|URL} pathLike\n * @param {RmOptions=} options\n * @returns {Promise}\n */\nexport async function removeSilent(pathLike: string | Buffer | URL, options: RmOptions): Promise {\n\ttry {\n\t\tawait rm(pathLike, {\n\t\t\tforce: true,\n\t\t\trecursive: true,\n\t\t\t...options,\n\t\t});\n\t} catch (__error) {\n\t\t//\n\t}\n}\n","import { lstat } from \"node:fs/promises\";\n\n/**\n * @name getLinkStatus\n * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to.\n * @url http://man7.org/linux/man-pages/man2/lstat.2.html\n * @since 1.1.0\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise<[import(\"node:fs\").Stats|undefined, Error|undefined]>}\n */\nexport async function getLinkStatus(\n\tpath: string | Buffer | URL,\n): Promise<[import(\"node:fs\").Stats | undefined, Error | undefined]> {\n\ttry {\n\t\treturn [await lstat(path), undefined];\n\t} catch (error: unknown) {\n\t\treturn [undefined, error as Error];\n\t}\n}\n","import { getStatus } from \"./get-status\";\n\n/**\n * @name isDirExists\n * @description Get directory status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isDirExists(path: string | Buffer | URL): Promise {\n\tconst [status, error] = await getStatus(path);\n\tif (error) {\n\t\treturn false;\n\t}\n\treturn (status as import(\"node:fs\").Stats).isDirectory();\n}\n","import { getStatus } from \"./get-status\";\n\n/**\n * @name isFileExists\n * @description Get file status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isFileExists(path: string | Buffer | URL): Promise {\n\tconst [status, error] = await getStatus(path);\n\tif (error) {\n\t\treturn false;\n\t}\n\treturn (status as import(\"node:fs\").Stats).isFile();\n}\n","import { getStatus } from \"./get-status\";\n\n/**\n * @name isPathExists\n * @description Get path status.\n * @since 0.0.11\n * @async\n * @param {string|Buffer|URL} path\n * @returns {Promise}\n */\nexport async function isPathExists(path: string | Buffer | URL): Promise {\n\tconst [status] = await getStatus(path);\n\treturn Boolean(status);\n}\n","import { createFile } from \"../create/create-file\";\nimport { isFileExists } from \"../status/is-file-exists\";\nimport { readFileToString } from \"../read/read-file-to-string\";\nimport { writeFile } from \"./write-file\";\n\n/**\n * @name writeFileTail\n * @description Asynchronously writes data to the end of a file.\n * @since 1.0.1\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {string} data\n * @param {*|null|string=} options\n * @returns {Promise}\n */\nexport async function writeFileTail(\n\tfilePath: string | Buffer | URL,\n\tdata: any,\n\toptions: any | null | string = null,\n): Promise {\n\tconst isFileExist = await isFileExists(filePath);\n\tif (!isFileExist) {\n\t\tconst isFileCreatedOrError = await createFile(filePath);\n\t\tif (isFileCreatedOrError !== true) {\n\t\t\treturn isFileCreatedOrError as Error;\n\t\t}\n\t}\n\tconst contentOrError = await readFileToString(filePath);\n\tif (contentOrError instanceof Error) {\n\t\treturn contentOrError;\n\t}\n\treturn new Promise((resolve, reject) => {\n\t\tsetTimeout(() => {\n\t\t\twriteFile(filePath, `${String(contentOrError)}${String(data)}`, options)\n\t\t\t\t.then(() => {\n\t\t\t\t\tresolve(true);\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\treject(error);\n\t\t\t\t});\n\t\t}, 1);\n\t});\n}\n","import { writeFile } from \"./write-file\";\n\n/**\n * @name objectKeys\n * @param {object} object\n * @returns {string[]}\n */\nfunction objectKeys(object: object) {\n\treturn Object.keys(object).sort((alpha, beta) => alpha.localeCompare(beta));\n}\n\n/**\n * name isObjectLike\n * @param {*} value\n * @returns {boolean}\n */\nfunction isObjectLike(value: any) {\n\treturn value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\n/**\n * @name collectionSortKeys\n * @param {*} value\n * @param {boolean=} [isDeep=true]\n * @returns {Record|any[]}\n */\nfunction collectionSortKeys(value: any, isDeep = true): Record | any[] {\n\tif (!isObjectLike(value)) {\n\t\tif (Array.isArray(value)) {\n\t\t\treturn value.map((arrayValue) => collectionSortKeys(arrayValue, isDeep));\n\t\t}\n\t\treturn value;\n\t}\n\tconst keys = objectKeys(value);\n\tif (!keys.length) {\n\t\treturn value;\n\t}\n\treturn keys.reduce((sorted: Record, key) => {\n\t\tif (isDeep && isObjectLike(value[key])) {\n\t\t\tsorted[key] = collectionSortKeys(value[key], isDeep);\n\t\t} else if (isDeep && Array.isArray(value[key])) {\n\t\t\tsorted[key] = collectionSortKeys(value[key], isDeep);\n\t\t} else {\n\t\t\tsorted[key] = value[key];\n\t\t}\n\t\treturn sorted;\n\t}, {});\n}\n\n/**\n * @name writeJson\n * @description Asynchronously writes data to a file, replacing the file if it already exists.\n * @since 0.1.25\n * @async\n * @param {string|Buffer|URL} filePath\n * @param {*} data\n * @param {*|null|string=} options\n * @param {{sort: boolean, space: number|string}=} configuration\n * @returns {Promise}\n */\nexport async function writeJson(\n\tfilePath: string | Buffer | URL,\n\tdata: any,\n\toptions: any | null | string = null,\n\tconfiguration: { sort: boolean; space: number | string } | undefined,\n): Promise {\n\tlet json;\n\tlet stringify = data;\n\ttry {\n\t\tif (configuration) {\n\t\t\tif (configuration.sort) {\n\t\t\t\tif (isObjectLike(data)) {\n\t\t\t\t\tstringify = collectionSortKeys(JSON.parse(JSON.stringify(data)));\n\t\t\t\t} else if (Array.isArray(data)) {\n\t\t\t\t\tstringify = JSON.parse(JSON.stringify(data));\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (configuration.space) {\n\t\t\t\tjson = JSON.stringify(stringify, null, configuration.space);\n\t\t\t}\n\t\t} else {\n\t\t\tjson = JSON.stringify(stringify);\n\t\t}\n\t} catch (error: unknown) {\n\t\treturn error as Error;\n\t}\n\treturn writeFile(filePath, json, options);\n}\n","import { absolutePathFrom } from \"./path/absolute-path-from\";\n\nimport { createDirectory } from \"./create/create-directory\";\nimport { createFile } from \"./create/create-file\";\n\nimport { dirIsExecutable } from \"./dir/dir-is-executable\";\nimport { dirIsReadable } from \"./dir/dir-is-readable\";\nimport { dirIsVisible } from \"./dir/dir-is-visible\";\nimport { dirIsWritable } from \"./dir/dir-is-writable\";\nimport { dirIsEmpty } from \"./dir/dir-is-empty\";\n\nimport { fileExtension } from \"./path/file-extension\";\nimport { fileIsExecutable } from \"./file/file-is-executable\";\nimport { fileIsReadable } from \"./file/file-is-readable\";\nimport { fileIsVisible } from \"./file/file-is-visible\";\nimport { fileIsWritable } from \"./file/file-is-writable\";\nimport { fileName } from \"./path/file-name\";\nimport { fileNameExt } from \"./path/file-name-ext\";\nimport { filePath } from \"./path/file-path\";\nimport { fileTruncate } from \"./file/file-truncate\";\n\nimport { listContents } from \"./list/contents\";\nimport { listDirectories } from \"./list/directories\";\nimport { listFiles } from \"./list/files\";\n\nimport { getLinkStatus } from \"./status/get-link-status\";\nimport { getStatus } from \"./status/get-status\";\n\nimport { isDirExists } from \"./status/is-dir-exists\";\nimport { isFileExists } from \"./status/is-file-exists\";\nimport { isPathExists } from \"./status/is-path-exists\";\n\nimport { move } from \"./move/move\";\n\nimport { pathFrom } from \"./path/path-from\";\n\nimport { readFileToBase64 } from \"./read/read-file-to-base64\";\nimport { readFileToBuffer } from \"./read/read-file-to-buffer\";\nimport { readFileToString } from \"./read/read-file-to-string\";\nimport { remove } from \"./remove/remove\";\nimport { removeNonBlocking } from \"./remove/remove-non-blocking\";\nimport { removeSilent } from \"./remove/remove-silent\";\n\nimport { writeFile } from \"./write/write-file\";\nimport { writeFileTail } from \"./write/write-file-tail\";\nimport { writeJson } from \"./write/write-json\";\n\nimport { hash } from \"./info/hash\";\nimport { hashCrc32 } from \"./info/hash-crc32\";\nimport { hashMd5 } from \"./info/hash-md5\";\nimport { hashMulti } from \"./info/hash-multi\";\nimport { hashSha1 } from \"./info/hash-sha1\";\nimport { hashSha256 } from \"./info/hash-sha256\";\nimport { hashSha512 } from \"./info/hash-sha512\";\n\nimport { size } from \"./info/size\";\n\nexport class HileSystemLocal {\n\t/**\n\t * @name absolutePathFrom\n\t * @description Join all arguments together and normalize the resulting path.\n\t * Creates absolute path from right to left until an absolute path is constructed.\n\t * @since 0.1.5\n\t * @public\n\t * @param {string|string[]} paths\n\t * @param {...string} morePaths\n\t * @returns {string}\n\t */\n\tabsolutePathFrom = absolutePathFrom;\n\t/**\n\t * @name createDirectory\n\t * @description Asynchronous create a directory.\n\t * @since 0.0.10\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} dirPath\n\t * @param {number|string=} mode\n\t * @param {boolean=} recursive\n\t * @returns {Promise}\n\t */\n\tcreateDirectory = createDirectory;\n\t/**\n\t * @name createFile\n\t * @description Asynchronous create a file.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathLike\n\t * @param {number|string=} mode\n\t * @returns {Promise}\n\t */\n\tcreateFile = createFile;\n\t/**\n\t * @name dirIsExecutable\n\t * @description Directory can be executed by the calling process\n\t * @since 0.0.5\n\t * @async\n\t * @public\n\t * @param {string} pathToDir\n\t * @returns {Promise}\n\t */\n\tdirIsExecutable = dirIsExecutable;\n\t/**\n\t * @name dirIsReadable\n\t * @description Directory is visible to the calling process\n\t * @since 0.0.1\n\t * @async\n\t * @public\n\t * @param {string} pathToDir\n\t * @returns {Promise}\n\t */\n\tdirIsReadable = dirIsReadable;\n\t/**\n\t * @name dirIsVisible\n\t * @description Directory is visible to the calling process\n\t * @since 0.0.5\n\t * @async\n\t * @public\n\t * @param {string} pathToDir\n\t * @returns {Promise}\n\t */\n\tdirIsVisible = dirIsVisible;\n\t/**\n\t * @name dirIsWritable\n\t * @description Directory can be written by the calling process\n\t * @since 0.0.1\n\t * @async\n\t * @public\n\t * @param {string} pathToDir\n\t * @returns {Promise}\n\t */\n\tdirIsWritable = dirIsWritable;\n\t/**\n\t * @name dirIsEmpty\n\t * @description Check if a directory is empty\n\t * @since 0.1.33\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToDir\n\t * @param {boolean=} excludeSystemFiles\n\t * @returns {Promise}\n\t * @throws {Error} If path is not a dir or is not readable.\n\t */\n\tdirIsEmpty = dirIsEmpty;\n\t/**\n\t * @name getLinkStatus\n\t * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to.\n\t * @url http://man7.org/linux/man-pages/man2/lstat.2.html\n\t * @since 1.1.0\n\t * @async\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise>}\n\t */\n\tgetLinkStatus = getLinkStatus;\n\t/**\n\t * @name getStatus\n\t * @description Get file status.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise>}\n\t */\n\tgetStatus = getStatus;\n\t/**\n\t * @name isDirExists\n\t * @description Get directory status.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise}\n\t */\n\tisDirExists = isDirExists;\n\t/**\n\t * @name isFileExists\n\t * @description Get file status.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise}\n\t */\n\tisFileExists = isFileExists;\n\t/**\n\t * @name isPathExists\n\t * @description Get path status.\n\t * @since 0.0.11\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} path\n\t * @returns {Promise}\n\t */\n\tisPathExists = isPathExists;\n\t/**\n\t * @name fileExtension\n\t * @description Get file extension.\n\t * @since 0.1.1\n\t * @public\n\t * @param {string} path\n\t * @returns {string}\n\t */\n\tfileExtension = fileExtension;\n\t/**\n\t * @name fileName\n\t * @description Return the file name without extension.\n\t * @since 0.1.1\n\t * @public\n\t * @param {string} path\n\t * @returns {string}\n\t */\n\tfileName = fileName;\n\t/**\n\t * @name fileNameExt\n\t * @description Return the last portion of a path.\n\t * @since 0.1.1\n\t * @public\n\t * @param {string} path\n\t * @returns {string}\n\t */\n\tfileNameExt = fileNameExt;\n\t/**\n\t * @name filePath\n\t * @description Return the directory name of a path.\n\t * @since 0.1.1\n\t * @public\n\t * @param {string} path\n\t * @returns {string}\n\t */\n\tfilePath = filePath;\n\t/**\n\t * @name fileIsExecutable\n\t * @description File can be executed by the calling process\n\t * @since 0.0.5\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\tfileIsExecutable = fileIsExecutable;\n\t/**\n\t * @name fileIsReadable\n\t * @description File is visible to the calling process\n\t * @since 0.0.1\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\tfileIsReadable = fileIsReadable;\n\t/**\n\t * @name fileIsVisible\n\t * @description File is visible to the calling process\n\t * @since 0.0.5\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\tfileIsVisible = fileIsVisible;\n\t/**\n\t * @name fileIsWritable\n\t * @description File can be written by the calling process\n\t * @since 0.0.1\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\tfileIsWritable = fileIsWritable;\n\t/**\n\t * @name fileTruncate\n\t * @description Truncate a file to a specified length\n\t * @since 0.0.6\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @param {number=} length\n\t * @returns {Promise}\n\t */\n\tfileTruncate = fileTruncate;\n\t/**\n\t * @name hash\n\t * @description Calculate hash.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @param {string} algorithm\n\t * @returns {Promise}\n\t * @throws {TypeError} If algorithm is not supported.\n\t */\n\thash = hash;\n\t/**\n\t * @name hashCrc32\n\t * @description CRC32.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashCrc32 = hashCrc32;\n\t/**\n\t * @name hashMd5\n\t * @description MD5.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashMd5 = hashMd5;\n\t/**\n\t * @name hashMulti\n\t * @description Calculates multiple hashes.\n\t * @since 1.1.1\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed.\n\t * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>}\n\t * @throws {Error|TypeError}\n\t */\n\thashMulti = hashMulti;\n\t/**\n\t * @name hashSha1\n\t * @description SHA-1.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashSha1 = hashSha1;\n\t/**\n\t * @name hashSha256\n\t * @description SHA-256.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashSha256 = hashSha256;\n\t/**\n\t * @name hashSha512\n\t * @description SHA-512.\n\t * @since 0.2.6\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @returns {Promise}\n\t */\n\thashSha512 = hashSha512;\n\t/**\n\t * @name listContents\n\t * @description Lists files and directories in path\n\t * @since 0.1.32\n\t * @async\n\t * @param {string|Buffer|URL} pathToDir\n\t * @returns {Promise}\n\t */\n\tlistContents = listContents;\n\t/**\n\t * @name listDirectories\n\t * @description Lists directories in path\n\t * @since 0.1.32\n\t * @async\n\t * @param {string|Buffer|URL} pathToDir\n\t * @returns {Promise}\n\t */\n\tlistDirectories = listDirectories;\n\t/**\n\t * @name listFiles\n\t * @description Lists files in path\n\t * @since 0.1.32\n\t * @async\n\t * @param {string|Buffer|URL} pathToDir\n\t * @returns {Promise}\n\t */\n\tlistFiles = listFiles;\n\t/**\n\t * @name move\n\t * @description Change the name or location of a file or directory.\n\t * @since 0.1.29\n\t * @public\n\t * @param {string} pathFrom\n\t * @param {string} pathTo\n\t * @returns {Promise}\n\t */\n\tmove = move;\n\t/**\n\t * @name pathFrom\n\t * @description Join all arguments together and normalize the resulting path.\n\t * @since 0.1.3\n\t * @public\n\t * @param {string|string[]} paths\n\t * @param {...string} morePaths\n\t * @returns {string}\n\t */\n\tpathFrom = pathFrom;\n\t/**\n\t * @name readFileToBase64\n\t * @description Asynchronously reads the entire contents of a file into string.\n\t * @since 0.1.21\n\t * @async\n\t * @param {string|Buffer|URL} pathLike\n\t * @returns {Promise}\n\t */\n\treadFileToBase64 = readFileToBase64;\n\t/**\n\t * @name readFileToBuffer\n\t * @description Asynchronously reads the entire contents of a file into buffer.\n\t * @since 0.1.19\n\t * @async\n\t * @param {string|Buffer|URL} pathLike\n\t * @returns {Promise}\n\t */\n\treadFileToBuffer = readFileToBuffer;\n\t/**\n\t * @name readFileToString\n\t * @description Asynchronously reads the entire contents of a file into string.\n\t * @since 0.1.7\n\t * @async\n\t * @param {string|Buffer|URL} pathLike\n\t * @returns {Promise}\n\t */\n\treadFileToString = readFileToString;\n\t/**\n\t * @name remove\n\t * @description Removes a file or directory.\n\t * @since 0.1.1\n\t * @async\n\t * @public\n\t * @param {string} pathLike\n\t * @returns {Promise}\n\t */\n\tremove = remove;\n\t/**\n\t * @name removeNonBlocking\n\t * @description Non-blocking remove of a file or directory.\n\t * @since 0.1.18\n\t * @public\n\t * @param {string} pathLike\n\t * @returns {void}\n\t */\n\tremoveNonBlocking = removeNonBlocking;\n\t/**\n\t * @name removeSilent\n\t * @description Removes files and directories (modeled on the standard POSIX rm utility).\n\t * @summary Minimum Node version 14.14.0\n\t * @since 0.1.36\n\t * @async\n\t * @param {string|Buffer|URL} pathLike\n\t * @param {object=} options\n\t * @returns {Promise}\n\t */\n\tremoveSilent = removeSilent;\n\t/**\n\t * @name size\n\t * @description File size in bytes.\n\t * @since 0.2.3\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} pathToFile\n\t * @param {boolean=} [asString=false]\n\t * @returns {Promise}\n\t */\n\tsize = size;\n\t/**\n\t * @name writeFile\n\t * @description Asynchronously writes data to a file, replacing the file if it already exists.\n\t * @since 0.0.10\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} filePath\n\t * @param {string} data\n\t * @param {*|null|string=} options\n\t * @returns {Promise}\n\t */\n\twriteFile = writeFile;\n\t/**\n\t * @name writeFileTail\n\t * @description Asynchronously writes data to the end of a file.\n\t * @since 1.0.1\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} filePath\n\t * @param {string} data\n\t * @param {*|null|string=} options\n\t * @returns {Promise}\n\t */\n\twriteFileTail = writeFileTail;\n\t/**\n\t * @name writeJson\n\t * @description Asynchronously writes data to a file, replacing the file if it already exists.\n\t * @since 0.1.25\n\t * @async\n\t * @public\n\t * @param {string|Buffer|URL} filePath\n\t * @param {*} data\n\t * @param {*|null|string=} options\n\t * @returns {Promise}\n\t */\n\twriteJson = writeJson;\n}\n"],"names":["createDirectory","dirPath","mode","recursive","mkdir","error","getStatus","path","stat","writeFile","filePath","data","options","writeFileNative","createFile","pathLike","status","dirname","dirCreated","fileWritten","readdir","errorExtractOptions","accessWrapper","access","dirIsReadable","pathToDir","_a","isWritable","_b","constants","ignoreList","junkRegex","isSystemJunk","fileName","isNotSystemJunk","listContents","ignoreJunk","contents","EXCLUDE","isEmptyContent","listOfDirsAndFiles","content","dirOrFileName","nameToExclude","dirIsEmpty","excludeSystemFiles","isReadableOrError","dirIsExecutable","dirIsVisible","dirIsWritable","hash","pathToFile","algorithm","getHashes","createHash","readFile","crc32","text","chars","actual","current","f","number","index","hashCrc32","hashMd5","hashSha1","hashSha256","hashSha512","hashMulti","md5","sha1","sha256","sha512","size","asString","fileStats","fileIsExecutable","fileIsReadable","fileIsVisible","fileIsWritable","fileTruncate","length","truncate","pathFrom","paths","morePaths","routes","normalize","join","listDirectories","contentPath","listFiles","move","pathTo","rename","HOME_DIRECTORY","homedir","absolutePath","pathWithTilde","absolutePathFrom","resolve","fileExtension","extname","parse","fileNameExt","basename","readFileToBase64","readFileToBuffer","result","readFileToString","IS_WINDOWS","defaults","method","fs","rimraf","callback","busyTries","localCallback","localOptions","assert","rimraf_","callbackRimraf","time","stats","fixWinEPERM","rmdir","errorChMod","errorStat","originalError","removeSubPath","files","count","errState","remove","removeNonBlocking","removeSilent","rm","getLinkStatus","lstat","isDirExists","isFileExists","isPathExists","writeFileTail","isFileCreatedOrError","contentOrError","reject","objectKeys","object","alpha","beta","isObjectLike","value","collectionSortKeys","isDeep","arrayValue","keys","sorted","key","writeJson","configuration","json","stringify","HileSystemLocal"],"mappings":";;;;;;AAYA,eAAsBA,EAErBC,GACAC,IAAsC,QACtCC,IAAiC,IACN;AACvB,MAAA;AACH,iBAAMC,EAAMH,GAAS,EAAE,MAAAC,GAAM,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,IAUC,KAAA,gBAAAC,IAYH,KAAA,aAAAL,IAUG,KAAA,gBAAA8F,IAUJ,KAAA,YAAApI,GAUE,KAAA,cAAAsI,IAUC,KAAA,eAAAC,GAUA,KAAA,eAAAC,IASC,KAAA,gBAAAxC,IASL,KAAA,WAAArE,IASG,KAAA,cAAAwE,IASH,KAAA,WAAA/F,IAUQ,KAAA,mBAAAmE,IAUF,KAAA,iBAAAC,IAUD,KAAA,gBAAAC,IAUC,KAAA,iBAAAC,IAWF,KAAA,eAAAC,IAYR,KAAA,OAAA/B,GAUK,KAAA,YAAAc,GAUF,KAAA,UAAAC,GAWE,KAAA,YAAAI,IAUD,KAAA,WAAAH,GAUE,KAAA,aAAAC,GAUA,KAAA,aAAAC,GASE,KAAA,eAAAjC,GASG,KAAA,kBAAAuD,IASN,KAAA,YAAAE,IAUL,KAAA,OAAAC,IAUI,KAAA,WAAAT,GASQ,KAAA,mBAAAuB,IASA,KAAA,mBAAAC,IASA,KAAA,mBAAAE,GAUV,KAAA,SAAAwB,GASW,KAAA,oBAAAC,IAWL,KAAA,eAAAC,IAWR,KAAA,OAAA9D,IAYK,KAAA,YAAAjE,GAYI,KAAA,gBAAAsI,IAYJ,KAAA,YAAAgB;AAAA,EAAA;AACb;"} \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..ff8b4c5 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1 @@ +export default {}; diff --git a/package.json b/package.json index eb5dc7d..03b2111 100644 --- a/package.json +++ b/package.json @@ -1,69 +1,81 @@ { - "author": "Anton Trofymenko", - "bugs": { - "url": "https://github.com/hilesystem/local/issues" - }, - "contributors": [ - { - "email": "r37r0m0d3l@protonmail.com", - "name": "Anton Trofymenko" - } - ], - "description": "Filesystem abstraction layer and common function wrappers", - "devDependencies": { - "@r37r0m0d3l/rollup-config-pkg": "git+https://github.com/r37r0m0d3l/rollup-config-pkg.git", - "@types/node": "16.11.7" - }, - "engines": { - "node": ">=16.17.0" - }, - "engineStrict": true, - "exports": { - ".": { - "node": { - "import": "./dist/index.mjs", - "require": "./dist/index.cjs" - }, - "import": "./dist/index.mjs", - "require": "./dist/index.cjs", - "default": "./dist/index.js", - "types": "./dist/index.d.ts" - } - }, - "files": [ - "dist/index.cjs", - "dist/index.cjs.map", - "dist/index.d.cts", - "dist/index.d.mts", - "dist/index.d.ts", - "dist/index.js", - "dist/index.js.map", - "dist/index.mjs", - "dist/index.mjs.map" - ], - "keywords": [ - "@hilesystem", - "file system", - "file", - "fs" - ], - "license": "MIT", - "main": "./dist/index.cjs", - "module": "./dist/index.mjs", - "name": "@hilesystem/local", - "repository": { - "type": "git", - "url": "git+https://github.com/hilesystem/local.git" - }, - "scripts": { - "build": "rollup --config rollup.config.mjs", - "build:watch": "rollup --config rollup.config.mjs --watch", - "lint": "eslint ./src/**/*.js", - "test": "npm run test:cjs && npm run test:mjs", - "test:cjs": "node --test ./test/index.test.cjs", - "test:mjs": "node --test ./test/index.test.mjs" - }, - "type": "module", - "types": "./dist/index.d.ts", - "version": "1.1.0" + "author": "Anton Trofymenko", + "bugs": { + "url": "https://github.com/hilesystem/local/issues" + }, + "contributors": [ + { + "email": "r37r0m0d3l@protonmail.com", + "name": "Anton Trofymenko" + } + ], + "description": "Filesystem abstraction layer and common function wrappers", + "devDependencies": { + "@types/node": "20.14.0", + "eslint": "8.57.0", + "eslint-config-standard": "17.1.0", + "eslint-plugin-import": "2.29.1", + "eslint-plugin-n": "16.6.2", + "eslint-plugin-promise": "6.2.0", + "prettier": "3.3.0", + "shx": "0.3.4", + "tsup": "8.1.0", + "typescript": "5.4.5", + "vite": "5.2.12", + "vite-plugin-node-externals": "0.0.1" + }, + "engines": { + "node": ">=18.20.2" + }, + "engineStrict": false, + "exports": { + ".": { + "node": { + "import": "./dist/index.mjs", + "require": "./dist/index.cjs" + }, + "import": "./dist/index.mjs", + "require": "./dist/index.cjs", + "default": "./dist/index.js", + "types": "./dist/index.d.ts" + } + }, + "files": [ + "dist/index.cjs", + "dist/index.cjs.map", + "dist/index.d.cts", + "dist/index.d.mts", + "dist/index.d.ts", + "dist/index.js", + "dist/index.js.map", + "dist/index.mjs", + "dist/index.mjs.map" + ], + "keywords": [ + "@hilesystem", + "file system", + "file", + "fs" + ], + "license": "MIT", + "main": "./dist/index.cjs", + "module": "./dist/index.mjs", + "name": "@hilesystem/local", + "repository": { + "type": "git", + "url": "git+https://github.com/hilesystem/local.git" + }, + "scripts": { + "build": "vite build --mode production & npm run build:after", + "build:after": "npm run build:dts & shx cp ./dist/index.mjs ./dist/index.js & shx cp ./dist/index.mjs.map ./dist/index.js.map & shx cp ./dist/index.d.ts ./dist/index.d.mts", + "build:dts": "tsup --dts & shx rm -r ./dist/src/", + "format": "prettier --write ./src/**/*.ts", + "lint": "eslint", + "test": "npm run test:cjs && npm run test:mjs", + "test:cjs": "node --test ./test/index.test.cjs", + "test:mjs": "node --test ./test/index.test.mjs" + }, + "type": "module", + "types": "./dist/index.d.ts", + "version": "1.2.0" } diff --git a/rollup.config.mjs b/rollup.config.mjs deleted file mode 100644 index be93b87..0000000 --- a/rollup.config.mjs +++ /dev/null @@ -1,18 +0,0 @@ -/* eslint-env node */ -import rollupConfigPkg from "@r37r0m0d3l/rollup-config-pkg"; - -let config = {}; -Object.assign(config, rollupConfigPkg("index", "index")); -Object.assign(config, { - external: [ - // - "node:assert", - "node:crypto", - "node:fs", - "node:fs/promises", - "node:path", - ], -}); -config.output[2].format = "cjs"; - -export default config; diff --git a/src/core/HileSystemLocal.js b/src/core/HileSystemLocal.js deleted file mode 100644 index 3523fdd..0000000 --- a/src/core/HileSystemLocal.js +++ /dev/null @@ -1,494 +0,0 @@ -import { absolutePathFrom } from "./path/absolutePathFrom.js"; - -import { createDirectory } from "./create/createDirectory.js"; -import { createFile } from "./create/createFile.js"; - -import { dirIsExecutable } from "./dir/dirIsExecutable.js"; -import { dirIsReadable } from "./dir/dirIsReadable.js"; -import { dirIsVisible } from "./dir/dirIsVisible.js"; -import { dirIsWritable } from "./dir/dirIsWritable.js"; -import { dirIsEmpty } from "./dir/dirIsEmpty.js"; - -import { fileExtension } from "./path/fileExtension.js"; -import { fileIsExecutable } from "./file/fileIsExecutable.js"; -import { fileIsReadable } from "./file/fileIsReadable.js"; -import { fileIsVisible } from "./file/fileIsVisible.js"; -import { fileIsWritable } from "./file/fileIsWritable.js"; -import { fileName } from "./path/fileName.js"; -import { fileNameExt } from "./path/fileNameExt.js"; -import { filePath } from "./path/filePath.js"; -import { fileTruncate } from "./file/fileTruncate.js"; - -import { listContents } from "./list/contents.js"; -import { listDirectories } from "./list/directories.js"; -import { listFiles } from "./list/files.js"; - -import { getLinkStatus } from "./status/getLinkStatus.js"; -import { getStatus } from "./status/getStatus.js"; - -import { isDirExists } from "./status/isDirExists.js"; -import { isFileExists } from "./status/isFileExists.js"; -import { isPathExists } from "./status/isPathExists.js"; - -import { move } from "./move/move.js"; - -import { pathFrom } from "./path/pathFrom.js"; - -import { readFileToBase64 } from "./read/readFileToBase64.js"; -import { readFileToBuffer } from "./read/readFileToBuffer.js"; -import { readFileToString } from "./read/readFileToString.js"; -import { remove } from "./remove/remove.js"; -import { removeNonBlocking } from "./remove/removeNonBlocking.js"; -import { removeSilent } from "./remove/removeSilent.js"; - -import { writeFile } from "./write/writeFile.js"; -import { writeFileTail } from "./write/writeFileTail.js"; -import { writeJSON } from "./write/writeJSON.js"; - -import { hash } from "./info/hash.js"; -import { hashCrc32 } from "./info/hash-crc32.js"; -import { hashMd5 } from "./info/hash-md5.js"; -import { hashSha1 } from "./info/hash-sha1.js"; -import { hashSha256 } from "./info/hash-sha256.js"; -import { hashSha512 } from "./info/hash-sha512.js"; - -import { size } from "./info/size.js"; - -export class HileSystemLocal { - /** - * @name absolutePathFrom - * @description Join all arguments together and normalize the resulting path. - * reates absolute path from right to left until an absolute path is constructed. - * @since 0.1.5 - * @public - * @param {string|Array.} paths - * @param {...string} morePaths - * @returns {string} - */ - absolutePathFrom = absolutePathFrom; - /** - * @name createDirectory - * @description Asynchronous create a directory. - * @since 0.0.10 - * @async - * @public - * @param {string|Buffer|URL} dirPath - * @param {number|string=} mode - * @param {boolean=} recursive - * @returns {Promise} - */ - createDirectory = createDirectory; - /** - * @name createFile - * @description Asynchronous create a file. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} pathLike - * @param {number|string=} mode - * @returns {Promise} - */ - createFile = createFile; - /** - * @name dirIsExecutable - * @description Directory can be executed by the calling process - * @since 0.0.5 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - dirIsExecutable = dirIsExecutable; - /** - * @name dirIsReadable - * @description Directory is visible to the calling process - * @since 0.0.1 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - dirIsReadable = dirIsReadable; - /** - * @name dirIsVisible - * @description Directory is visible to the calling process - * @since 0.0.5 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - dirIsVisible = dirIsVisible; - /** - * @name dirIsWritable - * @description Directory can be written by the calling process - * @since 0.0.1 - * @async - * @public - * @param {string} pathToDir - * @returns {Promise} - */ - dirIsWritable = dirIsWritable; - /** - * @name dirIsEmpty - * @description Check if a directory is empty - * @since 0.1.33 - * @async - * @public - * @param {string|Buffer|URL} pathToDir - * @param {boolean=} excludeSystemFiles - * @returns {Promise} - * @throws {Error} If path is not a dir or is not readable. - */ - dirIsEmpty = dirIsEmpty; - /** - * @name getLinkStatus - * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to. - * @url http://man7.org/linux/man-pages/man2/lstat.2.html - * @since 1.1.0 - * @async - * @param {string|Buffer|URL} path - * @returns {Promise>} - */ - getLinkStatus = getLinkStatus; - /** - * @name getStatus - * @description Get file status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise>} - */ - getStatus = getStatus; - /** - * @name isDirExists - * @description Get directory status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise} - */ - isDirExists = isDirExists; - /** - * @name isFileExists - * @description Get file status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise} - */ - isFileExists = isFileExists; - /** - * @name isPathExists - * @description Get path status. - * @since 0.0.11 - * @async - * @public - * @param {string|Buffer|URL} path - * @returns {Promise} - */ - isPathExists = isPathExists; - /** - * @name fileExtension - * @description Get file extension. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - fileExtension = fileExtension; - /** - * @name fileName - * @description Return the file name without extension. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - fileName = fileName; - /** - * @name fileNameExt - * @description Return the last portion of a path. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - fileNameExt = fileNameExt; - /** - * @name filePath - * @description Return the directory name of a path. - * @since 0.1.1 - * @public - * @param {string} path - * @returns {string} - */ - filePath = filePath; - /** - * @name fileIsExecutable - * @description File can be executed by the calling process - * @since 0.0.5 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - fileIsExecutable = fileIsExecutable; - /** - * @name fileIsReadable - * @description File is visible to the calling process - * @since 0.0.1 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - fileIsReadable = fileIsReadable; - /** - * @name fileIsVisible - * @description File is visible to the calling process - * @since 0.0.5 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - fileIsVisible = fileIsVisible; - /** - * @name fileIsWritable - * @description File can be written by the calling process - * @since 0.0.1 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - fileIsWritable = fileIsWritable; - /** - * @name fileTruncate - * @description Truncate a file to a specified length - * @since 0.0.6 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @param {number=} length - * @returns {Promise} - */ - fileTruncate = fileTruncate; - /** - * @name hash - * @description Calculate hash. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @param {string} algorithm - * @returns {Promise} - * @throws {TypeError} If algorithm is not supported. - */ - hash = hash; - /** - * @name hashCrc32 - * @description CRC32. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - hashCrc32 = hashCrc32; - /** - * @name hashMd5 - * @description MD5. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - hashMd5 = hashMd5; - /** - * @name hashSha1 - * @description SHA-1. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - hashSha1 = hashSha1; - /** - * @name hashSha256 - * @description SHA-256. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - hashSha256 = hashSha256; - /** - * @name hashSha512 - * @description SHA-512. - * @since 0.2.6 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ - hashSha512 = hashSha512; - /** - * @name listContents - * @description Lists files and directories in path - * @since 0.1.32 - * @async - * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ - listContents = listContents; - /** - * @name listDirectories - * @description Lists directories in path - * @since 0.1.32 - * @async - * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ - listDirectories = listDirectories; - /** - * @name listFiles - * @description Lists files in path - * @since 0.1.32 - * @async - * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ - listFiles = listFiles; - /** - * @name move - * @description Change the name or location of a file or directory. - * @since 0.1.29 - * @public - * @param {string} pathFrom - * @param {string} pathTo - * @returns {Promise} - */ - move = move; - /** - * @name pathFrom - * @description Join all arguments together and normalize the resulting path. - * @since 0.1.3 - * @public - * @param {string|Array.} paths - * @param {...string} morePaths - * @returns {string} - */ - pathFrom = pathFrom; - /** - * @name readFileToBase64 - * @description Asynchronously reads the entire contents of a file into string. - * @since 0.1.21 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ - readFileToBase64 = readFileToBase64; - /** - * @name readFileToBuffer - * @description Asynchronously reads the entire contents of a file into buffer. - * @since 0.1.19 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ - readFileToBuffer = readFileToBuffer; - /** - * @name readFileToString - * @description Asynchronously reads the entire contents of a file into string. - * @since 0.1.7 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ - readFileToString = readFileToString; - /** - * @name remove - * @description Removes a file or directory. - * @since 0.1.1 - * @async - * @public - * @param {string} pathLike - * @returns {Promise} - */ - remove = remove; - /** - * @name removeNonBlocking - * @description Non-blocking remove of a file or directory. - * @since 0.1.18 - * @public - * @param {string} pathLike - * @returns {void} - */ - removeNonBlocking = removeNonBlocking; - /** - * @name removeSilent - * @description Removes files and directories (modeled on the standard POSIX rm utility). - * @summary Minimum Node version 14.14.0 - * @since 0.1.36 - * @async - * @param {string|Buffer|URL} pathLike - * @param {object=} options - * @returns {Promise} - */ - removeSilent = removeSilent; - /** - * @name size - * @description File size in bytes. - * @since 0.2.3 - * @async - * @public - * @param {string|Buffer|URL} pathToFile - * @param {boolean=} [asString=false] - * @returns {Promise} - */ - size = size; - /** - * @name writeFile - * @description Asynchronously writes data to a file, replacing the file if it already exists. - * @since 0.0.10 - * @async - * @public - * @param {string|Buffer|URL} filePath - * @param {string} data - * @param {*|null|string=} options - * @returns {Promise} - */ - writeFile = writeFile; - /** - * @name writeFileTail - * @description Asynchronously writes data to the end of a file. - * @since 1.0.1 - * @async - * @public - * @param {string|Buffer|URL} filePath - * @param {string} data - * @param {*|null|string=} options - * @returns {Promise} - */ - writeFileTail = writeFileTail; - /** - * @name writeJSON - * @description Asynchronously writes data to a file, replacing the file if it already exists. - * @since 0.1.25 - * @async - * @public - * @param {string|Buffer|URL} filePath - * @param {*} data - * @param {*|null|string=} options - * @returns {Promise} - */ - writeJSON = writeJSON; -} diff --git a/src/core/Roadmap.js b/src/core/Roadmap.js deleted file mode 100644 index 52501ab..0000000 --- a/src/core/Roadmap.js +++ /dev/null @@ -1,56 +0,0 @@ -// https://deno.land/std/fs - -// https://github.com/denoland/deno/issues/5916 - -// import { fromFileUrl } from "http://deno.land/std@v0.52.0/path/mod.ts"; -// await Deno.open(fromFileUrl(new URL("../relative/path.txt", import.meta.url))); - -// class Roadmap { -// -// //#region File -// -// clearFile() {} -// copyDirectory() {} -// createDirectory() {} -// deleteDirectory() {} -// ensureFileExists() {} -// ensureSymlinkExists() {} -// getDirectoryVisibility() {} -// getFileLastModified() {} -// getFileMimeType() {} -// getFileSize() {} -// getFileTimestamp() {} -// getFileVisibility() {} -// isFileExists() {} -// moveFile() {} -// putStringToFile() {} -// readFileIntoJson() {} -// readStreamFromFile() {} -// readStringFromFile() {} -// renameFile() {} -// setFileVisibility() {} -// writeJsonFile() {} -// writeStreamToFile() {} -// writeStringToFile() {} -// -// //#endregion -// -// //#region Directory -// -// addStringToFile() {} -// clearDirectory() {} -// copyFile() {} -// deleteFile() {} -// ensureDirectoryExists() {} -// getDirectoryLastModified() {} -// getDirectorySize() {} -// getDirectoryTimestamp() {} -// isDirectoryExists() {} -// listDirectoryContent() {} -// moveDirectory() {} -// renameDirectory() {} -// setDirectoryVisibility() {} -// -// //#endregion -// -// } diff --git a/src/core/access/wrapper.js b/src/core/access/wrapper.ts similarity index 50% rename from src/core/access/wrapper.js rename to src/core/access/wrapper.ts index 49ff2db..98a48dd 100644 --- a/src/core/access/wrapper.js +++ b/src/core/access/wrapper.ts @@ -7,13 +7,13 @@ import { access } from "node:fs/promises"; * @async * @param {number} mode * @param {string|Buffer|URL} path - * @returns {Promise} + * @returns {Promise} */ -export async function accessWrapper(mode, path) { - try { - await access(path, mode); - return true; - } catch (error) { - return error; - } +export async function accessWrapper(mode: number, path: string | Buffer | URL): Promise { + try { + await access(path, mode); + return true; + } catch (error: unknown) { + return error as Error; + } } diff --git a/src/core/create/create-directory.ts b/src/core/create/create-directory.ts new file mode 100644 index 0000000..82c32d9 --- /dev/null +++ b/src/core/create/create-directory.ts @@ -0,0 +1,25 @@ +import { mkdir } from "node:fs/promises"; + +/** + * @name createDirectory + * @description Asynchronous create a directory. + * @since 0.0.10 + * @async + * @param {string|Buffer|URL} dirPath + * @param {number|string=} mode + * @param {boolean=} recursive + * @returns {Promise} + */ +export async function createDirectory( + // + dirPath: string | Buffer | URL, + mode: (number | string) | undefined = "0777", + recursive: boolean | undefined = true, +): Promise { + try { + await mkdir(dirPath, { mode, recursive }); + return true; + } catch (error: unknown) { + return error as Error; + } +} diff --git a/src/core/create/create-file.ts b/src/core/create/create-file.ts new file mode 100644 index 0000000..e4a4620 --- /dev/null +++ b/src/core/create/create-file.ts @@ -0,0 +1,49 @@ +import { dirname } from "node:path"; +import { readdir } from "node:fs/promises"; + +import { createDirectory } from "./create-directory"; +import { getStatus } from "../status/get-status"; +import { writeFile } from "../write/write-file"; + +/** + * @name createFile + * @description Asynchronous create a file. + * @since 0.0.11 + * @async + * @param {string|Buffer|URL} pathLike + * @param {number|string=} mode + * @returns {Promise} + */ +export async function createFile( + pathLike: string | Buffer | URL, + mode: string = "0777", +): Promise { + const [status, error] = await getStatus(pathLike); + if (!error && (status as import("node:fs").Stats).isFile()) { + return true; + } + const dirPath = dirname(pathLike as string); + if (error) { + if ((error as NodeJS.ErrnoException).code === "ENOENT") { + const dirCreated = await createDirectory(dirPath, mode); + if (dirCreated !== true) { + return dirCreated; + } + const fileWritten = await writeFile(pathLike, "", { mode, flag: "w" }); + if (fileWritten !== true) { + return fileWritten; + } + return true; + } + } + if ((status as import("node:fs").Stats).isDirectory()) { + return await writeFile(pathLike, "", { mode, flag: "w" }); + } else { + try { + await readdir(dirPath); + return undefined; + } catch (error: unknown) { + return error as Error; + } + } +} diff --git a/src/core/create/createDirectory.js b/src/core/create/createDirectory.js deleted file mode 100644 index d304232..0000000 --- a/src/core/create/createDirectory.js +++ /dev/null @@ -1,20 +0,0 @@ -import { mkdir } from "node:fs/promises"; - -/** - * @name createDirectory - * @description Asynchronous create a directory. - * @since 0.0.10 - * @async - * @param {string|Buffer|URL} dirPath - * @param {number|string=} mode - * @param {boolean=} recursive - * @returns {Promise} - */ -export async function createDirectory(dirPath, mode = "0777", recursive = true) { - try { - await mkdir(dirPath, { mode, recursive }); - return true; - } catch (error) { - return error; - } -} diff --git a/src/core/create/createFile.js b/src/core/create/createFile.js deleted file mode 100644 index 9e03559..0000000 --- a/src/core/create/createFile.js +++ /dev/null @@ -1,46 +0,0 @@ -import { dirname } from "node:path"; -import { readdir } from "node:fs/promises"; - -import { createDirectory } from "./createDirectory.js"; -import { getStatus } from "../status/getStatus.js"; -import { writeFile } from "../write/writeFile.js"; - -/** - * @name createFile - * @description Asynchronous create a file. - * @since 0.0.11 - * @async - * @param {string|Buffer|URL} pathLike - * @param {number|string=} mode - * @returns {Promise} - */ -export async function createFile(pathLike, mode = "0777") { - const [status, error] = await getStatus(pathLike); - if (!error && status.isFile()) { - return true; - } - const dirPath = dirname(pathLike); - if (error) { - if (error.code === "ENOENT") { - const dirCreated = await createDirectory(dirPath, mode); - if (dirCreated !== true) { - return dirCreated; - } - const fileWritten = await writeFile(pathLike, "", { mode, flag: "w" }); - if (fileWritten !== true) { - return fileWritten; - } - return true; - } - } - if (status.isDirectory()) { - return await writeFile(pathLike, "", { mode, flag: "w" }); - } else { - try { - await readdir(dirPath); - return undefined; - } catch (error) { - return error; - } - } -} diff --git a/src/core/dir/dir-is-empty.ts b/src/core/dir/dir-is-empty.ts new file mode 100644 index 0000000..bfcf923 --- /dev/null +++ b/src/core/dir/dir-is-empty.ts @@ -0,0 +1,96 @@ +import { errorExtractOptions } from "../error/error-extract-options"; +import { dirIsReadable } from "./dir-is-readable"; +import { listContents } from "../list/contents"; + +const EXCLUDE = [ + // macOS + ".AppleDB", + ".AppleDesktop", + ".AppleDouble", + ".DS_Store", + ".DocumentRevisions-V100", + ".LSOverride", + ".Spotlight-V100", + ".TemporaryItems", + ".Trashes", + ".VolumeIcon.icns", + // "._*", + ".apdisk", + ".com.apple.timemachine.donotpresent", + ".fseventsd", + "Network Trash Folder", + "Temporary Items", + // Windows + "$RECYCLE.BIN/", + // "*.cab", + // "*.lnk", + // "*.msi", + // "*.msix", + // "*.msm", + // "*.msp", + // "*.stackdump", + "Desktop.ini", + "Thumbs.db", + "Thumbs.db:encryptable", + "desktop.ini", + "ehthumbs.db", + "ehthumbs_vista.db", + // Linux + // "*~", + // ".Trash-*", + ".directory", + // ".fuse_hidden*", + // ".nfs*", +]; + +/** + * @name isEmptyContent + * @param {string[]} listOfDirsAndFiles + * @returns {boolean} + */ +function isEmptyContent(listOfDirsAndFiles: string[]): boolean { + const content = new Set(listOfDirsAndFiles); + listOfDirsAndFiles.length = 0; + content.forEach((dirOrFileName: string) => { + for (const nameToExclude of EXCLUDE) { + if (!dirOrFileName) { + continue; + } + if (dirOrFileName === nameToExclude || dirOrFileName.match(RegExp(nameToExclude))) { + content.delete(dirOrFileName); + } + } + }); + return content.size === 0; +} + +/** + * @name dirIsEmpty + * @description Check if a directory is empty + * @since 0.1.33 + * @async + * @param {string|Buffer|URL} pathToDir + * @param {boolean=} excludeSystemFiles + * @returns {Promise} + * @throws {Error} If path is not a dir or is not readable. + */ +export async function dirIsEmpty( + pathToDir: string | Buffer | URL, + excludeSystemFiles: boolean = true, +): Promise { + const isReadableOrError = await dirIsReadable(pathToDir); + if (isReadableOrError !== true) { + throw new Error((isReadableOrError as Error).message, errorExtractOptions(isReadableOrError)); + } + let listOfDirsAndFiles = await listContents(pathToDir); + if (listOfDirsAndFiles instanceof Error) { + throw listOfDirsAndFiles; + } + if ((listOfDirsAndFiles as string[]).length === 0) { + return true; + } + if (!excludeSystemFiles) { + return false; + } + return isEmptyContent(listOfDirsAndFiles as string[]); +} diff --git a/src/core/dir/dir-is-executable.ts b/src/core/dir/dir-is-executable.ts new file mode 100644 index 0000000..5fc0dbb --- /dev/null +++ b/src/core/dir/dir-is-executable.ts @@ -0,0 +1,15 @@ +import { constants } from "node:fs"; + +import { accessWrapper } from "../access/wrapper"; + +/** + * @name dirIsExecutable + * @description Directory can be executed by the calling process + * @since 0.0.5 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ +export async function dirIsExecutable(pathToDir: string | Buffer | URL): Promise { + return accessWrapper(constants.X_OK, pathToDir); +} diff --git a/src/core/dir/dir-is-readable.ts b/src/core/dir/dir-is-readable.ts new file mode 100644 index 0000000..b967ed8 --- /dev/null +++ b/src/core/dir/dir-is-readable.ts @@ -0,0 +1,21 @@ +import { constants } from "node:fs"; + +import { accessWrapper } from "../access/wrapper"; + +/** + * @name dirIsReadable + * @description Directory is visible to the calling process + * @since 0.0.1 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ +export async function dirIsReadable(pathToDir: string | Buffer | URL): Promise { + if (process?.permission?.has("fs.read") !== undefined) { + const isWritable = process.permission?.has("fs.read", pathToDir as string); + if (isWritable !== undefined) { + return isWritable; + } + } + return accessWrapper(constants.R_OK, pathToDir); +} diff --git a/src/core/dir/dir-is-visible.ts b/src/core/dir/dir-is-visible.ts new file mode 100644 index 0000000..2342900 --- /dev/null +++ b/src/core/dir/dir-is-visible.ts @@ -0,0 +1,15 @@ +import { constants } from "node:fs"; + +import { accessWrapper } from "../access/wrapper"; + +/** + * @name dirIsVisible + * @description Directory is visible to the calling process + * @since 0.0.5 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ +export async function dirIsVisible(pathToDir: string | Buffer | URL): Promise { + return accessWrapper(constants.F_OK, pathToDir); +} diff --git a/src/core/dir/dir-is-writable.ts b/src/core/dir/dir-is-writable.ts new file mode 100644 index 0000000..db82696 --- /dev/null +++ b/src/core/dir/dir-is-writable.ts @@ -0,0 +1,21 @@ +import { constants } from "node:fs"; + +import { accessWrapper } from "../access/wrapper"; + +/** + * @name dirIsWritable + * @description Directory can be written by the calling process + * @since 0.0.1 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ +export async function dirIsWritable(pathToDir: string | Buffer | URL): Promise { + if (process?.permission?.has("fs.write") !== undefined) { + const isWritable = process.permission?.has("fs.write", pathToDir as string); + if (isWritable !== undefined) { + return isWritable; + } + } + return accessWrapper(constants.W_OK, pathToDir); +} diff --git a/src/core/dir/dirIsEmpty.js b/src/core/dir/dirIsEmpty.js deleted file mode 100644 index b369bda..0000000 --- a/src/core/dir/dirIsEmpty.js +++ /dev/null @@ -1,93 +0,0 @@ -import { errorExtractOptions } from "../error/errorExtractOptions.js"; -import { dirIsReadable } from "./dirIsReadable.js"; -import { listContents } from "../list/contents.js"; - -const EXCLUDE = [ - // macOS - ".AppleDB", - ".AppleDesktop", - ".AppleDouble", - ".DS_Store", - ".DocumentRevisions-V100", - ".LSOverride", - ".Spotlight-V100", - ".TemporaryItems", - ".Trashes", - ".VolumeIcon.icns", - // "._*", - ".apdisk", - ".com.apple.timemachine.donotpresent", - ".fseventsd", - "Network Trash Folder", - "Temporary Items", - // Windows - "$RECYCLE.BIN/", - // "*.cab", - // "*.lnk", - // "*.msi", - // "*.msix", - // "*.msm", - // "*.msp", - // "*.stackdump", - "Desktop.ini", - "Thumbs.db", - "Thumbs.db:encryptable", - "desktop.ini", - "ehthumbs.db", - "ehthumbs_vista.db", - // Linux - // "*~", - // ".Trash-*", - ".directory", - // ".fuse_hidden*", - // ".nfs*", -]; - -/** - * @name isEmptyContent - * @param {Array.} listOfDirsAndFiles - * @returns {boolean} - */ -function isEmptyContent(listOfDirsAndFiles) { - const content = new Set(listOfDirsAndFiles); - listOfDirsAndFiles.length = 0; - content.forEach((dirOrFileName) => { - for (const nameToExclude of EXCLUDE) { - if (!dirOrFileName) { - continue; - } - if (dirOrFileName === nameToExclude || dirOrFileName.match(RegExp(nameToExclude))) { - content.delete(dirOrFileName); - } - } - }); - return content.size === 0; -} - -/** - * @name dirIsEmpty - * @description Check if a directory is empty - * @since 0.1.33 - * @async - * @param {string|Buffer|URL} pathToDir - * @param {boolean=} excludeSystemFiles - * @returns {Promise} - * @throws {Error} If path is not a dir or is not readable. - */ -export async function dirIsEmpty(pathToDir, excludeSystemFiles = true) { - const isReadableOrError = await dirIsReadable(pathToDir); - if (isReadableOrError !== true) { - throw new Error(isReadableOrError.message, errorExtractOptions(isReadableOrError)); - } - let listOfDirsAndFiles = await listContents(pathToDir); - if (listOfDirsAndFiles instanceof Error) { - throw listOfDirsAndFiles; - } - if (listOfDirsAndFiles.length === 0) { - return true; - } - if (!excludeSystemFiles) { - return false; - } - return isEmptyContent(listOfDirsAndFiles); -} diff --git a/src/core/dir/dirIsExecutable.js b/src/core/dir/dirIsExecutable.js deleted file mode 100644 index 073e67a..0000000 --- a/src/core/dir/dirIsExecutable.js +++ /dev/null @@ -1,15 +0,0 @@ -import { constants } from "node:fs"; - -import { accessWrapper } from "../access/wrapper.js"; - -/** - * @name dirIsExecutable - * @description Directory can be executed by the calling process - * @since 0.0.5 - * @async - * @param {string|Buffer|URL} pathToDir - * @returns {Promise} - */ -export async function dirIsExecutable(pathToDir) { - return accessWrapper(constants.X_OK, pathToDir); -} diff --git a/src/core/dir/dirIsReadable.js b/src/core/dir/dirIsReadable.js deleted file mode 100644 index 57a8c7c..0000000 --- a/src/core/dir/dirIsReadable.js +++ /dev/null @@ -1,15 +0,0 @@ -import { constants } from "node:fs"; - -import { accessWrapper } from "../access/wrapper.js"; - -/** - * @name dirIsReadable - * @description Directory is visible to the calling process - * @since 0.0.1 - * @async - * @param {string|Buffer|URL} pathToDir - * @returns {Promise} - */ -export async function dirIsReadable(pathToDir) { - return accessWrapper(constants.R_OK, pathToDir); -} diff --git a/src/core/dir/dirIsVisible.js b/src/core/dir/dirIsVisible.js deleted file mode 100644 index 5db7371..0000000 --- a/src/core/dir/dirIsVisible.js +++ /dev/null @@ -1,15 +0,0 @@ -import { constants } from "node:fs"; - -import { accessWrapper } from "../access/wrapper.js"; - -/** - * @name dirIsVisible - * @description Directory is visible to the calling process - * @since 0.0.5 - * @async - * @param {string|Buffer|URL} pathToDir - * @returns {Promise} - */ -export async function dirIsVisible(pathToDir) { - return accessWrapper(constants.F_OK, pathToDir); -} diff --git a/src/core/dir/dirIsWritable.js b/src/core/dir/dirIsWritable.js deleted file mode 100644 index 212cd33..0000000 --- a/src/core/dir/dirIsWritable.js +++ /dev/null @@ -1,15 +0,0 @@ -import { constants } from "node:fs"; - -import { accessWrapper } from "../access/wrapper.js"; - -/** - * @name dirIsWritable - * @description Directory can be written by the calling process - * @since 0.0.1 - * @async - * @param {string|Buffer|URL} pathToDir - * @returns {Promise} - */ -export async function dirIsWritable(pathToDir) { - return accessWrapper(constants.W_OK, pathToDir); -} diff --git a/src/core/dir/run.bat b/src/core/dir/run.bat new file mode 100644 index 0000000..847f45a --- /dev/null +++ b/src/core/dir/run.bat @@ -0,0 +1,3 @@ +:: node --no-warnings --experimental-permission --allow-fs-write=* --allow-fs-read=* dir-is-writable.js +:: node --no-warnings dir-is-writable.js +node --no-warnings --experimental-permission --allow-fs-write="C:\\Users\\P54l0\\WebstormProjects\\hilesystem\\local\\dist" --allow-fs-read=* dir-is-writable.js \ No newline at end of file diff --git a/src/core/error/error-extract-options.d.ts b/src/core/error/error-extract-options.d.ts new file mode 100644 index 0000000..1e3eab6 --- /dev/null +++ b/src/core/error/error-extract-options.d.ts @@ -0,0 +1,34 @@ +// @ts-ignore + +declare global { + /** + * @typedef {Object} ErrorOptions + * @property {Error | { code?: string, values?: any[] | { [key: string]: any } }} [cause] + */ + export interface ErrorOptions { + cause?: + | { cause: Error } + | { + code?: string; + values?: + | any[] + | { + [key: string]: any; + }; + }; + } + + export interface ErrorConstructor { + new (message?: string, options?: ErrorOptions): Error; + (message?: string): Error; + readonly prototype: Error; + } + + var Error: ErrorConstructor; +} + +/** + * @param {Error} error + * @returns {ErrorOptions} + */ +export declare function errorExtractOptions(error: Error): ErrorOptions; diff --git a/src/core/error/error-extract-options.ts b/src/core/error/error-extract-options.ts new file mode 100644 index 0000000..e798ba1 --- /dev/null +++ b/src/core/error/error-extract-options.ts @@ -0,0 +1,25 @@ +/** + * @name errorExtractOptions + * @param {Error} error + * @returns {{ cause: Error } | { cause: { code?: string, values?: any[] | { [key: string]: any } }}} + */ +export function errorExtractOptions( + error: any, +): { cause: Error } | { cause: { code?: string; values?: any[] | { [key: string]: any } } } { + if (!(error instanceof Error)) { + return { cause: error }; + } + if ("code" in error && "errno" in error && "path" in error && "syscall" in error) { + return { + cause: { + code: (error as NodeJS.ErrnoException).code as string, + values: { + errno: error.errno, + path: error.path, + syscall: error.syscall, + }, + }, + }; + } + return { cause: error }; +} diff --git a/src/core/error/errorExtractOptions.d.ts b/src/core/error/errorExtractOptions.d.ts deleted file mode 100644 index 76c84c2..0000000 --- a/src/core/error/errorExtractOptions.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -// @ts-ignore - -declare global { - /** - * @typedef {Object} ErrorOptions - * @property {Error | { code?: string, values?: any[] | { [key: string]: any } }} [cause] - */ - export interface ErrorOptions { - cause?: - | { cause: Error } - | { - code?: string; - values?: - | any[] - | { - [key: string]: any; - }; - }; - } - - export interface ErrorConstructor { - new (message?: string, options?: ErrorOptions): Error; - (message?: string): Error; - readonly prototype: Error; - } - - var Error: ErrorConstructor; -} - -/** - * @param {Error} error - * @returns {ErrorOptions} - */ -export declare function errorExtractOptions(error: Error): ErrorOptions; diff --git a/src/core/error/errorExtractOptions.js b/src/core/error/errorExtractOptions.js deleted file mode 100644 index 269080f..0000000 --- a/src/core/error/errorExtractOptions.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * @name errorExtractOptions - * @param {Error} error - * @returns {{ cause: Error } | { cause: { code?: string, values?: any[] | { [key: string]: any } }}} - */ -export function errorExtractOptions(error) { - if (!(error instanceof Error)) { - return { cause: error }; - } - if ("code" in error && "errno" in error && "path" in error && "syscall" in error) { - return { - cause: { - code: error.code, - values: { - errno: error.errno, - path: error.path, - syscall: error.syscall, - }, - }, - }; - } -} diff --git a/src/core/file/file-is-executable.ts b/src/core/file/file-is-executable.ts new file mode 100644 index 0000000..31a66e8 --- /dev/null +++ b/src/core/file/file-is-executable.ts @@ -0,0 +1,15 @@ +import { constants } from "node:fs"; + +import { accessWrapper } from "../access/wrapper"; + +/** + * @name fileIsExecutable + * @description File can be executed by the calling process + * @since 0.0.5 + * @async + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ +export async function fileIsExecutable(pathToFile: string | Buffer | URL): Promise { + return accessWrapper(constants.X_OK, pathToFile); +} diff --git a/src/core/file/file-is-readable.ts b/src/core/file/file-is-readable.ts new file mode 100644 index 0000000..84b81c7 --- /dev/null +++ b/src/core/file/file-is-readable.ts @@ -0,0 +1,15 @@ +import { constants } from "node:fs"; + +import { accessWrapper } from "../access/wrapper"; + +/** + * @name fileIsReadable + * @description File is visible to the calling process + * @since 0.0.1 + * @async + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ +export async function fileIsReadable(pathToFile: string | Buffer | URL): Promise { + return accessWrapper(constants.R_OK, pathToFile); +} diff --git a/src/core/file/file-is-visible.ts b/src/core/file/file-is-visible.ts new file mode 100644 index 0000000..39ed914 --- /dev/null +++ b/src/core/file/file-is-visible.ts @@ -0,0 +1,15 @@ +import { constants } from "node:fs"; + +import { accessWrapper } from "../access/wrapper"; + +/** + * @name fileIsVisible + * @description File is visible to the calling process + * @since 0.0.5 + * @async + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ +export async function fileIsVisible(pathToFile: string | Buffer | URL): Promise { + return accessWrapper(constants.F_OK, pathToFile); +} diff --git a/src/core/file/file-is-writable.ts b/src/core/file/file-is-writable.ts new file mode 100644 index 0000000..ad48a0b --- /dev/null +++ b/src/core/file/file-is-writable.ts @@ -0,0 +1,15 @@ +import { constants } from "node:fs"; + +import { accessWrapper } from "../access/wrapper"; + +/** + * @name fileIsWritable + * @description File can be written by the calling process + * @since 0.0.1 + * @async + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ +export async function fileIsWritable(pathToFile: string | Buffer | URL): Promise { + return accessWrapper(constants.W_OK, pathToFile); +} diff --git a/src/core/file/file-truncate.ts b/src/core/file/file-truncate.ts new file mode 100644 index 0000000..ba99813 --- /dev/null +++ b/src/core/file/file-truncate.ts @@ -0,0 +1,19 @@ +import { truncate } from "node:fs/promises"; + +/** + * @name fileTruncate + * @description Truncate a file to a specified length + * @since 0.0.6 + * @async + * @param {string|Buffer|URL} pathToFile + * @param {number=} length + * @returns {Promise} + */ +export async function fileTruncate(pathToFile: string | Buffer | URL, length: number = 0): Promise { + try { + await truncate(pathToFile, length); + return true; + } catch (error: unknown) { + return error as Error; + } +} diff --git a/src/core/file/fileIsExecutable.js b/src/core/file/fileIsExecutable.js deleted file mode 100644 index 3f400f7..0000000 --- a/src/core/file/fileIsExecutable.js +++ /dev/null @@ -1,15 +0,0 @@ -import { constants } from "node:fs"; - -import { accessWrapper } from "../access/wrapper.js"; - -/** - * @name fileIsExecutable - * @description File can be executed by the calling process - * @since 0.0.5 - * @async - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ -export async function fileIsExecutable(pathToFile) { - return accessWrapper(constants.X_OK, pathToFile); -} diff --git a/src/core/file/fileIsReadable.js b/src/core/file/fileIsReadable.js deleted file mode 100644 index 5dfa43f..0000000 --- a/src/core/file/fileIsReadable.js +++ /dev/null @@ -1,15 +0,0 @@ -import { constants } from "node:fs"; - -import { accessWrapper } from "../access/wrapper.js"; - -/** - * @name fileIsReadable - * @description File is visible to the calling process - * @since 0.0.1 - * @async - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ -export async function fileIsReadable(pathToFile) { - return accessWrapper(constants.R_OK, pathToFile); -} diff --git a/src/core/file/fileIsVisible.js b/src/core/file/fileIsVisible.js deleted file mode 100644 index 4740a11..0000000 --- a/src/core/file/fileIsVisible.js +++ /dev/null @@ -1,15 +0,0 @@ -import { constants } from "node:fs"; - -import { accessWrapper } from "../access/wrapper.js"; - -/** - * @name fileIsVisible - * @description File is visible to the calling process - * @since 0.0.5 - * @async - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ -export async function fileIsVisible(pathToFile) { - return accessWrapper(constants.F_OK, pathToFile); -} diff --git a/src/core/file/fileIsWritable.js b/src/core/file/fileIsWritable.js deleted file mode 100644 index 3a1bed6..0000000 --- a/src/core/file/fileIsWritable.js +++ /dev/null @@ -1,15 +0,0 @@ -import { constants } from "node:fs"; - -import { accessWrapper } from "../access/wrapper.js"; - -/** - * @name fileIsWritable - * @description File can be written by the calling process - * @since 0.0.1 - * @async - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ -export async function fileIsWritable(pathToFile) { - return accessWrapper(constants.W_OK, pathToFile); -} diff --git a/src/core/file/fileTruncate.js b/src/core/file/fileTruncate.js deleted file mode 100644 index 6a87aab..0000000 --- a/src/core/file/fileTruncate.js +++ /dev/null @@ -1,19 +0,0 @@ -import { truncate } from "node:fs/promises"; - -/** - * @name fileTruncate - * @description Truncate a file to a specified length - * @since 0.0.6 - * @async - * @param {string|Buffer|URL} pathToFile - * @param {number=} length - * @returns {Promise} - */ -export async function fileTruncate(pathToFile, length = 0) { - try { - await truncate(pathToFile, length); - return true; - } catch (error) { - return error; - } -} diff --git a/src/core/hile-system-local.ts b/src/core/hile-system-local.ts new file mode 100644 index 0000000..9069835 --- /dev/null +++ b/src/core/hile-system-local.ts @@ -0,0 +1,506 @@ +import { absolutePathFrom } from "./path/absolute-path-from"; + +import { createDirectory } from "./create/create-directory"; +import { createFile } from "./create/create-file"; + +import { dirIsExecutable } from "./dir/dir-is-executable"; +import { dirIsReadable } from "./dir/dir-is-readable"; +import { dirIsVisible } from "./dir/dir-is-visible"; +import { dirIsWritable } from "./dir/dir-is-writable"; +import { dirIsEmpty } from "./dir/dir-is-empty"; + +import { fileExtension } from "./path/file-extension"; +import { fileIsExecutable } from "./file/file-is-executable"; +import { fileIsReadable } from "./file/file-is-readable"; +import { fileIsVisible } from "./file/file-is-visible"; +import { fileIsWritable } from "./file/file-is-writable"; +import { fileName } from "./path/file-name"; +import { fileNameExt } from "./path/file-name-ext"; +import { filePath } from "./path/file-path"; +import { fileTruncate } from "./file/file-truncate"; + +import { listContents } from "./list/contents"; +import { listDirectories } from "./list/directories"; +import { listFiles } from "./list/files"; + +import { getLinkStatus } from "./status/get-link-status"; +import { getStatus } from "./status/get-status"; + +import { isDirExists } from "./status/is-dir-exists"; +import { isFileExists } from "./status/is-file-exists"; +import { isPathExists } from "./status/is-path-exists"; + +import { move } from "./move/move"; + +import { pathFrom } from "./path/path-from"; + +import { readFileToBase64 } from "./read/read-file-to-base64"; +import { readFileToBuffer } from "./read/read-file-to-buffer"; +import { readFileToString } from "./read/read-file-to-string"; +import { remove } from "./remove/remove"; +import { removeNonBlocking } from "./remove/remove-non-blocking"; +import { removeSilent } from "./remove/remove-silent"; + +import { writeFile } from "./write/write-file"; +import { writeFileTail } from "./write/write-file-tail"; +import { writeJson } from "./write/write-json"; + +import { hash } from "./info/hash"; +import { hashCrc32 } from "./info/hash-crc32"; +import { hashMd5 } from "./info/hash-md5"; +import { hashMulti } from "./info/hash-multi"; +import { hashSha1 } from "./info/hash-sha1"; +import { hashSha256 } from "./info/hash-sha256"; +import { hashSha512 } from "./info/hash-sha512"; + +import { size } from "./info/size"; + +export class HileSystemLocal { + /** + * @name absolutePathFrom + * @description Join all arguments together and normalize the resulting path. + * Creates absolute path from right to left until an absolute path is constructed. + * @since 0.1.5 + * @public + * @param {string|string[]} paths + * @param {...string} morePaths + * @returns {string} + */ + absolutePathFrom = absolutePathFrom; + /** + * @name createDirectory + * @description Asynchronous create a directory. + * @since 0.0.10 + * @async + * @public + * @param {string|Buffer|URL} dirPath + * @param {number|string=} mode + * @param {boolean=} recursive + * @returns {Promise} + */ + createDirectory = createDirectory; + /** + * @name createFile + * @description Asynchronous create a file. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} pathLike + * @param {number|string=} mode + * @returns {Promise} + */ + createFile = createFile; + /** + * @name dirIsExecutable + * @description Directory can be executed by the calling process + * @since 0.0.5 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsExecutable = dirIsExecutable; + /** + * @name dirIsReadable + * @description Directory is visible to the calling process + * @since 0.0.1 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsReadable = dirIsReadable; + /** + * @name dirIsVisible + * @description Directory is visible to the calling process + * @since 0.0.5 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsVisible = dirIsVisible; + /** + * @name dirIsWritable + * @description Directory can be written by the calling process + * @since 0.0.1 + * @async + * @public + * @param {string} pathToDir + * @returns {Promise} + */ + dirIsWritable = dirIsWritable; + /** + * @name dirIsEmpty + * @description Check if a directory is empty + * @since 0.1.33 + * @async + * @public + * @param {string|Buffer|URL} pathToDir + * @param {boolean=} excludeSystemFiles + * @returns {Promise} + * @throws {Error} If path is not a dir or is not readable. + */ + dirIsEmpty = dirIsEmpty; + /** + * @name getLinkStatus + * @description Get file status unless `path` refers to a symbolic link, in which case the link itself is stat-ed, not the file that it refers to. + * @url http://man7.org/linux/man-pages/man2/lstat.2.html + * @since 1.1.0 + * @async + * @param {string|Buffer|URL} path + * @returns {Promise>} + */ + getLinkStatus = getLinkStatus; + /** + * @name getStatus + * @description Get file status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise>} + */ + getStatus = getStatus; + /** + * @name isDirExists + * @description Get directory status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise} + */ + isDirExists = isDirExists; + /** + * @name isFileExists + * @description Get file status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise} + */ + isFileExists = isFileExists; + /** + * @name isPathExists + * @description Get path status. + * @since 0.0.11 + * @async + * @public + * @param {string|Buffer|URL} path + * @returns {Promise} + */ + isPathExists = isPathExists; + /** + * @name fileExtension + * @description Get file extension. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + fileExtension = fileExtension; + /** + * @name fileName + * @description Return the file name without extension. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + fileName = fileName; + /** + * @name fileNameExt + * @description Return the last portion of a path. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + fileNameExt = fileNameExt; + /** + * @name filePath + * @description Return the directory name of a path. + * @since 0.1.1 + * @public + * @param {string} path + * @returns {string} + */ + filePath = filePath; + /** + * @name fileIsExecutable + * @description File can be executed by the calling process + * @since 0.0.5 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsExecutable = fileIsExecutable; + /** + * @name fileIsReadable + * @description File is visible to the calling process + * @since 0.0.1 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsReadable = fileIsReadable; + /** + * @name fileIsVisible + * @description File is visible to the calling process + * @since 0.0.5 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsVisible = fileIsVisible; + /** + * @name fileIsWritable + * @description File can be written by the calling process + * @since 0.0.1 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + fileIsWritable = fileIsWritable; + /** + * @name fileTruncate + * @description Truncate a file to a specified length + * @since 0.0.6 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @param {number=} length + * @returns {Promise} + */ + fileTruncate = fileTruncate; + /** + * @name hash + * @description Calculate hash. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @param {string} algorithm + * @returns {Promise} + * @throws {TypeError} If algorithm is not supported. + */ + hash = hash; + /** + * @name hashCrc32 + * @description CRC32. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashCrc32 = hashCrc32; + /** + * @name hashMd5 + * @description MD5. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashMd5 = hashMd5; + /** + * @name hashMulti + * @description Calculates multiple hashes. + * @since 1.1.1 + * @async + * @public + * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed. + * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>} + * @throws {Error|TypeError} + */ + hashMulti = hashMulti; + /** + * @name hashSha1 + * @description SHA-1. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashSha1 = hashSha1; + /** + * @name hashSha256 + * @description SHA-256. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashSha256 = hashSha256; + /** + * @name hashSha512 + * @description SHA-512. + * @since 0.2.6 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ + hashSha512 = hashSha512; + /** + * @name listContents + * @description Lists files and directories in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ + listContents = listContents; + /** + * @name listDirectories + * @description Lists directories in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ + listDirectories = listDirectories; + /** + * @name listFiles + * @description Lists files in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ + listFiles = listFiles; + /** + * @name move + * @description Change the name or location of a file or directory. + * @since 0.1.29 + * @public + * @param {string} pathFrom + * @param {string} pathTo + * @returns {Promise} + */ + move = move; + /** + * @name pathFrom + * @description Join all arguments together and normalize the resulting path. + * @since 0.1.3 + * @public + * @param {string|string[]} paths + * @param {...string} morePaths + * @returns {string} + */ + pathFrom = pathFrom; + /** + * @name readFileToBase64 + * @description Asynchronously reads the entire contents of a file into string. + * @since 0.1.21 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ + readFileToBase64 = readFileToBase64; + /** + * @name readFileToBuffer + * @description Asynchronously reads the entire contents of a file into buffer. + * @since 0.1.19 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ + readFileToBuffer = readFileToBuffer; + /** + * @name readFileToString + * @description Asynchronously reads the entire contents of a file into string. + * @since 0.1.7 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ + readFileToString = readFileToString; + /** + * @name remove + * @description Removes a file or directory. + * @since 0.1.1 + * @async + * @public + * @param {string} pathLike + * @returns {Promise} + */ + remove = remove; + /** + * @name removeNonBlocking + * @description Non-blocking remove of a file or directory. + * @since 0.1.18 + * @public + * @param {string} pathLike + * @returns {void} + */ + removeNonBlocking = removeNonBlocking; + /** + * @name removeSilent + * @description Removes files and directories (modeled on the standard POSIX rm utility). + * @summary Minimum Node version 14.14.0 + * @since 0.1.36 + * @async + * @param {string|Buffer|URL} pathLike + * @param {object=} options + * @returns {Promise} + */ + removeSilent = removeSilent; + /** + * @name size + * @description File size in bytes. + * @since 0.2.3 + * @async + * @public + * @param {string|Buffer|URL} pathToFile + * @param {boolean=} [asString=false] + * @returns {Promise} + */ + size = size; + /** + * @name writeFile + * @description Asynchronously writes data to a file, replacing the file if it already exists. + * @since 0.0.10 + * @async + * @public + * @param {string|Buffer|URL} filePath + * @param {string} data + * @param {*|null|string=} options + * @returns {Promise} + */ + writeFile = writeFile; + /** + * @name writeFileTail + * @description Asynchronously writes data to the end of a file. + * @since 1.0.1 + * @async + * @public + * @param {string|Buffer|URL} filePath + * @param {string} data + * @param {*|null|string=} options + * @returns {Promise} + */ + writeFileTail = writeFileTail; + /** + * @name writeJson + * @description Asynchronously writes data to a file, replacing the file if it already exists. + * @since 0.1.25 + * @async + * @public + * @param {string|Buffer|URL} filePath + * @param {*} data + * @param {*|null|string=} options + * @returns {Promise} + */ + writeJson = writeJson; +} diff --git a/src/core/info/hash-crc32.js b/src/core/info/hash-crc32.js deleted file mode 100644 index fd6a37c..0000000 --- a/src/core/info/hash-crc32.js +++ /dev/null @@ -1,31 +0,0 @@ -import { readFile } from "node:fs/promises"; - -function crc32(text) { - let chars = []; - let actual; - for (let current = 0; current < 256; current++) { - actual = current; - for (let f = 0; f < 8; f++) { - actual = 1 & actual ? 3988292384 ^ (actual >>> 1) : actual >>> 1; - } - chars[current] = actual; - } - let number = -1; - let index = 0; - for (; index < text.length; index++) { - number = (number >>> 8) ^ chars[255 & (number ^ text.charCodeAt(index))]; - } - return (-1 ^ number) >>> 0; -} - -/** - * @name hashCrc32 - * @description CRC32. - * @since 0.2.3 - * @async - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ -export async function hashCrc32(pathToFile) { - return crc32((await readFile(pathToFile)).toString("binary")).toString(16); -} diff --git a/src/core/info/hash-crc32.ts b/src/core/info/hash-crc32.ts new file mode 100644 index 0000000..274c281 --- /dev/null +++ b/src/core/info/hash-crc32.ts @@ -0,0 +1,32 @@ +import { readFile } from "node:fs/promises"; + +function crc32(text: string): number { + let chars = []; + let actual; + for (let current = 0; current < 256; current++) { + actual = current; + for (let f = 0; f < 8; f++) { + actual = 1 & actual ? 3988292384 ^ (actual >>> 1) : actual >>> 1; + } + chars[current] = actual; + } + let number = -1; + let index = 0; + for (; index < text.length; index++) { + // @ts-ignore + number = (number >>> 8) ^ chars[255 & (number ^ text.charCodeAt(index))]; + } + return (-1 ^ number) >>> 0; +} + +/** + * @name hashCrc32 + * @description CRC32. + * @since 0.2.3 + * @async + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ +export async function hashCrc32(pathToFile: string | Buffer | URL): Promise { + return crc32((await readFile(pathToFile)).toString("binary")).toString(16); +} diff --git a/src/core/info/hash-md5.js b/src/core/info/hash-md5.js deleted file mode 100644 index 95108cb..0000000 --- a/src/core/info/hash-md5.js +++ /dev/null @@ -1,13 +0,0 @@ -import { hash } from "./hash.js"; - -/** - * @name hashMd5 - * @description MD5. - * @since 0.2.3 - * @async - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ -export async function hashMd5(pathToFile) { - return hash(pathToFile, "md5"); -} diff --git a/src/core/info/hash-md5.ts b/src/core/info/hash-md5.ts new file mode 100644 index 0000000..d504c7f --- /dev/null +++ b/src/core/info/hash-md5.ts @@ -0,0 +1,13 @@ +import { hash } from "./hash"; + +/** + * @name hashMd5 + * @description MD5. + * @since 0.2.3 + * @async + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ +export async function hashMd5(pathToFile: string | Buffer | URL): Promise { + return hash(pathToFile, "md5"); +} diff --git a/src/core/info/hash-multi.ts b/src/core/info/hash-multi.ts new file mode 100644 index 0000000..86a9869 --- /dev/null +++ b/src/core/info/hash-multi.ts @@ -0,0 +1,36 @@ +import { hashCrc32 } from "./hash-crc32"; +import { hashMd5 } from "./hash-md5"; +import { hashSha1 } from "./hash-sha1"; +import { hashSha256 } from "./hash-sha256"; +import { hashSha512 } from "./hash-sha512"; + +/** + * @name hashMulti + * @description Calculates multiple hashes. + * @summary The objective of the "hashMulti" function is to calculate multiple hashes (CRC32, MD5, SHA-1, SHA-256, and SHA-512) for a given file path and return them as an object. + * @since 1.1.1 + * @async + * @param {string|Buffer|URL} [pathToFile] - A string, buffer, or URL representing the path to the file to be hashed. + * @returns {Promise<{crc32: string, md5: string, sha1: string, sha256: string, sha512: string}>} + * @throws {Error|TypeError} + */ +export async function hashMulti( + pathToFile: string | Buffer | URL, +): Promise<{ crc32: string; md5: string; sha1: string; sha256: string; sha512: string }> { + return await Promise.all([ + hashCrc32(pathToFile) as Promise, + hashMd5(pathToFile) as Promise, + hashSha1(pathToFile) as Promise, + hashSha256(pathToFile) as Promise, + hashSha512(pathToFile) as Promise, + ]).then( + ([ + // + crc32, + md5, + sha1, + sha256, + sha512, + ]) => ({ crc32, md5, sha1, sha256, sha512 }), + ); +} diff --git a/src/core/info/hash-sha1.js b/src/core/info/hash-sha1.js deleted file mode 100644 index feff41d..0000000 --- a/src/core/info/hash-sha1.js +++ /dev/null @@ -1,13 +0,0 @@ -import { hash } from "./hash.js"; - -/** - * @name hashSha1 - * @description SHA-1. - * @since 0.2.3 - * @async - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ -export async function hashSha1(pathToFile) { - return hash(pathToFile, "sha1"); -} diff --git a/src/core/info/hash-sha1.ts b/src/core/info/hash-sha1.ts new file mode 100644 index 0000000..4e705eb --- /dev/null +++ b/src/core/info/hash-sha1.ts @@ -0,0 +1,13 @@ +import { hash } from "./hash"; + +/** + * @name hashSha1 + * @description SHA-1. + * @since 0.2.3 + * @async + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ +export async function hashSha1(pathToFile: string | Buffer | URL): Promise { + return hash(pathToFile, "sha1"); +} diff --git a/src/core/info/hash-sha256.js b/src/core/info/hash-sha256.js deleted file mode 100644 index 336a4ee..0000000 --- a/src/core/info/hash-sha256.js +++ /dev/null @@ -1,13 +0,0 @@ -import { hash } from "./hash.js"; - -/** - * @name hashSha256 - * @description SHA-256. - * @since 0.2.3 - * @async - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ -export async function hashSha256(pathToFile) { - return hash(pathToFile, "sha256"); -} diff --git a/src/core/info/hash-sha256.ts b/src/core/info/hash-sha256.ts new file mode 100644 index 0000000..9df8e9c --- /dev/null +++ b/src/core/info/hash-sha256.ts @@ -0,0 +1,13 @@ +import { hash } from "./hash"; + +/** + * @name hashSha256 + * @description SHA-256. + * @since 0.2.3 + * @async + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ +export async function hashSha256(pathToFile: string | Buffer | URL): Promise { + return hash(pathToFile, "sha256"); +} diff --git a/src/core/info/hash-sha512.js b/src/core/info/hash-sha512.js deleted file mode 100644 index 4d561db..0000000 --- a/src/core/info/hash-sha512.js +++ /dev/null @@ -1,13 +0,0 @@ -import { hash } from "./hash.js"; - -/** - * @name hashSha512 - * @description SHA-512. - * @since 0.2.6 - * @async - * @param {string|Buffer|URL} pathToFile - * @returns {Promise} - */ -export async function hashSha512(pathToFile) { - return hash(pathToFile, "sha512"); -} diff --git a/src/core/info/hash-sha512.ts b/src/core/info/hash-sha512.ts new file mode 100644 index 0000000..90edfdf --- /dev/null +++ b/src/core/info/hash-sha512.ts @@ -0,0 +1,13 @@ +import { hash } from "./hash"; + +/** + * @name hashSha512 + * @description SHA-512. + * @since 0.2.6 + * @async + * @param {string|Buffer|URL} pathToFile + * @returns {Promise} + */ +export async function hashSha512(pathToFile: string | Buffer | URL): Promise { + return hash(pathToFile, "sha512"); +} diff --git a/src/core/info/hash-worker.mjs b/src/core/info/hash-worker.mjs new file mode 100644 index 0000000..6c1575e --- /dev/null +++ b/src/core/info/hash-worker.mjs @@ -0,0 +1,71 @@ +import { Buffer } from "node:buffer"; +import { Worker } from "node:worker_threads"; +import { createHash } from "node:crypto"; +let create = (algorithm) => { + return async (buffer, { outputFormat = "hex" } = {}) => { + const hash = createHash(algorithm); + hash.update(buffer, typeof buffer === "string" ? "utf8" : undefined); + if (outputFormat === "hex") { + return hash.digest("hex"); + } + return hash.digest().buffer; + }; +}; +if (Worker !== undefined) { + // @ts-ignore + const threadFilePath = new URL("thread.mjs", import.meta.url); + let worker; // Lazy + let taskIdCounter = 0; + const tasks = new Map(); + const createWorker = () => { + worker = new Worker(threadFilePath); + worker.on("message", (message) => { + const task = tasks.get(message.id); + tasks.delete(message.id); + if (tasks.size === 0) { + worker.unref(); + } + task(message.value); + }); + worker.on("error", (error) => { + // Any error here is effectively an equivalent of segfault and have no scope, so we just throw it on callback level + throw error; + }); + }; + const taskWorker = (value, transferList) => new Promise((resolve) => { + const id = taskIdCounter++; + tasks.set(id, resolve); + if (worker === undefined) { + createWorker(); + } + worker.ref(); + worker.postMessage({ id, value }, transferList); + }); + create = + (algorithm) => async (source, { outputFormat = "hex" } = {}) => { + let buffer; + if (typeof source === "string") { + // Saving one copy operation by writing string to buffer right away and then transfering buffer + buffer = new ArrayBuffer(Buffer.byteLength(source, "utf8")); + Buffer.from(buffer).write(source, "utf8"); + } + else { + const finalSource = source instanceof ArrayBuffer ? new Uint8Array(source) : source; + // Creating a copy of buffer at call time, will be transfered later + buffer = finalSource.buffer.slice(0); + } + const result = await taskWorker({ algorithm, buffer }, [buffer]); + if (outputFormat === "hex") { + return Buffer.from(result).toString("hex"); + } + return result; + }; +} +export const sha1 = create("sha1"); +export const sha256 = create("sha256"); +export const sha384 = create("sha384"); +export const sha512 = create("sha512"); +(async () => { + const result = await sha512("unicorns"); + console.dir({ result }); +})(); diff --git a/src/core/info/hash-worker.mts b/src/core/info/hash-worker.mts new file mode 100644 index 0000000..f1aafbb --- /dev/null +++ b/src/core/info/hash-worker.mts @@ -0,0 +1,91 @@ +import { Buffer } from "node:buffer"; +import { Worker } from "node:worker_threads"; +import { createHash, Encoding } from "node:crypto"; +import { TransferListItem } from "worker_threads"; + +let create = (algorithm: string) => { + return async (buffer: any, { outputFormat = "hex" } = {}) => { + const hash = createHash(algorithm); + hash.update(buffer, (typeof buffer === "string" ? "utf8" : undefined) as Encoding); + + if (outputFormat === "hex") { + return hash.digest("hex"); + } + + return hash.digest().buffer; + }; +}; + +if (Worker !== undefined) { + // @ts-ignore + const threadFilePath = new URL("thread.mjs", import.meta.url); + + let worker: Worker; // Lazy + let taskIdCounter = 0; + const tasks = new Map(); + + const createWorker = () => { + worker = new Worker(threadFilePath); + + worker.on("message", (message) => { + const task = tasks.get(message.id); + tasks.delete(message.id); + if (tasks.size === 0) { + worker.unref(); + } + + task(message.value); + }); + + worker.on("error", (error) => { + // Any error here is effectively an equivalent of segfault and have no scope, so we just throw it on callback level + throw error; + }); + }; + + const taskWorker = (value: any, transferList: ReadonlyArray): Promise => + new Promise((resolve) => { + const id = taskIdCounter++; + tasks.set(id, resolve); + + if (worker === undefined) { + createWorker(); + } + + worker.ref(); + worker.postMessage({ id, value }, transferList); + }); + + create = + (algorithm) => + async (source: string | ArrayBuffer, { outputFormat = "hex" } = {}) => { + let buffer: ArrayBuffer; + if (typeof source === "string") { + // Saving one copy operation by writing string to buffer right away and then transferring buffer + buffer = new ArrayBuffer(Buffer.byteLength(source, "utf8")); + Buffer.from(buffer).write(source, "utf8"); + } else { + const finalSource = source instanceof ArrayBuffer ? new Uint8Array(source) : source; + + // Creating a copy of buffer at call time, will be transferred later + buffer = finalSource.buffer.slice(0); // eslint-disable-line unicorn/prefer-spread + } + + const result = await taskWorker({ algorithm, buffer }, [buffer]); + if (outputFormat === "hex") { + return Buffer.from(result).toString("hex"); + } + + return result; + }; +} + +export const sha1 = create("sha1"); +export const sha256 = create("sha256"); +// export const sha384 = create("sha384"); +export const sha512 = create("sha512"); + +(async () => { + const result = await sha512("unicorns"); + console.dir({ result }); +})(); diff --git a/src/core/info/hash.js b/src/core/info/hash.js deleted file mode 100644 index 842c89e..0000000 --- a/src/core/info/hash.js +++ /dev/null @@ -1,21 +0,0 @@ -import { createHash, getHashes } from "node:crypto"; -import { readFile } from "node:fs/promises"; - -/** - * @name hash - * @description Calculate hash. - * @since 0.2.3 - * @async - * @param {string|Buffer|URL} pathToFile - * @param {string} algorithm - * @returns {Promise} - * @throws {TypeError} If algorithm is not supported. - */ -export async function hash(pathToFile, algorithm) { - if (!getHashes().includes(algorithm)) { - throw new TypeError(`Digest algorithm [${algorithm}] is not supported.`); - } - return createHash(algorithm) - .update(await readFile(pathToFile)) - .digest("hex"); -} diff --git a/src/core/info/hash.ts b/src/core/info/hash.ts new file mode 100644 index 0000000..f38d4f3 --- /dev/null +++ b/src/core/info/hash.ts @@ -0,0 +1,21 @@ +import { createHash, getHashes } from "node:crypto"; +import { readFile } from "node:fs/promises"; + +/** + * @name hash + * @description Calculate hash. + * @since 0.2.3 + * @async + * @param {string|Buffer|URL} pathToFile + * @param {string} algorithm + * @returns {Promise} + * @throws {TypeError} If algorithm is not supported. + */ +export async function hash(pathToFile: string | Buffer | URL, algorithm: string): Promise { + if (!getHashes().includes(algorithm)) { + throw new TypeError(`Digest algorithm [${algorithm}] is not supported.`); + } + return createHash(algorithm) + .update(await readFile(pathToFile)) + .digest("hex"); +} diff --git a/src/core/info/size.js b/src/core/info/size.js deleted file mode 100644 index f3303ed..0000000 --- a/src/core/info/size.js +++ /dev/null @@ -1,18 +0,0 @@ -import { stat } from "node:fs/promises"; - -/** - * @name size - * @description File size in bytes. - * @since 0.2.3 - * @async - * @param {string|Buffer|URL} pathToFile - * @param {boolean=} [asString=false] - * @returns {Promise} - */ -export async function size(pathToFile, asString = false) { - const fileStats = await stat(pathToFile); - if (!asString) { - return fileStats.size; - } - return fileStats.size.toLocaleString("en").replace(/,/g, "_"); -} diff --git a/src/core/info/size.ts b/src/core/info/size.ts new file mode 100644 index 0000000..2e5400a --- /dev/null +++ b/src/core/info/size.ts @@ -0,0 +1,21 @@ +import { stat } from "node:fs/promises"; + +/** + * @name size + * @description File size in bytes. + * @since 0.2.3 + * @async + * @param {string|Buffer|URL} pathToFile + * @param {boolean=} [asString=false] + * @returns {Promise} + */ +export async function size( + pathToFile: string | Buffer | URL, + asString: boolean = false, +): Promise { + const fileStats = await stat(pathToFile); + if (!asString) { + return fileStats.size; + } + return fileStats.size.toLocaleString("en").replace(/,/g, "_"); +} diff --git a/src/core/info/thread.mjs b/src/core/info/thread.mjs new file mode 100644 index 0000000..355f752 --- /dev/null +++ b/src/core/info/thread.mjs @@ -0,0 +1,11 @@ +import { Buffer } from "node:buffer"; +import crypto from "node:crypto"; +import { parentPort } from "node:worker_threads"; +parentPort.on("message", (message) => { + const { algorithm, buffer } = message.value; + const hash = crypto.createHash(algorithm); + hash.update(Buffer.from(buffer)); + const arrayBuffer = hash.digest().buffer; + // Transferring buffer here for consistency, but considering buffer size it might be faster to just leave it for copying, needs perf test + parentPort.postMessage({ id: message.id, value: arrayBuffer }, [arrayBuffer]); +}); diff --git a/src/core/info/thread.mts b/src/core/info/thread.mts new file mode 100644 index 0000000..ee9dbe0 --- /dev/null +++ b/src/core/info/thread.mts @@ -0,0 +1,18 @@ +import { Buffer } from "node:buffer"; +import { createHash } from "node:crypto"; +import { parentPort } from "node:worker_threads"; + +const workerPort = parentPort; + +if (workerPort) { + workerPort.on("message", (message) => { + const { algorithm, buffer } = message.value; + const hash = createHash(algorithm); + hash.update(Buffer.from(buffer)); + const arrayBuffer = hash.digest().buffer; + // Transferring buffer here for consistency, but considering buffer size it might be faster to just leave it for copying, needs perf test + workerPort.postMessage({ id: message.id, value: arrayBuffer }, [arrayBuffer]); + }); +} else { + throw new Error("Worker port is not available"); +} diff --git a/src/core/list/contents.js b/src/core/list/contents.js deleted file mode 100644 index b3524b2..0000000 --- a/src/core/list/contents.js +++ /dev/null @@ -1,24 +0,0 @@ -import { readdir } from "node:fs/promises"; - -import { isNotSystemJunk } from "./is-not-system-junk.js"; - -/** - * @name listContents - * @description Lists files and directories in path - * @since 0.1.32 - * @async - * @param {string|Buffer|URL} pathToDir - * @param {boolean} [ignoreJunk=true] - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ -export async function listContents(pathToDir, ignoreJunk = true) { - try { - const contents = await readdir(pathToDir); - if (ignoreJunk) { - return contents.filter(isNotSystemJunk); - } - return contents; - } catch (error) { - return error; - } -} diff --git a/src/core/list/contents.ts b/src/core/list/contents.ts new file mode 100644 index 0000000..5fb7feb --- /dev/null +++ b/src/core/list/contents.ts @@ -0,0 +1,24 @@ +import { readdir } from "node:fs/promises"; + +import { isNotSystemJunk } from "./is-not-system-junk"; + +/** + * @name listContents + * @description Lists files and directories in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @param {boolean} [ignoreJunk=true] + * @returns {Promise} + */ +export async function listContents(pathToDir: string | Buffer | URL, ignoreJunk = true): Promise { + try { + const contents = await readdir(pathToDir); + if (ignoreJunk) { + return contents.filter(isNotSystemJunk); + } + return contents; + } catch (error: unknown) { + return error as Error; + } +} diff --git a/src/core/list/directories.js b/src/core/list/directories.js deleted file mode 100644 index 8c82bb2..0000000 --- a/src/core/list/directories.js +++ /dev/null @@ -1,32 +0,0 @@ -import { getStatus } from "../status/getStatus.js"; -import { listContents } from "./contents.js"; -import { pathFrom } from "../path/pathFrom.js"; - -/** - * @name listDirectories - * @description Lists directories in path - * @since 0.1.32 - * @async - * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ -export async function listDirectories(pathToDir) { - const contents = await listContents(pathToDir); - if (!Array.isArray(contents)) { - return contents; - } - const directories = await Promise.all( - contents.map(async (content) => { - const contentPath = pathFrom(pathToDir, content); - const [status, error] = await getStatus(contentPath); - if (error) { - return undefined; - } - if (!status.isDirectory()) { - return undefined; - } - return content; - }), - ); - return directories.filter((content) => content); -} diff --git a/src/core/list/directories.ts b/src/core/list/directories.ts new file mode 100644 index 0000000..523fe56 --- /dev/null +++ b/src/core/list/directories.ts @@ -0,0 +1,32 @@ +import { getStatus } from "../status/get-status"; +import { listContents } from "./contents"; +import { pathFrom } from "../path/path-from"; + +/** + * @name listDirectories + * @description Lists directories in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ +export async function listDirectories(pathToDir: string | Buffer | URL): Promise { + const contents = await listContents(pathToDir); + if (!Array.isArray(contents)) { + return contents; + } + const directories = await Promise.all( + contents.map(async (content) => { + const contentPath = pathFrom(pathToDir, content); + const [status, error] = await getStatus(contentPath); + if (error) { + return undefined; + } + if (!(status as import("node:fs").Stats).isDirectory()) { + return undefined; + } + return content; + }), + ); + return directories.filter((content) => content) as string[]; +} diff --git a/src/core/list/files.js b/src/core/list/files.js deleted file mode 100644 index 42015af..0000000 --- a/src/core/list/files.js +++ /dev/null @@ -1,32 +0,0 @@ -import { getStatus } from "../status/getStatus.js"; -import { listContents } from "./contents.js"; -import { pathFrom } from "../path/pathFrom.js"; - -/** - * @name listFiles - * @description Lists files in path - * @since 0.1.32 - * @async - * @param {string|Buffer|URL} pathToDir - * @returns {Promise|Error|{name: string, message: string, stack?: string}>} - */ -export async function listFiles(pathToDir) { - const contents = await listContents(pathToDir); - if (!Array.isArray(contents)) { - return contents; - } - const files = await Promise.all( - contents.map(async (content) => { - const contentPath = pathFrom(pathToDir, content); - const [status, error] = await getStatus(contentPath); - if (error) { - return undefined; - } - if (status.isDirectory()) { - return undefined; - } - return content; - }), - ); - return files.filter((content) => content); -} diff --git a/src/core/list/files.ts b/src/core/list/files.ts new file mode 100644 index 0000000..57f3514 --- /dev/null +++ b/src/core/list/files.ts @@ -0,0 +1,32 @@ +import { getStatus } from "../status/get-status"; +import { listContents } from "./contents"; +import { pathFrom } from "../path/path-from"; + +/** + * @name listFiles + * @description Lists files in path + * @since 0.1.32 + * @async + * @param {string|Buffer|URL} pathToDir + * @returns {Promise} + */ +export async function listFiles(pathToDir: string | Buffer | URL): Promise { + const contents = await listContents(pathToDir); + if (!Array.isArray(contents)) { + return contents; + } + const files = await Promise.all( + contents.map(async (content) => { + const contentPath = pathFrom(pathToDir, content); + const [status, error] = await getStatus(contentPath); + if (error) { + return undefined; + } + if ((status as import("node:fs").Stats).isDirectory()) { + return undefined; + } + return content; + }), + ); + return files.filter((content) => content) as string[]; +} diff --git a/src/core/list/is-not-system-junk.js b/src/core/list/is-not-system-junk.ts similarity index 54% rename from src/core/list/is-not-system-junk.js rename to src/core/list/is-not-system-junk.ts index d746a90..f0c1912 100644 --- a/src/core/list/is-not-system-junk.js +++ b/src/core/list/is-not-system-junk.ts @@ -1,4 +1,4 @@ -import { isSystemJunk } from "./is-system-junk.js"; +import { isSystemJunk } from "./is-system-junk"; /** * @name isNotSystemJunk @@ -7,6 +7,6 @@ import { isSystemJunk } from "./is-system-junk.js"; * @returns {boolean} * @since 0.2.0 */ -export function isNotSystemJunk(fileName) { - return !isSystemJunk(fileName); +export function isNotSystemJunk(fileName: string): boolean { + return !isSystemJunk(fileName); } diff --git a/src/core/list/is-system-junk.js b/src/core/list/is-system-junk.js deleted file mode 100644 index 9df7312..0000000 --- a/src/core/list/is-system-junk.js +++ /dev/null @@ -1,41 +0,0 @@ -// keep updated https://github.com/sindresorhus/junk - -const ignoreList = [ - // # All - "^npm-debug\\.log$", // Error log for npm - "^\\..*\\.swp$", // Swap file for vim state - - // # macOS - "^\\.DS_Store$", // Stores custom folder attributes - "^\\.AppleDouble$", // Stores additional file resources - "^\\.LSOverride$", // Contains the absolute path to the app to be used - "^Icon\\r$", // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop - "^\\._.*", // Thumbnail - "^\\.Spotlight-V100(?:$|\\/)", // Directory that might appear on external disk - "\\.Trashes", // File that might appear on external disk - "^__MACOSX$", // Resource fork - - // # Linux - "~$", // Backup file - - // # Windows - "^Thumbs\\.db$", // Image file cache - "^ehthumbs\\.db$", // Folder config file - "^Desktop\\.ini$", // Stores custom folder attributes - "@eaDir$", // Synology Diskstation "hidden" folder where the server stores thumbnails - "^\\$RECYCLE.BIN$", // Special folder with columns like Date deleted and Original location - "^System Volume Information$", -]; - -export const junkRegex = new RegExp(ignoreList.join("|")); - -/** - * @name isSystemJunk - * @description Returns true if filename matches a system junk file. - * @param {string} [fileName] - * @returns {boolean} - * @since 0.2.0 - */ -export function isSystemJunk(fileName) { - return junkRegex.test(fileName); -} diff --git a/src/core/list/is-system-junk.ts b/src/core/list/is-system-junk.ts new file mode 100644 index 0000000..216627c --- /dev/null +++ b/src/core/list/is-system-junk.ts @@ -0,0 +1,41 @@ +// keep updated https://github.com/sindresorhus/junk + +const ignoreList = [ + // # All + "^npm-debug\\.log$", // Error log for npm + "^\\..*\\.swp$", // Swap file for vim state + + // # macOS + "^\\.DS_Store$", // Stores custom folder attributes + "^\\.AppleDouble$", // Stores additional file resources + "^\\.LSOverride$", // Contains the absolute path to the app to be used + "^Icon\\r$", // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop + "^\\._.*", // Thumbnail + "^\\.Spotlight-V100(?:$|\\/)", // Directory that might appear on external disk + "\\.Trashes", // File that might appear on external disk + "^__MACOSX$", // Resource fork + + // # Linux + "~$", // Backup file + + // # Windows + "^Thumbs\\.db$", // Image file cache + "^ehthumbs\\.db$", // Folder config file + "^Desktop\\.ini$", // Stores custom folder attributes + "@eaDir$", // Synology Diskstation "hidden" folder where the server stores thumbnails + "^\\$RECYCLE.BIN$", // Special folder with columns like Date deleted and Original location + "^System Volume Information$", +]; + +export const junkRegex = new RegExp(ignoreList.join("|")); + +/** + * @name isSystemJunk + * @description Returns true if filename matches a system junk file. + * @param {string} [fileName] + * @returns {boolean} + * @since 0.2.0 + */ +export function isSystemJunk(fileName: string): boolean { + return junkRegex.test(fileName); +} diff --git a/src/core/move/move.js b/src/core/move/move.js deleted file mode 100644 index 00fa646..0000000 --- a/src/core/move/move.js +++ /dev/null @@ -1,18 +0,0 @@ -import { rename } from "node:fs/promises"; - -/** - * @name move - * @description Change the name or location of a file or directory. - * @since 0.1.29 - * @param {string} pathFrom - * @param {string} pathTo - * @returns {Promise} - */ -export async function move(pathFrom, pathTo) { - try { - await rename(pathFrom, pathTo); - return true; - } catch (error) { - return error; - } -} diff --git a/src/core/move/move.ts b/src/core/move/move.ts new file mode 100644 index 0000000..962a148 --- /dev/null +++ b/src/core/move/move.ts @@ -0,0 +1,18 @@ +import { rename } from "node:fs/promises"; + +/** + * @name move + * @description Change the name or location of a file or directory. + * @since 0.1.29 + * @param {string} pathFrom + * @param {string} pathTo + * @returns {Promise} + */ +export async function move(pathFrom: string, pathTo: string): Promise { + try { + await rename(pathFrom, pathTo); + return true; + } catch (error: unknown) { + return error as Error; + } +} diff --git a/src/core/path/absolute-path-from.ts b/src/core/path/absolute-path-from.ts new file mode 100644 index 0000000..934658d --- /dev/null +++ b/src/core/path/absolute-path-from.ts @@ -0,0 +1,25 @@ +import { resolve } from "node:path"; + +import { absolutePath } from "./absolute-path"; + +/** + * @name absolutePathFrom + * @description Join all arguments together and normalize the resulting path. + * Creates absolute path from right to left until an absolute path is constructed. + * @since 0.1.5 + * @param {string|string[]} paths + * @param {...string} morePaths + * @returns {string} + */ +export function absolutePathFrom(paths: string | string[], ...morePaths: string[]): string { + let routes: string[]; + if (Array.isArray(paths)) { + routes = paths.map((path) => path.toString()); + } else { + routes = [paths.toString()]; + } + if (morePaths.length) { + routes = routes.concat(morePaths.map((path) => path.toString())); + } + return absolutePath(resolve(...routes)); +} diff --git a/src/core/path/absolute-path.ts b/src/core/path/absolute-path.ts new file mode 100644 index 0000000..7b80931 --- /dev/null +++ b/src/core/path/absolute-path.ts @@ -0,0 +1,15 @@ +import { homedir } from "node:os"; + +const HOME_DIRECTORY = homedir(); + +/** + * @description deConvert a tilde path to an absolute path: ~/projects β†’ /Users/anon/projects + * @param {string} pathWithTilde + * @returns {string} + */ +export function absolutePath(pathWithTilde: string): string { + if (HOME_DIRECTORY) { + return String(pathWithTilde).replace(/^~(?=$|\/|\\)/, HOME_DIRECTORY); + } + return String(pathWithTilde); +} diff --git a/src/core/path/absolutePath.js b/src/core/path/absolutePath.js deleted file mode 100644 index 25435ab..0000000 --- a/src/core/path/absolutePath.js +++ /dev/null @@ -1,15 +0,0 @@ -import os from "os"; - -const HOME_DIRECTORY = os.homedir(); - -/** - * @description deConvert a tilde path to an absolute path: ~/projects β†’ /Users/anon/projects - * @param {string} pathWithTilde - * @returns {string} - */ -export function absolutePath(pathWithTilde) { - if (HOME_DIRECTORY) { - return String(pathWithTilde).replace(/^~(?=$|\/|\\)/, HOME_DIRECTORY); - } - return String(pathWithTilde); -} diff --git a/src/core/path/absolutePathFrom.js b/src/core/path/absolutePathFrom.js deleted file mode 100644 index fb8eccb..0000000 --- a/src/core/path/absolutePathFrom.js +++ /dev/null @@ -1,25 +0,0 @@ -import { resolve } from "node:path"; - -import { absolutePath } from "./absolutePath.js"; - -/** - * @name absolutePathFrom - * @description Join all arguments together and normalize the resulting path. - * Creates absolute path from right to left until an absolute path is constructed. - * @since 0.1.5 - * @param {string|Array.} paths - * @param {...string} morePaths - * @returns {string} - */ -export function absolutePathFrom(paths, ...morePaths) { - let routes; - if (Array.isArray(paths)) { - routes = paths.map((path) => path.toString()); - } else { - routes = [paths.toString()]; - } - if (morePaths.length) { - routes = routes.concat(morePaths.map((path) => path.toString())); - } - return absolutePath(resolve(...routes)); -} diff --git a/src/core/path/fileExtension.js b/src/core/path/file-extension.ts similarity index 65% rename from src/core/path/fileExtension.js rename to src/core/path/file-extension.ts index b0ecf48..50cb1df 100644 --- a/src/core/path/fileExtension.js +++ b/src/core/path/file-extension.ts @@ -7,6 +7,6 @@ import { extname } from "node:path"; * @param {string} path * @returns {string} */ -export function fileExtension(path) { - return extname(path).substring(1); +export function fileExtension(path: string): string { + return extname(path).substring(1); } diff --git a/src/core/path/fileNameExt.js b/src/core/path/file-name-ext.ts similarity index 70% rename from src/core/path/fileNameExt.js rename to src/core/path/file-name-ext.ts index 5c45aee..25a0881 100644 --- a/src/core/path/fileNameExt.js +++ b/src/core/path/file-name-ext.ts @@ -7,6 +7,6 @@ import { basename } from "node:path"; * @param {string} path * @returns {string} */ -export function fileNameExt(path) { - return basename(path); +export function fileNameExt(path: string): string { + return basename(path); } diff --git a/src/core/path/fileName.js b/src/core/path/file-name.ts similarity index 70% rename from src/core/path/fileName.js rename to src/core/path/file-name.ts index 18b66ac..dcbcdbc 100644 --- a/src/core/path/fileName.js +++ b/src/core/path/file-name.ts @@ -7,6 +7,6 @@ import { parse } from "node:path"; * @param {string} path * @returns {string} */ -export function fileName(path) { - return parse(path).name; +export function fileName(path: string): string { + return parse(path).name; } diff --git a/src/core/path/filePath.js b/src/core/path/file-path.ts similarity index 71% rename from src/core/path/filePath.js rename to src/core/path/file-path.ts index 924783d..47ecafb 100644 --- a/src/core/path/filePath.js +++ b/src/core/path/file-path.ts @@ -7,6 +7,6 @@ import { dirname } from "node:path"; * @param {string} path * @returns {string} */ -export function filePath(path) { - return dirname(path); +export function filePath(path: string): string { + return dirname(path); } diff --git a/src/core/path/path-from.ts b/src/core/path/path-from.ts new file mode 100644 index 0000000..7f91f56 --- /dev/null +++ b/src/core/path/path-from.ts @@ -0,0 +1,22 @@ +import { join, normalize } from "node:path"; + +/** + * @name pathFrom + * @description Join all arguments together and normalize the resulting path. + * @since 0.1.3 + * @param {string|Buffer|URL|string[]|Buffer[]|URL[]} paths + * @param {...string} morePaths + * @returns {string} + */ +export function pathFrom(paths: string | Buffer | URL | string[] | Buffer[] | URL[], ...morePaths: string[]): string { + let routes; + if (Array.isArray(paths)) { + routes = paths.map((path) => path.toString()); + } else { + routes = [paths.toString()]; + } + if (morePaths.length) { + routes = routes.concat(morePaths.map((path) => path.toString())); + } + return normalize(join(...routes)); +} diff --git a/src/core/path/pathFrom.js b/src/core/path/pathFrom.js deleted file mode 100644 index 0595794..0000000 --- a/src/core/path/pathFrom.js +++ /dev/null @@ -1,22 +0,0 @@ -import { join, normalize } from "node:path"; - -/** - * @name pathFrom - * @description Join all arguments together and normalize the resulting path. - * @since 0.1.3 - * @param {string|Array.} paths - * @param {...string} morePaths - * @returns {string} - */ -export function pathFrom(paths, ...morePaths) { - let routes; - if (Array.isArray(paths)) { - routes = paths.map((path) => path.toString()); - } else { - routes = [paths.toString()]; - } - if (morePaths.length) { - routes = routes.concat(morePaths.map((path) => path.toString())); - } - return normalize(join(...routes)); -} diff --git a/src/core/read/read-file-to-base64.ts b/src/core/read/read-file-to-base64.ts new file mode 100644 index 0000000..874f2db --- /dev/null +++ b/src/core/read/read-file-to-base64.ts @@ -0,0 +1,18 @@ +import { readFile } from "node:fs/promises"; + +/** + * @name readFileToBase64 + * @description Asynchronously reads the entire contents of a file into string. + * @since 0.1.21 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ +export async function readFileToBase64(pathLike: string | Buffer | URL): Promise { + try { + const result = await readFile(pathLike, "base64"); + return result.toString(); + } catch (error: unknown) { + return error as Error; + } +} diff --git a/src/core/read/read-file-to-buffer.ts b/src/core/read/read-file-to-buffer.ts new file mode 100644 index 0000000..f67f1ef --- /dev/null +++ b/src/core/read/read-file-to-buffer.ts @@ -0,0 +1,18 @@ +import { readFile } from "node:fs/promises"; + +/** + * @name readFileToBuffer + * @description Asynchronously reads the entire contents of a file into buffer. + * @since 0.1.19 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ +export async function readFileToBuffer(pathLike: string | Buffer | URL): Promise { + try { + const result = await readFile(pathLike, "binary"); + return Buffer.from(result); + } catch (error: unknown) { + return error as Error; + } +} diff --git a/src/core/read/read-file-to-string.ts b/src/core/read/read-file-to-string.ts new file mode 100644 index 0000000..32c47a1 --- /dev/null +++ b/src/core/read/read-file-to-string.ts @@ -0,0 +1,20 @@ +import { readFile } from "node:fs/promises"; + +import { absolutePath } from "../path/absolute-path"; + +/** + * @name readFileToString + * @description Asynchronously reads the entire contents of a file into string. + * @since 0.1.7 + * @async + * @param {string|Buffer|URL} pathLike + * @returns {Promise} + */ +export async function readFileToString(pathLike: string | Buffer | URL): Promise { + try { + const result = await readFile(absolutePath(pathLike as string), "utf8"); + return result.toString(); + } catch (error: unknown) { + return error as Error; + } +} diff --git a/src/core/read/readFileToBase64.js b/src/core/read/readFileToBase64.js deleted file mode 100644 index e7db594..0000000 --- a/src/core/read/readFileToBase64.js +++ /dev/null @@ -1,18 +0,0 @@ -import { readFile } from "node:fs/promises"; - -/** - * @name readFileToBase64 - * @description Asynchronously reads the entire contents of a file into string. - * @since 0.1.21 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ -export async function readFileToBase64(pathLike) { - try { - const result = await readFile(pathLike, "base64"); - return result.toString(); - } catch (error) { - return error; - } -} diff --git a/src/core/read/readFileToBuffer.js b/src/core/read/readFileToBuffer.js deleted file mode 100644 index 1c92272..0000000 --- a/src/core/read/readFileToBuffer.js +++ /dev/null @@ -1,18 +0,0 @@ -import { readFile } from "node:fs/promises"; - -/** - * @name readFileToBuffer - * @description Asynchronously reads the entire contents of a file into buffer. - * @since 0.1.19 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ -export async function readFileToBuffer(pathLike) { - try { - const result = await readFile(pathLike, "binary"); - return Buffer.from(result); - } catch (error) { - return error; - } -} diff --git a/src/core/read/readFileToString.js b/src/core/read/readFileToString.js deleted file mode 100644 index ff0b45f..0000000 --- a/src/core/read/readFileToString.js +++ /dev/null @@ -1,20 +0,0 @@ -import { readFile } from "node:fs/promises"; - -import { absolutePath } from "../path/absolutePath.js"; - -/** - * @name readFileToString - * @description Asynchronously reads the entire contents of a file into string. - * @since 0.1.7 - * @async - * @param {string|Buffer|URL} pathLike - * @returns {Promise} - */ -export async function readFileToString(pathLike) { - try { - const result = await readFile(absolutePath(pathLike), "utf8"); - return result.toString(); - } catch (error) { - return error; - } -} diff --git a/src/core/remove/remove-non-blocking.ts b/src/core/remove/remove-non-blocking.ts new file mode 100644 index 0000000..43269df --- /dev/null +++ b/src/core/remove/remove-non-blocking.ts @@ -0,0 +1,14 @@ +import { remove } from "./remove"; + +/** + * @name removeNonBlocking + * @description Non-blocking remove of a file or directory. + * @since 0.1.18 + * @param {string|Buffer|URL} pathLike + * @returns {void} + */ +export function removeNonBlocking(pathLike: string | Buffer | URL): void { + remove(pathLike) + .then(() => undefined) + .catch(() => undefined); // don't put it into next tick +} diff --git a/src/core/remove/removeSilent.js b/src/core/remove/remove-silent.ts similarity index 50% rename from src/core/remove/removeSilent.js rename to src/core/remove/remove-silent.ts index a526da8..5274236 100644 --- a/src/core/remove/removeSilent.js +++ b/src/core/remove/remove-silent.ts @@ -1,5 +1,7 @@ import { rm } from "node:fs/promises"; +import type { RmOptions } from "node:fs"; + /** * @name removeSilent * @description Removes files and directories (modeled on the standard POSIX rm utility). @@ -7,17 +9,17 @@ import { rm } from "node:fs/promises"; * @since 0.1.36 * @async * @param {string|Buffer|URL} pathLike - * @param {object=} options + * @param {RmOptions=} options * @returns {Promise} */ -export async function removeSilent(pathLike, options) { - try { - await rm(pathLike, { - force: true, - recursive: true, - ...options, - }); - } catch (__error) { - // - } +export async function removeSilent(pathLike: string | Buffer | URL, options: RmOptions): Promise { + try { + await rm(pathLike, { + force: true, + recursive: true, + ...options, + }); + } catch (__error) { + // + } } diff --git a/src/core/remove/remove.js b/src/core/remove/remove.js deleted file mode 100644 index 8a5781a..0000000 --- a/src/core/remove/remove.js +++ /dev/null @@ -1,217 +0,0 @@ -import fs from "fs"; -import assert from "node:assert"; -import { join } from "node:path"; - -const IS_WINDOWS = process.platform === "win32"; - -/** - * @param {object} options - */ -function defaults(options) { - const methods = ["unlink", "chmod", "stat", "lstat", "rmdir", "readdir"]; - methods.forEach((method) => { - options[method] = options[method] || fs[method]; - }); - options.maxBusyTries = options.maxBusyTries || 3; -} - -/** - * @param {string} pathLike - * @param {Function|object=} options - * @param {Function=} callback - */ -function rimraf(pathLike, options, callback) { - let busyTries = 0; - let localCallback = callback; - let localOptions = options; - if (typeof localOptions === "function") { - localCallback = localOptions; - localOptions = {}; - } - assert(pathLike, "remove(): missing path"); - assert.strictEqual(typeof pathLike, "string", "remove(): path should be a string"); - assert.strictEqual(typeof localCallback, "function", "remove(): callback function required"); - assert(localOptions, "remove(): invalid options argument provided"); - assert.strictEqual(typeof localOptions, "object", "remove(): options should be object"); - defaults(localOptions); - rimraf_(pathLike, localOptions, function callbackRimraf(error) { - if (error) { - if ( - (error.code === "EBUSY" || error.code === "ENOTEMPTY" || error.code === "EPERM") && - busyTries < localOptions.maxBusyTries - ) { - busyTries++; - const time = busyTries * 100; - setTimeout(() => rimraf_(pathLike, localOptions, callbackRimraf), time); - return; - } - if (error.code === "ENOENT") { - localCallback(null); - return; - } - } - localCallback(error); - }); -} - -/** - * @param {string} pathLike - * @param {Function|object=} options - * @param {Function=} callback - */ -function rimraf_(pathLike, options, callback) { - assert(pathLike); - assert(options); - assert(typeof callback === "function"); - options.lstat(pathLike, (error, stats) => { - if (error && error.code === "ENOENT") { - return callback(null); - } - if (error && error.code === "EPERM" && IS_WINDOWS) { - return fixWinEPERM(pathLike, options, error, callback); - } - if (stats && stats.isDirectory()) { - return rmdir(pathLike, options, error, callback); - } - options.unlink(pathLike, (error) => { - if (error) { - if (error.code === "ENOENT") { - return callback(null); - } - if (error.code === "EPERM") { - if (IS_WINDOWS) { - return fixWinEPERM(pathLike, options, error, callback); - } else { - return rmdir(pathLike, options, error, callback); - } - } - if (error.code === "EISDIR") { - return rmdir(pathLike, options, error, callback); - } - } - return callback(error); - }); - }); -} - -/** - * @param {string} pathLike - * @param {Function|object=} options - * @param {Error|null} error - * @param {Function=} callback - * @returns {null} - */ -function fixWinEPERM(pathLike, options, error, callback) { - assert(pathLike); - assert(options); - assert(typeof callback === "function"); - if (error) { - assert(error instanceof Error); - } - options.chmod(pathLike, 0o666, (errorChMod) => { - if (errorChMod) { - if (errorChMod.code === "ENOENT") { - callback(null); - } else { - callback(error); - } - } else { - options.stat(pathLike, (errorStat, stats) => { - if (errorStat) { - if (errorStat.code === "ENOENT") { - callback(null); - } else { - callback(error); - } - } else if (stats.isDirectory()) { - rmdir(pathLike, options, error, callback); - } else { - options.unlink(pathLike, callback); - } - }); - } - }); - return null; -} - -/** - * @param {string} pathLike - * @param {Function|object=} options - * @param {Error|null} originalError - * @param {Function=} callback - * @returns {null} - */ -function rmdir(pathLike, options, originalError, callback) { - assert(pathLike); - assert(options); - if (originalError) { - assert(originalError instanceof Error); - } - assert(typeof callback === "function"); - options.rmdir(pathLike, (error) => { - if (error && (error.code === "ENOTEMPTY" || error.code === "EEXIST" || error.code === "EPERM")) { - removeSubPath(pathLike, options, callback); - } else if (error && error.code === "ENOTDIR") { - callback(originalError); - } else { - callback(error); - } - }); - return null; -} - -/** - * @param {string} pathLike - * @param {Function|object=} options - * @param {Function=} callback - */ -function removeSubPath(pathLike, options, callback) { - assert(pathLike); - assert(options); - assert(typeof callback === "function"); - options.readdir(pathLike, (error, files) => { - if (error) { - return callback(error); - } - let count = files.length; - let errState; - if (count === 0) { - return options.rmdir(pathLike, callback); - } - files.forEach((filePath) => { - rimraf(join(pathLike, filePath), options, (error) => { - if (errState) { - return; - } - if (error) { - callback((errState = error)); - return; - } - --count; - if (count === 0) { - options.rmdir(pathLike, callback); - } - }); - }); - }); -} - -/** - * @name remove - * @description Removes a file or directory. - * @since 0.1.1 - * @async - * @param {string} pathLike - * @returns {Promise} - */ -export async function remove(pathLike) { - return new Promise((resolve) => { - rimraf(pathLike, {}, (error) => { - if (error) { - resolve(error); - } else { - resolve(); - } - }); - }); -} diff --git a/src/core/remove/remove.ts b/src/core/remove/remove.ts new file mode 100644 index 0000000..135fa5f --- /dev/null +++ b/src/core/remove/remove.ts @@ -0,0 +1,236 @@ +// @ts-ignore +import fs from "node:fs"; +// @ts-ignore +import assert from "node:assert"; +import { join } from "node:path"; + +const IS_WINDOWS = process.platform === "win32"; + +/** + * @param {object} options + */ +function defaults(options: any) { + const methods = ["unlink", "chmod", "stat", "lstat", "rmdir", "readdir"]; + methods.forEach((method) => { + options[method] = options[method] || fs[method]; + }); + options.maxBusyTries = options.maxBusyTries || 3; +} + +/** + * @param {string | Buffer | URL} pathLike + * @param {Function|object=} options + * @param {Function=} callback + */ +function rimraf( + pathLike: string | Buffer | URL, + options: any, + callback: (error: NodeJS.ErrnoException | null) => void, +): void { + let busyTries = 0; + let localCallback = callback; + let localOptions = options; + if (typeof localOptions === "function") { + localCallback = localOptions; + localOptions = {}; + } + assert(pathLike, "remove(): missing path"); + // assert.strictEqual(typeof pathLike, "string", "remove(): path should be a string"); + // assert.strictEqual(typeof localCallback, "function", "remove(): callback function required"); + assert(localOptions, "remove(): invalid options argument provided"); + // assert.strictEqual(typeof localOptions, "object", "remove(): options should be an object?"); + defaults(localOptions); + rimraf_(pathLike as string, localOptions, function callbackRimraf(error: NodeJS.ErrnoException | null) { + if (error) { + if ( + (error.code === "EBUSY" || error.code === "ENOTEMPTY" || error.code === "EPERM") && + busyTries < localOptions.maxBusyTries + ) { + busyTries++; + const time = busyTries * 100; + setTimeout(() => rimraf_(pathLike as string, localOptions, callbackRimraf), time); + return; + } + if (error.code === "ENOENT") { + localCallback(null); + return; + } + } + localCallback(error); + }); +} + +/** + * @param {string} pathLike + * @param {Function|object=} options + * @param {Function=} callback + */ +function rimraf_(pathLike: string, options: any, callback: (error: NodeJS.ErrnoException | null) => void): void { + assert(pathLike); + assert(options); + assert(typeof callback === "function"); + options.lstat(pathLike, (error: NodeJS.ErrnoException | null, stats: fs.Stats | fs.BigIntStats | undefined) => { + if (error && error.code === "ENOENT") { + return callback(null); + } + if (error && error.code === "EPERM" && IS_WINDOWS) { + return fixWinEPERM(pathLike, options, error, callback); + } + if (stats && stats.isDirectory()) { + return rmdir(pathLike, options, error as NodeJS.ErrnoException, callback); + } + options.unlink(pathLike, (error: NodeJS.ErrnoException | null): void | any => { + if (error) { + if (error.code === "ENOENT") { + return callback(null); + } + if (error.code === "EPERM") { + if (IS_WINDOWS) { + return fixWinEPERM(pathLike, options, error, callback); + } else { + return rmdir(pathLike, options, error, callback); + } + } + if (error.code === "EISDIR") { + return rmdir(pathLike, options, error, callback); + } + } + return callback(error); + }); + }); +} + +/** + * @param {string} pathLike + * @param {Function|object=} options + * @param {Error|null} error + * @param {Function=} callback + * @returns {null} + */ +function fixWinEPERM( + pathLike: string, + options: any, + error: NodeJS.ErrnoException | null, + callback: (error: NodeJS.ErrnoException | null) => void, +): null { + assert(pathLike); + assert(options); + assert(typeof callback === "function"); + if (error) { + assert(error instanceof Error); + } + options.chmod(pathLike, 0o666, (errorChMod: NodeJS.ErrnoException | null): void => { + if (errorChMod) { + if (errorChMod.code === "ENOENT") { + callback(null); + } else { + callback(error); + } + } else { + options.stat( + pathLike, + (errorStat: NodeJS.ErrnoException | null, stats: fs.Stats | fs.BigIntStats | undefined) => { + if (errorStat) { + if (errorStat.code === "ENOENT") { + callback(null); + } else { + callback(error); + } + } else if (stats.isDirectory()) { + rmdir(pathLike, options, error as NodeJS.ErrnoException, callback); + } else { + options.unlink(pathLike, callback); + } + }, + ); + } + }); + return null; +} + +/** + * @param {string} pathLike + * @param {Function|object=} options + * @param {Error|null} originalError + * @param {Function=} callback + * @returns {null} + */ +function rmdir( + pathLike: string, + options: any, + originalError: NodeJS.ErrnoException, + callback: (error: NodeJS.ErrnoException | null) => void, +) { + assert(pathLike); + assert(options); + if (originalError) { + assert(originalError instanceof Error); + } + assert(typeof callback === "function"); + options.rmdir(pathLike, (error: NodeJS.ErrnoException): void => { + if (error && (error.code === "ENOTEMPTY" || error.code === "EEXIST" || error.code === "EPERM")) { + removeSubPath(pathLike, options, callback); + } else if (error && error.code === "ENOTDIR") { + callback(originalError); + } else { + callback(error); + } + }); + return null; +} + +/** + * @param {string} pathLike + * @param {Function|object=} options + * @param {Function=} callback + */ +function removeSubPath(pathLike: string, options: any, callback: (error: NodeJS.ErrnoException | null) => void): void { + assert(pathLike); + assert(options); + assert(typeof callback === "function"); + options.readdir(pathLike, (error: Error | null, files: string[] | Buffer[] | fs.Dirent[]) => { + if (error) { + return callback(error); + } + let count = files.length; + let errState: Error | null = null; + if (count === 0) { + return options.rmdir(pathLike, callback); + } + files.forEach((filePath: string): void => { + rimraf(join(pathLike, filePath), options, (error): void => { + if (errState) { + return; + } + if (error) { + callback((errState = error)); + return; + } + --count; + if (count === 0) { + options.rmdir(pathLike, callback); + } + }); + }); + }); +} + +/** + * @name remove + * @description Removes a file or directory. + * @since 0.1.1 + * @async + * @param {string | Buffer | URL} pathLike + * @returns {Promise} + */ +export async function remove(pathLike: string | Buffer | URL): Promise { + return new Promise((resolve) => { + rimraf(pathLike, {}, (error: unknown) => { + if (error) { + resolve(error as Error); + } else { + resolve(true); + } + }); + }); +} diff --git a/src/core/remove/removeNonBlocking.js b/src/core/remove/removeNonBlocking.js deleted file mode 100644 index 60a199c..0000000 --- a/src/core/remove/removeNonBlocking.js +++ /dev/null @@ -1,14 +0,0 @@ -import { remove } from "./remove.js"; - -/** - * @name removeNonBlocking - * @description Non-blocking remove of a file or directory. - * @since 0.1.18 - * @param {string|Buffer|URL} pathLike - * @returns {void} - */ -export function removeNonBlocking(pathLike) { - remove(pathLike) - .then(() => undefined) - .catch(() => undefined); // don't put it into next tick -} diff --git a/src/core/status/getLinkStatus.js b/src/core/status/get-link-status.ts similarity index 50% rename from src/core/status/getLinkStatus.js rename to src/core/status/get-link-status.ts index 74931a1..47e4e14 100644 --- a/src/core/status/getLinkStatus.js +++ b/src/core/status/get-link-status.ts @@ -7,12 +7,14 @@ import { lstat } from "node:fs/promises"; * @since 1.1.0 * @async * @param {string|Buffer|URL} path - * @returns {Promise>} + * @returns {Promise<[import("node:fs").Stats|undefined, Error|undefined]>} */ -export async function getLinkStatus(path) { - try { - return [await lstat(path)]; - } catch (error) { - return [undefined, error]; - } +export async function getLinkStatus( + path: string | Buffer | URL, +): Promise<[import("node:fs").Stats | undefined, Error | undefined]> { + try { + return [await lstat(path), undefined]; + } catch (error: unknown) { + return [undefined, error as Error]; + } } diff --git a/src/core/status/get-status.ts b/src/core/status/get-status.ts new file mode 100644 index 0000000..2688ac4 --- /dev/null +++ b/src/core/status/get-status.ts @@ -0,0 +1,19 @@ +import { stat } from "node:fs/promises"; + +/** + * @name getStatus + * @description Get file status. + * @since 0.0.11 + * @async + * @param {string|Buffer|URL} path + * @returns {Promise<[import("node:fs").Stats|undefined, Error|undefined]>} + */ +export async function getStatus( + path: string | Buffer | URL, +): Promise<[import("node:fs").Stats | undefined, Error | undefined]> { + try { + return [await stat(path), undefined]; + } catch (error: unknown) { + return [undefined, error as Error]; + } +} diff --git a/src/core/status/getStatus.js b/src/core/status/getStatus.js deleted file mode 100644 index 3181650..0000000 --- a/src/core/status/getStatus.js +++ /dev/null @@ -1,17 +0,0 @@ -import { stat } from "node:fs/promises"; - -/** - * @name getStatus - * @description Get file status. - * @since 0.0.11 - * @async - * @param {string|Buffer|URL} path - * @returns {Promise>} - */ -export async function getStatus(path) { - try { - return [await stat(path)]; - } catch (error) { - return [undefined, error]; - } -} diff --git a/src/core/status/is-dir-exists.ts b/src/core/status/is-dir-exists.ts new file mode 100644 index 0000000..7926679 --- /dev/null +++ b/src/core/status/is-dir-exists.ts @@ -0,0 +1,17 @@ +import { getStatus } from "./get-status"; + +/** + * @name isDirExists + * @description Get directory status. + * @since 0.0.11 + * @async + * @param {string|Buffer|URL} path + * @returns {Promise} + */ +export async function isDirExists(path: string | Buffer | URL): Promise { + const [status, error] = await getStatus(path); + if (error) { + return false; + } + return (status as import("node:fs").Stats).isDirectory(); +} diff --git a/src/core/status/isExecutable.js b/src/core/status/is-executable.ts.orig similarity index 56% rename from src/core/status/isExecutable.js rename to src/core/status/is-executable.ts.orig index a4818b8..b3c15c7 100644 --- a/src/core/status/isExecutable.js +++ b/src/core/status/is-executable.ts.orig @@ -8,11 +8,11 @@ import { constants, promises } from "node:fs"; * @param {string|Buffer|URL} path * @returns {Promise}} */ -export async function isExecutable(path) { - try { - await promises.access(path, constants.X_OK); - return true; - } catch { - return false; - } +export async function isExecutable(path: string | Buffer | URL): Promise { + try { + await promises.access(path, constants.X_OK); + return true; + } catch { + return false; + } } diff --git a/src/core/status/is-file-exists.ts b/src/core/status/is-file-exists.ts new file mode 100644 index 0000000..cb82e97 --- /dev/null +++ b/src/core/status/is-file-exists.ts @@ -0,0 +1,17 @@ +import { getStatus } from "./get-status"; + +/** + * @name isFileExists + * @description Get file status. + * @since 0.0.11 + * @async + * @param {string|Buffer|URL} path + * @returns {Promise} + */ +export async function isFileExists(path: string | Buffer | URL): Promise { + const [status, error] = await getStatus(path); + if (error) { + return false; + } + return (status as import("node:fs").Stats).isFile(); +} diff --git a/src/core/status/is-path-exists.ts b/src/core/status/is-path-exists.ts new file mode 100644 index 0000000..d89d885 --- /dev/null +++ b/src/core/status/is-path-exists.ts @@ -0,0 +1,14 @@ +import { getStatus } from "./get-status"; + +/** + * @name isPathExists + * @description Get path status. + * @since 0.0.11 + * @async + * @param {string|Buffer|URL} path + * @returns {Promise} + */ +export async function isPathExists(path: string | Buffer | URL): Promise { + const [status] = await getStatus(path); + return Boolean(status); +} diff --git a/src/core/status/isReadable.js b/src/core/status/is-readable.ts.orig similarity index 56% rename from src/core/status/isReadable.js rename to src/core/status/is-readable.ts.orig index be5b976..807a168 100644 --- a/src/core/status/isReadable.js +++ b/src/core/status/is-readable.ts.orig @@ -8,11 +8,11 @@ import { constants, promises } from "node:fs"; * @param {string|Buffer|URL} path * @returns {Promise}} */ -export async function isReadable(path) { - try { - await promises.access(path, constants.R_OK); - return true; - } catch { - return false; - } +export async function isReadable(path: string | Buffer | URL): Promise { + try { + await promises.access(path, constants.R_OK); + return true; + } catch { + return false; + } } diff --git a/src/core/status/isVisible.js b/src/core/status/is-visible.ts.orig similarity index 55% rename from src/core/status/isVisible.js rename to src/core/status/is-visible.ts.orig index 79618ce..58ef1ad 100644 --- a/src/core/status/isVisible.js +++ b/src/core/status/is-visible.ts.orig @@ -8,11 +8,11 @@ import { constants, promises } from "node:fs"; * @param {string|Buffer|URL} path * @returns {Promise}} */ -export async function isVisible(path) { - try { - await promises.access(path, constants.F_OK); - return true; - } catch { - return false; - } +export async function isVisible(path: string | Buffer | URL): Promise { + try { + await promises.access(path, constants.F_OK); + return true; + } catch { + return false; + } } diff --git a/src/core/status/isWritable.js b/src/core/status/is-writable.ts.orig similarity index 56% rename from src/core/status/isWritable.js rename to src/core/status/is-writable.ts.orig index dd7eb01..2f85d74 100644 --- a/src/core/status/isWritable.js +++ b/src/core/status/is-writable.ts.orig @@ -8,11 +8,11 @@ import { constants, promises } from "node:fs"; * @param {string|Buffer|URL} path * @returns {Promise}} */ -export async function isWritable(path) { - try { - await promises.access(path, constants.W_OK); - return true; - } catch { - return false; - } +export async function isWritable(path: string | Buffer | URL): Promise { + try { + await promises.access(path, constants.W_OK); + return true; + } catch { + return false; + } } diff --git a/src/core/status/isDirExists.js b/src/core/status/isDirExists.js deleted file mode 100644 index 1936647..0000000 --- a/src/core/status/isDirExists.js +++ /dev/null @@ -1,17 +0,0 @@ -import { getStatus } from "./getStatus.js"; - -/** - * @name isDirExists - * @description Get directory status. - * @since 0.0.11 - * @async - * @param {string|Buffer|URL} path - * @returns {Promise} - */ -export async function isDirExists(path) { - const [status, error] = await getStatus(path); - if (error) { - return false; - } - return status.isDirectory(); -} diff --git a/src/core/status/isFileExists.js b/src/core/status/isFileExists.js deleted file mode 100644 index 5c6ef42..0000000 --- a/src/core/status/isFileExists.js +++ /dev/null @@ -1,17 +0,0 @@ -import { getStatus } from "./getStatus.js"; - -/** - * @name isFileExists - * @description Get file status. - * @since 0.0.11 - * @async - * @param {string|Buffer|URL} path - * @returns {Promise} - */ -export async function isFileExists(path) { - const [status, error] = await getStatus(path); - if (error) { - return false; - } - return status.isFile(); -} diff --git a/src/core/status/isPathExists.js b/src/core/status/isPathExists.js deleted file mode 100644 index 7fa64f9..0000000 --- a/src/core/status/isPathExists.js +++ /dev/null @@ -1,14 +0,0 @@ -import { getStatus } from "./getStatus.js"; - -/** - * @name isPathExists - * @description Get path status. - * @since 0.0.11 - * @async - * @param {string|Buffer|URL} path - * @returns {Promise} - */ -export async function isPathExists(path) { - const [status] = await getStatus(path); - return Boolean(status); -} diff --git a/src/core/write/write-file-tail.ts b/src/core/write/write-file-tail.ts new file mode 100644 index 0000000..eb9392c --- /dev/null +++ b/src/core/write/write-file-tail.ts @@ -0,0 +1,43 @@ +import { createFile } from "../create/create-file"; +import { isFileExists } from "../status/is-file-exists"; +import { readFileToString } from "../read/read-file-to-string"; +import { writeFile } from "./write-file"; + +/** + * @name writeFileTail + * @description Asynchronously writes data to the end of a file. + * @since 1.0.1 + * @async + * @param {string|Buffer|URL} filePath + * @param {string} data + * @param {*|null|string=} options + * @returns {Promise} + */ +export async function writeFileTail( + filePath: string | Buffer | URL, + data: any, + options: any | null | string = null, +): Promise { + const isFileExist = await isFileExists(filePath); + if (!isFileExist) { + const isFileCreatedOrError = await createFile(filePath); + if (isFileCreatedOrError !== true) { + return isFileCreatedOrError as Error; + } + } + const contentOrError = await readFileToString(filePath); + if (contentOrError instanceof Error) { + return contentOrError; + } + return new Promise((resolve, reject) => { + setTimeout(() => { + writeFile(filePath, `${String(contentOrError)}${String(data)}`, options) + .then(() => { + resolve(true); + }) + .catch((error) => { + reject(error); + }); + }, 1); + }); +} diff --git a/src/core/write/writeFile.js b/src/core/write/write-file.ts similarity index 69% rename from src/core/write/writeFile.js rename to src/core/write/write-file.ts index 56cc766..5e36ea2 100644 --- a/src/core/write/writeFile.js +++ b/src/core/write/write-file.ts @@ -8,7 +8,7 @@ import { writeFile as writeFileNative } from "node:fs/promises"; * @param {string|Buffer|URL} filePath * @param {string} data * @param {*|null|string=} options - * @returns {Promise} + * @returns {Promise} * @example * const controller = new AbortController(); * const { signal } = controller; @@ -23,11 +23,15 @@ import { writeFile as writeFileNative } from "node:fs/promises"; * // When the request should be aborted * controller.abort(); */ -export async function writeFile(filePath, data, options) { - try { - await writeFileNative(filePath, data, options); - return true; - } catch (error) { - return error; - } +export async function writeFile( + filePath: string | Buffer | URL, + data: any, + options: any | null | string = null, +): Promise { + try { + await writeFileNative(filePath, data, options); + return true; + } catch (error: unknown) { + return error as Error; + } } diff --git a/src/core/write/write-json.ts b/src/core/write/write-json.ts new file mode 100644 index 0000000..85785db --- /dev/null +++ b/src/core/write/write-json.ts @@ -0,0 +1,88 @@ +import { writeFile } from "./write-file"; + +/** + * @name objectKeys + * @param {object} object + * @returns {string[]} + */ +function objectKeys(object: object) { + return Object.keys(object).sort((alpha, beta) => alpha.localeCompare(beta)); +} + +/** + * name isObjectLike + * @param {*} value + * @returns {boolean} + */ +function isObjectLike(value: any) { + return value !== null && typeof value === "object" && !Array.isArray(value); +} + +/** + * @name collectionSortKeys + * @param {*} value + * @param {boolean=} [isDeep=true] + * @returns {Record|any[]} + */ +function collectionSortKeys(value: any, isDeep = true): Record | any[] { + if (!isObjectLike(value)) { + if (Array.isArray(value)) { + return value.map((arrayValue) => collectionSortKeys(arrayValue, isDeep)); + } + return value; + } + const keys = objectKeys(value); + if (!keys.length) { + return value; + } + return keys.reduce((sorted: Record, key) => { + if (isDeep && isObjectLike(value[key])) { + sorted[key] = collectionSortKeys(value[key], isDeep); + } else if (isDeep && Array.isArray(value[key])) { + sorted[key] = collectionSortKeys(value[key], isDeep); + } else { + sorted[key] = value[key]; + } + return sorted; + }, {}); +} + +/** + * @name writeJson + * @description Asynchronously writes data to a file, replacing the file if it already exists. + * @since 0.1.25 + * @async + * @param {string|Buffer|URL} filePath + * @param {*} data + * @param {*|null|string=} options + * @param {{sort: boolean, space: number|string}=} configuration + * @returns {Promise} + */ +export async function writeJson( + filePath: string | Buffer | URL, + data: any, + options: any | null | string = null, + configuration: { sort: boolean; space: number | string } | undefined, +): Promise { + let json; + let stringify = data; + try { + if (configuration) { + if (configuration.sort) { + if (isObjectLike(data)) { + stringify = collectionSortKeys(JSON.parse(JSON.stringify(data))); + } else if (Array.isArray(data)) { + stringify = JSON.parse(JSON.stringify(data)); + } + } + if (configuration.space) { + json = JSON.stringify(stringify, null, configuration.space); + } + } else { + json = JSON.stringify(stringify); + } + } catch (error: unknown) { + return error as Error; + } + return writeFile(filePath, json, options); +} diff --git a/src/core/write/writeFileTail.js b/src/core/write/writeFileTail.js deleted file mode 100644 index 4827dc6..0000000 --- a/src/core/write/writeFileTail.js +++ /dev/null @@ -1,39 +0,0 @@ -import { createFile } from "../create/createFile.js"; -import { isFileExists } from "../status/isFileExists.js"; -import { readFileToString } from "../read/readFileToString.js"; -import { writeFile } from "./writeFile.js"; - -/** - * @name writeFileTail - * @description Asynchronously writes data to the end of a file. - * @since 1.0.1 - * @async - * @param {string|Buffer|URL} filePath - * @param {string} data - * @param {*|null|string=} options - * @returns {Promise} - */ -export async function writeFileTail(filePath, data, options) { - const isFileExist = await isFileExists(filePath); - if (isFileExist === false) { - const isFileCreatedOrError = await createFile(filePath); - if (isFileCreatedOrError !== true) { - return isFileCreatedOrError; - } - } - const contentOrError = await readFileToString(filePath); - if (contentOrError instanceof Error) { - return contentOrError; - } - return new Promise((resolve, reject) => { - setTimeout(() => { - writeFile(filePath, `${String(contentOrError)}${String(data)}`, options) - .then(() => { - resolve(true); - }) - .catch((error) => { - reject(error); - }); - }, 1); - }); -} diff --git a/src/core/write/writeJSON.js b/src/core/write/writeJSON.js deleted file mode 100644 index 4182ca0..0000000 --- a/src/core/write/writeJSON.js +++ /dev/null @@ -1,85 +0,0 @@ -import { writeFile } from "./writeFile.js"; - -/** - * @name objectKeys - * @param {object} object - * @returns {Array.} - */ -function objectKeys(object) { - return Object.keys(object).sort((alpha, beta) => alpha.localeCompare(beta)); -} - -/** - * name isObjectLike - * @param {*} value - * @returns {boolean} - */ -function isObjectLike(value) { - return value !== null && typeof value === "object" && !Array.isArray(value); -} - -/** - * @name collectionSortKeys - * @param {*} value - * @param {boolean=} [isDeep=true] - * @returns {*} - */ -function collectionSortKeys(value, isDeep = true) { - if (!isObjectLike(value)) { - if (Array.isArray(value)) { - return value.map((arrayValue) => collectionSortKeys(arrayValue, isDeep)); - } - return value; - } - const keys = objectKeys(value); - if (!keys.length) { - return value; - } - return keys.reduce((sorted, key) => { - if (isDeep && isObjectLike(value[key])) { - sorted[key] = collectionSortKeys(value[key], isDeep); - } else if (isDeep && Array.isArray(value[key])) { - sorted[key] = collectionSortKeys(value[key], isDeep); - } else { - sorted[key] = value[key]; - } - return sorted; - }, {}); -} - -/** - * @name writeJSON - * @description Asynchronously writes data to a file, replacing the file if it already exists. - * @since 0.1.25 - * @async - * @param {string|Buffer|URL} filePath - * @param {*} data - * @param {*|null|string=} options - * @param {{sort: boolean, space: number|string}=} configuration - * @returns {Promise} - */ -export async function writeJSON(filePath, data, options, configuration) { - let json; - let stringify = data; - try { - if (configuration) { - if (configuration.sort) { - if (isObjectLike(data)) { - stringify = collectionSortKeys(JSON.parse(JSON.stringify(data))); - } else if (Array.isArray(data)) { - stringify = JSON.parse(JSON.stringify(data)); - } else { - stringify = data; - } - } - if (configuration.space) { - json = JSON.stringify(stringify, null, configuration.space); - } - } else { - json = JSON.stringify(stringify); - } - } catch (error) { - return error; - } - return writeFile(filePath, json, options); -} diff --git a/src/index.mjs b/src/index.mjs deleted file mode 100644 index b586428..0000000 --- a/src/index.mjs +++ /dev/null @@ -1,79 +0,0 @@ -//#region create -export { createDirectory } from "./core/create/createDirectory.js"; -export { createFile } from "./core/create/createFile.js"; -//#endregion - -//#region dir -export { dirIsEmpty } from "./core/dir/dirIsEmpty.js"; -export { dirIsExecutable } from "./core/dir/dirIsExecutable.js"; -export { dirIsReadable } from "./core/dir/dirIsReadable.js"; -export { dirIsVisible } from "./core/dir/dirIsVisible.js"; -export { dirIsWritable } from "./core/dir/dirIsWritable.js"; -//#endregion - -//#region info -export { hash } from "./core/info/hash.js"; -export { hashCrc32 } from "./core/info/hash-crc32.js"; -export { hashMd5 } from "./core/info/hash-md5.js"; -export { hashSha1 } from "./core/info/hash-sha1.js"; -export { hashSha256 } from "./core/info/hash-sha256.js"; -export { hashSha512 } from "./core/info/hash-sha512.js"; -export { size } from "./core/info/size.js"; -//#endregion - -//#region file -export { fileIsExecutable } from "./core/file/fileIsExecutable.js"; -export { fileIsReadable } from "./core/file/fileIsReadable.js"; -export { fileIsVisible } from "./core/file/fileIsVisible.js"; -export { fileIsWritable } from "./core/file/fileIsWritable.js"; -export { fileTruncate } from "./core/file/fileTruncate.js"; -//#endregion - -//#region list -export { listContents } from "./core/list/contents.js"; -export { listDirectories } from "./core/list/directories.js"; -export { listFiles } from "./core/list/files.js"; -//#endregion - -//#region move -export { move } from "./core/move/move.js"; -//#endregion - -//#region path -export { absolutePathFrom } from "./core/path/absolutePathFrom.js"; -export { fileExtension } from "./core/path/fileExtension.js"; -export { fileName } from "./core/path/fileName.js"; -export { fileNameExt } from "./core/path/fileNameExt.js"; -export { filePath } from "./core/path/filePath.js"; -export { pathFrom } from "./core/path/pathFrom.js"; -//#endregion - -//#region read -export { readFileToBase64 } from "./core/read/readFileToBase64.js"; -export { readFileToBuffer } from "./core/read/readFileToBuffer.js"; -export { readFileToString } from "./core/read/readFileToString.js"; -//#endregion - -//#region remove -export { remove } from "./core/remove/remove.js"; -export { removeNonBlocking } from "./core/remove/removeNonBlocking.js"; -export { removeSilent } from "./core/remove/removeSilent.js"; -//#endregion - -//#region status -export { getLinkStatus } from "./core/status/getLinkStatus.js"; -export { getStatus } from "./core/status/getStatus.js"; -export { isDirExists } from "./core/status/isDirExists.js"; -export { isFileExists } from "./core/status/isFileExists.js"; -export { isPathExists } from "./core/status/isPathExists.js"; -//#endregion - -//#region write -export { writeFile } from "./core/write/writeFile.js"; -export { writeFileTail } from "./core/write/writeFileTail.js"; -export { writeJSON } from "./core/write/writeJSON.js"; -//#endregion - -//#region default -export { HileSystemLocal } from "./core/HileSystemLocal.js"; -//#endregion diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..4001e9b --- /dev/null +++ b/src/index.ts @@ -0,0 +1,80 @@ +//#region create +export { createDirectory } from "./core/create/create-directory"; +export { createFile } from "./core/create/create-file"; +//#endregion + +//#region dir +export { dirIsEmpty } from "./core/dir/dir-is-empty"; +export { dirIsExecutable } from "./core/dir/dir-is-executable"; +export { dirIsReadable } from "./core/dir/dir-is-readable"; +export { dirIsVisible } from "./core/dir/dir-is-visible"; +export { dirIsWritable } from "./core/dir/dir-is-writable"; +//#endregion + +//#region info +export { hash } from "./core/info/hash"; +export { hashCrc32 } from "./core/info/hash-crc32"; +export { hashMd5 } from "./core/info/hash-md5"; +export { hashMulti } from "./core/info/hash-multi"; +export { hashSha1 } from "./core/info/hash-sha1"; +export { hashSha256 } from "./core/info/hash-sha256"; +export { hashSha512 } from "./core/info/hash-sha512"; +export { size } from "./core/info/size"; +//#endregion + +//#region file +export { fileIsExecutable } from "./core/file/file-is-executable"; +export { fileIsReadable } from "./core/file/file-is-readable"; +export { fileIsVisible } from "./core/file/file-is-visible"; +export { fileIsWritable } from "./core/file/file-is-writable"; +export { fileTruncate } from "./core/file/file-truncate"; +//#endregion + +//#region list +export { listContents } from "./core/list/contents"; +export { listDirectories } from "./core/list/directories"; +export { listFiles } from "./core/list/files"; +//#endregion + +//#region move +export { move } from "./core/move/move"; +//#endregion + +//#region path +export { absolutePathFrom } from "./core/path/absolute-path-from"; +export { fileExtension } from "./core/path/file-extension"; +export { fileName } from "./core/path/file-name"; +export { fileNameExt } from "./core/path/file-name-ext"; +export { filePath } from "./core/path/file-path"; +export { pathFrom } from "./core/path/path-from"; +//#endregion + +//#region read +export { readFileToBase64 } from "./core/read/read-file-to-base64"; +export { readFileToBuffer } from "./core/read/read-file-to-buffer"; +export { readFileToString } from "./core/read/read-file-to-string"; +//#endregion + +//#region remove +export { remove } from "./core/remove/remove"; +export { removeNonBlocking } from "./core/remove/remove-non-blocking"; +export { removeSilent } from "./core/remove/remove-silent"; +//#endregion + +//#region status +export { getLinkStatus } from "./core/status/get-link-status"; +export { getStatus } from "./core/status/get-status"; +export { isDirExists } from "./core/status/is-dir-exists"; +export { isFileExists } from "./core/status/is-file-exists"; +export { isPathExists } from "./core/status/is-path-exists"; +//#endregion + +//#region write +export { writeFile } from "./core/write/write-file"; +export { writeFileTail } from "./core/write/write-file-tail"; +export { writeJson } from "./core/write/write-json"; +//#endregion + +//#region default +export { HileSystemLocal } from "./core/hile-system-local"; +//#endregion diff --git a/test/index.test.cjs b/test/index.test.cjs index b46cb07..304c9d9 100644 --- a/test/index.test.cjs +++ b/test/index.test.cjs @@ -3,50 +3,51 @@ const path = require("node:path"); const test = require("node:test"); const { - HileSystemLocal, - absolutePathFrom, - createDirectory, - createFile, - dirIsEmpty, - dirIsExecutable, - dirIsReadable, - dirIsVisible, - dirIsWritable, - fileExtension, - fileIsExecutable, - fileIsReadable, - fileIsVisible, - fileIsWritable, - fileName, - fileNameExt, - filePath, - fileTruncate, - getLinkStatus, - getStatus, - hash, - hashCrc32, - hashMd5, - hashSha1, - hashSha256, - hashSha512, - isDirExists, - isFileExists, - isPathExists, - listContents, - listDirectories, - listFiles, - move, - pathFrom, - readFileToBase64, - readFileToBuffer, - readFileToString, - remove, - removeNonBlocking, - removeSilent, - size, - writeFile, - writeFileTail, - writeJSON, + HileSystemLocal, + absolutePathFrom, + createDirectory, + createFile, + dirIsEmpty, + dirIsExecutable, + dirIsReadable, + dirIsVisible, + dirIsWritable, + fileExtension, + fileIsExecutable, + fileIsReadable, + fileIsVisible, + fileIsWritable, + fileName, + fileNameExt, + filePath, + fileTruncate, + getLinkStatus, + getStatus, + hash, + hashCrc32, + hashMd5, + hashMulti, + hashSha1, + hashSha256, + hashSha512, + isDirExists, + isFileExists, + isPathExists, + listContents, + listDirectories, + listFiles, + move, + pathFrom, + readFileToBase64, + readFileToBuffer, + readFileToString, + remove, + removeNonBlocking, + removeSilent, + size, + writeFile, + writeFileTail, + writeJson, } = require("../dist/index.cjs"); const FILE_NAME = "index.test.cjs"; @@ -54,374 +55,404 @@ const FILE_NAME = "index.test.cjs"; const IS_EXECUTABLE = false; test.describe("Imported functions", () => { - test.it("absolutePathFrom()", () => { - assert.strictEqual( - absolutePathFrom(["path", "to", "file.txt"]), - __dirname.replace("test", "") + path.normalize("path/to/file.txt"), - ); - }); - test.it("createDirectory()", async () => { - const is = await createDirectory("./test/temp/"); - assert.strictEqual(is, true); - }); - test.it("createFile()", async () => { - const is = await createFile("./test/temp/cf.txt"); - assert.strictEqual(is, true); - }); - test.it("dirIsExecutable()", async () => { - const is = await dirIsExecutable("./test"); - assert.strictEqual(is, true); - }); - test.it("dirIsReadable()", async () => { - const is = await dirIsReadable("./test"); - assert.strictEqual(is, true); - }); - test.it("dirIsVisible()", async () => { - const is = await dirIsVisible("./test"); - assert.strictEqual(is, true); - }); - test.it("dirIsWritable()", async () => { - const is = await dirIsWritable("./test"); - assert.strictEqual(is, true); - }); - test.it("fileExtension()", () => { - assert.strictEqual(fileExtension("path/to/file.txt"), "txt"); - }); - test.it("fileName()", () => { - assert.strictEqual(fileName("path/to/file.txt"), "file"); - }); - test.it("fileNameExt()", () => { - assert.strictEqual(fileNameExt("path/to/file.txt"), "file.txt"); - }); - test.it("filePath()", () => { - assert.strictEqual(filePath("path/to/file.txt"), "path/to"); - }); - test.it("fileIsExecutable()", async () => { - const is = await fileIsExecutable(`./test/${FILE_NAME}`); - assert.notEqual(is, IS_EXECUTABLE); - }); - test.it("fileIsReadable()", async () => { - const is = await fileIsReadable(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("fileIsVisible()", async () => { - const is = await fileIsVisible(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("fileIsWritable()", async () => { - const is = await fileIsWritable(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("fileTruncate()", async () => { - const is = await fileTruncate("./test/test.file"); - assert.strictEqual(is, true); - }); - test.it("getLinkStatus()", async () => { - const [status, error] = await getLinkStatus(`./test/${FILE_NAME}`); - assert.notEqual(status, undefined); - assert.strictEqual(error, undefined); - }); - test.it("getStatus()", async () => { - const [status, error] = await getStatus(`./test/${FILE_NAME}`); - assert.notEqual(status, undefined); - assert.strictEqual(error, undefined); - }); - test.it("isDirExists()", async () => { - const is = await isDirExists("./test/"); - assert.strictEqual(is, true); - }); - test.it("isFileExists()", async () => { - const is = await isFileExists(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("isPathExists()", async () => { - const is = await isPathExists("./test/"); - assert.strictEqual(is, true); - }); - test.it("move()", async () => { - const testPathFrom = "./test/test_from.file"; - const testPathTo = "./test/test_to.file"; - await createFile(testPathFrom, "0777"); - const result = await move(testPathFrom, testPathTo); - await remove(testPathFrom); - await remove(testPathTo); - assert.strictEqual(result, true); - }); - test.it("pathFrom()", () => { - assert.strictEqual(pathFrom(["path", "to", "file.txt"]), path.normalize("path/to/file.txt")); - }); - test.it("writeFile()", async () => { - const is = await writeFile("./test/temp.txt", "test"); - assert.strictEqual(is, true); - }); - test.it("writeFileTail()", async () => { - const is = await writeFileTail("./test/temp-tail.txt", "tail"); - assert.strictEqual(is, true); - }); - test.it("writeJSON()", async () => { - const is = await writeJSON("./test/temp.json", "test"); - assert.strictEqual(is, true); - }); - test.it("remove()", async () => { - const result = await remove("./temp"); - assert.strictEqual(result, undefined); - }); - test.it("removeNonBlocking()", async () => { - const result = await removeNonBlocking("./temp_that_not_exists"); - assert.strictEqual(result, undefined); - }); - test.it("removeSilent()", async () => { - const result = await removeSilent("./temp_that_not_exists"); - assert.strictEqual(result, undefined); - }); - test.it("readFileToString()", async () => { - const is = await readFileToString("./test/temp.txt"); - assert.strictEqual(is, "test"); - }); - test.it("readFileToBuffer()", async () => { - const buf = await readFileToBuffer("./test/temp.txt"); - assert.strictEqual(buf.constructor.name, "Buffer"); - }); - test.it("readFileToBase64()", async () => { - const is = await readFileToBase64("./test/temp.txt"); - assert.strictEqual(is, "dGVzdA=="); - }); - test.it("listContents()", async () => { - const contents = await listContents("."); - assert.strictEqual(Array.isArray(contents), true); - }); - test.it("listDirectories()", async () => { - const contents = await listDirectories("."); - assert.strictEqual(Array.isArray(contents), true); - }); - test.it("listFiles()", async () => { - const contents = await listFiles("."); - assert.strictEqual(Array.isArray(contents), true); - }); - test.it("dirIsEmpty()", async () => { - const isEmpty = await dirIsEmpty("."); - assert.strictEqual(isEmpty, false); - }); - test.it("hash()", async () => { - const resultHash = await hash("./test/test.txt", "md5"); - assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); - }); - test.it("hashCrc32()", async () => { - const resultHash = await hashCrc32("./test/test.txt"); - assert.strictEqual(resultHash, "98b2c5bd"); - }); - test.it("hashMd5()", async () => { - const resultHash = await hashMd5("./test/test.txt"); - assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); - }); - test.it("hashSha1()", async () => { - const resultHash = await hashSha1("./test/test.txt"); - assert.strictEqual(resultHash, "cd36b370758a259b34845084a6cc38473cb95e27"); - }); - test.it("hashSha256()", async () => { - const resultHash = await hashSha256("./test/test.txt"); - assert.strictEqual(resultHash, "2d8c2f6d978ca21712b5f6de36c9d31fa8e96a4fa5d8ff8b0188dfb9e7c171bb"); - }); - test.it("hashSha512()", async () => { - const resultHash = await hashSha512("./test/test.txt"); - assert.strictEqual( - resultHash, - "8ba760cac29cb2b2ce66858ead169174057aa1298ccd581514e6db6dee3285280ee6e3a54c9319071dc8165ff061d77783100d449c937ff1fb4cd1bb516a69b9", - ); - }); - test.it("size() number", async () => { - const resultSize = await size("./test/test.txt"); - assert.strictEqual(resultSize, 445); - }); - test.it("size() string", async () => { - const resultSize = await size("./test/test.txt", true); - assert.strictEqual(resultSize, "445"); - }); + test.it("absolutePathFrom()", () => { + assert.strictEqual( + absolutePathFrom(["path", "to", "file.txt"]), + __dirname.replace("test", "") + path.normalize("path/to/file.txt"), + ); + }); + test.it("createDirectory()", async () => { + const is = await createDirectory("./test/temp/"); + assert.strictEqual(is, true); + }); + test.it("createFile()", async () => { + const is = await createFile("./test/temp/cf.txt"); + assert.strictEqual(is, true); + }); + test.it("dirIsExecutable()", async () => { + const is = await dirIsExecutable("./test"); + assert.strictEqual(is, true); + }); + test.it("dirIsReadable()", async () => { + const is = await dirIsReadable("./test"); + assert.strictEqual(is, true); + }); + test.it("dirIsVisible()", async () => { + const is = await dirIsVisible("./test"); + assert.strictEqual(is, true); + }); + test.it("dirIsWritable()", async () => { + const is = await dirIsWritable("./test"); + assert.strictEqual(is, true); + }); + test.it("fileExtension()", () => { + assert.strictEqual(fileExtension("path/to/file.txt"), "txt"); + }); + test.it("fileName()", () => { + assert.strictEqual(fileName("path/to/file.txt"), "file"); + }); + test.it("fileNameExt()", () => { + assert.strictEqual(fileNameExt("path/to/file.txt"), "file.txt"); + }); + test.it("filePath()", () => { + assert.strictEqual(filePath("path/to/file.txt"), "path/to"); + }); + test.it("fileIsExecutable()", async () => { + const is = await fileIsExecutable(`./test/${FILE_NAME}`); + assert.notEqual(is, IS_EXECUTABLE); + }); + test.it("fileIsReadable()", async () => { + const is = await fileIsReadable(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("fileIsVisible()", async () => { + const is = await fileIsVisible(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("fileIsWritable()", async () => { + const is = await fileIsWritable(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("fileTruncate()", async () => { + const is = await fileTruncate("./test/test.file"); + assert.strictEqual(is, true); + }); + test.it("getLinkStatus()", async () => { + const [status, error] = await getLinkStatus(`./test/${FILE_NAME}`); + assert.notEqual(status, undefined); + assert.strictEqual(error, undefined); + }); + test.it("getStatus()", async () => { + const [status, error] = await getStatus(`./test/${FILE_NAME}`); + assert.notEqual(status, undefined); + assert.strictEqual(error, undefined); + }); + test.it("isDirExists()", async () => { + const is = await isDirExists("./test/"); + assert.strictEqual(is, true); + }); + test.it("isFileExists()", async () => { + const is = await isFileExists(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("isPathExists()", async () => { + const is = await isPathExists("./test/"); + assert.strictEqual(is, true); + }); + test.it("move()", async () => { + const testPathFrom = "./test/test_from.file"; + const testPathTo = "./test/test_to.file"; + await createFile(testPathFrom, "0777"); + const result = await move(testPathFrom, testPathTo); + await remove(testPathFrom); + await remove(testPathTo); + assert.strictEqual(result, true); + }); + test.it("pathFrom()", () => { + assert.strictEqual(pathFrom(["path", "to", "file.txt"]), path.normalize("path/to/file.txt")); + }); + test.it("writeFile()", async () => { + const is = await writeFile("./test/temp.txt", "test"); + assert.strictEqual(is, true); + }); + test.it("writeFileTail()", async () => { + const is = await writeFileTail("./test/temp-tail.txt", "tail"); + assert.strictEqual(is, true); + }); + test.it("writeJson()", async () => { + const is = await writeJson("./test/temp.json", "test"); + assert.strictEqual(is, true); + }); + test.it("remove()", async () => { + const result = await remove("./temp"); + assert.strictEqual(result, true); + }); + test.it("removeNonBlocking()", async () => { + const result = await removeNonBlocking("./temp_that_not_exists"); + assert.strictEqual(result, undefined); + }); + test.it("removeSilent()", async () => { + const result = await removeSilent("./temp_that_not_exists"); + assert.strictEqual(result, undefined); + }); + test.it("readFileToString()", async () => { + const is = await readFileToString("./test/temp.txt"); + assert.strictEqual(is, "test"); + }); + test.it("readFileToBuffer()", async () => { + const buf = await readFileToBuffer("./test/temp.txt"); + assert.strictEqual(buf.constructor.name, "Buffer"); + }); + test.it("readFileToBase64()", async () => { + const is = await readFileToBase64("./test/temp.txt"); + assert.strictEqual(is, "dGVzdA=="); + }); + test.it("listContents()", async () => { + const contents = await listContents("."); + assert.strictEqual(Array.isArray(contents), true); + }); + test.it("listDirectories()", async () => { + const contents = await listDirectories("."); + assert.strictEqual(Array.isArray(contents), true); + }); + test.it("listFiles()", async () => { + const contents = await listFiles("."); + assert.strictEqual(Array.isArray(contents), true); + }); + test.it("dirIsEmpty()", async () => { + const isEmpty = await dirIsEmpty("."); + assert.strictEqual(isEmpty, false); + }); + test.it("hash()", async () => { + const resultHash = await hash("./test/test.txt", "md5"); + assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); + }); + test.it("hashCrc32()", async () => { + const resultHash = await hashCrc32("./test/test.txt"); + assert.strictEqual(resultHash, "98b2c5bd"); + }); + test.it("hashMd5()", async () => { + const resultHash = await hashMd5("./test/test.txt"); + assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); + }); + test.it("hashMulti()", async () => { + const expected = { + crc32: "98b2c5bd", + md5: "db89bb5ceab87f9c0fcc2ab36c189c2c", + sha1: "cd36b370758a259b34845084a6cc38473cb95e27", + sha256: "2d8c2f6d978ca21712b5f6de36c9d31fa8e96a4fa5d8ff8b0188dfb9e7c171bb", + sha512: "8ba760cac29cb2b2ce66858ead169174057aa1298ccd581514e6db6dee3285280ee6e3a54c9319071dc8165ff061d77783100d449c937ff1fb4cd1bb516a69b9", + }; + const result = await hashMulti("./test/test.txt"); + assert.strictEqual(result.crc32, expected.crc32); + assert.strictEqual(result.md5, expected.md5); + assert.strictEqual(result.sha1, expected.sha1); + assert.strictEqual(result.sha256, expected.sha256); + assert.strictEqual(result.sha512, expected.sha512); + }); + test.it("hashSha1()", async () => { + const resultHash = await hashSha1("./test/test.txt"); + assert.strictEqual(resultHash, "cd36b370758a259b34845084a6cc38473cb95e27"); + }); + test.it("hashSha256()", async () => { + const resultHash = await hashSha256("./test/test.txt"); + assert.strictEqual(resultHash, "2d8c2f6d978ca21712b5f6de36c9d31fa8e96a4fa5d8ff8b0188dfb9e7c171bb"); + }); + test.it("hashSha512()", async () => { + const resultHash = await hashSha512("./test/test.txt"); + assert.strictEqual( + resultHash, + "8ba760cac29cb2b2ce66858ead169174057aa1298ccd581514e6db6dee3285280ee6e3a54c9319071dc8165ff061d77783100d449c937ff1fb4cd1bb516a69b9", + ); + }); + test.it("size() number", async () => { + const resultSize = await size("./test/test.txt"); + assert.strictEqual(resultSize, 445); + }); + test.it("size() string", async () => { + const resultSize = await size("./test/test.txt", true); + assert.strictEqual(resultSize, "445"); + }); }); test.describe("Class with static helpers", () => { - const hileSystemLocal = new HileSystemLocal(); - test.it("HileSystemLocal.absolutePathFrom()", () => { - assert.strictEqual( - hileSystemLocal.absolutePathFrom(["path", "to", "file.txt"]), - __dirname.replace("test", "") + path.normalize("path/to/file.txt"), - ); - }); - test.it("HileSystemLocal.createDirectory()", async () => { - const is = await hileSystemLocal.createDirectory("./test/temp2/"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.createFile()", async () => { - const is = await hileSystemLocal.createFile("./test/temp2/cf.txt"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.dirIsExecutable()", async () => { - const is = await hileSystemLocal.dirIsExecutable("./test"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.dirIsReadable()", async () => { - const is = await hileSystemLocal.dirIsReadable("./test"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.dirIsVisible()", async () => { - const is = await hileSystemLocal.dirIsVisible("./test"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.dirIsWritable()", async () => { - const is = await hileSystemLocal.dirIsWritable("./test"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.fileExtension()", () => { - assert.strictEqual(hileSystemLocal.fileExtension("path/to/file.txt"), "txt"); - }); - test.it("HileSystemLocal.fileName()", () => { - assert.strictEqual(hileSystemLocal.fileName("path/to/file.txt"), "file"); - }); - test.it("HileSystemLocal.fileNameExt()", () => { - assert.strictEqual(hileSystemLocal.fileNameExt("path/to/file.txt"), "file.txt"); - }); - test.it("HileSystemLocal.filePath()", () => { - assert.strictEqual(hileSystemLocal.filePath("path/to/file.txt"), "path/to"); - }); - test.it("HileSystemLocal.fileIsExecutable()", async () => { - const is = await hileSystemLocal.fileIsExecutable(`./test/${FILE_NAME}`); - assert.notEqual(is, IS_EXECUTABLE); - }); - test.it("HileSystemLocal.fileIsReadable()", async () => { - const is = await hileSystemLocal.fileIsReadable(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.fileIsVisible()", async () => { - const is = await hileSystemLocal.fileIsVisible(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.fileIsWritable()", async () => { - const is = await hileSystemLocal.fileIsWritable(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.fileTruncate()", async () => { - const is = await hileSystemLocal.fileTruncate("./test/test.file"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.getLinkStatus()", async () => { - const [status, error] = await hileSystemLocal.getLinkStatus(`./test/${FILE_NAME}`); - assert.notEqual(status, undefined); - assert.strictEqual(error, undefined); - }); - test.it("HileSystemLocal.getStatus()", async () => { - const [status, error] = await hileSystemLocal.getStatus(`./test/${FILE_NAME}`); - assert.notEqual(status, undefined); - assert.strictEqual(error, undefined); - }); - test.it("HileSystemLocal.isDirExists()", async () => { - const is = await hileSystemLocal.isDirExists("./test/"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.isFileExists()", async () => { - const is = await hileSystemLocal.isFileExists(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.isPathExists()", async () => { - const is = await hileSystemLocal.isPathExists("./test/"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.move()", async () => { - const testPathFrom = "./test/test_from.file"; - const testPathTo = "./test/test_to.file"; - await hileSystemLocal.createFile(testPathFrom, "0777"); - const result = await hileSystemLocal.move(testPathFrom, testPathTo); - await hileSystemLocal.remove(testPathFrom); - await hileSystemLocal.remove(testPathTo); - assert.strictEqual(result, true); - }); - test.it("HileSystemLocal.pathFrom()", () => { - assert.strictEqual(hileSystemLocal.pathFrom(["path", "to", "file.txt"]), path.normalize("path/to/file.txt")); - }); - test.it("HileSystemLocal.writeFile()", async () => { - const is = await hileSystemLocal.writeFile("./test/temp2.txt", "test2"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.writeFileTail()", async () => { - const is = await hileSystemLocal.writeFileTail("./test/temp-tail.txt", "tail"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.writeJSON()", async () => { - const is = await hileSystemLocal.writeJSON("./test/temp2.json", "test2"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.remove()", async () => { - const result = await hileSystemLocal.remove("./temp"); - assert.strictEqual(result, undefined); - }); - test.it("HileSystemLocal.removeNonBlocking()", async () => { - const result = hileSystemLocal.removeNonBlocking("./temp_that_not_exists"); - assert.strictEqual(result, undefined); - }); - test.it("HileSystemLocal.removeSilent()", async () => { - const result = await hileSystemLocal.removeSilent("./temp_that_not_exists"); - assert.strictEqual(result, undefined); - }); - test.it("HileSystemLocal.readFileToString()", async () => { - const is = await hileSystemLocal.readFileToString("./test/temp.txt"); - assert.strictEqual(is, "test"); - }); - test.it("HileSystemLocal.readFileToBuffer()", async () => { - const buf = await hileSystemLocal.readFileToBuffer("./test/temp.txt"); - assert.strictEqual(buf.constructor.name, "Buffer"); - }); - test.it("HileSystemLocal.readFileToBase64()", async () => { - const is = await hileSystemLocal.readFileToBase64("./test/temp.txt"); - assert.strictEqual(is, "dGVzdA=="); - }); - test.it("HileSystemLocal.listContents()", async () => { - const contents = await hileSystemLocal.listContents("."); - assert.strictEqual(Array.isArray(contents), true); - }); - test.it("HileSystemLocal.listDirectories()", async () => { - const contents = await hileSystemLocal.listDirectories("."); - assert.strictEqual(Array.isArray(contents), true); - }); - test.it("HileSystemLocal.listFiles()", async () => { - const contents = await hileSystemLocal.listFiles("."); - assert.strictEqual(Array.isArray(contents), true); - }); - test.it("HileSystemLocal.dirIsEmpty()", async () => { - const isEmpty = await hileSystemLocal.dirIsEmpty("."); - assert.strictEqual(isEmpty, false); - }); - test.it("HileSystemLocal.hash()", async () => { - const resultHash = await hileSystemLocal.hash("./test/test.txt", "md5"); - assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); - }); - test.it("HileSystemLocal.hashCrc32()", async () => { - const resultHash = await hileSystemLocal.hashCrc32("./test/test.txt"); - assert.strictEqual(resultHash, "98b2c5bd"); - }); - test.it("HileSystemLocal.hashMd5()", async () => { - const resultHash = await hileSystemLocal.hashMd5("./test/test.txt"); - assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); - }); - test.it("HileSystemLocal.hashSha1()", async () => { - const resultHash = await hileSystemLocal.hashSha1("./test/test.txt"); - assert.strictEqual(resultHash, "cd36b370758a259b34845084a6cc38473cb95e27"); - }); - test.it("HileSystemLocal.hashSha256()", async () => { - const resultHash = await hileSystemLocal.hashSha256("./test/test.txt"); - assert.strictEqual(resultHash, "2d8c2f6d978ca21712b5f6de36c9d31fa8e96a4fa5d8ff8b0188dfb9e7c171bb"); - }); - test.it("HileSystemLocal.hashSha512()", async () => { - const resultHash = await hileSystemLocal.hashSha512("./test/test.txt"); - assert.strictEqual( - resultHash, - "8ba760cac29cb2b2ce66858ead169174057aa1298ccd581514e6db6dee3285280ee6e3a54c9319071dc8165ff061d77783100d449c937ff1fb4cd1bb516a69b9", - ); - }); - test.it("HileSystemLocal.size() number", async () => { - const resultSize = await hileSystemLocal.size("./test/test.txt"); - assert.strictEqual(resultSize, 445); - }); - test.it("HileSystemLocal.size() string", async () => { - const resultSize = await hileSystemLocal.size("./test/test.txt", true); - assert.strictEqual(resultSize, "445"); - }); + const hileSystemLocal = new HileSystemLocal(); + test.it("HileSystemLocal.absolutePathFrom()", () => { + assert.strictEqual( + hileSystemLocal.absolutePathFrom(["path", "to", "file.txt"]), + __dirname.replace("test", "") + path.normalize("path/to/file.txt"), + ); + }); + test.it("HileSystemLocal.createDirectory()", async () => { + const is = await hileSystemLocal.createDirectory("./test/temp2/"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.createFile()", async () => { + const is = await hileSystemLocal.createFile("./test/temp2/cf.txt"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.dirIsExecutable()", async () => { + const is = await hileSystemLocal.dirIsExecutable("./test"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.dirIsReadable()", async () => { + const is = await hileSystemLocal.dirIsReadable("./test"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.dirIsVisible()", async () => { + const is = await hileSystemLocal.dirIsVisible("./test"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.dirIsWritable()", async () => { + const is = await hileSystemLocal.dirIsWritable("./test"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.fileExtension()", () => { + assert.strictEqual(hileSystemLocal.fileExtension("path/to/file.txt"), "txt"); + }); + test.it("HileSystemLocal.fileName()", () => { + assert.strictEqual(hileSystemLocal.fileName("path/to/file.txt"), "file"); + }); + test.it("HileSystemLocal.fileNameExt()", () => { + assert.strictEqual(hileSystemLocal.fileNameExt("path/to/file.txt"), "file.txt"); + }); + test.it("HileSystemLocal.filePath()", () => { + assert.strictEqual(hileSystemLocal.filePath("path/to/file.txt"), "path/to"); + }); + test.it("HileSystemLocal.fileIsExecutable()", async () => { + const is = await hileSystemLocal.fileIsExecutable(`./test/${FILE_NAME}`); + assert.notEqual(is, IS_EXECUTABLE); + }); + test.it("HileSystemLocal.fileIsReadable()", async () => { + const is = await hileSystemLocal.fileIsReadable(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.fileIsVisible()", async () => { + const is = await hileSystemLocal.fileIsVisible(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.fileIsWritable()", async () => { + const is = await hileSystemLocal.fileIsWritable(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.fileTruncate()", async () => { + const is = await hileSystemLocal.fileTruncate("./test/test.file"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.getLinkStatus()", async () => { + const [status, error] = await hileSystemLocal.getLinkStatus(`./test/${FILE_NAME}`); + assert.notEqual(status, undefined); + assert.strictEqual(error, undefined); + }); + test.it("HileSystemLocal.getStatus()", async () => { + const [status, error] = await hileSystemLocal.getStatus(`./test/${FILE_NAME}`); + assert.notEqual(status, undefined); + assert.strictEqual(error, undefined); + }); + test.it("HileSystemLocal.isDirExists()", async () => { + const is = await hileSystemLocal.isDirExists("./test/"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.isFileExists()", async () => { + const is = await hileSystemLocal.isFileExists(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.isPathExists()", async () => { + const is = await hileSystemLocal.isPathExists("./test/"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.move()", async () => { + const testPathFrom = "./test/test_from.file"; + const testPathTo = "./test/test_to.file"; + await hileSystemLocal.createFile(testPathFrom, "0777"); + const result = await hileSystemLocal.move(testPathFrom, testPathTo); + await hileSystemLocal.remove(testPathFrom); + await hileSystemLocal.remove(testPathTo); + assert.strictEqual(result, true); + }); + test.it("HileSystemLocal.pathFrom()", () => { + assert.strictEqual(hileSystemLocal.pathFrom(["path", "to", "file.txt"]), path.normalize("path/to/file.txt")); + }); + test.it("HileSystemLocal.writeFile()", async () => { + const is = await hileSystemLocal.writeFile("./test/temp2.txt", "test2"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.writeFileTail()", async () => { + const is = await hileSystemLocal.writeFileTail("./test/temp-tail.txt", "tail"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.writeJson()", async () => { + const is = await hileSystemLocal.writeJson("./test/temp2.json", "test2"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.remove()", async () => { + const result = await hileSystemLocal.remove("./temp"); + assert.strictEqual(result, true); + }); + test.it("HileSystemLocal.removeNonBlocking()", async () => { + const result = hileSystemLocal.removeNonBlocking("./temp_that_not_exists"); + assert.strictEqual(result, undefined); + }); + test.it("HileSystemLocal.removeSilent()", async () => { + const result = await hileSystemLocal.removeSilent("./temp_that_not_exists"); + assert.strictEqual(result, undefined); + }); + test.it("HileSystemLocal.readFileToString()", async () => { + const is = await hileSystemLocal.readFileToString("./test/temp.txt"); + assert.strictEqual(is, "test"); + }); + test.it("HileSystemLocal.readFileToBuffer()", async () => { + const buf = await hileSystemLocal.readFileToBuffer("./test/temp.txt"); + assert.strictEqual(buf.constructor.name, "Buffer"); + }); + test.it("HileSystemLocal.readFileToBase64()", async () => { + const is = await hileSystemLocal.readFileToBase64("./test/temp.txt"); + assert.strictEqual(is, "dGVzdA=="); + }); + test.it("HileSystemLocal.listContents()", async () => { + const contents = await hileSystemLocal.listContents("."); + assert.strictEqual(Array.isArray(contents), true); + }); + test.it("HileSystemLocal.listDirectories()", async () => { + const contents = await hileSystemLocal.listDirectories("."); + assert.strictEqual(Array.isArray(contents), true); + }); + test.it("HileSystemLocal.listFiles()", async () => { + const contents = await hileSystemLocal.listFiles("."); + assert.strictEqual(Array.isArray(contents), true); + }); + test.it("HileSystemLocal.dirIsEmpty()", async () => { + const isEmpty = await hileSystemLocal.dirIsEmpty("."); + assert.strictEqual(isEmpty, false); + }); + test.it("HileSystemLocal.hash()", async () => { + const resultHash = await hileSystemLocal.hash("./test/test.txt", "md5"); + assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); + }); + test.it("HileSystemLocal.hashCrc32()", async () => { + const resultHash = await hileSystemLocal.hashCrc32("./test/test.txt"); + assert.strictEqual(resultHash, "98b2c5bd"); + }); + test.it("HileSystemLocal.hashMd5()", async () => { + const resultHash = await hileSystemLocal.hashMd5("./test/test.txt"); + assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); + }); + test.it("HileSystemLocal.hashMulti()", async () => { + const expected = { + crc32: "98b2c5bd", + md5: "db89bb5ceab87f9c0fcc2ab36c189c2c", + sha1: "cd36b370758a259b34845084a6cc38473cb95e27", + sha256: "2d8c2f6d978ca21712b5f6de36c9d31fa8e96a4fa5d8ff8b0188dfb9e7c171bb", + sha512: "8ba760cac29cb2b2ce66858ead169174057aa1298ccd581514e6db6dee3285280ee6e3a54c9319071dc8165ff061d77783100d449c937ff1fb4cd1bb516a69b9", + }; + const resultHash = await hileSystemLocal.hashMulti("./test/test.txt"); + assert.strictEqual(resultHash.crc32, expected.crc32); + assert.strictEqual(resultHash.md5, expected.md5); + assert.strictEqual(resultHash.sha1, expected.sha1); + assert.strictEqual(resultHash.sha256, expected.sha256); + assert.strictEqual(resultHash.sha512, expected.sha512); + }); + test.it("HileSystemLocal.hashSha1()", async () => { + const resultHash = await hileSystemLocal.hashSha1("./test/test.txt"); + assert.strictEqual(resultHash, "cd36b370758a259b34845084a6cc38473cb95e27"); + }); + test.it("HileSystemLocal.hashSha256()", async () => { + const resultHash = await hileSystemLocal.hashSha256("./test/test.txt"); + assert.strictEqual(resultHash, "2d8c2f6d978ca21712b5f6de36c9d31fa8e96a4fa5d8ff8b0188dfb9e7c171bb"); + }); + test.it("HileSystemLocal.hashSha512()", async () => { + const resultHash = await hileSystemLocal.hashSha512("./test/test.txt"); + assert.strictEqual( + resultHash, + "8ba760cac29cb2b2ce66858ead169174057aa1298ccd581514e6db6dee3285280ee6e3a54c9319071dc8165ff061d77783100d449c937ff1fb4cd1bb516a69b9", + ); + }); + test.it("HileSystemLocal.size() number", async () => { + const resultSize = await hileSystemLocal.size("./test/test.txt"); + assert.strictEqual(resultSize, 445); + }); + test.it("HileSystemLocal.size() string", async () => { + const resultSize = await hileSystemLocal.size("./test/test.txt", true); + assert.strictEqual(resultSize, "445"); + }); }); diff --git a/test/index.test.mjs b/test/index.test.mjs index 8687155..2b5caf6 100644 --- a/test/index.test.mjs +++ b/test/index.test.mjs @@ -4,50 +4,51 @@ import test from "node:test"; import url from "node:url"; import { - HileSystemLocal, - absolutePathFrom, - createDirectory, - createFile, - dirIsEmpty, - dirIsExecutable, - dirIsReadable, - dirIsVisible, - dirIsWritable, - fileExtension, - fileIsExecutable, - fileIsReadable, - fileIsVisible, - fileIsWritable, - fileName, - fileNameExt, - filePath, - fileTruncate, - getLinkStatus, - getStatus, - hash, - hashCrc32, - hashMd5, - hashSha1, - hashSha256, - hashSha512, - isDirExists, - isFileExists, - isPathExists, - listContents, - listDirectories, - listFiles, - move, - pathFrom, - readFileToBase64, - readFileToBuffer, - readFileToString, - remove, - removeNonBlocking, - removeSilent, - size, - writeFile, - writeFileTail, - writeJSON, + HileSystemLocal, + absolutePathFrom, + createDirectory, + createFile, + dirIsEmpty, + dirIsExecutable, + dirIsReadable, + dirIsVisible, + dirIsWritable, + fileExtension, + fileIsExecutable, + fileIsReadable, + fileIsVisible, + fileIsWritable, + fileName, + fileNameExt, + filePath, + fileTruncate, + getLinkStatus, + getStatus, + hash, + hashCrc32, + hashMd5, + hashMulti, + hashSha1, + hashSha256, + hashSha512, + isDirExists, + isFileExists, + isPathExists, + listContents, + listDirectories, + listFiles, + move, + pathFrom, + readFileToBase64, + readFileToBuffer, + readFileToString, + remove, + removeNonBlocking, + removeSilent, + size, + writeFile, + writeFileTail, + writeJson, } from "../dist/index.mjs"; const FILE_NAME = "index.test.mjs"; @@ -58,374 +59,404 @@ const __filename = url.fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); test.describe("Imported functions", () => { - test.it("absolutePathFrom()", () => { - assert.strictEqual( - absolutePathFrom(["path", "to", "file.txt"]), - __dirname.replace("test", "") + path.normalize("path/to/file.txt"), - ); - }); - test.it("createDirectory()", async () => { - const is = await createDirectory("./test/temp/"); - assert.strictEqual(is, true); - }); - test.it("createFile()", async () => { - const is = await createFile("./test/temp/cf.txt"); - assert.strictEqual(is, true); - }); - test.it("dirIsExecutable()", async () => { - const is = await dirIsExecutable("./test"); - assert.strictEqual(is, true); - }); - test.it("dirIsReadable()", async () => { - const is = await dirIsReadable("./test"); - assert.strictEqual(is, true); - }); - test.it("dirIsVisible()", async () => { - const is = await dirIsVisible("./test"); - assert.strictEqual(is, true); - }); - test.it("dirIsWritable()", async () => { - const is = await dirIsWritable("./test"); - assert.strictEqual(is, true); - }); - test.it("fileExtension()", () => { - assert.strictEqual(fileExtension("path/to/file.txt"), "txt"); - }); - test.it("fileName()", () => { - assert.strictEqual(fileName("path/to/file.txt"), "file"); - }); - test.it("fileNameExt()", () => { - assert.strictEqual(fileNameExt("path/to/file.txt"), "file.txt"); - }); - test.it("filePath()", () => { - assert.strictEqual(filePath("path/to/file.txt"), "path/to"); - }); - test.it("fileIsExecutable()", async () => { - const is = await fileIsExecutable(`./test/${FILE_NAME}`); - assert.notEqual(is, IS_EXECUTABLE); - }); - test.it("fileIsReadable()", async () => { - const is = await fileIsReadable(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("fileIsVisible()", async () => { - const is = await fileIsVisible(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("fileIsWritable()", async () => { - const is = await fileIsWritable(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("fileTruncate()", async () => { - const is = await fileTruncate("./test/test.file"); - assert.strictEqual(is, true); - }); - test.it("getLinkStatus()", async () => { - const [status, error] = await getLinkStatus(`./test/${FILE_NAME}`); - assert.notEqual(status, undefined); - assert.strictEqual(error, undefined); - }); - test.it("getStatus()", async () => { - const [status, error] = await getStatus(`./test/${FILE_NAME}`); - assert.notEqual(status, undefined); - assert.strictEqual(error, undefined); - }); - test.it("isDirExists()", async () => { - const is = await isDirExists("./test/"); - assert.strictEqual(is, true); - }); - test.it("isFileExists()", async () => { - const is = await isFileExists(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("isPathExists()", async () => { - const is = await isPathExists("./test/"); - assert.strictEqual(is, true); - }); - test.it("move()", async () => { - const testPathFrom = "./test/test_from.file"; - const testPathTo = "./test/test_to.file"; - await createFile(testPathFrom, "0777"); - const result = await move(testPathFrom, testPathTo); - await remove(testPathFrom); - await remove(testPathTo); - assert.strictEqual(result, true); - }); - test.it("pathFrom()", () => { - assert.strictEqual(pathFrom(["path", "to", "file.txt"]), path.normalize("path/to/file.txt")); - }); - test.it("writeFile()", async () => { - const is = await writeFile("./test/temp.txt", "test"); - assert.strictEqual(is, true); - }); - test.it("writeFileTail()", async () => { - const is = await writeFileTail("./test/temp-tail.txt", "tail"); - assert.strictEqual(is, true); - }); - test.it("writeJSON()", async () => { - const is = await writeJSON("./test/temp.json", "test"); - assert.strictEqual(is, true); - }); - test.it("remove()", async () => { - const result = await remove("./temp"); - assert.strictEqual(result, undefined); - }); - test.it("removeNonBlocking()", async () => { - const result = await removeNonBlocking("./temp_that_not_exists"); - assert.strictEqual(result, undefined); - }); - test.it("removeSilent()", async () => { - const result = await removeSilent("./temp_that_not_exists"); - assert.strictEqual(result, undefined); - }); - test.it("readFileToString()", async () => { - const is = await readFileToString("./test/temp.txt"); - assert.strictEqual(is, "test"); - }); - test.it("readFileToBuffer()", async () => { - const buf = await readFileToBuffer("./test/temp.txt"); - assert.strictEqual(buf.constructor.name, "Buffer"); - }); - test.it("readFileToBase64()", async () => { - const is = await readFileToBase64("./test/temp.txt"); - assert.strictEqual(is, "dGVzdA=="); - }); - test.it("listContents()", async () => { - const contents = await listContents("."); - assert.strictEqual(Array.isArray(contents), true); - }); - test.it("listDirectories()", async () => { - const contents = await listDirectories("."); - assert.strictEqual(Array.isArray(contents), true); - }); - test.it("listFiles()", async () => { - const contents = await listFiles("."); - assert.strictEqual(Array.isArray(contents), true); - }); - test.it("dirIsEmpty()", async () => { - const isEmpty = await dirIsEmpty("."); - assert.strictEqual(isEmpty, false); - }); - test.it("hash()", async () => { - const resultHash = await hash("./test/test.txt", "md5"); - assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); - }); - test.it("hashCrc32()", async () => { - const resultHash = await hashCrc32("./test/test.txt"); - assert.strictEqual(resultHash, "98b2c5bd"); - }); - test.it("hashMd5()", async () => { - const resultHash = await hashMd5("./test/test.txt"); - assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); - }); - test.it("hashSha1()", async () => { - const resultHash = await hashSha1("./test/test.txt"); - assert.strictEqual(resultHash, "cd36b370758a259b34845084a6cc38473cb95e27"); - }); - test.it("hashSha256()", async () => { - const resultHash = await hashSha256("./test/test.txt"); - assert.strictEqual(resultHash, "2d8c2f6d978ca21712b5f6de36c9d31fa8e96a4fa5d8ff8b0188dfb9e7c171bb"); - }); - test.it("hashSha512()", async () => { - const resultHash = await hashSha512("./test/test.txt"); - assert.strictEqual( - resultHash, - "8ba760cac29cb2b2ce66858ead169174057aa1298ccd581514e6db6dee3285280ee6e3a54c9319071dc8165ff061d77783100d449c937ff1fb4cd1bb516a69b9", - ); - }); - test.it("size() number", async () => { - const resultSize = await size("./test/test.txt"); - assert.strictEqual(resultSize, 445); - }); - test.it("size() string", async () => { - const resultSize = await size("./test/test.txt", true); - assert.strictEqual(resultSize, "445"); - }); + test.it("absolutePathFrom()", () => { + assert.strictEqual( + absolutePathFrom(["path", "to", "file.txt"]), + __dirname.replace("test", "") + path.normalize("path/to/file.txt"), + ); + }); + test.it("createDirectory()", async () => { + const is = await createDirectory("./test/temp/"); + assert.strictEqual(is, true); + }); + test.it("createFile()", async () => { + const is = await createFile("./test/temp/cf.txt"); + assert.strictEqual(is, true); + }); + test.it("dirIsExecutable()", async () => { + const is = await dirIsExecutable("./test"); + assert.strictEqual(is, true); + }); + test.it("dirIsReadable()", async () => { + const is = await dirIsReadable("./test"); + assert.strictEqual(is, true); + }); + test.it("dirIsVisible()", async () => { + const is = await dirIsVisible("./test"); + assert.strictEqual(is, true); + }); + test.it("dirIsWritable()", async () => { + const is = await dirIsWritable("./test"); + assert.strictEqual(is, true); + }); + test.it("fileExtension()", () => { + assert.strictEqual(fileExtension("path/to/file.txt"), "txt"); + }); + test.it("fileName()", () => { + assert.strictEqual(fileName("path/to/file.txt"), "file"); + }); + test.it("fileNameExt()", () => { + assert.strictEqual(fileNameExt("path/to/file.txt"), "file.txt"); + }); + test.it("filePath()", () => { + assert.strictEqual(filePath("path/to/file.txt"), "path/to"); + }); + test.it("fileIsExecutable()", async () => { + const is = await fileIsExecutable(`./test/${FILE_NAME}`); + assert.notEqual(is, IS_EXECUTABLE); + }); + test.it("fileIsReadable()", async () => { + const is = await fileIsReadable(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("fileIsVisible()", async () => { + const is = await fileIsVisible(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("fileIsWritable()", async () => { + const is = await fileIsWritable(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("fileTruncate()", async () => { + const is = await fileTruncate("./test/test.file"); + assert.strictEqual(is, true); + }); + test.it("getLinkStatus()", async () => { + const [status, error] = await getLinkStatus(`./test/${FILE_NAME}`); + assert.notEqual(status, undefined); + assert.strictEqual(error, undefined); + }); + test.it("getStatus()", async () => { + const [status, error] = await getStatus(`./test/${FILE_NAME}`); + assert.notEqual(status, undefined); + assert.strictEqual(error, undefined); + }); + test.it("isDirExists()", async () => { + const is = await isDirExists("./test/"); + assert.strictEqual(is, true); + }); + test.it("isFileExists()", async () => { + const is = await isFileExists(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("isPathExists()", async () => { + const is = await isPathExists("./test/"); + assert.strictEqual(is, true); + }); + test.it("move()", async () => { + const testPathFrom = "./test/test_from.file"; + const testPathTo = "./test/test_to.file"; + await createFile(testPathFrom, "0777"); + const result = await move(testPathFrom, testPathTo); + await remove(testPathFrom); + await remove(testPathTo); + assert.strictEqual(result, true); + }); + test.it("pathFrom()", () => { + assert.strictEqual(pathFrom(["path", "to", "file.txt"]), path.normalize("path/to/file.txt")); + }); + test.it("writeFile()", async () => { + const is = await writeFile("./test/temp.txt", "test"); + assert.strictEqual(is, true); + }); + test.it("writeFileTail()", async () => { + const is = await writeFileTail("./test/temp-tail.txt", "tail"); + assert.strictEqual(is, true); + }); + test.it("writeJson()", async () => { + const is = await writeJson("./test/temp.json", "test"); + assert.strictEqual(is, true); + }); + test.it("remove()", async () => { + const result = await remove("./temp"); + assert.strictEqual(result, true); + }); + test.it("removeNonBlocking()", async () => { + const result = await removeNonBlocking("./temp_that_not_exists"); + assert.strictEqual(result, undefined); + }); + test.it("removeSilent()", async () => { + const result = await removeSilent("./temp_that_not_exists"); + assert.strictEqual(result, undefined); + }); + test.it("readFileToString()", async () => { + const is = await readFileToString("./test/temp.txt"); + assert.strictEqual(is, "test"); + }); + test.it("readFileToBuffer()", async () => { + const buf = await readFileToBuffer("./test/temp.txt"); + assert.strictEqual(buf.constructor.name, "Buffer"); + }); + test.it("readFileToBase64()", async () => { + const is = await readFileToBase64("./test/temp.txt"); + assert.strictEqual(is, "dGVzdA=="); + }); + test.it("listContents()", async () => { + const contents = await listContents("."); + assert.strictEqual(Array.isArray(contents), true); + }); + test.it("listDirectories()", async () => { + const contents = await listDirectories("."); + assert.strictEqual(Array.isArray(contents), true); + }); + test.it("listFiles()", async () => { + const contents = await listFiles("."); + assert.strictEqual(Array.isArray(contents), true); + }); + test.it("dirIsEmpty()", async () => { + const isEmpty = await dirIsEmpty("."); + assert.strictEqual(isEmpty, false); + }); + test.it("hash()", async () => { + const resultHash = await hash("./test/test.txt", "md5"); + assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); + }); + test.it("hashCrc32()", async () => { + const resultHash = await hashCrc32("./test/test.txt"); + assert.strictEqual(resultHash, "98b2c5bd"); + }); + test.it("hashMd5()", async () => { + const resultHash = await hashMd5("./test/test.txt"); + assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); + }); + test.it("hashMulti()", async () => { + const expected = { + crc32: "98b2c5bd", + md5: "db89bb5ceab87f9c0fcc2ab36c189c2c", + sha1: "cd36b370758a259b34845084a6cc38473cb95e27", + sha256: "2d8c2f6d978ca21712b5f6de36c9d31fa8e96a4fa5d8ff8b0188dfb9e7c171bb", + sha512: "8ba760cac29cb2b2ce66858ead169174057aa1298ccd581514e6db6dee3285280ee6e3a54c9319071dc8165ff061d77783100d449c937ff1fb4cd1bb516a69b9", + }; + const result = await hashMulti("./test/test.txt"); + assert.strictEqual(result.crc32, expected.crc32); + assert.strictEqual(result.md5, expected.md5); + assert.strictEqual(result.sha1, expected.sha1); + assert.strictEqual(result.sha256, expected.sha256); + assert.strictEqual(result.sha512, expected.sha512); + }); + test.it("hashSha1()", async () => { + const resultHash = await hashSha1("./test/test.txt"); + assert.strictEqual(resultHash, "cd36b370758a259b34845084a6cc38473cb95e27"); + }); + test.it("hashSha256()", async () => { + const resultHash = await hashSha256("./test/test.txt"); + assert.strictEqual(resultHash, "2d8c2f6d978ca21712b5f6de36c9d31fa8e96a4fa5d8ff8b0188dfb9e7c171bb"); + }); + test.it("hashSha512()", async () => { + const resultHash = await hashSha512("./test/test.txt"); + assert.strictEqual( + resultHash, + "8ba760cac29cb2b2ce66858ead169174057aa1298ccd581514e6db6dee3285280ee6e3a54c9319071dc8165ff061d77783100d449c937ff1fb4cd1bb516a69b9", + ); + }); + test.it("size() number", async () => { + const resultSize = await size("./test/test.txt"); + assert.strictEqual(resultSize, 445); + }); + test.it("size() string", async () => { + const resultSize = await size("./test/test.txt", true); + assert.strictEqual(resultSize, "445"); + }); }); test.describe("Class with static helpers", () => { - const hileSystemLocal = new HileSystemLocal(); - test.it("HileSystemLocal.absolutePathFrom()", () => { - assert.strictEqual( - hileSystemLocal.absolutePathFrom(["path", "to", "file.txt"]), - __dirname.replace("test", "") + path.normalize("path/to/file.txt"), - ); - }); - test.it("HileSystemLocal.createDirectory()", async () => { - const is = await hileSystemLocal.createDirectory("./test/temp2/"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.createFile()", async () => { - const is = await hileSystemLocal.createFile("./test/temp2/cf.txt"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.dirIsExecutable()", async () => { - const is = await hileSystemLocal.dirIsExecutable("./test"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.dirIsReadable()", async () => { - const is = await hileSystemLocal.dirIsReadable("./test"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.dirIsVisible()", async () => { - const is = await hileSystemLocal.dirIsVisible("./test"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.dirIsWritable()", async () => { - const is = await hileSystemLocal.dirIsWritable("./test"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.fileExtension()", () => { - assert.strictEqual(hileSystemLocal.fileExtension("path/to/file.txt"), "txt"); - }); - test.it("HileSystemLocal.fileName()", () => { - assert.strictEqual(hileSystemLocal.fileName("path/to/file.txt"), "file"); - }); - test.it("HileSystemLocal.fileNameExt()", () => { - assert.strictEqual(hileSystemLocal.fileNameExt("path/to/file.txt"), "file.txt"); - }); - test.it("HileSystemLocal.filePath()", () => { - assert.strictEqual(hileSystemLocal.filePath("path/to/file.txt"), "path/to"); - }); - test.it("HileSystemLocal.fileIsExecutable()", async () => { - const is = await hileSystemLocal.fileIsExecutable(`./test/${FILE_NAME}`); - assert.notEqual(is, IS_EXECUTABLE); - }); - test.it("HileSystemLocal.fileIsReadable()", async () => { - const is = await hileSystemLocal.fileIsReadable(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.fileIsVisible()", async () => { - const is = await hileSystemLocal.fileIsVisible(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.fileIsWritable()", async () => { - const is = await hileSystemLocal.fileIsWritable(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.fileTruncate()", async () => { - const is = await hileSystemLocal.fileTruncate("./test/test.file"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.getLinkStatus()", async () => { - const [status, error] = await hileSystemLocal.getLinkStatus(`./test/${FILE_NAME}`); - assert.notEqual(status, undefined); - assert.strictEqual(error, undefined); - }); - test.it("HileSystemLocal.getStatus()", async () => { - const [status, error] = await hileSystemLocal.getStatus(`./test/${FILE_NAME}`); - assert.notEqual(status, undefined); - assert.strictEqual(error, undefined); - }); - test.it("HileSystemLocal.isDirExists()", async () => { - const is = await hileSystemLocal.isDirExists("./test/"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.isFileExists()", async () => { - const is = await hileSystemLocal.isFileExists(`./test/${FILE_NAME}`); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.isPathExists()", async () => { - const is = await hileSystemLocal.isPathExists("./test/"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.move()", async () => { - const testPathFrom = "./test/test_from.file"; - const testPathTo = "./test/test_to.file"; - await hileSystemLocal.createFile(testPathFrom, "0777"); - const result = await hileSystemLocal.move(testPathFrom, testPathTo); - await hileSystemLocal.remove(testPathFrom); - await hileSystemLocal.remove(testPathTo); - assert.strictEqual(result, true); - }); - test.it("HileSystemLocal.pathFrom()", () => { - assert.strictEqual(hileSystemLocal.pathFrom(["path", "to", "file.txt"]), path.normalize("path/to/file.txt")); - }); - test.it("HileSystemLocal.writeFile()", async () => { - const is = await hileSystemLocal.writeFile("./test/temp2.txt", "test2"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.writeFileTail()", async () => { - const is = await hileSystemLocal.writeFileTail("./test/temp-tail.txt", "tail"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.writeJSON()", async () => { - const is = await hileSystemLocal.writeJSON("./test/temp2.json", "test2"); - assert.strictEqual(is, true); - }); - test.it("HileSystemLocal.remove()", async () => { - const result = await hileSystemLocal.remove("./temp"); - assert.strictEqual(result, undefined); - }); - test.it("HileSystemLocal.removeNonBlocking()", async () => { - const result = hileSystemLocal.removeNonBlocking("./temp_that_not_exists"); - assert.strictEqual(result, undefined); - }); - test.it("HileSystemLocal.removeSilent()", async () => { - const result = await hileSystemLocal.removeSilent("./temp_that_not_exists"); - assert.strictEqual(result, undefined); - }); - test.it("HileSystemLocal.readFileToString()", async () => { - const is = await hileSystemLocal.readFileToString("./test/temp.txt"); - assert.strictEqual(is, "test"); - }); - test.it("HileSystemLocal.readFileToBuffer()", async () => { - const buf = await hileSystemLocal.readFileToBuffer("./test/temp.txt"); - assert.strictEqual(buf.constructor.name, "Buffer"); - }); - test.it("HileSystemLocal.readFileToBase64()", async () => { - const is = await hileSystemLocal.readFileToBase64("./test/temp.txt"); - assert.strictEqual(is, "dGVzdA=="); - }); - test.it("HileSystemLocal.listContents()", async () => { - const contents = await hileSystemLocal.listContents("."); - assert.strictEqual(Array.isArray(contents), true); - }); - test.it("HileSystemLocal.listDirectories()", async () => { - const contents = await hileSystemLocal.listDirectories("."); - assert.strictEqual(Array.isArray(contents), true); - }); - test.it("HileSystemLocal.listFiles()", async () => { - const contents = await hileSystemLocal.listFiles("."); - assert.strictEqual(Array.isArray(contents), true); - }); - test.it("HileSystemLocal.dirIsEmpty()", async () => { - const isEmpty = await hileSystemLocal.dirIsEmpty("."); - assert.strictEqual(isEmpty, false); - }); - test.it("HileSystemLocal.hash()", async () => { - const resultHash = await hileSystemLocal.hash("./test/test.txt", "md5"); - assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); - }); - test.it("HileSystemLocal.hashCrc32()", async () => { - const resultHash = await hileSystemLocal.hashCrc32("./test/test.txt"); - assert.strictEqual(resultHash, "98b2c5bd"); - }); - test.it("HileSystemLocal.hashMd5()", async () => { - const resultHash = await hileSystemLocal.hashMd5("./test/test.txt"); - assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); - }); - test.it("HileSystemLocal.hashSha1()", async () => { - const resultHash = await hileSystemLocal.hashSha1("./test/test.txt"); - assert.strictEqual(resultHash, "cd36b370758a259b34845084a6cc38473cb95e27"); - }); - test.it("HileSystemLocal.hashSha256()", async () => { - const resultHash = await hileSystemLocal.hashSha256("./test/test.txt"); - assert.strictEqual(resultHash, "2d8c2f6d978ca21712b5f6de36c9d31fa8e96a4fa5d8ff8b0188dfb9e7c171bb"); - }); - test.it("HileSystemLocal.hashSha512()", async () => { - const resultHash = await hileSystemLocal.hashSha512("./test/test.txt"); - assert.strictEqual( - resultHash, - "8ba760cac29cb2b2ce66858ead169174057aa1298ccd581514e6db6dee3285280ee6e3a54c9319071dc8165ff061d77783100d449c937ff1fb4cd1bb516a69b9", - ); - }); - test.it("HileSystemLocal.size() number", async () => { - const resultSize = await hileSystemLocal.size("./test/test.txt"); - assert.strictEqual(resultSize, 445); - }); - test.it("HileSystemLocal.size() string", async () => { - const resultSize = await hileSystemLocal.size("./test/test.txt", true); - assert.strictEqual(resultSize, "445"); - }); + const hileSystemLocal = new HileSystemLocal(); + test.it("HileSystemLocal.absolutePathFrom()", () => { + assert.strictEqual( + hileSystemLocal.absolutePathFrom(["path", "to", "file.txt"]), + __dirname.replace("test", "") + path.normalize("path/to/file.txt"), + ); + }); + test.it("HileSystemLocal.createDirectory()", async () => { + const is = await hileSystemLocal.createDirectory("./test/temp2/"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.createFile()", async () => { + const is = await hileSystemLocal.createFile("./test/temp2/cf.txt"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.dirIsExecutable()", async () => { + const is = await hileSystemLocal.dirIsExecutable("./test"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.dirIsReadable()", async () => { + const is = await hileSystemLocal.dirIsReadable("./test"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.dirIsVisible()", async () => { + const is = await hileSystemLocal.dirIsVisible("./test"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.dirIsWritable()", async () => { + const is = await hileSystemLocal.dirIsWritable("./test"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.fileExtension()", () => { + assert.strictEqual(hileSystemLocal.fileExtension("path/to/file.txt"), "txt"); + }); + test.it("HileSystemLocal.fileName()", () => { + assert.strictEqual(hileSystemLocal.fileName("path/to/file.txt"), "file"); + }); + test.it("HileSystemLocal.fileNameExt()", () => { + assert.strictEqual(hileSystemLocal.fileNameExt("path/to/file.txt"), "file.txt"); + }); + test.it("HileSystemLocal.filePath()", () => { + assert.strictEqual(hileSystemLocal.filePath("path/to/file.txt"), "path/to"); + }); + test.it("HileSystemLocal.fileIsExecutable()", async () => { + const is = await hileSystemLocal.fileIsExecutable(`./test/${FILE_NAME}`); + assert.notEqual(is, IS_EXECUTABLE); + }); + test.it("HileSystemLocal.fileIsReadable()", async () => { + const is = await hileSystemLocal.fileIsReadable(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.fileIsVisible()", async () => { + const is = await hileSystemLocal.fileIsVisible(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.fileIsWritable()", async () => { + const is = await hileSystemLocal.fileIsWritable(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.fileTruncate()", async () => { + const is = await hileSystemLocal.fileTruncate("./test/test.file"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.getLinkStatus()", async () => { + const [status, error] = await hileSystemLocal.getLinkStatus(`./test/${FILE_NAME}`); + assert.notEqual(status, undefined); + assert.strictEqual(error, undefined); + }); + test.it("HileSystemLocal.getStatus()", async () => { + const [status, error] = await hileSystemLocal.getStatus(`./test/${FILE_NAME}`); + assert.notEqual(status, undefined); + assert.strictEqual(error, undefined); + }); + test.it("HileSystemLocal.isDirExists()", async () => { + const is = await hileSystemLocal.isDirExists("./test/"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.isFileExists()", async () => { + const is = await hileSystemLocal.isFileExists(`./test/${FILE_NAME}`); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.isPathExists()", async () => { + const is = await hileSystemLocal.isPathExists("./test/"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.move()", async () => { + const testPathFrom = "./test/test_from.file"; + const testPathTo = "./test/test_to.file"; + await hileSystemLocal.createFile(testPathFrom, "0777"); + const result = await hileSystemLocal.move(testPathFrom, testPathTo); + await hileSystemLocal.remove(testPathFrom); + await hileSystemLocal.remove(testPathTo); + assert.strictEqual(result, true); + }); + test.it("HileSystemLocal.pathFrom()", () => { + assert.strictEqual(hileSystemLocal.pathFrom(["path", "to", "file.txt"]), path.normalize("path/to/file.txt")); + }); + test.it("HileSystemLocal.writeFile()", async () => { + const is = await hileSystemLocal.writeFile("./test/temp2.txt", "test2"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.writeFileTail()", async () => { + const is = await hileSystemLocal.writeFileTail("./test/temp-tail.txt", "tail"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.writeJson()", async () => { + const is = await hileSystemLocal.writeJson("./test/temp2.json", "test2"); + assert.strictEqual(is, true); + }); + test.it("HileSystemLocal.remove()", async () => { + const result = await hileSystemLocal.remove("./temp"); + assert.strictEqual(result, true); + }); + test.it("HileSystemLocal.removeNonBlocking()", async () => { + const result = hileSystemLocal.removeNonBlocking("./temp_that_not_exists"); + assert.strictEqual(result, undefined); + }); + test.it("HileSystemLocal.removeSilent()", async () => { + const result = await hileSystemLocal.removeSilent("./temp_that_not_exists"); + assert.strictEqual(result, undefined); + }); + test.it("HileSystemLocal.readFileToString()", async () => { + const is = await hileSystemLocal.readFileToString("./test/temp.txt"); + assert.strictEqual(is, "test"); + }); + test.it("HileSystemLocal.readFileToBuffer()", async () => { + const buf = await hileSystemLocal.readFileToBuffer("./test/temp.txt"); + assert.strictEqual(buf.constructor.name, "Buffer"); + }); + test.it("HileSystemLocal.readFileToBase64()", async () => { + const is = await hileSystemLocal.readFileToBase64("./test/temp.txt"); + assert.strictEqual(is, "dGVzdA=="); + }); + test.it("HileSystemLocal.listContents()", async () => { + const contents = await hileSystemLocal.listContents("."); + assert.strictEqual(Array.isArray(contents), true); + }); + test.it("HileSystemLocal.listDirectories()", async () => { + const contents = await hileSystemLocal.listDirectories("."); + assert.strictEqual(Array.isArray(contents), true); + }); + test.it("HileSystemLocal.listFiles()", async () => { + const contents = await hileSystemLocal.listFiles("."); + assert.strictEqual(Array.isArray(contents), true); + }); + test.it("HileSystemLocal.dirIsEmpty()", async () => { + const isEmpty = await hileSystemLocal.dirIsEmpty("."); + assert.strictEqual(isEmpty, false); + }); + test.it("HileSystemLocal.hash()", async () => { + const resultHash = await hileSystemLocal.hash("./test/test.txt", "md5"); + assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); + }); + test.it("HileSystemLocal.hashCrc32()", async () => { + const resultHash = await hileSystemLocal.hashCrc32("./test/test.txt"); + assert.strictEqual(resultHash, "98b2c5bd"); + }); + test.it("HileSystemLocal.hashMd5()", async () => { + const resultHash = await hileSystemLocal.hashMd5("./test/test.txt"); + assert.strictEqual(resultHash, "db89bb5ceab87f9c0fcc2ab36c189c2c"); + }); + test.it("HileSystemLocal.hashMulti()", async () => { + const expected = { + crc32: "98b2c5bd", + md5: "db89bb5ceab87f9c0fcc2ab36c189c2c", + sha1: "cd36b370758a259b34845084a6cc38473cb95e27", + sha256: "2d8c2f6d978ca21712b5f6de36c9d31fa8e96a4fa5d8ff8b0188dfb9e7c171bb", + sha512: "8ba760cac29cb2b2ce66858ead169174057aa1298ccd581514e6db6dee3285280ee6e3a54c9319071dc8165ff061d77783100d449c937ff1fb4cd1bb516a69b9", + }; + const resultHash = await hileSystemLocal.hashMulti("./test/test.txt"); + assert.strictEqual(resultHash.crc32, expected.crc32); + assert.strictEqual(resultHash.md5, expected.md5); + assert.strictEqual(resultHash.sha1, expected.sha1); + assert.strictEqual(resultHash.sha256, expected.sha256); + assert.strictEqual(resultHash.sha512, expected.sha512); + }); + test.it("HileSystemLocal.hashSha1()", async () => { + const resultHash = await hileSystemLocal.hashSha1("./test/test.txt"); + assert.strictEqual(resultHash, "cd36b370758a259b34845084a6cc38473cb95e27"); + }); + test.it("HileSystemLocal.hashSha256()", async () => { + const resultHash = await hileSystemLocal.hashSha256("./test/test.txt"); + assert.strictEqual(resultHash, "2d8c2f6d978ca21712b5f6de36c9d31fa8e96a4fa5d8ff8b0188dfb9e7c171bb"); + }); + test.it("HileSystemLocal.hashSha512()", async () => { + const resultHash = await hileSystemLocal.hashSha512("./test/test.txt"); + assert.strictEqual( + resultHash, + "8ba760cac29cb2b2ce66858ead169174057aa1298ccd581514e6db6dee3285280ee6e3a54c9319071dc8165ff061d77783100d449c937ff1fb4cd1bb516a69b9", + ); + }); + test.it("HileSystemLocal.size() number", async () => { + const resultSize = await hileSystemLocal.size("./test/test.txt"); + assert.strictEqual(resultSize, 445); + }); + test.it("HileSystemLocal.size() string", async () => { + const resultSize = await hileSystemLocal.size("./test/test.txt", true); + assert.strictEqual(resultSize, "445"); + }); }); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..a290136 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,37 @@ +{ + "compilerOptions": { + // Strict Checks + "alwaysStrict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "useUnknownInCatchVariables": true, + "strictPropertyInitialization": true, + "strictFunctionTypes": true, + "noImplicitThis": true, + "strictBindCallApply": true, + "noPropertyAccessFromIndexSignature": true, + "noUncheckedIndexedAccess": true, + "exactOptionalPropertyTypes": true, + // Linter Checks + "noImplicitReturns": true, + "noImplicitOverride": true, + "forceConsistentCasingInFileNames": true, + // https://eslint.org/docs/rules/consistent-return ? + "noFallthroughCasesInSwitch": true, + // https://eslint.org/docs/rules/no-fallthrough + "noUnusedLocals": true, + // https://eslint.org/docs/rules/no-unused-vars + "noUnusedParameters": true, + // https://eslint.org/docs/rules/no-unused-vars#args + "allowUnreachableCode": false, + // https://eslint.org/docs/rules/no-unreachable ? + "allowUnusedLabels": false, + // https://eslint.org/docs/rules/no-unused-labels + // Base Strict Checks + "noImplicitUseStrict": false, + "suppressExcessPropertyErrors": false, + "suppressImplicitAnyIndexErrors": false, + "noStrictGenericChecks": false, + "lib": ["esnext"] + } +} diff --git a/tsup.config.ts b/tsup.config.ts new file mode 100644 index 0000000..2074360 --- /dev/null +++ b/tsup.config.ts @@ -0,0 +1,19 @@ +import type { Options } from "tsup"; + +const tsup: Options = { + splitting: false, + clean: false, + dts: true, + format: ["cjs", "esm"], + minify: false, + bundle: true, + skipNodeModulesBundle: true, + outDir: "dist", + entry: ["src/index.ts"], + esbuildOptions(options) { + // the directory structure will be the same as the source + options.outbase = "./"; + }, +}; + +export default tsup; diff --git a/vite.config.mjs b/vite.config.mjs new file mode 100644 index 0000000..ce575a9 --- /dev/null +++ b/vite.config.mjs @@ -0,0 +1,29 @@ +import nodeExternals from "vite-plugin-node-externals"; +import { defineConfig } from "vite"; + +export default defineConfig({ + build: { + lib: { + entry: "./src/index.ts", + formats: ["cjs", "es"], + fileName: (format) => `index.${format === "cjs" ? "cjs" : "mjs"}`, + }, + rollupOptions: { + external: [ + // + "node:assert", + "node:crypto", + "node:fs", + "node:fs/promises", + "node:os", + "node:path", + ], + }, + plugins: [ + // + nodeExternals(), + ], + sourcemap: true, + minify: 'esbuild', + }, +});