0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

View file

@ -0,0 +1,83 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.resolvePathname = factory());
}(this, (function () { 'use strict';
function isAbsolute(pathname) {
return pathname.charAt(0) === '/';
}
// About 1.5x faster than the two-arg version of Array#splice()
function spliceOne(list, index) {
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) {
list[i] = list[k];
}
list.pop();
}
// This implementation is based heavily on node's url.parse
function resolvePathname(to, from) {
if (from === undefined) from = '';
var toParts = (to && to.split('/')) || [];
var fromParts = (from && from.split('/')) || [];
var isToAbs = to && isAbsolute(to);
var isFromAbs = from && isAbsolute(from);
var mustEndAbs = isToAbs || isFromAbs;
if (to && isAbsolute(to)) {
// to is absolute
fromParts = toParts;
} else if (toParts.length) {
// to is relative, drop the filename
fromParts.pop();
fromParts = fromParts.concat(toParts);
}
if (!fromParts.length) return '/';
var hasTrailingSlash;
if (fromParts.length) {
var last = fromParts[fromParts.length - 1];
hasTrailingSlash = last === '.' || last === '..' || last === '';
} else {
hasTrailingSlash = false;
}
var up = 0;
for (var i = fromParts.length; i >= 0; i--) {
var part = fromParts[i];
if (part === '.') {
spliceOne(fromParts, i);
} else if (part === '..') {
spliceOne(fromParts, i);
up++;
} else if (up) {
spliceOne(fromParts, i);
up--;
}
}
if (!mustEndAbs) for (; up--; up) fromParts.unshift('..');
if (
mustEndAbs &&
fromParts[0] !== '' &&
(!fromParts[0] || !isAbsolute(fromParts[0]))
)
fromParts.unshift('');
var result = fromParts.join('/');
if (hasTrailingSlash && result.substr(-1) !== '/') result += '/';
return result;
}
return resolvePathname;
})));

View file

@ -0,0 +1 @@
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.resolvePathname=e()}(this,function(){"use strict";function p(t){return"/"===t.charAt(0)}function d(t,e){for(var n=e,o=n+1,r=t.length;o<r;n+=1,o+=1)t[n]=t[o];t.pop()}return function(t,e){void 0===e&&(e="");var n,o=t&&t.split("/")||[],r=e&&e.split("/")||[],f=t&&p(t),i=e&&p(e),u=f||i;if(t&&p(t)?r=o:o.length&&(r.pop(),r=r.concat(o)),!r.length)return"/";if(r.length){var s=r[r.length-1];n="."===s||".."===s||""===s}else n=!1;for(var l=0,a=r.length;0<=a;a--){var c=r[a];"."===c?d(r,a):".."===c?(d(r,a),l++):l&&(d(r,a),l--)}if(!u)for(;l--;l)r.unshift("..");!u||""===r[0]||r[0]&&p(r[0])||r.unshift("");var h=r.join("/");return n&&"/"!==h.substr(-1)&&(h+="/"),h}});