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

parse-json-config

v0.4.2

Published

Works like the way Babel parses its presets

Readme

parse-json-config

NPM version NPM downloads CircleCI codecov donate

Install

yarn add parse-json-config

Usage

const parse = require("parse-json-config");

parse(["foo", "bar"])[
  //=> return
  (require("$cwd/node_modules/foo")(), require("$cwd/node_modules/bar")())
];

Use options

To provide options while calling the function:

parse([["foo", options], "bar"])[
  //=> return
  (require("$cwd/node_modules/foo")(options),
  require("$cwd/node_modules/bar")())
];

Local path or function

You can also use a local path or function:

parse([
  function() {
    return "foo";
  },
  ["./bar.js", options]
])[
  //=> return
  (function() {
    return "foo";
  },
  require("$cwd/bar.js")(options))
];

If you're using a non-string, we directly return it without calling it with the options even if you provide it as [resolved, options], since if you can use a function / object as resolved you can already execute it yourself, but there's also a isCalled option for you to customize it.

By default relative path is resolve from process.cwd()

Custom caller

Each item in the config is in name or [name, options] format, by default we directly call the name with option as the only argument, but you can use a custom caller:

parse(["./foo.js"], {
  caller: (resolved, options) => resolved(options, "hi")
})[
  //=> return
  require("$cwd/foo.js")(options, "hi")
];

Default caller is (resolved, options) => typeof resolved === 'object' ? resolve.apply(options) : resolved(options)

Prefix

Use a prefix:

parse([
  'es2015',
  'babel-preset-stage-2',
  '@org/async',
], { prefix: 'babel-preset-' })
//=> return
[
  require('$cwd/node_modules/babel-preset-es2015')(),
  require('$cwd/node_modules/babel-preset-stage-2')(),
  require('$cwd/node_modules/@org/babel-preset-async')(),
]

You can also use addPrefix method to handle some edge cases:

parse([
  'es2015',
  'babel-preset-stage-2',
  '@org/async',
  '@my/async',
], {
  prefix: 'babel-preset-',
  addPrefix(input, prefix) {
    if (input.startsWith('@my/')) {
      return input.replace(/^@my\/(preset-)?/, '@my/preset-')
    }
    return true
  }
})
//=> return
[
  require('$cwd/node_modules/babel-preset-es2015')(),
  require('$cwd/node_modules/babel-preset-stage-2')(),
  require('$cwd/node_modules/@org/babel-preset-async')(),
  require('$cwd/node_modules/@my/preset-async')(),
]

Pure object

Use pure object as config:

Similar to using an array:

[
  ["foo", options],
  [
    "./bar.js",
    {
      isBar: true
    }
  ]
];

is equivalent to:

{
  'foo': options,
  './bar.js': {
    isBar: true
  }
}

API

parse(config, [options])

options

cwd

Type: string Default: process.cwd()

The path to resolve relative path and npm packages.

caller

Type: function Default: (resolved, options) => resolved(options)

The caller defines what to do with resolved and options.

prefix

Type: string Default: undefined

Prefix for package name.

addPrefix

Type: (originalItem, prefix) => string | boolean

Return a string as prefixed value, return true to use default addPrefix handler, return false to skip adding prefix.

isResolved

Type: originalItem => boolean Default: item => item && typeof item !== 'string'

Check if the item is resolved, by default considering all non-string types as resolved.

isCalled

Type: (originalItem, resolvedItem) => boolean Default: Same as isResolved.

Check if the item is called with options, by default considering all non-string types as called, but you can customize it:

parse(
  [
    function foo() {
      return "foo";
    },
    function bar() {
      return "bar";
    }
  ],
  {
    // Only used when config item is provided as function
    isCalled(fn) {
      // Consider it's called when its name is foo
      return fn.name === "foo";
    }
  }
)[
  //=> return
  (function foo() {
    return "foo";
  },
  "bar")
];
// function bar will be called as `bar(options)`

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

parse-json-config © egoist, Released under the MIT License. Authored and maintained by egoist with help from contributors (list).

egoist.moe · GitHub @egoist · Twitter @_egoistlily