Skip to content

Tiny library to read config files like your.config.js, your.config.mjs, your.config.ts, your.config.json and your.config.json5 from disk.

License

Notifications You must be signed in to change notification settings

jsheaven/read-config-file

Repository files navigation

@jsheaven/read-config-file

Tiny library to read config files like your.config.js, your.config.mjs, your.config.ts, your.conifg.json or your.config.json5 from disk.

User Stories

  1. As a developer, I want to read config files for my project/library/framework
  2. As a developer, I don't want to write that code again and again

Features

  • ✅ Reads and evalutates config files from disk: .js, .mjs, .ts, .json and .json5
  • ✅ Available as a simple API and simple to use CLI
  • ✅ Just 636 bytes nano sized (ESM, gizpped)
  • ✅ Tree-shakable and side-effect free
  • ✅ Runs on Windows, Mac, Linux, CI tested
  • ✅ First class TypeScript support
  • ✅ 100% Unit Test coverage

Example usage (CLI)

NODE_OPTIONS='--experimental-vm-modules' npx @jsheaven/read-config-file --config ./test/some.config.ts

You need at least version 18 of Node.js installed.

Example usage (API, as a library)

Setup

  • yarn: yarn add @jsheaven/read-config-file
  • npm: npm install @jsheaven/read-config-file

ESM

import { readConfigFile } from '@jsheaven/read-config-file'

const result = await readConfigFile({
  configFilePath: './test/some.config.ts',
})

CommonJS

const { readConfigFile } = require('@jsheaven/read-config-file')

// same API like ESM variant

About

Tiny library to read config files like your.config.js, your.config.mjs, your.config.ts, your.config.json and your.config.json5 from disk.

Topics

Resources

License

Stars

Watchers

Forks