UNPKG

baseframe-js

Version:

Baseframe JS is a comprehensive suite of modular plugins and utilities designed for front-end development

20 lines (19 loc) 1.31 kB
import $be from 'base-elem-js'; import parseObjectFromString from './parseObjectFromString'; const { merge, toType, isArr, isStr, oa, af } = $be; // region DOM shortcuts const d = document, body = d.body, root = d.documentElement, isFunc = (fn) => toType(fn) === 'function', reflow = (elem) => elem.offsetHeight, docTop = () => document.documentElement.scrollTop || document.body.scrollTop || 0, noop = () => { }; // region plugin helpers const setParams = (defaults, options, dataOptions) => { const useOptions = toType(options) === 'object' ? options : {}; return merge([true], {}, defaults, useOptions, dataOptions); }; const getDataOptions = (el, evtName) => parseObjectFromString(el.dataset[evtName + 'Options']); // region string manipulation const kebabCase = (str) => str.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(); const camelCase = (str) => str.replace(/-./g, x => x.toUpperCase()[1]); const lowercaseFirstLetter = (str) => str.charAt(0).toLowerCase() + str.substring(1); // region device const isMobileOS = () => /Android|webOS|iPhone|iPad|iPod|Opera Mini/i.test(navigator.userAgent); export { d, body, root, oa, af, isArr, isFunc, isStr, reflow, docTop, noop, setParams, getDataOptions, kebabCase, camelCase, lowercaseFirstLetter, isMobileOS }; export default {};