refactor: import rollup

This commit is contained in:
harttle
2018-08-20 23:58:41 +08:00
parent 4ece4e208f
commit bc9d8f92af
82 changed files with 8589 additions and 3963 deletions
+20 -4
View File
@@ -1,5 +1,4 @@
import resolveUrl from 'resolve-url'
import _ from './underscore'
import {last, isArray} from './underscore'
const splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^/]+?|)(\.[^./]*|))(?:[/]*)$/
const urlRe = /^(?:\w+:)?\/\/([^\s.]+\.\S{2}|localhost[:?\d]*)\S*$/
@@ -15,11 +14,28 @@ export function valid (path) {
}
export function resolve (root, path) {
if (Object.prototype.toString.call(root) === '[object Array]') {
if (isArray(root)) {
root = root[0]
}
if (root && _.last(root) !== '/') {
if (root && last(root) !== '/') {
root += '/'
}
return resolveUrl(root, path)
}
function resolveUrl (root, path) {
const base = document.createElement('base')
base.href = arguments[0]
const head = document.getElementsByTagName('head')[0]
head.insertBefore(base, head.firstChild)
const a = document.createElement('a')
a.href = path
const resolved = a.href
base.href = resolved
head.removeChild(base)
return resolved
}