Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

znv

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

znv - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

6

dist/extra-schemas.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

36

dist/preprocessors.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -40,4 +44,5 @@ if (k2 === undefined) k2 = k;

return (arg) => {
if (/^\d+(\.\d+)?$/.test(arg))
if (typeof arg === "string" && /^-?\d+(\.\d+)?$/.test(arg)) {
return Number(arg);
}
return arg;

@@ -47,4 +52,5 @@ };

return (arg) => {
if (/^\d+$/.test(arg))
if (typeof arg === "string" && /^-?\d+$/.test(arg)) {
return BigInt(arg);
}
return arg;

@@ -72,14 +78,16 @@ };

return (arg) => {
switch (arg) {
case "true":
case "yes":
case "1":
return true;
case "false":
case "no":
case "0":
return false;
default:
return arg;
if (typeof arg === "string") {
// eslint-disable-next-line default-case
switch (arg) {
case "true":
case "yes":
case "1":
return true;
case "false":
case "no":
case "0":
return false;
}
}
return arg;
};

@@ -86,0 +94,0 @@ case TypeName.ZodArray:

{
"name": "znv",
"version": "0.3.1",
"version": "0.3.2",
"description": "Parse your environment with Zod schemas",

@@ -39,3 +39,3 @@ "keywords": [

"dependencies": {
"colorette": "^2.0.16"
"colorette": "^2.0.19"
},

@@ -46,12 +46,12 @@ "peerDependencies": {

"devDependencies": {
"@types/jest": "^27.4.0",
"@types/node": "^16.9.6",
"eslint": "^8.6.0",
"eslint-config-lostfictions": "^3.1.0",
"jest": "^27.4.7",
"@types/jest": "^29.2.4",
"@types/node": "^16.18.8",
"eslint": "^8.29.0",
"eslint-config-lostfictions": "^5.0.0",
"jest": "^29.3.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1",
"ts-jest": "^27.1.2",
"ts-node": "^10.4.0",
"typescript": "^4.5.4",
"prettier": "^2.8.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.7.4",
"zod": "^3.11.6"

@@ -62,8 +62,11 @@ },

"rootDir": "src",
"globals": {
"ts-jest": {
"isolatedModules": true
}
"transform": {
"^.+\\.tsx?$": [
"ts-jest",
{
"isolatedModules": true
}
]
}
}
}

@@ -21,2 +21,12 @@ # znv

## Status
Unstable: znv has not yet hit v1.0.0, and per semver there may be breaking
changes in minor versions before the v1.0.0 release. Any (known) breaking
changes will be documented in release notes. znv is used in production in
several services at the primary author's workplace. Feedback and suggestions
about final API design are welcome.
## Contents
- [Quickstart](#quickstart)

@@ -32,2 +42,21 @@ - [Motivation](#motivation)

/////////// notes
- Parsing and validation of embedded JSON makes it convenient to define a bundle
of related (non-orthogonal) config values, arrays of values, etc. Also eases
the transition to/from config files.
- Robust defaults management
todo:
- allow passing getter function to defaults keys
- allow passing function to defaults
- recipe: merging multiple configurations (actually hard if it's not all stringly-typed)
- recipe: use with next.js
- antipattern: complex dependencies/defaults
## Quickstart

@@ -48,3 +77,3 @@

export const { NICKNAME, LLAMA_COUNT, COLOR, SHINY } = parseEnv(process.env, {
NICKNAME: z.string().nonempty(),
NICKNAME: z.string().min(1),
LLAMA_COUNT: z.number().int().positive(),

@@ -99,3 +128,3 @@ COLOR: z.enum(["red", "blue"]),

HOST: {
schema: z.string().nonempty(),
schema: z.string().min(1),

@@ -125,3 +154,3 @@ // the description is handy as in-code documentation, but is also printed

// `JSON.parse` the env var if it's present.
EDITORS: z.array(z.string().nonempty()),
EDITORS: z.array(z.string().min(1)),

@@ -162,2 +191,4 @@ // optional values are also supported and provide a way to benefit from the

https://danluu.com/postmortem-lessons/
Env vars represent one of the _boundaries_ of your application, just like file

@@ -174,7 +205,7 @@ I/O or a server request. In TypeScript, as in many other typed languages, these

defined, are always strings, Zod schemas like `z.number()` will fail to parse
them out-of-the-box. Zod offers a [`preprocess`
them out-of-the-box. Zod allows you to use a [`preprocess`
schema](https://github.com/colinhacks/zod#preprocess) to handle coercions, but
it can make authoring schemas verbose and clunky. znv wraps each of the Zod
schemas you pass to `parseEnv` in a preprocessor that tries to coerce a string
to a type the schema expects.
peppering your schemas with preprocessors to this end is verbose, error-prone,
and clunky. znv wraps each of the Zod schemas you pass to `parseEnv` in a
preprocessor that tries to coerce a string to a type the schema expects.

@@ -187,5 +218,5 @@ These preprocessors don't do any validation of their own — in fact, they try to

znv also makes it easy to define defaults for env vars based on your
environment. Zod allows you to define schema defaults, but making a given
default vary by environment or only act as a fallback in certain environments is
not straightforward.
environment. Zod allows you to add a default value for a schema, but making a
given default vary by environment or only act as a fallback in certain
environments is not straightforward.

@@ -234,3 +265,3 @@ ## Usage

FRUIT: {
schema: z.string().nonempty(),
schema: z.string().min(1),
defaults: {

@@ -354,3 +385,4 @@ production: "orange",

- If your schema's input is an object or array (or record or tuple), znv will
attempt to `JSON.parse` the input value if it's not `undefined` or empty.
attempt to `JSON.parse` the input value if it's not `undefined` or the empty
string.

@@ -403,2 +435,32 @@ > **Remember, with great power comes great responsibility!** If you're using

=====================
comparisons
=====================
config comparison
https://github.com/lorenwest/node-config
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/config/index.d.ts
mostly not for env but supports it. totally untyped and untypeable, needlessly
complex, "validation" is throwing on undefined and that's it, mostly goes
against 12 factor
convict comparison
https://github.com/mozilla/node-convict/tree/master/packages/convict
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/convict/index.d.ts
not just for env -- handles command-line args, loads from file, merges.
interesting best-effort typings but the library itself allows too much
looseness. validation is limited and not composeable, uses validate method that
you can forget to call (violates "parse, don't validate")
nconf comparison
https://github.com/indexzero/nconf
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/nconf/index.d.ts
untyped. does too much (encryption! storage engines!) but no validation
cosmiconfig
https://github.com/davidtheclark/cosmiconfig
not for env
==========================
## Complementary tooling

@@ -405,0 +467,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc