/
eb
/
js-excel
Обзор
Документация
Войти
/
eb
/
js-excel
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/core/utils.js
64 строки
1 KB
Evgeniy Budaev
Routing implemented
17 июн 2020, 10:58
17 июн 2020, 10:58
6622668
Код
Авторство
О чём код?
// Pure functions export function capitalize(string) { if (typeof string !== 'string') { return '' } return string.charAt(0).toUpperCase() + string.slice(1) } export function range(start, end) { if (start > end) { [end, start] = [start, end] } return new Array(end - start + 1) .fill('') .map((_, index) => start + index) } // input: 0, 3 // output: [0, 1, 2, 3] export function storage(key, data = null) { if (!data) { return JSON.parse(localStorage.getItem(key)) } localStorage.setItem(key, JSON.stringify(data)) } export function isEqual(a, b) { if (typeof a === 'object' && b === 'object') { return JSON.stringify(a) === JSON.stringify(b) } return a === b } export function camelToDashCase(str) { return str.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`) } export function toInlineStyles(styles = {}) { return Object.keys(styles) .map(key => `${camelToDashCase(key)}:${styles[key]}`) .join(';') } export function debounce(fn, wait) { let timeout return function(...args) { const later = () => { clearTimeout(timeout) // eslint-disable-next-line fn.apply(this, args) } clearTimeout(timeout) timeout = setTimeout(later, wait) } } export function clone(obj) { return JSON.parse(JSON.stringify(obj)) } export function preventDefault(event) { event.preventDefault() }