-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpath.min.js
More file actions
1 lines (1 loc) · 2.76 KB
/
path.min.js
File metadata and controls
1 lines (1 loc) · 2.76 KB
1
!function(t,n){"use strict";"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?module.exports=n.call(t):t.path=n.call(t)}(this,function(){"use strict";function t(t){var n=d.createElement("a");n.href=t;var e=n.protocol,r=n.hostname,o=n.port,s=n.pathname,i=n.search,u=n.hash,a=n.host,h=n.origin,l=y.test(s)?y.exec(s)[1]:"",c=j.test(s)?j.exec(s)[1]:"",f=A.test(s)?A.exec(s)[1]:"";return{protocol:e,domain:r,port:o,host:a,origin:h,path:s,search:i,hash:u,dir:l,base:c,ext:f}}function n(n,e){var r=t(n).base;return e&&r.substr(-1*e.length)===e&&(r=r.substr(0,r.length-e.length)),r}function e(n){return t(n).dir}function r(n){return t(n).ext}function o(){var t="",n=w.call(arguments,0);arguments.length<=1&&n.unshift(p());for(var e=0;e<n.length;e+=1){var r=n[e];if(!v(r))throw new TypeError("Arguemnts to path.join must be strings");r&&(t+=t?"/"+r:r)}return l(t)}function s(){for(var t="",n=!1,e=!1,r=arguments.length-1;r>=-1&&!n;r-=1){var o=r>=0?arguments[r]:e?"":p();if(e||(e=g(o)),!v(o))throw new TypeError("Arguments to path.resolve must be strings");o&&(t=o+"/"+t,n="/"===o[0])}return t=c(t.split("/"),!n).join("/"),(n?"/":"")+t||"."}function i(t,n){t=s(t).substr(1),n=s(n).substr(1);for(var e=m(t.split("/")),r=m(n.split("/")),o=Math.min(e.length,r.length),i=o,u=0;o>u;u+=1)if(e[u]!==r[u]){i=u;break}for(var a=[],u=i;u<e.length;u+=1)a.push("..");return a=a.concat(r.slice(i)),a.join("/")}function u(t,n){1===arguments.length&&(t=p(),n=arguments[0]),f(n)||(n=o(p(),n)),f(t)||(t=o(p(),t));for(var e=m(t.split("/")),s=m(n.split("/")),i=Math.max(e.length,s.length),u=e.length-s.length,a=!0,h=0;i>h;h+=1)"**"!==s[h]?"*"!==s[h]&&(/^(\*\.)/.test(s[h])&&r(e[h])===r(s[h])||e[h]!==s[h]&&(a=!1)):u--&&s.splice(h,0,"**");return a}function a(t,n,e){return u(t)?n&&n():e&&e()}function h(t,n){arguments.length<2&&(t=p(),n=arguments[0]);for(var e=f(t)?"/":"",r=m(t.split("/")),o=m(n.split("/")),s=r.length,i=0,u=0;s>u;u+=1)r[u]===o[i]&&(i+=1);var a=s-i,h=r.slice(0,a),l=h.concat(o);return e+l.join("/")}function l(t){var n=f(t),e=t&&"/"===t[t.length-1];return t=c(t.split("/"),!n).join("/"),t||n||(t+="."),t&&e&&(t+="/"),(n?"/":"")+t}function c(t,n){for(var e=[],r=0;r<t.length;r+=1){var o=t[r];o&&"."!==o&&(".."===o?e.length&&".."!==e[e.length-1]?e.pop():n&&e.push(".."):/^http(s)?:/.test(o)?e.push(o+"/"):e.push(o))}return e}function f(t){return"/"===t.charAt(0)}function g(t){return E.test(t)}function p(){return e(t(x.href).path)}function m(t){return t.filter(function(t){return""!==t})}function v(t){return"string"==typeof t}var b=this||window,d=b.document,x=b.location,w=[].slice,j=/([^\/?#]*)$/,y=/(?:([^?#]*)\/)*/,A=/(?:[^.\/]+)(\.[^\/.]+)$/,E=/(?:^[\w]+?\:\/{2,})/;return function(){return{parse:t,basename:n,dirname:e,extname:r,join:o,cwd:p,resolve:s,relative:i,normalize:l,equal:u,pass:a,misbutton:h}}()});