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

create-dotenv

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-dotenv - npm Package Compare versions

Comparing version 2.0.8 to 2.0.9

56

index.js

@@ -18,3 +18,21 @@ #!/usr/bin/env node

}
const doubleQuoteSpecialChars = '\\\n\r"';
function doubleQuoteEscape(line) {
for (const char of doubleQuoteSpecialChars) {
let toReplace = "\\" + char;
if (char == "\n") {
toReplace = "\\n";
}
if (char == "\r") {
toReplace = "\\r";
}
line = line.replaceAll(char, toReplace);
}
return line;
}
class Parser {

@@ -107,2 +125,4 @@ map = new Map();

const spawn$1 = require("cross-spawn");
class DotEnv {

@@ -127,2 +147,38 @@ parser = new Parser();

exec(filenames, cmd, cmdArgs) {
this.load(filenames, {
override: true
});
const ls = spawn$1.sync(cmd, cmdArgs, {
env: process.env
});
return ls.stdout.toString("utf-8");
}
write(map, filename) {
const lines = this.marshal(map).concat("\n");
try {
fs__default["default"].writeFileSync(filename, lines);
return true;
} catch (error) {
console.error(error);
return false;
}
}
marshal(map) {
const lines = [];
for (const [key, value] of map) {
if (!isNaN(parseInt(value))) {
lines.push(`${key}=${value}`);
} else {
lines.push(`${key}="${doubleQuoteEscape(value)}"`);
}
}
return lines.join("\n");
}
loadFile(filename, overload) {

@@ -129,0 +185,0 @@ const map = this.readFile(filename);

4

package.json
{
"name": "create-dotenv",
"version": "2.0.8",
"version": "2.0.9",
"description": "Loads environment variables from .env file",

@@ -40,3 +40,3 @@ "publishConfig": {

"dependencies": {
"@jsdotenv/core": "^2.0.8",
"@jsdotenv/core": "^2.0.9",
"minimist": "^1.2.6",

@@ -43,0 +43,0 @@ "cross-spawn": "^7.0.3"

@@ -15,2 +15,4 @@ # dotenv

### Load env file
Add your application configuration to your `.env` file in the root of your project:

@@ -25,3 +27,3 @@

```js
```ts
import dotenv from "@jsdotenv/core";

@@ -68,4 +70,43 @@

## Command Mode
### Writing Env Files
dotenv can also write a map representing the environment to a correctly-formatted and escaped file.
```ts
const map = new Map();
map.set("BASIC", "basic");
map.set("KEY", "value");
const filepath = path.resolve(__dirname, "./jsfile/.env");
dotenv.write(map, filepath);
```
... or to a string
```ts
const map = new Map();
map.set("BASIC", "basic");
map.set("KEY", "value");
const lines = dotenv.marshal(map);
```
### Exec commands
dotenv can run commands and inherit output.
exec bash commands
```ts
const pathname = path.resolve(__dirname + "/env/.env");
const out = dotenv.exec([pathname], "bash", ["-c", 'echo "$BASIC"']);
```
exec nodejs commands
```ts
const pathname = path.resolve(__dirname, "./jsfile/hello.js");
const out = dotenv.exec([], "node", [pathname]);
```
## Cli
```shell

@@ -88,1 +129,7 @@ npm i create-dotenv -g

```
Execute commands --help for Usage
```shell
dotenv-cli --help
```
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