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