https://github.com/tiaanduplessis/pika
Efficient DOM element selection in 427 bytes (gzipped)
https://github.com/tiaanduplessis/pika
dom elements selector
Last synced: 9 months ago
JSON representation
Efficient DOM element selection in 427 bytes (gzipped)
- Host: GitHub
- URL: https://github.com/tiaanduplessis/pika
- Owner: tiaanduplessis
- License: mit
- Created: 2017-07-11T21:09:47.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-11-21T10:27:34.000Z (over 6 years ago)
- Last Synced: 2024-08-11T00:52:12.802Z (over 1 year ago)
- Topics: dom, elements, selector
- Language: JavaScript
- Homepage:
- Size: 95.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pika
> Efficient DOM element selection in 427 bytes (gzipped)
[](https://npmjs.org/package/@tiaanduplessis/pika)
[](https://npmjs.org/package/@tiaanduplessis/pika)
[](https://github.com/feross/standard)
[](https://greenkeeper.io)
[](https://travis-ci.org/tiaanduplessis/pika)
[](https://github.com/tiaanduplessis/pika/blob/master/LICENSE)
[](http://makeapullrequest.com)
## Table of Contents
- [Install](#install)
- [Usage](#usage)
- [Contribute](contribute)
- [License](#license)
## Install
```sh
$ npm install @tiaanduplessis/pika
# OR
$ yarn add @tiaanduplessis/pika
```
## Usage
The most relevant method for locating a DOM element will be chosen, because some times [`document.querySelector` won't do](https://jsperf.com/getelementbyid-vs-queryselector-vs-queryselector-by-id):
```js
import pika from '@tiaanduplessis/pika'
pika('body') // document.body
pika('head') // document.head
pika('#foo') // document.getElementById
pika('.foo') // document.getElementsByClassName
pika('div') // document.getElementsByTagName
pika('[value]') // document.querySelectorAll
```
You can optionally specify your own context(defaults to `document`):
```js
// find span within #foo
pika('span', { context: pika('#foo') })
```
If the `first` option is specified and their is only one element that matches the selector, that element will be returned instead of a array.
## Contributing
Contributions are welcome!
1. Fork it.
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D
Or open up [a issue](https://github.com/tiaanduplessis/pika/issues).
## License
Licensed under the MIT License.