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

config-parser-master

v0.5.1

Published

This is a simple config parser that can read and write to a config file.

Downloads

11

Readme

config-parser-master

Description

This is a simple config parser that can read and write to a config file.

Currently, it only supports reading and writing to a config file in the following formats:

  • js、mjs、ts、mts(export default)
  • cjs(module.exports)
  • json、rc(json)
  • yml、yaml

Additionally, it also supports reading javascript or typescript files. (including jsx and tsx)

Install

$ npm install config-parser-master

Simple Usage

import { ConfigParser } from 'config-parser-master';

const config = ConfigParser.parse('./package.json')
config.put('scripts.hi', 'echo hi')
config.save()

ParseJs Exammple

If you want to parse a javascript or typescript file, you can use the parseJs or parse function, the difference is that the parseJs function will return a BaseJSConfig object, which has some additional functions.

If your javascript or typescript file isn't a config file, you can set the skipCheck parameter to true, and it will not check if the file is a config file.

Parse a source file

/*
file: main.js
---
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'

createApp(App).mount('#app')

function sum(a, b) {
  return a + b
}

sum(1, 2)
*/
import { ConfigParser } from 'config-parser-master';

const config = ConfigParser.parseJs('main.js', true)

// import
config.import('main.css') // import "main.css";
config.import('Home.vue', { defaultKey: 'Home' }) // import Home from "Home.vue";
config.import('config-parser-master', { keys: ['ConfigParser'] }) // import { ConfigParser } from "config-parser-master";
config.import('some-package', { defaultKey: 'defaultKey', keys: ['a', 'b'] }) // import defaultKey, { a, b } from "some-package";

// isContainCallExpression
console.log(config.isContainCallExpression('createApp()')) // true
console.log(config.isContainCallExpression('createApp().mount()')) // true
console.log(config.isContainCallExpression('sum()')) // true
console.log(config.isContainCallExpression('add()')) // false

console.log(config.content)
/*
import defaultKey, { a, b } from "some-package";
import { ConfigParser } from "config-parser-master";
import Home from "Home.vue";
import "main.css";
import { createApp } from 'vue';
import './style.css';
import App from './App.vue';
createApp(App).mount('#app');
function sum(a, b) {
  return a + b;
}
sum(1, 2);
*/

Parse a config file

/*
file: config.js
---
import { svelte } from '@sveltejs/vite-plugin-svelte'

function sum(a, b) {
  return a + b
}

export default {
  plugins: [svelte(), sum(1, 2)],
}
*/
const config = ConfigParser.parseJs('config.js')
const plugins = config.get('plugins') as ParserValueType[]

// isSameCallExpression and isStrictSameCallExpression
console.log(
  plugins.map((plugin) => config.isSameCallExpression(plugin, 'svelte()'))
) // [true, false]
console.log(
  plugins.map((plugin) => config.isSameCallExpression(plugin, 'sum()'))
) // [false, true]
console.log(
  plugins.map((plugin) => config.isStrictSameCallExpression(plugin, 'sum()'))
) // [false, false]
console.log(
  plugins.map((plugin) =>
    config.isStrictSameCallExpression(plugin, 'sum()', [1, 2])
  )
) // [false, true]

// getCallExpressionArgs
console.log(plugins.map((plugin) => config.getCallExpressionArgs(plugin))) // [[], [1, 2]]

// createCallExpression and put
const plugin = config.createCallExpression('plugin', [1, 2, 3])
plugins.push(plugin)
config.put('plugins', plugins)

console.log(config.content)
/*
import { svelte } from '@sveltejs/vite-plugin-svelte';
function sum(a, b) {
  return a + b;
}
export default {
  plugins: [svelte(), sum(1, 2), plugin(1, 2, 3)]
};
*/

API

ConfigParser

  • ConfigParser.parse(path: string): BaseConfig
    • Parse a config file and return a Config object.
  • ConfigParser.parseJs(path: string, skipCheck?: boolean = false): BaseJSConfig
    • Parse a javascript or typescript file and return a Config object.

BaseConfig

  • BaseConfig.put(key: string, value: ParserValueType): BaseConfig
    • Put a value into the config object.
  • BaseConfig.get(key: string, defaultValue?: ParserValueType | ParserValueType[]): ParserValueType
    • Retrieve a value from the config object.
  • BaseConfig.delete(key: string): BaseConfig
    • Delete a value from the config object.
  • async Config.save(): Promise<void>
    • Save the config object to the config file.

BaseJSConfig

  • Extends BaseConfig
  • import(source: string, options: { defaultKey?: string, keys?: string[] } = {}): BaseJSConfig
    • Insert 「import defaultKey, { ...keys } from source」 to the config file.
  • require(source: string, options: { defaultKey?: string, keys?: string[] } = {}): BaseJSConfig
    • Insert 「const defaultKey, { ...keys } = require(source)」 to the config file.
  • createCallExpression(name: string, args?: ParserValueType[]): t.CallExpression
    • Create a call expression.
  • isStrictSameCallExpression(callExpression: t.Expression, name: string, args?: ParserValueType[]): boolean
    • Check if the call expression is strict same (including name and args).
  • isSameCallExpression(callExpression: t.Expression, name: string): boolean
    • Check if the call expression is same.
  • getCallExpressionArgs(callExpression: t.Expression): ParserValueType[]
    • Get the arguments of the call expression.
  • isContainCallExpression(name: string, args?: ParserValueType[]): boolean
    • Check if the config file contains the call expression.

Propterites

BaseConfig.file: string

The path of the config file.

BaseConfig.content: string

The content of the config file.

Types

ParserValueType

type ParserValueType =
  | string
  | number
  | boolean
  | t.CallExpression
  | ParserValueType[]
  | { [key: string]: ParserValueType }

In simple terms, configuration values can be strings, numbers, boolean, t.CallExpression values, arrays, or objects.