npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

camel-case-selector

v1.0.1

Published

DOM elements selector with camel case class names

Downloads

8

Readme

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); //function

  console.log(document.querySelector('div') === S('div')[0]) //true

  var $div = document.querySelector('div');
  console.log(S($div) === $div); //true

  console.log(S() === document); //true

  console.log(S(document) === document); //true

  console.log(S(window) === window); //true

  console.log(S('html')); //prints array with first element html
  console.log(S('div')); //prints all divs in array

####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 parent
  S(window) //S parent
  S(document) //S parent
  S('div') // S parent

  var $div = document.querySelector('div');
  S($div) //S parent

  var $divs = document.querySelectorAll('div');
  S($divs) //S parent (parents)

#####Query function is properties (or methods) of S parent

	S.query[special_query_selector] //query_selector is special selector. See below
    S.queryAll[special_query_selector]
    S.query(query_selector) //query_selector is simple string 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); //first div element in DOM
    
    var $divs = S.queryAll.div;
	console.log($divs); //all divs in DOM

	var $as = S.query.nav.query.ul.queryAll.li.queryAll.a;
	console.log($as); //all a elements in navigation bar
    
    //alternatives using simple DOM selectors
    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'); //selects all divs of #MainContent
    S.query.Wrapper.query.ContentWrapper.queryAll.div; //selects all divs of #ContentWrapper of #Wrapper

######To select elements by class names use dynamic property as class ame in camel case format:

	S.queryAll.redButton; //selects all elements with class name red-button
    S.query.multipleForm.queryAll.input; //selects all input elements of first element with class name multiple-form
    
    /*if class name property is same as one of the html tag, priority is to html tag. E.g.:*/
    
    S.queryAll.form; //if DOM element has class name form (<div class="form"></div>, returns the form element (by tag name) or null if no form elements in DOM
    
    

####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

	//Queries all li items in navigation bar
	S.query.MainContent.query.header.query.nav.queryAll.li;
    
    //Queries first section
    S.query.MainContent.queryAll.section[0];
    
    //Queries second section paragraph
    S.query.MainContent.query.sampleSection.query.p;
    
    //Queries mobile phone element in footer (using dynamic property)
    var mobile_phone = 'mobilePhone';
    S.query.Contacts.query[mobile_phone];
    
    //Queries address element with simple query
    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.