getVariable(domElement, '--example')
// 'hello'
getVariable(domElement, '--example', (v) => parseInt(v, 36))
// 29234652
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 copyTextToClipboard = async (text: string) => { | |
| await navigator.clipboard.writeText(text) | |
| } |
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 capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1) |
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 randomNumberInRange = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min |
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 createElement(html, className) { | |
| return Object.assign(document.createElement('div', { | |
| className, | |
| innerHtml: html, | |
| })) | |
| } |
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
| /** | |
| * Plural forms for russian words | |
| * @param {Integer} count quantity for word | |
| * @param {Array} words Array of words. Example: ['депутат', 'депутата', 'депутатов'], ['коментарий', 'коментария', 'комментариев'] | |
| * @return {String} Count + plural form for word | |
| */ | |
| function pluralize(count, words) { | |
| var cases = [2, 0, 1, 1, 1, 2]; | |
| return count + ' ' + words[ (count % 100 > 4 && count % 100 < 20) ? 2 : cases[ Math.min(count % 10, 5)] ]; | |
| } |
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
| document.querySelectorAll('[data-js]') | |
| // will get you all elements with this attribute. | |
| document.querySelectorAll('[data-js="someFooElement"]') | |
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
| let cacheMap = new Map() | |
| let fib = n => { | |
| if (cacheMap.has(n)) { | |
| return cacheMap.get(n) | |
| } | |
| let result = n <= 1 ? n : fib(n - 1) + fib(n - 2) | |
| cacheMap.set(n, result) | |
| return result | |
| } | |
| fib(15) |
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 debounce(func, ms) { | |
| let timeout | |
| return function () { | |
| clearTimeout(timeout) | |
| timeout = setTimeout(() => func.apply(this, arguments), ms) | |
| } | |
| } |
NewerOlder