camel-case-selector
npm install --save camel-case-selector
or
yarn add camel-case-selector
Usage
import S from 'camel-case-selector';
Generic rules and types
console.log(typeof S);
console.log(document.querySelector('div') === S('div')[0])
var $div = document.querySelector('div');
console.log(S($div) === $div);
console.log(S() === document);
console.log(S(document) === document);
console.log(S(window) === window);
console.log(S('html'));
console.log(S('div'));
####Query chaining
#####To query dom element use chaining method.
S parent -> query function -> [special query selector] -> ...
#####S parent is dom element (elements) or selector (string type) wrapper with S function
S
S(window)
S(document)
S('div')
var $div = document.querySelector('div');
S($div)
var $divs = document.querySelectorAll('div');
S($divs)
#####Query function is properties (or methods) of S parent
S.query[special_query_selector]
S.queryAll[special_query_selector]
S.query(query_selector)
S.queryAll(query_selector)
#####Special selector is dynamic property which selects child (or childs) of parent (or parents) in DOM
######To select elements by tag name use dynamic property as tag name:
var $div = S.query.div;
console.log($div);
var $divs = S.queryAll.div;
console.log($divs);
var $as = S.query.nav.query.ul.queryAll.li.queryAll.a;
console.log($as);
var $div = S('html').query('div');
var $divs = S('html').queryAll('div');
var $as = S('html nav').queryAll('ul').queryAll('li').queryAll('a');
######To select elements by ID use dynamic property as ID in upper camel case format:
Id's in DOM must be in upper camel case format: MainContent, Wrapper, ContentWrapper and etc.
S.query.MainContent.queryAll('div');
S.query.Wrapper.query.ContentWrapper.queryAll.div;
######To select elements by class names use dynamic property as class ame in camel case format:
S.queryAll.redButton;
S.query.multipleForm.queryAll.input;
S.queryAll.form;
####Example
Suppose we have the following html markup
<div id="MainContent">
<main>
<header>
<nav>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</nav>
</header>
<article>
<section id="FirstSection">
<h1>Heading 1</h1>
<p>Paragraph 1</p>
</section>
<section id="SecondSection" class="sample-section">
<h2>Heading 2</h2>
<p>Paragraph 2</p>
</section>
</article>
<footer>
<div id="Contacts">
<div class="mobile-phone">xxxxxxx</div>
<div class="address">xxxxxxx</div>
</div>
<footer>
</main>
</div>
Queries examples
S.query.MainContent.query.header.query.nav.queryAll.li;
S.query.MainContent.queryAll.section[0];
S.query.MainContent.query.sampleSection.query.p;
var mobile_phone = 'mobilePhone';
S.query.Contacts.query[mobile_phone];
S.query.MainContent.query('#Contacts .address');
###Author
Edvinas pranka
https://www.ceonnel.lt
License
The MIT License (MIT)
Copyright (c) 2017 Edvinas Pranka
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.