New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

editenv

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

editenv - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

2

package.json
{
"name": "editenv",
"version": "0.0.7",
"version": "0.0.8",
"description": "EditEnv is a simple and efficient Node.js library for loading, parsing, editing, and saving .env files. Ideal for programmatically managing environment variables in your projects.",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -17,7 +17,9 @@ # EditEnv

```js
const EditEnv = require('editenv');
const { EditEnvLoad, EditEnvAsJson, EditEnvGet, EditEnvSet } = require('editenv');
const envEditor = new EditEnv('./.env');
envEditor.edit('NEW_KEY', 'new_value');
envEditor.save();
EditEnvLoad('./.env');
EditEnvAsJson('./.env');
EditEnvGet('./.env', 'EXISTING_KEY')
EditEnvSet('./.env', 'EXISTING_KEY', 'new_value');
EditEnvSet('./.env', 'NEW_KEY', 'new_value');
```

@@ -9,2 +9,6 @@ const fs = require('fs');

get() {
return this.originalContent;
}
load() {

@@ -42,2 +46,28 @@ return this.parse();

module.exports = EditEnv;
function EditEnvGet(filePath, key) {
const envEditor = new EditEnv(filePath);
return envEditor.load()[key];
}
function EditEnvLoad(filePath) {
const envEditor = new EditEnv(filePath);
return envEditor.get();
}
function EditEnvAsJson(filePath) {
const envEditor = new EditEnv(filePath);
return envEditor.parse();
}
function EditEnvSet(filePath, key, value) {
const envEditor = new EditEnv(filePath);
envEditor.edit(key, value);
envEditor.save();
}
module.exports = {
EditEnvLoad,
EditEnvAsJson,
EditEnvGet,
EditEnvSet,
}
const fs = require('fs');
const EditEnv = require('../src/index');
const { EditEnvLoad, EditEnvAsJson, EditEnvSet } = require('../src/index');

@@ -9,8 +9,3 @@ // Cria um arquivo .env de teste

describe('EditEnv', () => {
let envEditor;
beforeEach(() => {
envEditor = new EditEnv(testEnvPath);
});
afterEach(() => {

@@ -21,3 +16,3 @@ fs.writeFileSync(testEnvPath, '#MAIN TEST\n\nEXISTING_KEY=existing_value\nANOTHER_KEY=another_value\n');

test('should load .env file', () => {
const envConfig = envEditor.load();
const envConfig = EditEnvAsJson(testEnvPath);
expect(envConfig).toEqual({

@@ -30,3 +25,3 @@ EXISTING_KEY: 'existing_value',

test('should parse .env file', () => {
const parsedConfig = envEditor.parse();
const parsedConfig = EditEnvAsJson(testEnvPath);
expect(parsedConfig).toEqual({

@@ -39,5 +34,5 @@ EXISTING_KEY: 'existing_value',

test('should edit .env file', () => {
envEditor.edit('NEW_KEY', 'new_value');
envEditor.edit('EXISTING_KEY', 'updated_value');
const parsedConfig = envEditor.parse();
EditEnvSet(testEnvPath, 'NEW_KEY', 'new_value');
EditEnvSet(testEnvPath, 'EXISTING_KEY', 'updated_value');
const parsedConfig = EditEnvAsJson(testEnvPath);
expect(parsedConfig).toEqual({

@@ -51,8 +46,6 @@ EXISTING_KEY: 'updated_value',

test('should save .env file', () => {
envEditor.edit('NEW_KEY', 'new_value');
envEditor.save();
const fileContent = fs.readFileSync(testEnvPath, 'utf-8');
EditEnvSet(testEnvPath, 'NEW_KEY', 'new_value');
const fileContent = EditEnvLoad(testEnvPath);
expect(fileContent).toContain('NEW_KEY=new_value');
});
});
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