2018-02-01 12:17:04 +00:00
|
|
|
function removeLastDir (url) {
|
|
|
|
var arr = url.split('/')
|
|
|
|
if (arr.pop() === '') {
|
|
|
|
arr.pop()
|
|
|
|
}
|
|
|
|
|
|
|
|
return arr.join('/')
|
|
|
|
}
|
|
|
|
|
2019-07-05 11:13:14 +00:00
|
|
|
// this code borrow from mozilla
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#Examples
|
|
|
|
function encodeRFC5987ValueChars(str) {
|
|
|
|
return encodeURIComponent(str).
|
|
|
|
// Note that although RFC3986 reserves "!", RFC5987 does not,
|
|
|
|
// so we do not need to escape it
|
|
|
|
replace(/['()]/g, escape). // i.e., %27 %28 %29
|
|
|
|
replace(/\*/g, '%2A').
|
|
|
|
// The following are not required for percent-encoding per RFC5987,
|
|
|
|
// so we can allow for a little better readability over the wire: |`^
|
|
|
|
replace(/%(?:7C|60|5E)/g, unescape);
|
|
|
|
}
|
|
|
|
|
2018-02-01 12:17:04 +00:00
|
|
|
export default {
|
2019-07-05 11:13:14 +00:00
|
|
|
encodeRFC5987ValueChars: encodeRFC5987ValueChars,
|
2018-02-01 12:17:04 +00:00
|
|
|
removeLastDir: removeLastDir
|
|
|
|
}
|