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 delay = ms => new Promise(resolve => setTimeout(resolve, ms)) | |
const inc = async i => (await delay(500), ++i) | |
const foo = async () => { | |
for(let i = 1; i <= 5; i = await inc(i)) | |
console.log(i) // prints 1, 2, 3, 4, 5 with a delay | |
} | |
foo() |
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 isRTL(s){ | |
var ltrChars = 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF'+'\u2C00-\uFB1C\uFDFE-\uFE6F\uFEFD-\uFFFF', | |
rtlChars = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC', | |
rtlDirCheck = new RegExp('^[^'+ltrChars+']*['+rtlChars+']'); | |
return rtlDirCheck.test(s); | |
}; |
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
/** | |
* @param {string} s [HTML string] | |
*/ | |
function minify( s ){ | |
return s ? s | |
.replace(/\>[\r\n ]+\</g, "><") // Removes new lines and irrelevant spaces which might affect layout, and are better gone | |
.replace(/(<.*?>)|\s+/g, (m, $1) => $1 ? $1 : ' ') | |
.trim() | |
: "" | |
} |
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
/** | |
* Concatenates N arrays without dups. | |
* If an array's item is an Object, compare by `value` | |
* @param {*} k | |
*/ | |
export const concatWithoutDups = (...key) => { | |
const result = (...args) => { | |
const newArr = [], | |
existingObj = {}; |
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 removeStyleProp = (elm, prop) => | |
elm.style.cssText = elm.style.cssText // cssText automatically (luckily) adds spaces between declarations | |
.split('; ') | |
.filter(p => !p.startsWith(prop) ) | |
.join(';'); |
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
/***** ceil ******/ | |
/* For a value between 0 - 1, where 1 is the maximum possible */ | |
--ceil: clamp(0, calc((1 - var(--value)) * 100), 1); | |
/***** floor ******/ | |
/* For a value between 0 - 1, where 1 is the maximum possible, use a value just a tiny bit below the maximum for the | |
math to work, so the output will be either positive or negative when magnified by a factor of 999999*/ |
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
// https://css-tricks.com/css-switch-case-conditions | |
// simplified version of my method: | |
.foo { | |
--feature: 1; // 1 is "on", 0 is "off" | |
animation: foo_styles 1s calc(-1s * (var(--feature) - 1)) paused; | |
@keyframes foo_styles { | |
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
JSON.parse = (JP => (...args) => { | |
try { return JP(...args) } catch{} | |
})(JSON.parse) |
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
import { Meta, Description, Props, Source, Canvas } from '@storybook/addon-docs/blocks'; | |
import Comp from './Comp'; | |
import CompRaw from '!raw-loader!./Comp.jsx'; | |
import readme from '!raw-loader!./readme.md'; | |
<Meta | |
title="Comp/MDX" | |
component={Comp} | |
/> |
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
import {isString} from 'utility/types'; | |
export const VERSION = 1; // current version of persisted data. if code change breaks persisted data, verison number should be bumped. | |
export const STORAGE_KEY_PREFIX = 'amdocs/catalog'; | |
/** | |
* checks arguments are as expected | |
* @param {string} keyName | |
* @param {string} type | |
* @returns boolean |
NewerOlder