Skip to content

Instantly share code, notes, and snippets.

export default function *filterMap (predicate, mapFn, it) {
let i = 0,
j = 0;
for (const x of it) {
if (predicate(x, i++, it))
yield mapFn(x, j++, it);
}
};
"use strict";
const fs = require("fs"),
fsP = fs.promises;
const path = require("path");
const { chdir, cwd } = process;
async function removeEVERYTHING (targetDir) {
const oldDir = cwd();
chdir(targetDir);
"use strict";
/**
* @param {string} tagName .
* @param {object} [options] .
* @param {string} options.className - The CSS class(es) to give to the node. Takes precedence over classList
* @param {string[]} options.classList - The CSS classes to give to the node
* @param {object<string, (string|number)>} options.style - The CSS style(s) to additionally give to the node
* @param {string} options.textContent - The content of the node
* @param {...<string, (string|number)>} options.attributes - Any other attributes to give to the node
@Phoenix35
Phoenix35 / util-sort.mjs
Last active May 4, 2019 22:32
A few utility functions to make sorting easier
function shallowCompare (comparator, prop) {
return ({ [prop]: a }, { [prop]: b }) => comparator(a, b);
}
function deepCompare (comparator, props) {
return (aRoot, bRoot) => {
let a = aRoot,
b = bRoot;
for (const prop of props) {
"use strict";
const fsP = require("fs").promises;
const path = require("path");
const { cwd, chdir } = process;
/*
Breadth-first
*/
/**
@Phoenix35
Phoenix35 / prepareAsync.js
Last active April 6, 2019 02:37
Small utility function to delay async operations
/**
* prepareAsync - Wraps an asynchronous function to be called several times with a delay between each call.
* @param {AsyncFunction} cb - The callback to wait for
* @param {number} delay - The delay (in milliseconds) between each call
* @param {Function} onFulfill - Function called after each success
* @param {Function} onError - Function to handle errors thrown during the resolutions of `cb` AND `onFulfill`
* @return {AsyncIterable}
*/
export default function prepareAsync (cb, delay, onFulfill, onError) {
const sleep = { then (resolve) {
"use strict";
/*
User-defined settings
*/
const protocol = "https"; // Change to http for old-school
/*
Begin!
*/
@Phoenix35
Phoenix35 / README.md
Last active December 4, 2018 11:35
JavaScript - where to start?

If you are completely new to JavaScript or programming in general, follow these steps:

0. Use an evergreen browser (Mozilla Firefox or Google Chrome)

  1. Install DevDocs desktop.
    In "Preferences", enable following documentation
    • CSS
    • DOM
    • DOM Events
  • ESLint
// Some generator fun!
// WORK IN PROGRESS
// Only accepts two arguments in the `cb` call for the moment
"use strict";
const cbOnPrev = ((reset) => Object.defineProperty(
function* cbOnPrev (cb) {
let a = yield; // Replace `yield` with `function.sent` once it's a thing
let b = yield a;
// If the Partial Application Syntax is not available, use this
// Code by Kusu
const partialBinder = ((hole, rest) => {
"use strict";
function partiallyBound(fn, args, ...missing) {
const argsLen = args.length;
const missingIter = missing[Symbol.iterator]();
for (let i = 0; i < argsLen; ++i) {
switch (args[i]) {