initial commit (work in progress)
This commit is contained in:
parent
13fdb60f66
commit
559369016d
83 changed files with 10461 additions and 0 deletions
29
module/module.js
Normal file
29
module/module.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
"use strict"
|
||||
|
||||
require.$$modules = {}
|
||||
require.$$current = function() {
|
||||
var href = window.location.href
|
||||
var searchIndex = href.indexOf("?")
|
||||
var hashIndex = href.indexOf("#")
|
||||
var pathnameEnd = searchIndex > -1 ? searchIndex : hashIndex > -1 ? hashIndex : href.length
|
||||
try {throw new Error} catch (e) {var error = e}
|
||||
var src = error.stack.match(/^(?:(?!^Error|\/module\/module\.js).)*$/m).toString().match(/((?:file|https|http):\/\/.+)(?::\d+){2}/)[1] || href.slice(0, pathnameEnd)
|
||||
var base = href.slice(0, href.lastIndexOf("/", pathnameEnd) + 1)
|
||||
return src.replace(/\.js$/, "")
|
||||
}
|
||||
|
||||
var module = {
|
||||
get exports() {return require.$$modules[require.$$current()]},
|
||||
set exports(value) {require.$$modules[require.$$current()] = value},
|
||||
}
|
||||
|
||||
function require(name) {
|
||||
var relative = require.$$current()
|
||||
var slashIndex = relative.lastIndexOf("/")
|
||||
var path = slashIndex > -1 ? relative.slice(0, slashIndex + 1) : "./"
|
||||
var absolute = (path + name).replace(/\/\.\//g, "/")
|
||||
var dotdot = /\/[^\/]+?\/\.{2}/
|
||||
while (dotdot.test(absolute)) absolute = absolute.replace(dotdot, "")
|
||||
if (absolute in require.$$modules) return require.$$modules[absolute]
|
||||
else throw new Error("Module does not exist: " + absolute)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue