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
function isArray(target) { | |
return Object.prototype.toString.call(target) === "[object Array]"; | |
} | |
function isClassSelector(selector) { | |
return /^\.[\w-]+$/.test(selector); | |
} | |
function getSelector(array) { | |
if (!array || !array.length) return; |
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
function separator(array, delimiter) { | |
let len = array.length; | |
const arr = new Array(len * 2 - 1).fill(0); | |
return arr.reduceRight((p, _, i) => | |
[ | |
i % 2 === 0 | |
? array[--len] |
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
function getBase64Image(img: HTMLImageElement) { | |
const canvas = document.createElement('canvas') | |
canvas.width = img.width | |
canvas.height = img.height | |
const ctx = canvas.getContext('2d') | |
ctx.drawImage(img, 0, 0) | |
const dataURL = canvas.toDataURL('image/png') | |
return dataURL.replace(/^data:image\/(png|jpg);base64,/, '') |
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
function delegationEvent( | |
type: string, | |
target: HTMLElement, | |
selector: string, | |
callback: ( | |
this: HTMLElement | null, | |
event: Event, | |
element: HTMLElement | null | |
) => any | |
) { |
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 DELIMITER = "," | |
const GROUP_QUOTES = ['"', "'"] | |
function parse(input: string) { | |
const rows = input.trim().split(/\r?\n/) | |
return rows.map((row, rowIndex) => { | |
let [start, cursor, end] = [0, 0, row.length - 1] | |
const fields: string[] = [] |