mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
refactor: bundle template.js respectively
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
export function get (url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest()
|
||||
xhr.onload = () => {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
resolve(xhr.responseText)
|
||||
} else {
|
||||
reject(new Error(xhr.statusText))
|
||||
}
|
||||
}
|
||||
xhr.onerror = () => {
|
||||
reject(new Error('An error occurred whilst sending the response.'))
|
||||
}
|
||||
xhr.open('GET', url)
|
||||
xhr.send()
|
||||
})
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
import {last, isArray} from './underscore'
|
||||
|
||||
const splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^/]+?|)(\.[^./]*|))(?:[/]*)$/
|
||||
const urlRe = /^(?:\w+:)?\/\/([^\s.]+\.\S{2}|localhost[:?\d]*)\S*$/
|
||||
|
||||
// https://github.com/jinder/path/blob/master/path.js#L567
|
||||
export function extname (path) {
|
||||
return splitPathRe.exec(path).slice(1)[3]
|
||||
}
|
||||
|
||||
// https://www.npmjs.com/package/is-url
|
||||
export function valid (path) {
|
||||
return urlRe.test(path)
|
||||
}
|
||||
|
||||
export function resolve (root, path) {
|
||||
if (isArray(root)) {
|
||||
root = root[0]
|
||||
}
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user