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 🙏

© 2026 – Pkg Stats / Ryan Hefner

c3s

v0.0.14

Published

use css selector to select js object content.

Readme

c3s

CSS Selector, use css selector to select js object content.

Code Example

var root = {
  a: {
    b: {
      c:'c-val'
    }
  }
}

c3s(root).selectOne('b>c');
// get "c-val"

more demo

Installation

npm install c3s

Support Syntax

Elemental selectors

  • prop select property value which name is prop
  • * select any property

Attribute selectors

  • #idVal select object which contain id、Id or ID property and this property value is idVal

  • .classVal select object which constructor.name is classVal

  • [att] select contain att property object

  • [att=val] select object which contain att property and this property value(toString()) is val

  • [att^=val] select object which contain att property and this property value(toString()) begins with val

  • [att$=val] select object which contain att property and this property value(toString()) ends with val

  • [att*=val] select object which contain att property and this property value(toString()) contains val

  • [att=val i] case insensitive

Pseudo-classes

  • :regexpTest(arg) select match regexp's arg value

  • :equal(arg) select equal arg value

  • :type(arg) select type equal arg value

You can define new pseudo-class in c3s option.pseudoClasses, ex:

c3s(root, {
  pseudoClasses: {
    newClass: function (
      nodeInfo, // current search results, nodeInfo instance
      arg, // arguments in selector statement
      /* arg2, ... */
    ) {
      /* 
      return 
        Truthy, select this node
        Falsy, don't select this node
    */
    }
  }
})
.selectOne(':newClass, :newClass(arg), :newClass("arg1", 3.14)');

Combinators

  • prop1 prop2 search prop1 property and contain object property, if statement start isn't Combinator, prepend  , ex: prop1 =  prop1

  • prop1>prop2 search prop1 property

  • prop1~prop2 seach prop1 sibling property

API Reference

c3s

create and return Selector instance by paramters

var root = { a : { b: { c: 'target' } } };
c3s(root, {});

Returns

Selector instance by paramters

Parameters

  • root: object, search target
  • option: object
    • pseudoClasses: object, declare new pseudo-class

c3s.getByPath

get value on path form root, if path is not found, return undefined

var root = { a : { b: { c: 'target' } } };
c3s.getByPath(root, 'a/b/c'); 
// 'target'

Returns

return search result

Parameters

  • root: object, search object
  • path: string, property path
  • delimiter: string, default = '/'

SelectorInstance.selectOne

get first match seach statement value and detail in root

var root = { a : { b: { c: 'target' } } };
c3s(root).selectOne('c');
// NodeInfos by 'target'

Returns

NodeInfo instance, contains the following parameters:

  • node: search result
  • path: property path from root to node
  • parent: all parents from root to node
  • root: object being queried

Parameters

  • input: string, search statement

SelectorInstance.selectAll

get all match seach statement values and detail in root

var root = { a : { 
  b: { c: 'target1' },
  c: 'target2'
} };
c3s(root).selectAll('c');
// NodeInfos by 'target1' and 'target2'

Returns

Array, contain match value NodeInfo instance

Parameters

  • input: string, search statement

SelectorInstance.getFromPath

get value on path form Selector search target, if path is not found, return undefined

var root = { a : { b: { c: 'target' } } };
c3s(root).getByPath('a/b/c');
// 'target'

Returns

return a NodeInfo Instance contain search result

Parameters

  • path: string, property path
  • delimiter: string, default = '/'

Tests

npm run test

debug

npm run debug