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

@nodesecure/rc

v1.5.0

Published

NodeSecure runtime configuration

Downloads

98

Readme

NodeSecure runtime configuration.

Requirements

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @nodesecure/rc
# or
$ yarn add @nodesecure/rc

Usage example

read:

import * as RC from "@nodesecure/rc";

const configurationPayload = (
  await RC.read(void 0, { createIfDoesNotExist: true })
).unwrap();
console.log(configurationPayload);

write:

import assert from "node:assert/strict";
import * as RC from "@nodesecure/rc";

const writeOpts: RC.writeOptions = {
  payload: { version: "2.0.0" },
  partialUpdate: true,
};

const result = (await RC.write(void 0, writeOpts)).unwrap();
assert.strictEqual(result, void 0);

memoize/memoized:

import * as RC from "@nodesecure/rc";
import assert from "node:assert";

const configurationPayload = (
    await RC.read(void 0, { createMode: "ci" })
).unwrap()

RC.memoize(configurationPayload, { overwrite: true });

const memoizedPayload = RC.memoized();
assert.deepEqual(configurationPayload, memoizedPayload);

👀 .read and .write return Rust like Result object.

API

If undefined the location will be assigned to process.cwd().

read(location?: string, options?: readOptions): Promise< Result< RC, NodeJS.ErrnoException > >

interface createReadOptions {
  /**
   * If enabled the file will be created if it does not exist on the disk.
   *
   * @default false
   */
  createIfDoesNotExist?: boolean;
  /**
   * RC Generation mode. This option allows to generate a more or less complete configuration for some NodeSecure tools.
   *
   * @default `minimal`
   */
  createMode?: RCGenerationMode | RCGenerationMode[];
  /**
   * RC automatic caching option. This option allows to cache a configuration passed in parameter.
   *
   * @default false
   */
  memoize?: boolean;
}

export type readOptions = RequireAtLeastOne<
  createReadOptions,
  "createIfDoesNotExist" | "createMode"
>;

The createIfDoesNotExist argument can be ignored if createMode is provided.

import * as RC from "@nodesecure/rc";

const configurationPayload = (
  await RC.read(void 0, { createMode: "ci" })
).unwrap();
console.log(configurationPayload);

write(location?: string, options: writeOptions): Promise< Result< void, NodeJS.ErrnoException > >

By default the write API will overwrite the current payload with the provided one. When the partialUpdate option is enabled it will merge the new properties with the existing one.

/**
 * Overwrite the complete payload. partialUpdate property is mandatory.
 */
export interface writeCompletePayload {
  payload: RC;
  partialUpdate?: false;
}

/**
 * Partially update the payload. This implies not to rewrite the content of the file when enabled.
 **/
export interface writePartialPayload {
  payload: Partial<RC>;
  partialUpdate: true;
}

export type writeOptions = writeCompletePayload | writePartialPayload;

memoize(payload: Partial< RC >, options: memoizeOptions = {}): void

By default, the memory API overwrites the previous stored payload. When the OVERWRITE option is false, it merges new properties with existing properties.

export interface memoizeOptions {
  overwrite?: boolean;
}

The overwrite option is used to specify whether data should be overwritten or merged.

memoized(options: memoizedOptions): Partial< RC > | null

This method returns null, when the default value is null, otherwise, it returns the current value of memoizedValue.

export interface memoizedOptions {
  defaultValue: Partial<RC>;
}

If the defaultValue property is at null, then this value will be returned when memoized is called.

clearMemoized(): void

Clear/reset memoized RC

homedir(): string

Dedicated directory for NodeSecure to store the configuration in the os HOME directory.

import * as RC from "@nodesecure/rc";

const homedir = RC.homedir();

CONSTANTS

import assert from "node:assert/strict";
import * as RC from "@nodesecure/rc";

assert.strictEqual(RC.CONSTANTS.CONFIGURATION_NAME, ".nodesecurerc");

Generation Mode

We provide by default a configuration generation that we consider minimal. On the contrary, a complete value will indicate the generation with all possible default keys.

export type RCGenerationMode = "minimal" | "ci" | "report" | "scanner" | "complete";

However, depending on the NodeSecure tool you are working on, it can be interesting to generate a configuration with some property sets specific to your needs.

Note that you can combine several modes:

import * as RC from "@nodesecure/rc";

await RC.read(void 0, { createMode: ["ci", "report"] });

JSON Schema

The runtime configuration is validated with a JSON Schema: ./src/schema/nodesecurerc.json.

It can be retrieved by API if required:

import * as RC from "@nodesecure/rc";

console.log(RC.JSONSchema);

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):

License

MIT