UNPKG

patha

Version:

File paths library. All you need to work with paths. Tiny drop-in replacement for 'path'. Works in Node, Browser, and Deno.

3 lines (2 loc) 8.02 kB
function e(e,r){return Object.keys(r).forEach((t=>{"default"===t||"__esModule"===t||e.hasOwnProperty(t)||Object.defineProperty(e,t,{enumerable:!0,get(){return r[t]}})})),e}function r(e,r,t,n){Object.defineProperty(e,r,{get:t,set:n,enumerable:!0,configurable:!0})}function t(e){return e&&e.__esModule?e.default:e}function n(){throw Error("setTimeout has not been defined")}function a(){throw Error("clearTimeout has not been defined")}function i(e){if(w===setTimeout)return setTimeout(e,0);if((w===n||!w)&&setTimeout)return w=setTimeout,setTimeout(e,0);try{return w(e,0)}catch(r){try{return w.call(null,e,0)}catch(r){return w.call(this,e,0)}}}function o(){P&&j&&(P=!1,j.length?k=j.concat(k):O=-1,k.length&&s())}function s(){if(!P){var e=i(o);P=!0;for(var r=k.length;r;){for(j=k,k=[];++O<r;)j&&j[O].run();O=-1,r=k.length}j=null,P=!1,function(e){if(T===clearTimeout)return clearTimeout(e);if((T===a||!T)&&clearTimeout)return T=clearTimeout,clearTimeout(e);try{T(e)}catch(r){try{return T.call(null,e)}catch(r){return T.call(this,e)}}}(e)}}function l(e,r){this.fun=e,this.array=r}function c(){}function u(e){if("string"!=typeof e)throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function f(e,r){for(var t,n="",a=0,i=-1,o=0,s=0;e.length>=s;++s){if(e.length>s)t=e.charCodeAt(s);else{if(47===t)break;t=47}if(47===t){if(i===s-1||1===o);else if(i!==s-1&&2===o){if(2>n.length||2!==a||46!==n.charCodeAt(n.length-1)||46!==n.charCodeAt(n.length-2))if(n.length>2){var l=n.lastIndexOf("/");if(l!==n.length-1){-1===l?(n="",a=0):a=(n=n.slice(0,l)).length-1-n.lastIndexOf("/"),i=s,o=0;continue}}else if(2===n.length||1===n.length){n="",a=0,i=s,o=0;continue}r&&(n.length>0?n+="/..":n="..",a=2)}else n.length>0?n+="/"+e.slice(i+1,s):n=e.slice(i+1,s),a=s-i-1;i=s,o=0}else 46===t&&-1!==o?++o:o=-1}return n}function h(e,r=!0){return r?(0,C.basename)(e):(0,C.basename)(e,(0,C.extname)(e))}function d(e){return(0,C.normalize)(e).replace(RegExp((e=>{if("string"!=typeof e)throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")})(C.sep)+"$"),"")}function m(e,r=".exe",t=""){return"win32"===E.platform?`${e}${r}`:`${e}${t}`}function g(e,r){const t=(0,C.extname)(e),n=`${r}${(0,C.basename)(e,t)}${t}`;return(0,C.join)((0,C.dirname)(e),n)}function v(e,r){const t=(0,C.extname)(e),n=`${(0,C.basename)(e,t)}${r}${t}`;return(0,C.join)((0,C.dirname)(e),n)}function p(e,r=".cmd",t=".sh"){return"win32"===E.platform?`${e}${r}`:`${e}${t}`}function b(e){return"win32"===E.platform?e:"./"+e}function x(e){const r=(0,C.extname)(e).length;return e.slice(0,-r)}function y(e,r){return t(q)(e,r)}function A(e,r){const t=(0,C.relative)(r,e);return!(!t||".."===t||t.startsWith(".."+C.sep)||t===(0,C.resolve)(e))}var w,T,C={},E={},$=E={};(()=>{try{w="function"==typeof setTimeout?setTimeout:n}catch(e){w=n}try{T="function"==typeof clearTimeout?clearTimeout:a}catch(e){T=a}})();var j,k=[],P=!1,O=-1;$.nextTick=function(e){var r=Array(arguments.length-1);if(arguments.length>1)for(var t=1;arguments.length>t;t++)r[t-1]=arguments[t];k.push(new l(e,r)),1!==k.length||P||i(s)},l.prototype.run=function(){this.fun.apply(null,this.array)},$.title="browser",$.browser=!0,$.env={},$.argv=[],$.version="",$.versions={},$.on=c,$.addListener=c,$.once=c,$.off=c,$.removeListener=c,$.removeAllListeners=c,$.emit=c,$.prependListener=c,$.prependOnceListener=c,$.listeners=e=>[],$.binding=e=>{throw Error("process.binding is not supported")},$.cwd=()=>"/",$.chdir=e=>{throw Error("process.chdir is not supported")},$.umask=()=>0;var z={resolve(){for(var e,r="",t=!1,n=arguments.length-1;n>=-1&&!t;n--){var a;0>n?(void 0===e&&(e=E.cwd()),a=e):a=arguments[n],u(a),0!==a.length&&(r=a+"/"+r,t=47===a.charCodeAt(0))}return r=f(r,!t),t?r.length>0?"/"+r:"/":r.length>0?r:"."},normalize(e){if(u(e),0===e.length)return".";var r=47===e.charCodeAt(0),t=47===e.charCodeAt(e.length-1);return 0!==(e=f(e,!r)).length||r||(e="."),e.length>0&&t&&(e+="/"),r?"/"+e:e},isAbsolute(e){return u(e),e.length>0&&47===e.charCodeAt(0)},join(){if(0===arguments.length)return".";for(var e,r=0;arguments.length>r;++r){var t=arguments[r];u(t),t.length>0&&(void 0===e?e=t:e+="/"+t)}return void 0===e?".":z.normalize(e)},relative(e,r){if(u(e),u(r),e===r)return"";if((e=z.resolve(e))===(r=z.resolve(r)))return"";for(var t=1;e.length>t&&47===e.charCodeAt(t);++t);for(var n=e.length,a=n-t,i=1;r.length>i&&47===r.charCodeAt(i);++i);for(var o=r.length-i,s=o>a?a:o,l=-1,c=0;s>=c;++c){if(c===s){if(o>s){if(47===r.charCodeAt(i+c))return r.slice(i+c+1);if(0===c)return r.slice(i+c)}else a>s&&(47===e.charCodeAt(t+c)?l=c:0===c&&(l=0));break}var f=e.charCodeAt(t+c);if(f!==r.charCodeAt(i+c))break;47===f&&(l=c)}var h="";for(c=t+l+1;n>=c;++c)c!==n&&47!==e.charCodeAt(c)||(h+=0===h.length?"..":"/..");return h.length>0?h+r.slice(i+l):(47===r.charCodeAt(i+=l)&&++i,r.slice(i))},_makeLong(e){return e},dirname(e){if(u(e),0===e.length)return".";for(var r=e.charCodeAt(0),t=47===r,n=-1,a=!0,i=e.length-1;i>=1;--i)if(47===(r=e.charCodeAt(i))){if(!a){n=i;break}}else a=!1;return-1===n?t?"/":".":t&&1===n?"//":e.slice(0,n)},basename(e,r){if(void 0!==r&&"string"!=typeof r)throw new TypeError('"ext" argument must be a string');u(e);var t,n=0,a=-1,i=!0;if(void 0!==r&&r.length>0&&e.length>=r.length){if(r.length===e.length&&r===e)return"";var o=r.length-1,s=-1;for(t=e.length-1;t>=0;--t){var l=e.charCodeAt(t);if(47===l){if(!i){n=t+1;break}}else-1===s&&(i=!1,s=t+1),0>o||(l===r.charCodeAt(o)?-1==--o&&(a=t):(o=-1,a=s))}return n===a?a=s:-1===a&&(a=e.length),e.slice(n,a)}for(t=e.length-1;t>=0;--t)if(47===e.charCodeAt(t)){if(!i){n=t+1;break}}else-1===a&&(i=!1,a=t+1);return-1===a?"":e.slice(n,a)},extname(e){u(e);for(var r=-1,t=0,n=-1,a=!0,i=0,o=e.length-1;o>=0;--o){var s=e.charCodeAt(o);if(47!==s)-1===n&&(a=!1,n=o+1),46===s?-1===r?r=o:1!==i&&(i=1):-1!==r&&(i=-1);else if(!a){t=o+1;break}}return-1===r||-1===n||0===i||1===i&&r===n-1&&r===t+1?"":e.slice(r,n)},format(e){if(null===e||"object"!=typeof e)throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return((e,r)=>{var t=r.dir||r.root,n=r.base||(r.name||"")+(r.ext||"");return t?t===r.root?t+n:t+"/"+n:n})(0,e)},parse(e){u(e);var r={root:"",dir:"",base:"",ext:"",name:""};if(0===e.length)return r;var t,n=e.charCodeAt(0),a=47===n;a?(r.root="/",t=1):t=0;for(var i=-1,o=0,s=-1,l=!0,c=e.length-1,f=0;c>=t;--c)if(47!==(n=e.charCodeAt(c)))-1===s&&(l=!1,s=c+1),46===n?-1===i?i=c:1!==f&&(f=1):-1!==i&&(f=-1);else if(!l){o=c+1;break}return-1===i||-1===s||0===f||1===f&&i===s-1&&i===o+1?-1!==s&&(r.base=r.name=e.slice(0===o&&a?1:o,s)):(0===o&&a?(r.name=e.slice(1,i),r.base=e.slice(1,s)):(r.name=e.slice(o,i),r.base=e.slice(o,s)),r.ext=e.slice(i,s)),o>0?r.dir=e.slice(0,o-1):a&&(r.dir="/"),r},sep:"/",delimiter:":",win32:null,posix:null};z.posix=z,C=z;var N={},S={};r(S,"name",(()=>h));var L={};r(L,"normalizeTrim",(()=>d));var R={};r(R,"addExeExt",(()=>m));var _={};r(_,"addNamePrefix",(()=>g));var I={};r(I,"addNameSuffix",(()=>v));var M={};r(M,"addShExt",(()=>p));var J={};r(J,"addShRelativePrefix",(()=>b));var W={};r(W,"removeExt",(()=>x));var q,B={};r(B,"replaceExt",(()=>y)),q=(e,r)=>{if("string"!=typeof e)return e;if(0===e.length)return e;var t,n=C.basename(e,C.extname(e))+r,a=C.join(C.dirname(e),n);return(t=e.slice(0,2))==="."+C.sep||"./"===t?"."+C.sep+a:a};var D={};r(D,"isPathInside",(()=>A)),e(N,S),e(N,L),e(N,R),e(N,_),e(N,I),e(N,M),e(N,J),e(N,W),e(N,B),e(N,D);const{basename:F,delimiter:G,dirname:H,extname:K,format:Q,isAbsolute:U,join:V,normalize:X,parse:Y,posix:Z,relative:ee,resolve:re,sep:te,toNamespacedPath:ne,win32:ae}=C;export{F as basename,G as delimiter,H as dirname,K as extname,Q as format,U as isAbsolute,V as join,X as normalize,Y as parse,Z as posix,ee as relative,re as resolve,te as sep,ne as toNamespacedPath,ae as win32,h as name,d as normalizeTrim,m as addExeExt,g as addNamePrefix,v as addNameSuffix,p as addShExt,b as addShRelativePrefix,x as removeExt,y as replaceExt,A as isPathInside}; //# sourceMappingURL=index.browser.mjs.map