
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@nkp/config
Advanced tools
Utility for parsing environment variables and bootstrapping configuration objects.
@nkp/config
exports both CommonJS and ES modules.
npm install @nkp/config
yarn add @nkp/config
pnpm add @nkp/config
import { parse, boolean, string, integer, key, oneOf } from '@nkp/config';
/**
* the parse function correctly sets the type of `config`
* {
* DEBUG: false;
* MAIL: string | undefined;
* HOST: string;
* PORT: number;
* env: 'development' | 'testing' | 'production';
* }
*/
const config = parse({
// coerces DEBUG is a boolean defaulting to false if not provided
DEBUG: boolean().default(false),
// coerces MAIL_HOST to string, or leaves undefined if it doesn't exist
MAIL_HOST: string().optional(),
// coerces process.env.HOST to string
HOST: string() ,
// coerces process.env.PORT to string
// if not provided, defaults to 3000
PORT: integer().default(3000),
// ensures procese.env.NODE_ENV is one of the given values
env: key('NODE_ENV')
.oneOf(['development', 'testing', 'production',] as const),
}, process.env);
Instead of parsing an object, a single key can be parsed.
import { key, string } from '@nkp/config';
// by key - required
const email1: string = key('EMAIL')
.string()
.parse(process.env);
// by key - optional
const email2: string | undefined = key('EMAIL')
.string()
.optional()
.parse(process.env);
// by value - with default
const email3: string = string()
.default('example@example.com')
.parse(process.env['EMAIL']);
Default values can be provided.
import { key, integer } from '@nkp/config';
const port = key('PORT').integer().default(3000).parse(process.env);
If no default value is provided and the key is not found, an error will be thrown.
import { key, string } from '@nkp/config';
const vars = {};
const value = key('MISSING_VALUE').string().parse(vars);
// throws TypeError "MISSING_VALUE is not defined"
To a release a new version:
master
branch on GitHubnew release
on GitHub for the latest versionThis will trigger a GitHub action that tests and publishes the npm package.
1.1.1 - 2022-03-04
Fix release v1.1.0
FAQs
Tools to bootstrap a configuration objects in JavaScript
We found that @nkp/config demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.