Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tealight

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tealight

Enhanced query selector API

  • 0.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.4K
decreased by-23.07%
Maintainers
1
Weekly downloads
 
Created
Source

tealight

ES2015 module for DOM queries.

Build status Coverage Version 0.4KB min+gzip MIT License

Browser compatibility matrix



Installation

Browser

A simple and fast way to get started is to include this script on your page:

<script src="https://unpkg.com/tealight"></script>

This will create the global variable tealight.

Module

$ npm install tealight
CommonJS
const tealight = require('tealight')
ES2015
import tealight from 'tealight'


Usage

tealight accepts a single argument, target, and will always return an array of 0 or more DOM nodes.

tealight(target) => Array<Node>

For the examples below, assume we have this HTML fragment to query against:

<div id="jar">
	<div class="chocolate-chip cookie"></div>
	<div class="peanut-butter cookie"></div>
	<div class="short-bread cookie"></div>
</div>

tealight(String<Selector>)

String arguments will be used as DOM query selectors.

tealight('#jar')
// => [ <div#jar> ]
tealight('.cookie')
// => [ <div.chocolate-chip.cookie>, <div.peanut-butter.cookie>, <div.short-bread.cookie> ]

Keep in mind that document.querySelectorAll throws an error when passed an invalid selector (requiring a try/catch block), whereas tealight will swallow the error and return an empty array.


tealight(Node)

Node arguments will be wrapped in an Array.

const node = document.querySelector('#jar')

tealight(node)
// => [ <div#jar> ]

tealight(NodeList)

NodeList arguments will be converted to Array.

const nodeList = document.querySelectorAll('.cookie')

tealight(nodeList)
// => [ <div.chocolate-chip.cookie>, <div.peanut-butter.cookie>, <div.short-bread.cookie> ]

tealight(Array)

Array arguments will be filtered, leaving only Node items.

const node = document.querySelector('#jar')
const array = [node, null, '.cookie']

tealight(array)
// => [ <div#jar> ]


© 2018 FISSSION, LLC.
Open source under the MIT License.

Keywords

FAQs

Package last updated on 25 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc