ktfile 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.min.js CHANGED
@@ -1 +1 @@
1
- let t=[];function s(s,e=t){"/"===s[0]||"\\"===s[0]?(e=[],s=s.slice(1)):e=[...e];const i=s.split(/[\\/]/g);for(const t of i)".."===t?e.pop():"."!==t&&""!==t&&e.push(t);return e}"undefined"!=typeof process&&"cwd"in process&&"function"==typeof process.cwd&&(t=s(process.cwd()));const e=new Map;function i(t,s,e){const i=t.listeners(s);t.removeAllListeners(s);for(const n of i)n!==e&&t.on(s,n);t.on(s,e)}function n(){for(const[t,s]of e.entries())new d(t).delete(s);e.clear(),"undefined"!=typeof process?(process.off("SIGINT",r),process.off("SIGTERM",l),process.off("exit",n)):"undefined"!=typeof window&&(window.removeEventListener("beforeunload",n),window.removeEventListener("pagehide",n))}function r(){n(),process.exit(130)}function l(){n(),process.exit(143)}function a(){"undefined"!=typeof process?(i(process,"exit",n),i(process,"SIGINT",r),i(process,"SIGTERM",l)):"undefined"!=typeof window&&(window.addEventListener("beforeunload",n),window.addEventListener("pagehide",n))}class h{split;constructor(t){this.split="string"==typeof t?s(t):[...t]}get fullPath(){return 0===this.split.length?this.separator:this.split.join(this.separator)}createWriteStream(t){if("object"==typeof this.fs&&"createWriteStream"in this.fs&&"function"==typeof this.fs.createWriteStream)return this.fs.createWriteStream(this.split.join("/"),t);throw new Error("File system does not support createWriteStream")}createReadStream(t){if("object"==typeof this.fs&&"createReadStream"in this.fs&&"function"==typeof this.fs.createReadStream)return this.fs.createReadStream(this.split.join("/"),t);throw new Error("File system does not support createReadStream")}createAppendStream(t){if("object"==typeof this.fs&&"createWriteStream"in this.fs&&"function"==typeof this.fs.createWriteStream)return this.fs.createWriteStream(this.split.join("/"),{flags:"a",encoding:t});throw new Error("File system does not support createAppendStream")}createInputStream(t){if("object"==typeof this.fs&&"createReadStream"in this.fs&&"function"==typeof this.fs.createReadStream)return this.fs.createReadStream(this.split.join("/"),{flags:"r",encoding:t});throw new Error("File system does not support createInputStream")}}async function u(t){try{return t().then(()=>!0).catch(()=>!1)}catch(t){return!1}}async function f(t){try{return t().then(t=>t).catch(()=>null)}catch(t){return null}}class c extends h{static fs;static sep="/";static createTempFile(t,s="ktfile-temp",e=".tmp"){if(!("mkdTemp"in c.fs))throw new Error("mkdTemp is not available in the current FS.");const i=t?t.fullPath:".",n=this.fs.mkdtemp(`${i}/${s}-`);return new c(`${n}${e}`)}get fs(){return c.fs}canExecute(){return u(()=>this.fs.access(this.fullPath,this.fs?.constants?.X_OK??1))}async setExecutable(t=!0){return await u(()=>this.fs.chmod(this.fullPath,t?493:420))?this:null}canRead(){return u(()=>this.fs.access(this.fullPath,this.fs?.constants?.R_OK??4))}async setReadable(t=!0){return await u(()=>this.fs.chmod(this.fullPath,t?420:0))?this:null}canWrite(){return u(()=>this.fs.access(this.fullPath,this.fs?.constants?.W_OK??2))}async setWritable(t=!0){return await u(()=>this.fs.chmod(this.fullPath,t?420:292))?this:null}creationTime(){return f(()=>this.fs.stat(this.fullPath).then(t=>t.birthtime).catch(()=>null))}async setCreationTime(t){return await u(()=>this.fs.utimes(this.fullPath,t,t))?this:null}async lastModified(){return await f(()=>this.fs.stat(this.fullPath).then(t=>t.mtime).catch(()=>null))}async setLastModified(t){return await u(()=>this.fs.utimes(this.fullPath,t,t))?this:null}exists(){return f(()=>this.fs.exists(this.fullPath))}lastAccess(){return f(()=>this.fs.stat(this.fullPath).then(t=>t.atime).catch(()=>null))}get name(){return this.fullPath.split(this.separator).pop()||""}get nameWithoutExtension(){const t=this.name,s=t.lastIndexOf(".");return-1===s?t:t.substring(0,s)}get extension(){const t=this.name,s=t.lastIndexOf(".");return-1===s?"":t.substring(s+1)}get parent(){return 0===this.split.length?null:new c(this.split.slice(0,-1))}get uri(){return`file://${this.fullPath}`}get separator(){return c.sep}isDirectory(){return f(()=>this.fs.stat(this.fullPath).then(t=>t.isDirectory()).catch(()=>null))}isFile(){return f(()=>this.fs.stat(this.fullPath).then(t=>t.isFile()).catch(()=>null))}get isHidden(){return this.name.startsWith(".")||this.fullPath.split(this.separator).some(t=>t.startsWith("."))}isSymbolicLink(){return f(()=>this.fs.lstat(this.fullPath).then(t=>t.isSymbolicLink()).catch(()=>null))}size(){return f(()=>this.fs.stat(this.fullPath).then(t=>t.size).catch(()=>null))}async sizeKB(){const t=await this.size();return null!==t?t/1024:null}async sizeMB(){const t=await this.size();return null!==t?t/1048576:null}async sizeGB(){const t=await this.size();return null!==t?t/1073741824:null}to(...t){return new c(this.fullPath+"/"+t.join("/"))}contains(t){if(t.split.length<=this.split.length)return!1;for(let s=0;s<this.split.length;s++)if(this.split[s]!==t.split[s])return!1;return!0}async createFile(){return await this.exists()?await this.isFile()?this:null:await this.write("")?this:null}async delete(t,s=t){if(t){if("rmSync"in this.fs)return await u(()=>this.fs.rm(this.fullPath,{recursive:!0,force:s}))?this:null;if("rmdirSync"in this.fs)return await u(()=>this.fs.rmdir(this.fullPath,{recursive:!0}))?this:null;let t=!1;for(const s of await this.listFiles()||[])await s.delete(!0)||(t=!0);if(t)return null}return await u(()=>this.fs.unlink(this.fullPath))?this:null}deleteOnExit(t){e.set(this.fullPath,t),a()}async clear(t){if(t){const t=await this.listFiles();if(null===t)return null;let s=!1;for(const e of t||[])await e.delete(!0)||(s=!0);return s?null:this}return await this.write(""),null}async listFiles(){if(!this.isDirectory)return null;const t=await f(()=>this.fs.readdir(this.fullPath));return t?t.map(t=>new c(`${this.fullPath}/${t}`)):null}listFilenames(){return f(()=>this.fs.readdir(this.fullPath))}async mkdir(t=!1){return await u(()=>this.fs.mkdir(this.fullPath,{recursive:t}))?this:null}async mkdirs(){return await this.mkdir(!0)?this:null}async renameTo(t,s,e){return this.fullPath===t.fullPath?this:!t.exists||s||await t.delete(e)?(e&&await(this.parent?.mkdirs()),await u(()=>this.fs.rename(this.fullPath,t.fullPath))?this:null):null}async copyTo(t,s,e){if(this.fullPath===t.fullPath)return this;if(!this.exists)return null;if(t.exists&&!s&&!await t.delete(e))return null;if(this.isFile){const s=await this.read();return null===s?null:await t.write(s)?this:null}if(!await t.mkdir(e))return null;const i=await this.listFiles();if(null===i)return null;let n=!1;for(const r of i){const i=t.to(r.name);await r.copyTo(i,s,e)||(n=!0)}return n?null:this}async*walk(){if(this.isDirectory){yield this;for(const t of await this.listFiles()||[])yield*t.walk()}else yield this}read(t){return f(()=>this.fs.readFile(this.fullPath,t))}async readLines(t="utf8"){const s=await this.read(t);return"string"==typeof s?s.split(/\r?\n/):null}async readJSON(){const t=await this.read("utf8");if("string"!=typeof t)return null;try{return JSON.parse(t)}catch(t){return null}}async readlink(){if(!this.isSymbolicLink)return null;const t=await f(()=>this.fs.readlink(this.fullPath));return t?new c(t):null}async write(t,s){return null!==s&&"object"==typeof s&&"write"in s&&"function"==typeof s.write&&(t=s.write()),await u(()=>this.fs.writeFile(this.fullPath,t,s))?this:null}async writeJSON(t){return await u(()=>this.write(JSON.stringify(t,null,2)))?this:null}async append(t,s){return await u(()=>this.fs.appendFile(this.fullPath,t,s))?this:null}get sync(){return new d(this.split)}}function o(t){try{return t(),!0}catch(t){return!1}}function p(t){try{return t()}catch(t){return null}}class d extends h{static fs;static sep="/";static createTempFile(t,s="ktfile-temp",e=".tmp"){if(!("mkdTempSync"in d.fs))throw new Error("mkdTempSync is not available in the current FS.");const i=t?t.fullPath:".",n=this.fs.mkdtempSync(`${i}/${s}-`);return new d(`${n}${e}`)}get fs(){return d.fs}get canExecute(){return o(()=>this.fs.accessSync(this.fullPath,this.fs?.constants?.X_OK??1))}set canExecute(t){o(()=>this.fs.chmodSync(this.fullPath,t?493:420))}get canRead(){return o(()=>this.fs.accessSync(this.fullPath,this.fs?.constants?.R_OK??4))}set canRead(t){o(()=>this.fs.chmodSync(this.fullPath,t?420:0))}get canWrite(){return o(()=>this.fs.accessSync(this.fullPath,this.fs?.constants?.W_OK??2))}set canWrite(t){o(()=>this.fs.chmodSync(this.fullPath,t?420:292))}get creationTime(){return p(()=>this.fs.statSync(this.fullPath).birthtime)}set creationTime(t){o(()=>this.fs.utimesSync(this.fullPath,t,t))}get lastModified(){return p(()=>this.fs.statSync(this.fullPath).mtime)}set lastModified(t){o(()=>this.fs.utimesSync(this.fullPath,t,t))}get exists(){return p(()=>this.fs.existsSync(this.fullPath))}get lastAccess(){return p(()=>this.fs.statSync(this.fullPath).atime)}get name(){return this.fullPath.split(this.separator).pop()||""}get nameWithoutExtension(){const t=this.name,s=t.lastIndexOf(".");return-1===s?t:t.substring(0,s)}get extension(){const t=this.name,s=t.lastIndexOf(".");return-1===s?"":t.substring(s+1)}get parent(){return 0===this.split.length?null:new d(this.split.slice(0,-1))}get uri(){return`file://${this.fullPath}`}get separator(){return d.sep}get isDirectory(){return p(()=>this.fs.statSync(this.fullPath).isDirectory())}get isFile(){return p(()=>this.fs.statSync(this.fullPath).isFile())}get isHidden(){return this.name.startsWith(".")||this.fullPath.split(this.separator).some(t=>t.startsWith("."))}get isSymbolicLink(){return p(()=>this.fs.lstatSync(this.fullPath).isSymbolicLink())}get size(){return p(()=>this.fs.statSync(this.fullPath).size)}get sizeKB(){const t=this.size;return null!==t?t/1024:null}get sizeMB(){const t=this.size;return null!==t?t/1048576:null}get sizeGB(){const t=this.size;return null!==t?t/1073741824:null}to(...t){return new d(this.fullPath+"/"+t.join("/"))}contains(t){if(t.split.length<=this.split.length)return!1;for(let s=0;s<this.split.length;s++)if(this.split[s]!==t.split[s])return!1;return!0}createFile(){return this.exists?this.isFile?this:null:this.write("")?this:null}delete(t,s=t){if(t){if("rmSync"in this.fs)return o(()=>this.fs.rmSync(this.fullPath,{recursive:!0,force:s}))?this:null;if("rmdirSync"in this.fs)return o(()=>this.fs.rmdirSync(this.fullPath,{recursive:!0}))?this:null;let t=!1;for(const s of this.listFiles()||[])s.delete(!0)||(t=!0);if(t)return null}return o(()=>this.fs.unlinkSync(this.fullPath))?this:null}deleteOnExit(t){e.set(this.fullPath,t),a()}clear(t){if(t){const t=this.listFiles();if(null===t)return null;let s=!1;for(const e of t||[])e.delete(!0)||(s=!0);return s?null:this}return this.write(""),null}listFiles(){if(!this.isDirectory)return null;const t=p(()=>this.fs.readdirSync(this.fullPath));return t?t.map(t=>new d(`${this.fullPath}/${t}`)):null}listFilenames(){return p(()=>this.fs.readdirSync(this.fullPath))}mkdir(t=!1){return o(()=>this.fs.mkdirSync(this.fullPath,{recursive:t}))?this:null}mkdirs(){return this.mkdir(!0)?this:null}renameTo(t,s,e){return this.fullPath===t.fullPath?this:!t.exists||s||t.delete(e)?(e&&this.parent?.mkdirs(),o(()=>this.fs.renameSync(this.fullPath,t.fullPath))?this:null):null}copyTo(t,s,e){if(this.fullPath===t.fullPath)return this;if(!this.exists)return null;if(t.exists&&!s&&!t.delete(e))return null;if(this.isFile){const s=this.read();return null===s?null:t.write(s)?this:null}if(!t.mkdir(e))return null;const i=this.listFiles();if(null===i)return null;let n=!1;for(const r of i){const i=t.to(r.name);r.copyTo(i,s,e)||(n=!0)}return n?null:this}*walk(){if(this.isDirectory){yield this;for(const t of this.listFiles()||[])yield*t.walk()}else yield this}read(t){return p(()=>this.fs.readFileSync(this.fullPath,t))}readLines(t="utf8"){const s=this.read(t);return"string"==typeof s?s.split(/\r?\n/):null}readJSON(){const t=this.read("utf8");if("string"!=typeof t)return null;try{return JSON.parse(t)}catch(t){return null}}readlink(){if(!this.isSymbolicLink)return null;const t=p(()=>this.fs.readlinkSync(this.fullPath));return t?new d(t):null}write(t,s){return null!==s&&"object"==typeof s&&"write"in s&&"function"==typeof s.write&&(t=s.write()),o(()=>this.fs.writeFileSync(this.fullPath,t,s))?this:null}writeJSON(t){return o(()=>this.write(JSON.stringify(t,null,2)))?this:null}append(t,s){return o(()=>this.fs.appendFileSync(this.fullPath,t,s))?this:null}get async(){return new c(this.split)}}function y(t){d.fs=t,c.fs=t.promises}function m(t){return new d(t)}function w(t){return new c(t)}if("undefined"!=typeof process)try{y(await import("fs")),d.sep=c.sep="win32"===process.platform?"\\":"/"}catch{}export{d as File,c as FileAsync,d as FileSync,w as fileAsync,m as fileSync,y as initFS};
1
+ let t=[];function s(s,e=t){"/"===s[0]||"\\"===s[0]?(e=[],s=s.slice(1)):e=[...e];const i=s.split(/[\\/]/g);for(const t of i)".."===t?e.pop():"."!==t&&""!==t&&e.push(t);return e}"undefined"!=typeof process&&"cwd"in process&&"function"==typeof process.cwd&&(t=s(process.cwd()));const e=new Map;function i(t,s,e){const i=t.listeners(s);t.removeAllListeners(s);for(const n of i)n!==e&&t.on(s,n);t.on(s,e)}function n(){for(const[t,s]of e.entries())new d(t).delete(s);e.clear(),"undefined"!=typeof process?(process.off("SIGINT",r),process.off("SIGTERM",l),process.off("exit",n)):"undefined"!=typeof window&&(window.removeEventListener("beforeunload",n),window.removeEventListener("pagehide",n))}function r(){n(),process.exit(130)}function l(){n(),process.exit(143)}function a(){"undefined"!=typeof process?(i(process,"exit",n),i(process,"SIGINT",r),i(process,"SIGTERM",l)):"undefined"!=typeof window&&(window.addEventListener("beforeunload",n),window.addEventListener("pagehide",n))}class h{split;constructor(t){this.split="string"==typeof t?s(t):[...t]}get fullPath(){return 0===this.split.length?this.separator:this.split.join(this.separator)}createWriteStream(t){if("object"==typeof this.fs&&"createWriteStream"in this.fs&&"function"==typeof this.fs.createWriteStream)return this.fs.createWriteStream(this.split.join("/"),t);throw new Error("File system does not support createWriteStream")}createReadStream(t){if("object"==typeof this.fs&&"createReadStream"in this.fs&&"function"==typeof this.fs.createReadStream)return this.fs.createReadStream(this.split.join("/"),t);throw new Error("File system does not support createReadStream")}createAppendStream(t){if("object"==typeof this.fs&&"createWriteStream"in this.fs&&"function"==typeof this.fs.createWriteStream)return this.fs.createWriteStream(this.split.join("/"),{flags:"a",encoding:t});throw new Error("File system does not support createAppendStream")}createInputStream(t){if("object"==typeof this.fs&&"createReadStream"in this.fs&&"function"==typeof this.fs.createReadStream)return this.fs.createReadStream(this.split.join("/"),{flags:"r",encoding:t});throw new Error("File system does not support createInputStream")}}async function u(t){try{return t().then(()=>!0).catch(()=>!1)}catch(t){return!1}}async function f(t){try{return t().then(t=>t).catch(()=>null)}catch(t){return null}}class c extends h{static fs;static sep="/";static createTempFile(t,s="ktfile-temp",e=".tmp"){if(!("mkdTemp"in c.fs))throw new Error("mkdTemp is not available in the current FS.");const i=t?t.fullPath:".",n=this.fs.mkdtemp(`${i}/${s}-`);return new c(`${n}${e}`)}get fs(){return c.fs}canExecute(){return u(()=>this.fs.access(this.fullPath,this.fs?.constants?.X_OK??1))}async setExecutable(t=!0){return await u(()=>this.fs.chmod(this.fullPath,t?493:420))?this:null}canRead(){return u(()=>this.fs.access(this.fullPath,this.fs?.constants?.R_OK??4))}async setReadable(t=!0){return await u(()=>this.fs.chmod(this.fullPath,t?420:0))?this:null}canWrite(){return u(()=>this.fs.access(this.fullPath,this.fs?.constants?.W_OK??2))}async setWritable(t=!0){return await u(()=>this.fs.chmod(this.fullPath,t?420:292))?this:null}creationTime(){return f(()=>this.fs.stat(this.fullPath).then(t=>t.birthtime).catch(()=>null))}async setCreationTime(t){return await u(()=>this.fs.utimes(this.fullPath,t,t))?this:null}async lastModified(){return await f(()=>this.fs.stat(this.fullPath).then(t=>t.mtime).catch(()=>null))}async setLastModified(t){return await u(()=>this.fs.utimes(this.fullPath,t,t))?this:null}exists(){return f(()=>this.fs.exists(this.fullPath))}lastAccess(){return f(()=>this.fs.stat(this.fullPath).then(t=>t.atime).catch(()=>null))}get name(){return this.fullPath.split(this.separator).pop()||""}get nameWithoutExtension(){const t=this.name,s=t.lastIndexOf(".");return-1===s?t:t.substring(0,s)}get extension(){const t=this.name,s=t.lastIndexOf(".");return-1===s?"":t.substring(s+1)}get parent(){return 0===this.split.length?null:new c(this.split.slice(0,-1))}get uri(){return`file://${this.fullPath}`}get separator(){return c.sep}isDirectory(){return f(()=>this.fs.stat(this.fullPath).then(t=>t.isDirectory()).catch(()=>null))}isFile(){return f(()=>this.fs.stat(this.fullPath).then(t=>t.isFile()).catch(()=>null))}get isHidden(){return this.name.startsWith(".")||this.fullPath.split(this.separator).some(t=>t.startsWith("."))}isSymbolicLink(){return f(()=>this.fs.lstat(this.fullPath).then(t=>t.isSymbolicLink()).catch(()=>null))}size(){return f(()=>this.fs.stat(this.fullPath).then(t=>t.size).catch(()=>null))}async sizeKB(){const t=await this.size();return null!==t?t/1024:null}async sizeMB(){const t=await this.size();return null!==t?t/1048576:null}async sizeGB(){const t=await this.size();return null!==t?t/1073741824:null}to(...t){return new c(this.fullPath+"/"+t.join("/"))}contains(t){if(t.split.length<=this.split.length)return!1;for(let s=0;s<this.split.length;s++)if(this.split[s]!==t.split[s])return!1;return!0}async createFile(t="",s){return await this.exists()?await this.isFile()?this:null:await this.write(t,s)?this:null}async delete(t,s=t){if(t){if("rmSync"in this.fs)return await u(()=>this.fs.rm(this.fullPath,{recursive:!0,force:s}))?this:null;if("rmdirSync"in this.fs)return await u(()=>this.fs.rmdir(this.fullPath,{recursive:!0}))?this:null;let t=!1;for(const s of await this.listFiles()||[])await s.delete(!0)||(t=!0);if(t)return null}return await u(()=>this.fs.unlink(this.fullPath))?this:null}deleteOnExit(t){e.set(this.fullPath,t),a()}async clear(t){if(t){const t=await this.listFiles();if(null===t)return null;let s=!1;for(const e of t||[])await e.delete(!0)||(s=!0);return s?null:this}return await this.write(""),null}async listFiles(){if(!this.isDirectory)return null;const t=await f(()=>this.fs.readdir(this.fullPath));return t?t.map(t=>new c(`${this.fullPath}/${t}`)):null}listFilenames(){return f(()=>this.fs.readdir(this.fullPath))}async mkdir(t=!1){return await u(()=>this.fs.mkdir(this.fullPath,{recursive:t}))?this:null}async mkdirs(){return await this.mkdir(!0)?this:null}async renameTo(t,s,e){return this.fullPath===t.fullPath?this:!t.exists||s||await t.delete(e)?(e&&await(this.parent?.mkdirs()),await u(()=>this.fs.rename(this.fullPath,t.fullPath))?this:null):null}async copyTo(t,s,e){if(this.fullPath===t.fullPath)return this;if(!this.exists)return null;if(t.exists&&!s&&!await t.delete(e))return null;if(this.isFile){const s=await this.read();return null===s?null:await t.write(s)?this:null}if(!await t.mkdir(e))return null;const i=await this.listFiles();if(null===i)return null;let n=!1;for(const r of i){const i=t.to(r.name);await r.copyTo(i,s,e)||(n=!0)}return n?null:this}async*walk(){if(this.isDirectory){yield this;for(const t of await this.listFiles()||[])yield*t.walk()}else yield this}read(t){return f(()=>this.fs.readFile(this.fullPath,t))}async readLines(t="utf8"){const s=await this.read(t);return"string"==typeof s?s.split(/\r?\n/):null}async readJSON(){const t=await this.read("utf8");if("string"!=typeof t)return null;try{return JSON.parse(t)}catch(t){return null}}async readlink(){if(!this.isSymbolicLink)return null;const t=await f(()=>this.fs.readlink(this.fullPath));return t?new c(t):null}async write(t,s){return null!==s&&"object"==typeof s&&"write"in s&&"function"==typeof s.write&&(t=s.write()),await u(()=>this.fs.writeFile(this.fullPath,t,s))?this:null}async writeJSON(t){return await u(()=>this.write(JSON.stringify(t,null,2)))?this:null}async append(t,s){return await u(()=>this.fs.appendFile(this.fullPath,t,s))?this:null}get sync(){return new d(this.split)}}function o(t){try{return t(),!0}catch(t){return!1}}function p(t){try{return t()}catch(t){return null}}class d extends h{static fs;static sep="/";static createTempFile(t,s="ktfile-temp",e=".tmp"){if(!("mkdTempSync"in d.fs))throw new Error("mkdTempSync is not available in the current FS.");const i=t?t.fullPath:".",n=this.fs.mkdtempSync(`${i}/${s}-`);return new d(`${n}${e}`)}get fs(){return d.fs}get canExecute(){return o(()=>this.fs.accessSync(this.fullPath,this.fs?.constants?.X_OK??1))}set canExecute(t){o(()=>this.fs.chmodSync(this.fullPath,t?493:420))}get canRead(){return o(()=>this.fs.accessSync(this.fullPath,this.fs?.constants?.R_OK??4))}set canRead(t){o(()=>this.fs.chmodSync(this.fullPath,t?420:0))}get canWrite(){return o(()=>this.fs.accessSync(this.fullPath,this.fs?.constants?.W_OK??2))}set canWrite(t){o(()=>this.fs.chmodSync(this.fullPath,t?420:292))}get creationTime(){return p(()=>this.fs.statSync(this.fullPath).birthtime)}set creationTime(t){o(()=>this.fs.utimesSync(this.fullPath,t,t))}get lastModified(){return p(()=>this.fs.statSync(this.fullPath).mtime)}set lastModified(t){o(()=>this.fs.utimesSync(this.fullPath,t,t))}get exists(){return p(()=>this.fs.existsSync(this.fullPath))}get lastAccess(){return p(()=>this.fs.statSync(this.fullPath).atime)}get name(){return this.fullPath.split(this.separator).pop()||""}get nameWithoutExtension(){const t=this.name,s=t.lastIndexOf(".");return-1===s?t:t.substring(0,s)}get extension(){const t=this.name,s=t.lastIndexOf(".");return-1===s?"":t.substring(s+1)}get parent(){return 0===this.split.length?null:new d(this.split.slice(0,-1))}get uri(){return`file://${this.fullPath}`}get separator(){return d.sep}get isDirectory(){return p(()=>this.fs.statSync(this.fullPath).isDirectory())}get isFile(){return p(()=>this.fs.statSync(this.fullPath).isFile())}get isHidden(){return this.name.startsWith(".")||this.fullPath.split(this.separator).some(t=>t.startsWith("."))}get isSymbolicLink(){return p(()=>this.fs.lstatSync(this.fullPath).isSymbolicLink())}get size(){return p(()=>this.fs.statSync(this.fullPath).size)}get sizeKB(){const t=this.size;return null!==t?t/1024:null}get sizeMB(){const t=this.size;return null!==t?t/1048576:null}get sizeGB(){const t=this.size;return null!==t?t/1073741824:null}to(...t){return new d(this.fullPath+"/"+t.join("/"))}contains(t){if(t.split.length<=this.split.length)return!1;for(let s=0;s<this.split.length;s++)if(this.split[s]!==t.split[s])return!1;return!0}createFile(t="",s){return this.exists?this.isFile?this:null:this.write(t,s)?this:null}delete(t,s=t){if(t){if("rmSync"in this.fs)return o(()=>this.fs.rmSync(this.fullPath,{recursive:!0,force:s}))?this:null;if("rmdirSync"in this.fs)return o(()=>this.fs.rmdirSync(this.fullPath,{recursive:!0}))?this:null;let t=!1;for(const s of this.listFiles()||[])s.delete(!0)||(t=!0);if(t)return null}return o(()=>this.fs.unlinkSync(this.fullPath))?this:null}deleteOnExit(t){e.set(this.fullPath,t),a()}clear(t){if(t){const t=this.listFiles();if(null===t)return null;let s=!1;for(const e of t||[])e.delete(!0)||(s=!0);return s?null:this}return this.write(""),null}listFiles(){if(!this.isDirectory)return null;const t=p(()=>this.fs.readdirSync(this.fullPath));return t?t.map(t=>new d(`${this.fullPath}/${t}`)):null}listFilenames(){return p(()=>this.fs.readdirSync(this.fullPath))}mkdir(t=!1){return o(()=>this.fs.mkdirSync(this.fullPath,{recursive:t}))?this:null}mkdirs(){return this.mkdir(!0)?this:null}renameTo(t,s,e){return this.fullPath===t.fullPath?this:!t.exists||s||t.delete(e)?(e&&this.parent?.mkdirs(),o(()=>this.fs.renameSync(this.fullPath,t.fullPath))?this:null):null}copyTo(t,s,e){if(this.fullPath===t.fullPath)return this;if(!this.exists)return null;if(t.exists&&!s&&!t.delete(e))return null;if(this.isFile){const s=this.read();return null===s?null:t.write(s)?this:null}if(!t.mkdir(e))return null;const i=this.listFiles();if(null===i)return null;let n=!1;for(const r of i){const i=t.to(r.name);r.copyTo(i,s,e)||(n=!0)}return n?null:this}*walk(){if(this.isDirectory){yield this;for(const t of this.listFiles()||[])yield*t.walk()}else yield this}read(t){return p(()=>this.fs.readFileSync(this.fullPath,t))}readLines(t="utf8"){const s=this.read(t);return"string"==typeof s?s.split(/\r?\n/):null}readJSON(){const t=this.read("utf8");if("string"!=typeof t)return null;try{return JSON.parse(t)}catch(t){return null}}readlink(){if(!this.isSymbolicLink)return null;const t=p(()=>this.fs.readlinkSync(this.fullPath));return t?new d(t):null}write(t,s){return null!==s&&"object"==typeof s&&"write"in s&&"function"==typeof s.write&&(t=s.write()),o(()=>this.fs.writeFileSync(this.fullPath,t,s))?this:null}writeJSON(t){return o(()=>this.write(JSON.stringify(t,null,2)))?this:null}append(t,s){return o(()=>this.fs.appendFileSync(this.fullPath,t,s))?this:null}get async(){return new c(this.split)}}function y(t){d.fs=t,c.fs=t.promises}function m(t){return new d(t)}function w(t){return new c(t)}if("undefined"!=typeof process)try{y(await import("fs")),d.sep=c.sep="win32"===process.platform?"\\":"/"}catch{}export{d as File,c as FileAsync,d as FileSync,w as fileAsync,m as fileSync,y as initFS};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ktfile",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "A powerful, cross-platform file system library for JavaScript/TypeScript that provides both synchronous and asynchronous APIs with a clean, object-oriented interface.",
5
5
  "main": "index.min.js",
