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 function memoize (callback) { | |
| const cache = new Map() | |
| return (...args) => { | |
| const key = JSON.stringify(args) | |
| if (cache.has(key)) return cache.get(key); | |
| const result = callback(...args) | |
| cache.set(key, result); | |
| return result; | |
| } | |
| } |
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 prepExpression (e) { | |
| const returnText = 'return ' | |
| const inlineReturnPattern = /(?:\)|\n| |\}|\;|\:|\])return(?: |\(|\{|\[)/ | |
| const expression = e.startsWith(returnText) || inlineReturnPattern.test(e) ? e : returnText.concat(e) | |
| return `(function () {${expression};})();` | |
| } |
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 find (collection = [], matchObject = {}) { | |
| return (collection || []) | |
| .find(obj => Object.keys(matchObject).every(key => obj[key] === matchObject[key])) || null; | |
| } | |
| function without (collection = [], matchObject = {}) { | |
| return collection.filter(obj => { | |
| return Object | |
| .keys(matchObject) | |
| .every(key => |
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
| // -- Example usage: | |
| // const demo = logger('@example') | |
| // -- can be used directly, | |
| // demo('oh my goodness') | |
| // -- or you can call the normal console fns | |
| // demo.info('Interesting message text', 'someVar to dump to console', [1,2,3,4]) | |
| const logger = (tagText) => { | |
| const l = (method = 'log') => (message, ...otherArgs) => { | |
| const tag = `[${tagText}]` |
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
| // Demo usage (run to see output) | |
| // Print 0-120: | |
| // (new Array(120)).fill({}).map((x,i) => ordinal(i)) | |
| // Print bolded html ordinal | |
| // ordinal(4, v => `<b>${v}</b>`) | |
| export function ordinal (number, wrapSuffix) { | |
| const chars = number.toString().split(''); | |
| const lastDigit = chars.pop() | |
| const secondToLastDigit = chars.pop(); |
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 strip (...selectors) { selectors.forEach(s => Array.from(document.querySelectorAll(s)).forEach(x => x.remove())) }; | |
| function destyle (x) { x.removeAttribute('style'); x.childNodes.forEach(c => c.nodeType == 1 ? destyle(c) : null) }; | |
| strip('style', 'link'); | |
| destyle(document.body); | |
| })(); |
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 function splitBySentences (givenText = '', additionalFalseEndings = []) { | |
| const text = givenText.trim() | |
| const initialisms = 'abcdefghijklmnopqrstuvwxyz'.split('') | |
| const commonFalseEndings = ['St', 'Rd', 'Ave', 'Mr', 'Mrs', 'Dr', 'Prof', 'Esq', 'Ln', 'Inc', 'Corp', 'Blvd', 'Pl', 'Av', 'Ct'] | |
| const falseEndings = [...commonFalseEndings, ...initialisms, ...additionalFalseEndings] | |
| .map(c => [c, c.toUpperCase(), c.toLowerCase()]) | |
| .flat() | |
| .reduce((o, v) => o.includes(v) ? o : o.concat(v), []) | |
| .map(c => ` ${c}. `) | |
| const toUniqueSymbol = (str) => `βΉΒ«!#ββ${falseEndings.indexOf(str)}ββ#!Β»βΊ` |
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 cursiveLetters = { | |
| A: 'π', | |
| B: 'π΅', | |
| C: 'π', | |
| D: 'π', | |
| E: 'πΈ', | |
| F: 'πΉ', | |
| G: 'π’', | |
| H: 'π»', |
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 blockLetters = { a: 'π°', b: 'π±', c: 'π²', d: 'π³', e: 'π΄', f: 'π΅', g: 'πΆ', h: 'π·', i: 'πΈ', j: 'πΉ', k: 'πΊ', l: 'π»', m: 'πΌ', n: 'π½', o: 'πΎ', p: 'πΏ', q: 'π ', r: 'π ', s: 'π ', t: 'π ', u: 'π ', v: 'π ', w: 'π ', x: 'π ', y: 'π ', z: 'π ' } | |
| const asBlockLetters = (text) => text.split('').map(c => c.toLowerCase() in blockLetters ? blockLetters[c.toLowerCase()] : c).join(''); | |
| asBlockLetters('BLOCK LETTERS') |
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 reverse (list) { | |
| return typeof list === 'string' | |
| ? list.split('').reduce((o, v) => `${v}${o}`, '') | |
| : Array.isArray(list) | |
| ? list.reduce((o, v) => [v, ...o], []) | |
| : TypeError('No array or string given'); | |
| } | |
| function chunkIntoN (list, n) { | |
| return (typeof list === 'string' ? list.split('') : list ? list : []).reduce((o, x) => { |
NewerOlder