mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2026-02-06 13:30:31 -07:00
2 lines
4.9 KiB
JavaScript
2 lines
4.9 KiB
JavaScript
import{i as w}from"./is-buffer-Boa4a7IC.js";import{V as p}from"./vfile-message-BOGBuebs.js";const h={basename:y,dirname:b,extname:A,join:E,sep:"/"};function y(n,e){if(e!==void 0&&typeof e!="string")throw new TypeError('"ext" argument must be a string');f(n);let t=0,r=-1,i=n.length,s;if(e===void 0||e.length===0||e.length>n.length){for(;i--;)if(n.charCodeAt(i)===47){if(s){t=i+1;break}}else r<0&&(s=!0,r=i+1);return r<0?"":n.slice(t,r)}if(e===n)return"";let o=-1,l=e.length-1;for(;i--;)if(n.charCodeAt(i)===47){if(s){t=i+1;break}}else o<0&&(s=!0,o=i+1),l>-1&&(n.charCodeAt(i)===e.charCodeAt(l--)?l<0&&(r=i):(l=-1,r=o));return t===r?r=o:r<0&&(r=n.length),n.slice(t,r)}function b(n){if(f(n),n.length===0)return".";let e=-1,t=n.length,r;for(;--t;)if(n.charCodeAt(t)===47){if(r){e=t;break}}else r||(r=!0);return e<0?n.charCodeAt(0)===47?"/":".":e===1&&n.charCodeAt(0)===47?"//":n.slice(0,e)}function A(n){f(n);let e=n.length,t=-1,r=0,i=-1,s=0,o;for(;e--;){const l=n.charCodeAt(e);if(l===47){if(o){r=e+1;break}continue}t<0&&(o=!0,t=e+1),l===46?i<0?i=e:s!==1&&(s=1):i>-1&&(s=-1)}return i<0||t<0||s===0||s===1&&i===t-1&&i===r+1?"":n.slice(i,t)}function E(...n){let e=-1,t;for(;++e<n.length;)f(n[e]),n[e]&&(t=t===void 0?n[e]:t+"/"+n[e]);return t===void 0?".":R(t)}function R(n){f(n);const e=n.charCodeAt(0)===47;let t=C(n,!e);return t.length===0&&!e&&(t="."),t.length>0&&n.charCodeAt(n.length-1)===47&&(t+="/"),e?"/"+t:t}function C(n,e){let t="",r=0,i=-1,s=0,o=-1,l,a;for(;++o<=n.length;){if(o<n.length)l=n.charCodeAt(o);else{if(l===47)break;l=47}if(l===47){if(!(i===o-1||s===1))if(i!==o-1&&s===2){if(t.length<2||r!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){if(a=t.lastIndexOf("/"),a!==t.length-1){a<0?(t="",r=0):(t=t.slice(0,a),r=t.length-1-t.lastIndexOf("/")),i=o,s=0;continue}}else if(t.length>0){t="",r=0,i=o,s=0;continue}}e&&(t=t.length>0?t+"/..":"..",r=2)}else t.length>0?t+="/"+n.slice(i+1,o):t=n.slice(i+1,o),r=o-i-1;i=o,s=0}else l===46&&s>-1?s++:s=-1}return t}function f(n){if(typeof n!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(n))}const x={cwd:L};function L(){return"/"}function m(n){return n!==null&&typeof n=="object"&&n.href&&n.origin}function I(n){if(typeof n=="string")n=new URL(n);else if(!m(n)){const e=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+n+"`");throw e.code="ERR_INVALID_ARG_TYPE",e}if(n.protocol!=="file:"){const e=new TypeError("The URL must be of scheme file");throw e.code="ERR_INVALID_URL_SCHEME",e}return S(n)}function S(n){if(n.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const e=n.pathname;let t=-1;for(;++t<e.length;)if(e.charCodeAt(t)===37&&e.charCodeAt(t+1)===50){const r=e.charCodeAt(t+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(e)}const d=["history","path","basename","stem","extname","dirname"];class U{constructor(e){let t;e?typeof e=="string"||_(e)?t={value:e}:m(e)?t={path:e}:t=e:t={},this.data={},this.messages=[],this.history=[],this.cwd=x.cwd(),this.value,this.stored,this.result,this.map;let r=-1;for(;++r<d.length;){const s=d[r];s in t&&t[s]!==void 0&&t[s]!==null&&(this[s]=s==="history"?[...t[s]]:t[s])}let i;for(i in t)d.includes(i)||(this[i]=t[i])}get path(){return this.history[this.history.length-1]}set path(e){m(e)&&(e=I(e)),u(e,"path"),this.path!==e&&this.history.push(e)}get dirname(){return typeof this.path=="string"?h.dirname(this.path):void 0}set dirname(e){g(this.basename,"dirname"),this.path=h.join(e||"",this.basename)}get basename(){return typeof this.path=="string"?h.basename(this.path):void 0}set basename(e){u(e,"basename"),c(e,"basename"),this.path=h.join(this.dirname||"",e)}get extname(){return typeof this.path=="string"?h.extname(this.path):void 0}set extname(e){if(c(e,"extname"),g(this.dirname,"extname"),e){if(e.charCodeAt(0)!==46)throw new Error("`extname` must start with `.`");if(e.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=h.join(this.dirname,this.stem+(e||""))}get stem(){return typeof this.path=="string"?h.basename(this.path,this.extname):void 0}set stem(e){u(e,"stem"),c(e,"stem"),this.path=h.join(this.dirname||"",e+(this.extname||""))}toString(e){return(this.value||"").toString(e||void 0)}message(e,t,r){const i=new p(e,t,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}info(e,t,r){const i=this.message(e,t,r);return i.fatal=null,i}fail(e,t,r){const i=this.message(e,t,r);throw i.fatal=!0,i}}function c(n,e){if(n&&n.includes(h.sep))throw new Error("`"+e+"` cannot be a path: did not expect `"+h.sep+"`")}function u(n,e){if(!n)throw new Error("`"+e+"` cannot be empty")}function g(n,e){if(!n)throw new Error("Setting `"+e+"` requires `path` to be set too")}function _(n){return w(n)}export{U as V};
|