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

cannibalizr

v3.0.8

Published

Turns an old pile of rusty files into a new json data source

Downloads

81

Readme

Cannibalizr

npm version Verify Coverage Status

A tool to pull strings from multiple files into a json file using regexes.

What?

"Turns an old pile of rusty files into a shiny, new json data source!"

This tool pulls select strings from multiple files and writes them to a structured json file. So, it allows you to use those files as input to something else, making them the single source of truth.

This is not the tool you are looking for.

Use this as a last resort.

By nature, this is a brittle solution as the input files will (presumably) change over time, and inevitably evade your capturing regexes at some point. The usefulness of this tool depends on your regexes and the nature of the input they capture against (and other viable options available to you in your timeframe).

Ideally, you should never have to do this, but sometimes, things are not ideal. However, if there are strings in your code that are NOT easy available in any other data form (I'm looking at you, asset references in CSS), this could be a useful way to keep DRY without overcomplicating things.

Example using all options

import cannibalizr from 'cannibalizr';

cannibalizr({
  output: {
    // manifest is an optional object with arbitrary data to store in the output
    manifest: {
      id: 123,
      version: '0.1.0',
      whatever: 'data I want here'
    }
    file: 'data.json' // the json output file path, always overwritten.
  },
  input: {
    someIdentifier: [{
      file: 'somefile.css',
      captures: [{
        global: true, // true if the regex is global (/g)
        matchIndex: 1, // the match index to pull data from
        re: /url\(([^\)]+)\)/ig // the actual regex
      }]
    }],
    anotherIdentifier: [{
      file: 'somefile.js',
      captures: [{
        global: false,
        matchIndex: 1,
        re: /xhrPath\s*\:\s*(?:'|")([^'"]+)/
      }]
    }]
  },
  // A logging function. If omitted, nothing is logged.
  logger: console.log
});

// data.json:
{
  "manifest": {
    "id": 123,
    "version": "0.1.0",
    "whatever": "data I want here"
  },
  "someIdentifier": [
    "//fonts.gstatic.com/s/sourcesanspro/v9/guid.woff2",
    "//fonts.gstatic.com/s/sourcesanspro/v9/guid.woff",
    "//fonts.gstatic.com/s/sourcesanspro/v9/guid.ttf"
  ]
  "anotherIdentifier": [
    "/api"
  ]
}