bewcloud/public/js/@jsr/std__path@1.1.4/denonext/posix/relative.mjs

3 lines
833 B
JavaScript
Raw Permalink Normal View History

/* esm.sh - @jsr/std__path@1.1.4/posix/relative */
import{isPosixPathSeparator as s}from"./_util.mjs";import{resolve as A}from"./resolve.mjs";import{assertArgs as g}from"../_common/relative.mjs";function m(i,r){if(g(i,r),i=A(i),r=A(r),i===r)return"";let n=1,a=i.length;for(;n<a&&s(i.charCodeAt(n));++n);let f=a-n,t=1,d=r.length;for(;t<d&&s(r.charCodeAt(t));++t);let h=d-t,c=f<h?f:h,l=-1,e=0;for(;e<=c;++e){if(e===c){if(h>c){if(s(r.charCodeAt(t+e)))return r.slice(t+e+1);if(e===0)return r.slice(t+e)}else f>c&&(s(i.charCodeAt(n+e))?l=e:e===0&&(l=0));break}let C=i.charCodeAt(n+e),u=r.charCodeAt(t+e);if(C!==u)break;s(C)&&(l=e)}let o="";for(e=n+l+1;e<=a;++e)(e===a||s(i.charCodeAt(e)))&&(o.length===0?o+="..":o+="/..");return o.length>0?o+r.slice(t+l):(t+=l,s(r.charCodeAt(t))&&++t,r.slice(t))}export{m as relative};
//relative.mjs.map