Last active
October 11, 2017 13:38
-
-
Save blivesta/752032e9dcc150ff20c191be98f72e7a to your computer and use it in GitHub Desktop.
selectors
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
/** | |
* canUseDOM | |
* @return {Boolean} | |
*/ | |
export const canUseDOM = !!( | |
typeof window !== 'undefined' && window.document && window.document.createElement | |
) | |
/** | |
* win | |
* @return {Boolean} | |
*/ | |
export const win = canUseDOM ? window : null | |
/** | |
* doc | |
* @return {Boolean} | |
*/ | |
export const doc = canUseDOM ? document : null |
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 { canUseDOM, doc } from './dom' | |
/** | |
* $$ | |
* @param {element} selector | |
* @param {element} context | |
* @return {object} | |
*/ | |
export function $$ (selector, context = null) { | |
if (!selector) return | |
return (context == null ? doc : context).querySelector(selector) | |
} | |
/** | |
* $$$ | |
* @param {element} selector | |
* @param {element} context | |
* @return {array} | |
*/ | |
export function $$$ (selector, context = null) { | |
if (!selector) return | |
const elms = (context == null ? doc : context).querySelectorAll(selector) | |
return Array.apply(null, elms) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment