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 counter = (min, max, initial) => { | |
| let index = initial - min | |
| let length = max - min + 1 | |
| return (modifier = 0) => { | |
| index = (index + modifier) % length | |
| if (index>=0) index = 0 + index |
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 toggler = (initState) => { | |
| initState = initState!==false | |
| let state = initState | |
| return { | |
| get : () => state, | |
| reset : () => state = initState, | |
| toggle : () => state = !state, |
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 select = (query, elem = null) => { | |
| elem = (elem==null ? document : elem) | |
| let elems = elem.querySelectorAll(query) | |
| if (elems==null) return [] | |
| else return Array.prototype.slice.call(elems, 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
| const debounce = function(fn, duration) { | |
| let timeout = null | |
| return (...args) => { | |
| clearTimeout(timeout) | |
| timeout = setTimeout(() => fn(...args), duration) |
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 hasTouchscreen = () => { | |
| const mobileDevice = (/Android|iPhone|iPad|iPod/i).test(navigator.userAgent || navigator.vendor || window.opera) | |
| const onTouchEnd = ('ontouchend' in document.documentElement) | |
| return (mobileDevice && onTouchEnd) | |
| } |
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 nicetry = (fn) => { | |
| try { return fn() } | |
| catch (e) {} | |
| } |
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 decodeHTML = (str) => { | |
| const elem = document.createElement('div') | |
| elem.innerHTML = str | |
| return (elem.childNodes.length===0 ? '' : elem.childNodes[0].nodeValue) | |
| } |
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 hasLocalStorage = () => { | |
| const tmp = 'tmp' | |
| try { | |
| localStorage.setItem(tmp, tmp) | |
| localStorage.removeItem(tmp) | |
| return true |
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
| mime { | |
| .atom application/atom+xml | |
| .json application/json | |
| .map application/json | |
| .topojson application/json | |
| .jsonld application/ld+json | |
| .rss application/rss+xml | |
| .geojson application/vnd.geo+json | |
| .rdf application/xml | |
| .xml application/xml |
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 formatNumber = (num, delimiter = ',') => num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, delimiter) |