View args.ts
import * as fs from "https://deno.land/std@0.93.0/fs/mod.ts"; | |
import * as path from "https://deno.land/std@0.93.0/path/mod.ts"; | |
export default () => { | |
let [execCmdTemplate, basedir = ".", fileExt = ""] = Deno.args; | |
if (!execCmdTemplate) throw new Error("No command was given"); | |
if (!basedir || !fs.existsSync(basedir)) throw new Error("DIR doesn't exist"); | |
basedir = path.resolve(".", basedir); | |
return { execCmdTemplate, basedir, fileExt }; | |
} |
View dl.ts
import { Timeout, TimeoutError } from "https://deno.land/x/timeout/mod.ts" | |
export default async function download( | |
source: string, | |
destination: string | |
): Promise<boolean> { | |
try { | |
const req = fetch(source); | |
const response = await Timeout.race([req], 5000); | |
const blob = await response.blob(); |
View fetcher.js
const fetch = require('node-fetch') | |
module.exports = async ({q, url}) => | |
fetch( | |
url | |
? decodeURIComponent(url) | |
: `https://en.wikipedia.org/wiki/${decodeURIComponent(q)}` | |
).then(res => res.text()) |
View fetch-file.js
const fs = require("fs"); | |
const fetch = require("node-fetch"); | |
function dl(url, destFilename) { | |
return new Promise((resolve, reject) => { | |
fetch(url).then((res) => { | |
res.body.pipe(fs.createWriteStream(destFilename)) | |
res.body.on('end', resolve) | |
res.body.on('error', reject) | |
}).catch(reject) |
View file-logger.js
const newFileLogger = (filename, init = false) => { | |
if (init) fs.writeFileSync(filename, '', 'utf8'); // wipe/reset | |
return (...lines) => { | |
fs.appendFileSync( | |
filename, | |
lines | |
.map(l => JSON.stringify(l, null, 2)) | |
.join('\n') + '\n', | |
'utf8' | |
) |
View by-line-lib.js
const fs = require("fs"); | |
const readline = require("readline"); | |
const byLine = async ({file, handleLine, charset="utf8"}) => { | |
return new Promise((done, err) => { | |
if (!fs.existsSync(file)) { | |
return err(new Error('File not found!')); | |
} | |
const rl = readline.createInterface({ | |
input: fs.createReadStream(file, charset), |
View lock.js
function newThrottler({isBusy, lock, unlock, waitMs}) { | |
const delay = (ms) => new Promise((r) => setTimeout(r, ms)); | |
return async function throttler(cb, ...args) { | |
while (isBusy()) { | |
await delay(waitMs()); | |
} | |
lock(); | |
// ... DO ALL WORK for result |
View listify.js
// see: https://kentcdodds.com/blog/listify-a-java-script-array | |
function listify( | |
array, | |
{ | |
type = 'conjunction', | |
style = 'long', | |
stringify = JSON.stringify, | |
lang = 'en' | |
} = {} |
View scramble.css
@import 'https://fonts.googleapis.com/css?family=Roboto+Mono:100'; | |
html, | |
body { | |
font-family: 'Roboto Mono', monospace; | |
background: #212121; | |
height: 100%; | |
} | |
.container { | |
height: 100%; |
View escalade-test.js
const e = require("./escalade"); | |
(async () => { | |
// A - for-await-of loop | |
let g = e(__dirname); | |
for await (const { dir, filenames } of g) { | |
console.log(dir, filenames); | |
} | |
// B - .next() |
NewerOlder