text: /*!
   * rxfile-write
   * version: 0.0.8
   * repo: https://github.com/cheere/rxfile-write
   * build: 2022-04-02 15:44:06
   */
  !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("fs"),require("path")):"function"==typeof define&&define.amd?define(["fs","path"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).fs,t.path)}(this,(function(t,e){"use strict";function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=n(t),r=n(e);const o={};function c(t){return!!(t&&t.indexOf("rxfile-write.js")>=0)}o.error=function(t,e){if(e=e||"",t){if("object"==typeof t)return t}else t="unknow";const n=new Error("RxfileWrite-error=> "+e+" -> "+t);let i=n.stack;if(i){const t=i.split("at"),e=t.length,r=[],o=[],s=[];let f=!0;for(let n=0;n<e;n+=2){let i=t[n]||"",u=n+1<e?t[n+1]:"";0!==n&&(i=i?"at"+i:"",u=u?"at"+u:"");const l=u?u+i:i;0===n?(r.push(i),u&&o.push("at"+u)):i&&(c(i)||c(u))?l&&o.push(l):f?(f=!1,i&&o.push(i),u&&s.push(u)):l&&s.push(l)}const u=o.reverse(),l=r.concat(u).concat(s).join("");n.stack=l}return n};const s={exists:function(t){const e=this;return new Promise(((n,r)=>{e.isString(t)?i.default.stat(t,((t,i)=>{t?r(t):i.isDirectory()?n({dir:!0,file:!1}):i.isFile()?n({dir:!1,file:!0}):r(e.error("RxfileWrite-exist=> stats not dir/file"))})):r(e.error("RxfileWrite-exist=> path undefined or null"))}))},existsSync:function(t){const e=this;if(!t)return e.error("RxfileWrite-existsSync=> path undefined"),{dir:!1,file:!1};try{const n=i.default.statSync(t);return n.isDirectory()?{dir:!0,file:!1}:n.isFile()?{dir:!1,file:!0}:(e.error("RxfileWrite-exist=> stats not dir/file"),{dir:!1,file:!1})}catch(t){return e.error("RxfileWrite-exist=> stats not dir/file"),{dir:!1,file:!1}}}},f={};f.read=function(t){const e=this;return new Promise(((n,r)=>{e.exists(t).then((()=>{(function(t){return new Promise(((e,n)=>{i.default.readFile(t,"utf-8",((t,i)=>{t?n(t):e(i)}))}))})(t).then((t=>{n(t)})).catch((t=>{r(t)}))})).catch((t=>{r(t)}))}))};const u={};u.cp=function(t,e){const n=this;return new Promise(((r,o)=>{n.exists(t).then((c=>{c.dir?n.loopCp(t,e).then(r).catch(o):c.file?function(t,e){return new Promise(((n,r)=>{i.default.copyFile(t,e,(function(t){t?r(t):n("")}))}))}(t,e).then((()=>{r("")})).catch((t=>{o(t)})):o("fileInfo type unknow")})).catch((t=>{o(t)}))}))},u.cpSync=function(t,e){const n=this,r=this.existsSync(t);return r.file?function(t,e){try{i.default.copyFileSync(t,e)}catch(t){return!1}return!0}(t,e):!!r.dir&&n.loopCpSync(t,e)};const l={};function a(t){try{const e=i.default.statSync(t);e.isDirectory()||e.isFile()||i.default.mkdirSync(t)}catch(e){i.default.mkdirSync(t)}}l.loopCpSync=function(t,e){const n=this,o=n.existsSync(t);let c=!1;if(o.dir){a(e);let o=e;i.default.readdirSync(t).forEach((s=>{const f=r.default.resolve(t,s),u=i.default.statSync(f);if(o=r.default.resolve(e,s),u.isDirectory())return n.loopCpSync(f,o);u.isFile()&&(c=n.cpSync(f,o))}))}else c=n.cpSync(t,e);return c},l.loopCp=function(t,e){const n=this;return new Promise(((o,c)=>{n.exists(t).then((s=>{if(s.dir){a(e);let c=e,s="";i.default.readdirSync(t).forEach((o=>{const f=r.default.resolve(t,o),u=i.default.statSync(f);let l=!1;c=r.default.resolve(e,o),u.isDirectory()?l=n.loopCpSync(f,c):u.isFile()&&(l=n.cpSync(f,c)),l&&(s&&(s+="\n"),s+="error-loopCp: file="+o+"__fullPath="+f)})),o(s)}else s.file?n.cp(t,e).then(o).catch(c):c("fileInfo type unknow")})).catch((t=>{c(t)}))}))};const d={write:function(t,e){return this.writeTo(t,e)},writeSync:function(t,e){S(t,e)},writeAppend:function(t,e){return this.writeTo(t,e,!0)},writeAppendSync:function(t,e){S(t,e,!0)}};d.writeTo=function(t,e,n=!1){return new Promise(((o,c)=>{let s=t;try{s=r.default.dirname(t)}catch(t){console.log("writeTo -> path.dirname error:",t)}this.isData(e)?this.exists(s).then((()=>{y(t,e,n).then(o).catch(c)})).catch((()=>{(function(t){return new Promise(((e,n)=>{i.default.mkdir(t,{mode:h,flag:"w+"},(function(t){t?n(t):e()}))}))})(t).then((()=>{y(t,e,n).then(o).catch(c)})).catch(c)})):c(this.error("text not `string or buffer` ","writeTo"))}))};const h=parseInt("0755",8),p=parseInt("0666",8);function y(t,e,n=!1){let r="w+",o=i.default.writeFile;return n&&(o=i.default.appendFile,r="as+"),new Promise(((n,i)=>{o(t,e,{encoding:"utf8",mode:p,flag:r},(function(t){t?i(t):n()}))}))}function S(t,e,n=!1){let r="w+",o=i.default.writeFileSync;n&&(o=i.default.appendFileSync,r="as+");try{o(t,e,{encoding:"utf8",mode:p,flag:r})}catch(t){console.error(t)}}const w={};function x(t){let e=[];i.default.existsSync(t)&&(e=i.default.readdirSync(t),e.forEach((e=>{const n=t+"/"+e;i.default.statSync(n).isDirectory()?x(n):i.default.unlinkSync(n)})),i.default.rmdirSync(t))}w.remove=function(t){const e=this;return new Promise(((n,r)=>{e.exists(t).then((()=>{(function(t){return new Promise(((e,n)=>{try{i.default.statSync(t).isDirectory()?x(t):i.default.unlinkSync(t),e()}catch(t){console.log("RxfileWrite-remove=> error=",t),n(t)}}))})(t).then((()=>{n()})).catch((t=>{r(t)}))})).catch((t=>{r(t)}))}))};var m="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(t){return null!=t&&(!!t._isBuffer||P(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&P(t.slice(0,0))}(t))}function P(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}void 0===m.TYPED_ARRAY_SUPPORT||m.TYPED_ARRAY_SUPPORT;const F={isUndef:function(t){return null==t},isTrue:function(t){return!0===t},isFalse:function(t){return!1===t},isString:function(t){return!(!t||"string"!=typeof t)},isObject:function(t){return!(!t||"object"!=typeof t)},isData:function(t){return!(!t||"string"!=typeof t&&!g(t))}},R=Object.assign(s,f,u,l,d,w,F),b=Object.assign(o,R);b.version='"0.0.8"',module.exports=b}));
  