vscode-uri
Version:
The URI implementation that is used by VS Code and its extensions
2 lines • 10.5 kB
JavaScript
var t={975(t){function e(t){if("string"!=typeof t)throw new TypeError("Path must be a string. Received "+JSON.stringify(t))}function r(t,e){for(var r,n="",i=0,o=-1,h=0,s=0;s<=t.length;++s){if(s<t.length)r=t.charCodeAt(s);else{if(47===r)break;r=47}if(47===r){if(o===s-1||1===h);else if(o!==s-1&&2===h){if(n.length<2||2!==i||46!==n.charCodeAt(n.length-1)||46!==n.charCodeAt(n.length-2))if(n.length>2){var a=n.lastIndexOf("/");if(a!==n.length-1){-1===a?(n="",i=0):i=(n=n.slice(0,a)).length-1-n.lastIndexOf("/"),o=s,h=0;continue}}else if(2===n.length||1===n.length){n="",i=0,o=s,h=0;continue}e&&(n.length>0?n+="/..":n="..",i=2)}else n.length>0?n+="/"+t.slice(o+1,s):n=t.slice(o+1,s),i=s-o-1;o=s,h=0}else 46===r&&-1!==h?++h:h=-1}return n}var n={resolve:function(){for(var t,n="",i=!1,o=arguments.length-1;o>=-1&&!i;o--){var h;o>=0?h=arguments[o]:(void 0===t&&(t=process.cwd()),h=t),e(h),0!==h.length&&(n=h+"/"+n,i=47===h.charCodeAt(0))}return n=r(n,!i),i?n.length>0?"/"+n:"/":n.length>0?n:"."},normalize:function(t){if(e(t),0===t.length)return".";var n=47===t.charCodeAt(0),i=47===t.charCodeAt(t.length-1);return 0!==(t=r(t,!n)).length||n||(t="."),t.length>0&&i&&(t+="/"),n?"/"+t:t},isAbsolute:function(t){return e(t),t.length>0&&47===t.charCodeAt(0)},join:function(){if(0===arguments.length)return".";for(var t,r=0;r<arguments.length;++r){var i=arguments[r];e(i),i.length>0&&(void 0===t?t=i:t+="/"+i)}return void 0===t?".":n.normalize(t)},relative:function(t,r){if(e(t),e(r),t===r)return"";if((t=n.resolve(t))===(r=n.resolve(r)))return"";for(var i=1;i<t.length&&47===t.charCodeAt(i);++i);for(var o=t.length,h=o-i,s=1;s<r.length&&47===r.charCodeAt(s);++s);for(var a=r.length-s,c=h<a?h:a,f=-1,u=0;u<=c;++u){if(u===c){if(a>c){if(47===r.charCodeAt(s+u))return r.slice(s+u+1);if(0===u)return r.slice(s+u)}else h>c&&(47===t.charCodeAt(i+u)?f=u:0===u&&(f=0));break}var l=t.charCodeAt(i+u);if(l!==r.charCodeAt(s+u))break;47===l&&(f=u)}var g="";for(u=i+f+1;u<=o;++u)u!==o&&47!==t.charCodeAt(u)||(0===g.length?g+="..":g+="/..");return g.length>0?g+r.slice(s+f):(s+=f,47===r.charCodeAt(s)&&++s,r.slice(s))},_makeLong:function(t){return t},dirname:function(t){if(e(t),0===t.length)return".";for(var r=t.charCodeAt(0),n=47===r,i=-1,o=!0,h=t.length-1;h>=1;--h)if(47===(r=t.charCodeAt(h))){if(!o){i=h;break}}else o=!1;return-1===i?n?"/":".":n&&1===i?"//":t.slice(0,i)},basename:function(t,r){if(void 0!==r&&"string"!=typeof r)throw new TypeError('"ext" argument must be a string');e(t);var n,i=0,o=-1,h=!0;if(void 0!==r&&r.length>0&&r.length<=t.length){if(r.length===t.length&&r===t)return"";var s=r.length-1,a=-1;for(n=t.length-1;n>=0;--n){var c=t.charCodeAt(n);if(47===c){if(!h){i=n+1;break}}else-1===a&&(h=!1,a=n+1),s>=0&&(c===r.charCodeAt(s)?-1===--s&&(o=n):(s=-1,o=a))}return i===o?o=a:-1===o&&(o=t.length),t.slice(i,o)}for(n=t.length-1;n>=0;--n)if(47===t.charCodeAt(n)){if(!h){i=n+1;break}}else-1===o&&(h=!1,o=n+1);return-1===o?"":t.slice(i,o)},extname:function(t){e(t);for(var r=-1,n=0,i=-1,o=!0,h=0,s=t.length-1;s>=0;--s){var a=t.charCodeAt(s);if(47!==a)-1===i&&(o=!1,i=s+1),46===a?-1===r?r=s:1!==h&&(h=1):-1!==r&&(h=-1);else if(!o){n=s+1;break}}return-1===r||-1===i||0===h||1===h&&r===i-1&&r===n+1?"":t.slice(r,i)},format:function(t){if(null===t||"object"!=typeof t)throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof t);return function(t,e){var r=e.dir||e.root,n=e.base||(e.name||"")+(e.ext||"");return r?r===e.root?r+n:r+"/"+n:n}(0,t)},parse:function(t){e(t);var r={root:"",dir:"",base:"",ext:"",name:""};if(0===t.length)return r;var n,i=t.charCodeAt(0),o=47===i;o?(r.root="/",n=1):n=0;for(var h=-1,s=0,a=-1,c=!0,f=t.length-1,u=0;f>=n;--f)if(47!==(i=t.charCodeAt(f)))-1===a&&(c=!1,a=f+1),46===i?-1===h?h=f:1!==u&&(u=1):-1!==h&&(u=-1);else if(!c){s=f+1;break}return-1===h||-1===a||0===u||1===u&&h===a-1&&h===s+1?-1!==a&&(r.base=r.name=0===s&&o?t.slice(1,a):t.slice(s,a)):(0===s&&o?(r.name=t.slice(1,h),r.base=t.slice(1,a)):(r.name=t.slice(s,h),r.base=t.slice(s,a)),r.ext=t.slice(h,a)),s>0?r.dir=t.slice(0,s-1):o&&(r.dir="/"),r},sep:"/",delimiter:":",win32:null,posix:null};n.posix=n,t.exports=n}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,r),o.exports}let n;if(r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),"object"==typeof process)n="win32"===process.platform;else if("object"==typeof navigator){let t=navigator.userAgent;n=t.indexOf("Windows")>=0}const i=/^\w[\w\d+.-]*$/,o=/^\//,h=/^\/\//;function s(t,e){if(!t.scheme&&e)throw new Error(`[UriError]: Scheme is missing: {scheme: "", authority: "${t.authority}", path: "${t.path}", query: "${t.query}", fragment: "${t.fragment}"}`);if(t.scheme&&!i.test(t.scheme))throw new Error("[UriError]: Scheme contains illegal characters.");if(t.path)if(t.authority){if(!o.test(t.path))throw new Error('[UriError]: If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character')}else if(h.test(t.path))throw new Error('[UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")')}const a="",c="/",f=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;class u{static isUri(t){return t instanceof u||!!t&&"string"==typeof t.authority&&"string"==typeof t.fragment&&"string"==typeof t.path&&"string"==typeof t.query&&"string"==typeof t.scheme&&"string"==typeof t.fsPath&&"function"==typeof t.with&&"function"==typeof t.toString}scheme;authority;path;query;fragment;constructor(t,e,r,n,i,o=!1){"object"==typeof t?(this.scheme=t.scheme||a,this.authority=t.authority||a,this.path=t.path||a,this.query=t.query||a,this.fragment=t.fragment||a):(this.scheme=function(t,e){return t||e?t:"file"}(t,o),this.authority=e||a,this.path=function(t,e){switch(t){case"https":case"http":case"file":e?e[0]!==c&&(e=c+e):e=c}return e}(this.scheme,r||a),this.query=n||a,this.fragment=i||a,s(this,o))}get fsPath(){return y(this,!1)}with(t){if(!t)return this;let{scheme:e,authority:r,path:n,query:i,fragment:o}=t;return void 0===e?e=this.scheme:null===e&&(e=a),void 0===r?r=this.authority:null===r&&(r=a),void 0===n?n=this.path:null===n&&(n=a),void 0===i?i=this.query:null===i&&(i=a),void 0===o?o=this.fragment:null===o&&(o=a),e===this.scheme&&r===this.authority&&n===this.path&&i===this.query&&o===this.fragment?this:new g(e,r,n,i,o)}static parse(t,e=!1){const r=f.exec(t);return r?new g(r[2]||a,A(r[4]||a),A(r[5]||a),A(r[7]||a),A(r[9]||a),e):new g(a,a,a,a,a)}static file(t){let e=a;if(n&&(t=t.replace(/\\/g,c)),t[0]===c&&t[1]===c){const r=t.indexOf(c,2);-1===r?(e=t.substring(2),t=c):(e=t.substring(2,r),t=t.substring(r)||c)}return new g("file",e,t,a,a)}static from(t){const e=new g(t.scheme,t.authority,t.path,t.query,t.fragment);return s(e,!0),e}toString(t=!1){return v(this,t)}toJSON(){return this}static revive(t){if(t){if(t instanceof u)return t;{const e=new g(t);return e._formatted=t.external,e._fsPath=t._sep===l?t.fsPath:null,e}}return t}}const l=n?1:void 0;class g extends u{_formatted=null;_fsPath=null;get fsPath(){return this._fsPath||(this._fsPath=y(this,!1)),this._fsPath}toString(t=!1){return t?v(this,!0):(this._formatted||(this._formatted=v(this,!1)),this._formatted)}toJSON(){const t={$mid:1};return this._fsPath&&(t.fsPath=this._fsPath,t._sep=l),this._formatted&&(t.external=this._formatted),this.path&&(t.path=this.path),this.scheme&&(t.scheme=this.scheme),this.authority&&(t.authority=this.authority),this.query&&(t.query=this.query),this.fragment&&(t.fragment=this.fragment),t}}const p={58:"%3A",47:"%2F",63:"%3F",35:"%23",91:"%5B",93:"%5D",64:"%40",33:"%21",36:"%24",38:"%26",39:"%27",40:"%28",41:"%29",42:"%2A",43:"%2B",44:"%2C",59:"%3B",61:"%3D",32:"%20"};function d(t,e,r){let n,i=-1;for(let o=0;o<t.length;o++){const h=t.charCodeAt(o);if(h>=97&&h<=122||h>=65&&h<=90||h>=48&&h<=57||45===h||46===h||95===h||126===h||e&&47===h||r&&91===h||r&&93===h||r&&58===h)-1!==i&&(n+=encodeURIComponent(t.substring(i,o)),i=-1),void 0!==n&&(n+=t.charAt(o));else{void 0===n&&(n=t.substr(0,o));const e=p[h];void 0!==e?(-1!==i&&(n+=encodeURIComponent(t.substring(i,o)),i=-1),n+=e):-1===i&&(i=o)}}return-1!==i&&(n+=encodeURIComponent(t.substring(i))),void 0!==n?n:t}function m(t){let e;for(let r=0;r<t.length;r++){const n=t.charCodeAt(r);35===n||63===n?(void 0===e&&(e=t.substr(0,r)),e+=p[n]):void 0!==e&&(e+=t[r])}return void 0!==e?e:t}function y(t,e){let r;return r=t.authority&&t.path.length>1&&"file"===t.scheme?`//${t.authority}${t.path}`:47===t.path.charCodeAt(0)&&(t.path.charCodeAt(1)>=65&&t.path.charCodeAt(1)<=90||t.path.charCodeAt(1)>=97&&t.path.charCodeAt(1)<=122)&&58===t.path.charCodeAt(2)?e?t.path.substr(1):t.path[1].toLowerCase()+t.path.substr(2):t.path,n&&(r=r.replace(/\//g,"\\")),r}function v(t,e){const r=e?m:d;let n="",{scheme:i,authority:o,path:h,query:s,fragment:a}=t;if(i&&(n+=i,n+=":"),(o||"file"===i)&&(n+=c,n+=c),o){let t=o.indexOf("@");if(-1!==t){const e=o.substr(0,t);o=o.substr(t+1),t=e.lastIndexOf(":"),-1===t?n+=r(e,!1,!1):(n+=r(e.substr(0,t),!1,!1),n+=":",n+=r(e.substr(t+1),!1,!0)),n+="@"}o=o.toLowerCase(),t=o.lastIndexOf(":"),-1===t?n+=r(o,!1,!0):(n+=r(o.substr(0,t),!1,!0),n+=o.substr(t))}if(h){if(h.length>=3&&47===h.charCodeAt(0)&&58===h.charCodeAt(2)){const t=h.charCodeAt(1);t>=65&&t<=90&&(h=`/${String.fromCharCode(t+32)}:${h.substr(3)}`)}else if(h.length>=2&&58===h.charCodeAt(1)){const t=h.charCodeAt(0);t>=65&&t<=90&&(h=`${String.fromCharCode(t+32)}:${h.substr(2)}`)}n+=r(h,!0,!1)}return s&&(n+="?",n+=r(s,!1,!1)),a&&(n+="#",n+=e?a:d(a,!1,!1)),n}function b(t){try{return decodeURIComponent(t)}catch{return t.length>3?t.substr(0,3)+b(t.substr(3)):t}}const C=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function A(t){return t.match(C)?t.replace(C,t=>b(t)):t}var w=r(975);const x=w.posix||w,P="/";var _;!function(t){t.joinPath=function(t,...e){return t.with({path:x.join(t.path,...e)})},t.resolvePath=function(t,...e){let r=t.path,n=!1;r[0]!==P&&(r=P+r,n=!0);let i=x.resolve(r,...e);return n&&i[0]===P&&!t.authority&&(i=i.substring(1)),t.with({path:i})},t.dirname=function(t){if(0===t.path.length||t.path===P)return t;let e=x.dirname(t.path);return 1===e.length&&46===e.charCodeAt(0)&&(e=""),t.with({path:e})},t.basename=function(t){return x.basename(t.path)},t.extname=function(t){return x.extname(t.path)}}(_||(_={}));const q={URI:u,Utils:_};export{u as URI,_ as Utils,q as default};
//# sourceMappingURL=index.mjs.map