resolve-pathname
Advanced tools
Comparing version 1.0.5 to 2.0.0
'use strict'; | ||
var _invariant = require('invariant'); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var isAbsolute = function isAbsolute(pathname) { | ||
@@ -13,30 +7,50 @@ return pathname.charAt(0) === '/'; | ||
var isIndex = function isIndex(pathname) { | ||
return pathname.charAt(pathname.length - 1) === '/'; | ||
// About 1.5x faster than the two-arg version of Array#splice() | ||
var spliceOne = 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 | ||
var resolvePathname = function resolvePathname(to) { | ||
var from = arguments.length <= 1 || arguments[1] === undefined ? '/' : arguments[1]; | ||
var from = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1]; | ||
if (!to) return from; | ||
var toParts = to && to.split('/') || []; | ||
var fromParts = from && from.split('/') || []; | ||
if (isAbsolute(to)) { | ||
!(to.indexOf('..') === -1) ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'Pathname "%s" is not a valid URL pathname', to) : (0, _invariant2.default)(false) : void 0; | ||
var isToAbs = to && isAbsolute(to); | ||
var isFromAbs = from && isAbsolute(from); | ||
var mustEndAbs = isToAbs || isFromAbs; | ||
return to; | ||
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); | ||
} | ||
var prefix = isAbsolute(from) ? '/' : ''; | ||
var pathname = from + (isIndex(from) ? '' : '/../') + to; | ||
var parts = pathname.split('/').filter(function (part) { | ||
return !!part; | ||
}); | ||
if (!fromParts.length) return '/'; | ||
var hasTrailingSlash = void 0; | ||
if (fromParts.length) { | ||
var last = fromParts[fromParts.length - 1]; | ||
hasTrailingSlash = last === '.' || last === '..' || last === ''; | ||
} else { | ||
hasTrailingSlash = false; | ||
} | ||
var up = 0; | ||
for (var i = parts.length - 1; i >= 0; i--) { | ||
if (parts[i] === '..') { | ||
parts.splice(i, 1); | ||
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) { | ||
parts.splice(i, 1); | ||
spliceOne(fromParts, i); | ||
up--; | ||
@@ -46,7 +60,13 @@ } | ||
!(up === 0) ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'Pathname "%s" is not a valid URL pathname', pathname) : (0, _invariant2.default)(false) : void 0; | ||
if (!mustEndAbs) for (; up--; up) { | ||
fromParts.unshift('..'); | ||
}if (mustEndAbs && fromParts[0] !== '' && (!fromParts[0] || !isAbsolute(fromParts[0]))) fromParts.unshift(''); | ||
return prefix + parts.join('/'); | ||
var result = fromParts.join('/'); | ||
if (hasTrailingSlash && result.substr(-1) !== '/') result += '/'; | ||
return result; | ||
}; | ||
module.exports = resolvePathname; |
{ | ||
"name": "resolve-pathname", | ||
"version": "1.0.5", | ||
"version": "2.0.0", | ||
"description": "Resolve URL pathnames using JavaScript", | ||
@@ -23,5 +23,2 @@ "author": "Michael Jackson", | ||
}, | ||
"dependencies": { | ||
"invariant": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -28,0 +25,0 @@ "babel-cli": "^6.5.1", |
@@ -64,3 +64,3 @@ # resolve-pathname [![Travis][build-badge]][build] [![npm package][npm-badge]][npm] | ||
- [url.resolve](https://nodejs.org/api/url.html#url_url_resolve_from_to) - node's `url.resolve` implementation for full URLs | ||
- [resolve-url](https://www.npmjs.com/package/resolve-url) - A DOM-dependent implementation of the same algorithm | ||
- [path.resolve](https://nodejs.org/api/path.html#path_path_resolve_from_to) - node's posix-compliant path resolution algorithm for filesystems |
@@ -55,12 +55,6 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
/* 0 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
var _invariant = __webpack_require__(1); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var isAbsolute = function isAbsolute(pathname) { | ||
@@ -70,30 +64,50 @@ return pathname.charAt(0) === '/'; | ||
var isIndex = function isIndex(pathname) { | ||
return pathname.charAt(pathname.length - 1) === '/'; | ||
// About 1.5x faster than the two-arg version of Array#splice() | ||
var spliceOne = 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 | ||
var resolvePathname = function resolvePathname(to) { | ||
var from = arguments.length <= 1 || arguments[1] === undefined ? '/' : arguments[1]; | ||
var from = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1]; | ||
if (!to) return from; | ||
var toParts = to && to.split('/') || []; | ||
var fromParts = from && from.split('/') || []; | ||
if (isAbsolute(to)) { | ||
!(to.indexOf('..') === -1) ? false ? (0, _invariant2.default)(false, 'Pathname "%s" is not a valid URL pathname', to) : (0, _invariant2.default)(false) : void 0; | ||
var isToAbs = to && isAbsolute(to); | ||
var isFromAbs = from && isAbsolute(from); | ||
var mustEndAbs = isToAbs || isFromAbs; | ||
return to; | ||
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); | ||
} | ||
var prefix = isAbsolute(from) ? '/' : ''; | ||
var pathname = from + (isIndex(from) ? '' : '/../') + to; | ||
var parts = pathname.split('/').filter(function (part) { | ||
return !!part; | ||
}); | ||
if (!fromParts.length) return '/'; | ||
var hasTrailingSlash = void 0; | ||
if (fromParts.length) { | ||
var last = fromParts[fromParts.length - 1]; | ||
hasTrailingSlash = last === '.' || last === '..' || last === ''; | ||
} else { | ||
hasTrailingSlash = false; | ||
} | ||
var up = 0; | ||
for (var i = parts.length - 1; i >= 0; i--) { | ||
if (parts[i] === '..') { | ||
parts.splice(i, 1); | ||
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) { | ||
parts.splice(i, 1); | ||
spliceOne(fromParts, i); | ||
up--; | ||
@@ -103,66 +117,15 @@ } | ||
!(up === 0) ? false ? (0, _invariant2.default)(false, 'Pathname "%s" is not a valid URL pathname', pathname) : (0, _invariant2.default)(false) : void 0; | ||
if (!mustEndAbs) for (; up--; up) { | ||
fromParts.unshift('..'); | ||
}if (mustEndAbs && fromParts[0] !== '' && (!fromParts[0] || !isAbsolute(fromParts[0]))) fromParts.unshift(''); | ||
return prefix + parts.join('/'); | ||
}; | ||
var result = fromParts.join('/'); | ||
module.exports = resolvePathname; | ||
if (hasTrailingSlash && result.substr(-1) !== '/') result += '/'; | ||
/***/ }, | ||
/* 1 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/** | ||
* Copyright 2013-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
/** | ||
* Use invariant() to assert state which your program assumes to be true. | ||
* | ||
* Provide sprintf-style format (only %s is supported) and arguments | ||
* to provide information about what broke and what you were | ||
* expecting. | ||
* | ||
* The invariant message will be stripped in production, but the invariant | ||
* will remain to ensure logic does not differ in production. | ||
*/ | ||
var invariant = function(condition, format, a, b, c, d, e, f) { | ||
if (false) { | ||
if (format === undefined) { | ||
throw new Error('invariant requires an error message argument'); | ||
} | ||
} | ||
if (!condition) { | ||
var error; | ||
if (format === undefined) { | ||
error = new Error( | ||
'Minified exception occurred; use the non-minified dev environment ' + | ||
'for the full error message and additional helpful warnings.' | ||
); | ||
} else { | ||
var args = [a, b, c, d, e, f]; | ||
var argIndex = 0; | ||
error = new Error( | ||
format.replace(/%s/g, function() { return args[argIndex++]; }) | ||
); | ||
error.name = 'Invariant Violation'; | ||
} | ||
error.framesToPop = 1; // we don't care about invariant's own frame | ||
throw error; | ||
} | ||
return result; | ||
}; | ||
module.exports = invariant; | ||
module.exports = resolvePathname; | ||
/***/ } | ||
@@ -169,0 +132,0 @@ /******/ ]) |
@@ -1,1 +0,1 @@ | ||
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.resolvePathname=r():e.resolvePathname=r()}(this,function(){return function(e){function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,r),o.loaded=!0,o.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r,t){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}var o=t(1),i=n(o),f=function(e){return"/"===e.charAt(0)},u=function(e){return"/"===e.charAt(e.length-1)},a=function(e){var r=arguments.length<=1||void 0===arguments[1]?"/":arguments[1];if(!e)return r;if(f(e))return-1!==e.indexOf("..")?(0,i["default"])(!1):void 0,e;for(var t=f(r)?"/":"",n=r+(u(r)?"":"/../")+e,o=n.split("/").filter(function(e){return!!e}),a=0,c=o.length-1;c>=0;c--)".."===o[c]?(o.splice(c,1),a++):a&&(o.splice(c,1),a--);return 0!==a?(0,i["default"])(!1):void 0,t+o.join("/")};e.exports=a},function(e,r,t){"use strict";var n=function(e,r,t,n,o,i,f,u){if(!e){var a;if(void 0===r)a=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[t,n,o,i,f,u],s=0;a=new Error(r.replace(/%s/g,function(){return c[s++]})),a.name="Invariant Violation"}throw a.framesToPop=1,a}};e.exports=n}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.resolvePathname=e():t.resolvePathname=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e){"use strict";var r=function(t){return"/"===t.charAt(0)},n=function(t,e){for(var r=e,n=r+1,o=t.length;o>n;r+=1,n+=1)t[r]=t[n];t.pop()},o=function(t){var e=arguments.length<=1||void 0===arguments[1]?"":arguments[1],o=t&&t.split("/")||[],i=e&&e.split("/")||[],f=t&&r(t),s=e&&r(e),u=f||s;if(t&&r(t)?i=o:o.length&&(i.pop(),i=i.concat(o)),!i.length)return"/";var p=void 0;if(i.length){var a=i[i.length-1];p="."===a||".."===a||""===a}else p=!1;for(var c=0,l=i.length;l>=0;l--){var v=i[l];"."===v?n(i,l):".."===v?(n(i,l),c++):c&&(n(i,l),c--)}if(!u)for(;c--;c)i.unshift("..");!u||""===i[0]||i[0]&&r(i[0])||i.unshift("");var d=i.join("/");return p&&"/"!==d.substr(-1)&&(d+="/"),d};t.exports=o}])}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
0
8
0
17078
287
- Removedinvariant@^2.0.0
- Removedinvariant@2.2.4(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)