Skip to content

Instantly share code, notes, and snippets.

@blivesta
Last active October 11, 2017 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blivesta/752032e9dcc150ff20c191be98f72e7a to your computer and use it in GitHub Desktop.
Save blivesta/752032e9dcc150ff20c191be98f72e7a to your computer and use it in GitHub Desktop.
selectors
/**
* 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
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