
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
@ashgw/ts-env
Advanced tools
Type-safe environment variable validator. Catch errors at runtime with strict configs
A lightweight TypeScript utility for managing and validating environment variables with zod
.
zod
schema.NEXT_PUBLIC_
for variables.npm install @ashgw/ts-env zod
or with pnpm
:
pnpm add @ashgw/ts-env zod
import { z } from 'zod';
import { createEnv } from '@ashgw/ts-env';
const env = createEnv({
vars: {
API_URL: z.string().url(),
PORT: z.string().regex(/^\d+$/, 'PORT must be a number'),
},
});
console.log(env.API_URL); // e.g., "https://example.com"
console.log(env.PORT); // e.g., "3000"
If your environment variables have a common prefix, you can specify it:
import { z } from 'zod';
import { createEnv } from '@ashgw/ts-env';
const env = createEnv({
vars: {
API_URL: z.string().url(),
PORT: z.string().regex(/^\d+$/, 'PORT must be a number'),
},
prefix: 'NEXT_PUBLIC',
});
console.log(env.NEXT_PUBLIC_API_URL); // e.g., "https://example.com"
console.log(env.NEXT_PUBLIC_PORT); // e.g., "3000"
Disable the prefix for specific variables using the disablePrefix
option:
import { z } from 'zod';
import { createEnv } from '@ashgw/ts-env';
const env = createEnv({
vars: {
API_URL: z.string().url(),
NODE_ENV: z.string().min(1),
PORT: z.string().regex(/^\d+$/, 'PORT must be a number'),
},
prefix: 'NEXT_PUBLIC',
disablePrefix: ['NODE_ENV'],
});
console.log(env.NEXT_PUBLIC_API_URL); // e.g., "https://example.com"
console.log(env.NEXT_PUBLIC_PORT); // e.g., "3000"
console.log(env.NODE_ENV); // e.g., "development"
To skip validation, set skipValidation
to true
:
import { z } from 'zod';
import { createEnv } from '@ashgw/ts-env';
const env = createEnv({
vars: {
API_URL: z.string(),
PORT: z.string(),
},
skipValidation: true,
});
console.log(env.API_URL);
console.log(env.PORT);
createEnv
vars
: A record of variable names and their zod
schemas.prefix
(optional): A prefix to apply to variables (e.g., 'NEXT_PUBLIC'
).disablePrefix
(optional): An array of variable names to exclude from the prefix.skipValidation
(optional): If true
, skips validation.A type-safe object containing your environment variables.
When validation fails, createEnv
throws an error with details:
❌ Invalid environment variables: {
NEXT_PUBLIC_API_URL: [ 'Invalid url' ],
NEXT_PUBLIC_PORT: [ 'PORT must be a number' ],
NODE_ENV: [ 'String must contain at least 1 character(s)' ]
}
Error: Invalid environment variables
at createEnv (.../index.ts:XX:XX)
...
FAQs
Type-safe environment variable validator. Catch errors at runtime with strict configs
The npm package @ashgw/ts-env receives a total of 40 weekly downloads. As such, @ashgw/ts-env popularity was classified as not popular.
We found that @ashgw/ts-env demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.