6
6
  "types": "types/ktfile.d.ts",
@@ -351,10 +351,12 @@ export declare class FileAsync extends IFile<IAsyncFS> {
351
351
  * } else {
352
352
  * console.log("Failed to create file.");
353
353
  * }
354
+ * @param {string | Buffer} [value=""] - The initial content to write to the file.
355
+ * @param {BufferEncoding} [encoding] - The encoding to use when writing the content.
354
356
  * @returns {Promise<FileAsync | null>} The FileAsync object if the file was created successfully or already exists,
355
357
  * or null if the file could not be created.
356
358
  */
357
- createFile(): Promise<FileAsync | null>;
359
+ createFile(value?: string | Buffer, encoding?: BufferEncoding): Promise<FileAsync | null>;
358
360
  /**
359
361
  * @description Deletes the file or directory.
360
362
  * If the file is a directory and `recursive` is true, it will delete all files and subdirectories within it.
@@ -344,10 +344,12 @@ export declare class FileSync extends IFile<ISyncFS> {
344
344
  * } else {
345
345
  * console.log("Failed to create file.");
346
346
  * }
347
+ * @param {string | Buffer} [value=""] - The initial content to write to the file.
348
+ * @param {BufferEncoding} [encoding] - The encoding to use when writing the content.
347
349
  * @returns {FileSync | null} The FileSync object if the file was created successfully or already exists,
348
350
  * or null if the file could not be created.
349
351
  */
350
- createFile(): FileSync | null;
352
+ createFile(value?: string | Buffer, encoding?: BufferEncoding): FileSync | null;
351
353
  /**
352
354
  * @description Deletes the file or directory.
353
355
  * If the file is a directory and `recursive` is true, it will delete all files and subdirectories within it.