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

rc9

v2.1.2

Published

Read/Write config couldn't be easier!

Downloads

3,922,781

Readme

RC9

npm version npm downloads bundle size codecov

Read/Write RC configs couldn't be easier!

Install

Install dependencies:

# ✨ Auto-detect
npx nypm install rc9

# npm
npm install rc9

# yarn
yarn add rc9

# pnpm
pnpm install rc9

# bun
bun install rc9

Import utils:

ESM (Node.js, Bun)

import {
  defaults,
  parse,
  parseFile,
  read,
  readUser,
  serialize,
  write,
  writeUser,
  update,
  updateUser,
} from "rc9";

CommonJS (Legacy Node.js)

const {
  defaults,
  parse,
  parseFile,
  read,
  readUser,
  serialize,
  write,
  writeUser,
  update,
  updateUser,
} = require("rc9");

Usage

.conf:

db.username=username
db.password=multi word password
db.enabled=true

Update config:

update({ 'db.enabled': false }) // or update(..., { name: '.conf' })

Push to an array:

update({ 'modules[]': 'test' })

Read/Write config:

const config = read() // or read('.conf')

// config = {
//   db: {
//     username: 'username',
//     password: 'multi word password',
//     enabled: true
//   }
// }

config.enabled = false
write(config) // or write(config, '.conf')

User Config:

It is common to keep config in user home directory (MacOS: /Users/{name}, Linux: /home/{name}, Windows: C:\users\{name})

you can use readUser/writeuser/updateUser shortcuts to quickly do this:

writeUser({ token: 123 }, '.zoorc') // Will be saved in {home}/.zoorc

const conf = readUser('.zoorc') // { token: 123 }

Unflatten

RC uses flat to automatically flat/unflat when writing and reading rcfile.

It means that you can use . for keys to define objects. Some examples:

  • hello.world = true <=> { hello: { world: true }
  • test.0 = A <=> tags: [ 'A' ]

Note: If you use keys that can override like x= and x.y=, you can disable this feature by passing flat: true option.

Tip: You can use keys ending with [] to push to an array like test[]=A

Native Values

RC uses destr to convert values into native javascript values.

So reading count=123 results { count: 123 } (instead of { count: "123" }) if you want to preserve strings as is, can use count="123".

Exports

const defaults: RCOptions;
function parse(contents: string, options?: RCOptions): RC
function parseFile(path: string, options?: RCOptions): RC
function read(options?: RCOptions | string): RC;
function readUser(options?: RCOptions | string): RC;
function serialize(config: RC): string;
function write(config: RC, options?: RCOptions | string): void;
function writeUser(config: RC, options?: RCOptions | string): void;
function update(config: RC, options?: RCOptions | string): RC;
function updateUser(config: RC, options?: RCOptions | string): RC;

Types:

type RC = Record<string, any>;
interface RCOptions {
    name?: string;
    dir?: string;
    flat?: boolean;
}

Defaults:

{
  name: '.conf',
  dir: process.cwd(),
  flat: false
}

Why RC9?

Be the first one to guess 🐇

License

Published under the MIT license. Made by community 💛