This file contains hidden or 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
const fs = require("fs"); | |
const stream = fs.createWriteStream("./fake-read-stream"); | |
const fakeReadableStream = new (class { | |
readable = true; | |
constructor() { | |
this.data = | |
"abc ewij fj wiefj ewi tj94htr834h u4 hru4 u9jr92i3 i09rj 239ij erw9i fgj3u94it 34i9 tj"; | |
this.cursor = 0; |
This file contains hidden or 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
/** | |
Only .ai file with PDF compatible. | |
Except IE... | |
*/ | |
const AI_FILE_DIR = './test.ai' | |
const main = async () => { try { | |
const res = await fetch(AI_FILE_DIR) | |
const originBlob = await res.blob() |
This file contains hidden or 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
const isp = v => v === curry._; | |
const memo = fn => { | |
const cache = {}; | |
return (...p) => { | |
const key = JSON.stringify(p); | |
return key in cache ? cache[key] : cache[key] = fn(...p); | |
} | |
}; | |
function curry(fn, length = fn.length) { | |
if (length === 0) return fn; |
This file contains hidden or 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
const p1Cache = f => { | |
const store = new Map; | |
console.log(store); | |
return a => store.has(a) ? store.get(a) : store.set(a, f(a)).get(a); | |
}; | |
const p2Cache = f => { | |
const store = new Map; | |
return (a, b) => { |
This file contains hidden or 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
class ArrayMap extends Map { | |
constructor(...params) { | |
super(); | |
params.forEach(([key, value]) => this.set(key, value)); | |
} | |
set(key, value) { | |
const len = key.length; | |
const cp = [...key]; | |
let chn = super.has(len) ? super.get(len) : (super.set(len, new Map),super.get(len)); | |
let prop = cp.shift(); |
This file contains hidden or 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
const range = (first, last, dist = (last - first) / Math.abs(last - first)) => Array.from({length: Math.ceil((last - first) / dist)}, (_, i) => first + i * dist); |
This file contains hidden or 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
export type PointerType = 'pointerdown'|'pointermove'|'pointerup'|'scroll'; | |
export interface CursorCoordinate { | |
type: PointerType; | |
x: number; | |
y: number; | |
dx?: number; | |
dy?: number; | |
} |
This file contains hidden or 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
class TPromise<T> extends Promise<T> { | |
static TimeoutError = class extends Error {}; | |
constructor( | |
f: ( | |
resolve: (value: T | PromiseLike<T>) => void, | |
reject: (reason?: any) => void | |
) => void, | |
timeout: number = Infinity | |
) { |
This file contains hidden or 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
const loadImage = ( | |
src: string, | |
{ | |
save = true, | |
timeout = Infinity, | |
crossOrigin, | |
}: Partial<{ | |
save: boolean; | |
timeout: number; | |
crossOrigin: string; |
This file contains hidden or 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
class TPromise<T> extends Promise<T> { | |
static TimeoutError = class extends Error {}; | |
constructor( | |
f: ( | |
resolve: (value: T | PromiseLike<T>) => void, | |
reject: (reason?: any) => void | |
) => void, | |
timeout: number = Infinity | |
) { |