generated from justjavac/deno_starter
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
345 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
# Changelog | ||
|
||
## 0.2.0 - [2020-09-17] | ||
|
||
- new `Vendor` type | ||
- new `isVendor()` for checking if something is a vendor | ||
- added `./bundle/web/deno-vendors.js` bundle for the web | ||
- updated `mod.ts` | ||
- updated tests | ||
|
||
## 0.1.0 - [2020-08-07] | ||
|
||
- first release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. | ||
|
||
// This is a specialised implementation of a System module loader. | ||
|
||
"use strict"; | ||
|
||
// @ts-nocheck | ||
/* eslint-disable */ | ||
let System, __instantiate; | ||
(() => { | ||
const r = new Map(); | ||
|
||
System = { | ||
register(id, d, f) { | ||
r.set(id, { d, f, exp: {} }); | ||
}, | ||
}; | ||
async function dI(mid, src) { | ||
let id = mid.replace(/\.\w+$/i, ""); | ||
if (id.includes("./")) { | ||
const [o, ...ia] = id.split("/").reverse(), | ||
[, ...sa] = src.split("/").reverse(), | ||
oa = [o]; | ||
let s = 0, | ||
i; | ||
while ((i = ia.shift())) { | ||
if (i === "..") s++; | ||
else if (i === ".") break; | ||
else oa.push(i); | ||
} | ||
if (s < sa.length) oa.push(...sa.slice(s)); | ||
id = oa.reverse().join("/"); | ||
} | ||
return r.has(id) ? gExpA(id) : import(mid); | ||
} | ||
|
||
function gC(id, main) { | ||
return { | ||
id, | ||
import: (m) => dI(m, id), | ||
meta: { url: id, main }, | ||
}; | ||
} | ||
|
||
function gE(exp) { | ||
return (id, v) => { | ||
v = typeof id === "string" ? { [id]: v } : id; | ||
for (const [id, value] of Object.entries(v)) { | ||
Object.defineProperty(exp, id, { | ||
value, | ||
writable: true, | ||
enumerable: true, | ||
}); | ||
} | ||
}; | ||
} | ||
|
||
function rF(main) { | ||
for (const [id, m] of r.entries()) { | ||
const { f, exp } = m; | ||
const { execute: e, setters: s } = f(gE(exp), gC(id, id === main)); | ||
delete m.f; | ||
m.e = e; | ||
m.s = s; | ||
} | ||
} | ||
|
||
async function gExpA(id) { | ||
if (!r.has(id)) return; | ||
const m = r.get(id); | ||
if (m.s) { | ||
const { d, e, s } = m; | ||
delete m.s; | ||
delete m.e; | ||
for (let i = 0; i < s.length; i++) s[i](await gExpA(d[i])); | ||
const r = e(); | ||
if (r) await r; | ||
} | ||
return m.exp; | ||
} | ||
|
||
function gExp(id) { | ||
if (!r.has(id)) return; | ||
const m = r.get(id); | ||
if (m.s) { | ||
const { d, e, s } = m; | ||
delete m.s; | ||
delete m.e; | ||
for (let i = 0; i < s.length; i++) s[i](gExp(d[i])); | ||
e(); | ||
} | ||
return m.exp; | ||
} | ||
__instantiate = (m, a) => { | ||
System = __instantiate = undefined; | ||
rF(m); | ||
return a ? gExpA(m) : gExp(m); | ||
}; | ||
})(); | ||
|
||
System.register("vendors", [], function (exports_1, context_1) { | ||
"use strict"; | ||
var vendors; | ||
var __moduleName = context_1 && context_1.id; | ||
return { | ||
setters: [], | ||
execute: function () { | ||
exports_1("vendors", vendors = [ | ||
"ah", | ||
"apple", | ||
"atsc", | ||
"epub", | ||
"fx", | ||
"hp", | ||
"khtml", | ||
"moz", | ||
"ms", | ||
"o", | ||
"rim", | ||
"ro", | ||
"tc", | ||
"wap", | ||
"webkit", | ||
"xv", | ||
]); | ||
} | ||
}; | ||
}); | ||
System.register("types/vendor", [], function (exports_2, context_2) { | ||
"use strict"; | ||
var __moduleName = context_2 && context_2.id; | ||
return { | ||
setters: [], | ||
execute: function () { | ||
} | ||
}; | ||
}); | ||
System.register("is_vendor", ["vendors"], function (exports_3, context_3) { | ||
"use strict"; | ||
var vendors_ts_1; | ||
var __moduleName = context_3 && context_3.id; | ||
function isVendor(vendor) { | ||
return vendors_ts_1.vendors.includes(vendor); | ||
} | ||
exports_3("isVendor", isVendor); | ||
return { | ||
setters: [ | ||
function (vendors_ts_1_1) { | ||
vendors_ts_1 = vendors_ts_1_1; | ||
} | ||
], | ||
execute: function () { | ||
} | ||
}; | ||
}); | ||
System.register("mod", ["vendors", "is_vendor"], function (exports_4, context_4) { | ||
"use strict"; | ||
var __moduleName = context_4 && context_4.id; | ||
return { | ||
setters: [ | ||
function (vendors_ts_2_1) { | ||
exports_4({ | ||
"vendors": vendors_ts_2_1["vendors"] | ||
}); | ||
}, | ||
function (is_vendor_ts_1_1) { | ||
exports_4({ | ||
"isVendor": is_vendor_ts_1_1["isVendor"] | ||
}); | ||
} | ||
], | ||
execute: function () { | ||
} | ||
}; | ||
}); | ||
|
||
const __exp = __instantiate("mod", false); | ||
export const Vendor = __exp["Vendor"]; | ||
export const vendors = __exp["vendors"]; | ||
export const isVendor = __exp["isVendor"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { Vendor } from "./types/vendor.ts"; | ||
import { vendors } from "./vendors.ts"; | ||
|
||
/** | ||
* Returns whether a given `vendor` string is an official vendor. | ||
* | ||
* @param vendor the given vendor string | ||
* @returns boolean for if the `vendor` argument is in the `vendors` list | ||
*/ | ||
export function isVendor(vendor: string) { | ||
return vendors.includes(<Vendor> vendor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,3 @@ | ||
const venders = [ | ||
"ah", | ||
"apple", | ||
"atsc", | ||
"epub", | ||
"hp", | ||
"khtml", | ||
"moz", | ||
"ms", | ||
"o", | ||
"rim", | ||
"ro", | ||
"tc", | ||
"wap", | ||
"webkit", | ||
"xv", | ||
] as const; | ||
|
||
export default venders; | ||
export type { Vendor } from "./types/vendor.ts"; | ||
export { vendors } from "./vendors.ts"; | ||
export { isVendor } from "./is_vendor.ts"; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { | ||
assert, | ||
assertStrictEquals, | ||
} from "https://deno.land/std@0.69.0/testing/asserts.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { assert } from "./deps.ts"; | ||
|
||
import { isVendor, vendors } from "../mod.ts"; | ||
|
||
Deno.test("isVendor()", () => { | ||
for (const vendor of vendors) { | ||
assert(isVendor(vendor), `\`isVendor("${vendor}")\` should return true`); | ||
} | ||
|
||
const falseVendors = ["", "not a vendor", "def not a vendor"]; | ||
for (const falseVendor of falseVendors) { | ||
assert( | ||
!isVendor(falseVendor), | ||
`\`isVendor("${falseVendor}")\` should return false`, | ||
); | ||
} | ||
}); |
Oops, something went wrong.