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 🙏

© 2025 – Pkg Stats / Ryan Hefner

kirinuki-core

v3.1.0

Published

Parse html by CSS query selectors

Downloads

21

Readme

kirinuki-core npm version Build Status codecov

Kirinuki is a library that convert any html to JSON using CSS selectors.

Demo

https://rike422.github.io/kirinuki-core

Usage

Node.js

Parse string and build DOM by cheerio and extract JSON from that.

  • browser(schema: Object, node: string)

  • browser(schema: Object, node: string, context: object)


import { node as kirinuki } from 'kirinuki-core';
const html = `
<html>
  <head>
    <title>Hero News!</title>
  </head>
  <body>
    <div class="main">
        <h3 class="topic">Amalgam</h3>
        <ul class="news-list">
            <li>
              <span class="content">Batman come back in Gossam City!</span>
              <img class="thumbnail" src="https://exmaple.com/batman.png"></img>
            </li>
            <li>
              <span class="content">Dr. Strange got into a traffic accident.</span>
              <img  class="thumbnail" src="https://exmaple.com/strange.png"></img>
            </li>
        </ul>
    </div>
  </body>
</html>
`;
const schema = {
  topic: {
    content: ".content",
    contents: ".content"
  }
}

kirinuki(schema, html)
// > { topic: { 
// content: 'Batman come back in Gossam City!' 
// contents: [
//  'Batman come back in Gossam City!',
//  'Dr. Strange got into a traffic accident.',
// ]
// } }

Text Node

If you want to scrape text node in A tag, you can do it in follow code


const html = `

<div class="sub">
  <ul class="sub-news-list">
    <li>
      <a href="https://example.com/stark.png">close in on the "truth" of Stark industries.</a>
    </li>
    <li>
      <a href="https://example.com/mvp.png">MVP of the month.</a>
    </li>
  </ul>
</div>
`
const schema = 
  { 
    topics: { 
      _unfold: true,
      title: [".sub-news-list a", "text"],
      link: ".sub-news-list a"
   } 
}

kirinuki(schema, html)

Auto complete

If url is a relative path and you want to change from that to absolute path, pass context object. Relative paths are convert by origin property

const html = `
<div class="main">
  <h3 class="topic">Amalgam</h3>
  <ul class="news-list">
    <li>
      <a href="/batman/news/1">
        <span class="content">Batman come back in Gossam City!</span>
      </a>
      <img class="thumbnail" src="/assets/batman.png"/>
    </li>
    <li>
      <a href="/dr_strage/news/1">
        <span class="content">Dr. Strange got into a traffic accident.</span>
      </a>
      <img class="thumbnail" src="/assets/strange.png"/>
    </li>
  </ul>
</div>
`

const context = {
  origin: 'https://example.com'
}

const schema = {
   unfoldTopics: {
        _unfold: true,
        content: ".news-list .content",
        image: ".news-list img",
         link: ".news-list a"
    },
    topics: {
        contents: ".news-list .content",
        images: ".news-list img",
        links: ".news-list a"
    }
}

kirinuki(schema, html, context)

// { unfoldTopics:
//    [ { content: 'Batman come back in Gossam City!',
//        image: 'https://example.com/assets/batman.png',
//        link: 'https://example.com/batman/news/1' },
//      { content: 'Dr. Strange got into a traffic accident.',
//        image: 'https://example.com/assets/strange.png',
//        link: 'https://example.com/dr_strage/news/1' } ],
//   topics:
//    { contents:
//       [ 'Batman come back in Gossam City!',
//         'Dr. Strange got into a traffic accident.' ],
//      images:
//       [ 'https://example.com/assets/batman.png',
//         'https://example.com/assets/strange.png' ],
//      links:
//       [ 'https://example.com/batman/news/1',
//         'https://example.com/dr_strage/news/1' ] } }```

browser

scrape to Doucment or HTMLElement by DOM API

  • browser(schema: Object, node: Document)
  • browser(schema: Object, node: HTMLElement)
  • browser(schema: Object, node: string)
  • browser(schema: Object) // auto assign to window.document to node variable
import { browser as kirinuki } from 'kirinuki-core';


const schema = {
  topic: {
    content: ".content",
    contents: ".content"
  }
}

kirinuki(schema)

// > { topic: { 
// content: 'Batman come back in Gossam City!' 
// contents: [
//  'Batman come back in Gossam City!',
//  'Dr. Strange got into a traffic accident.',
// ]
// } }

Standalone js file

kirinuki.standalone.js is builded at umd style, that is Included only libraries for browser javascript engien