Skip to content

Commit

Permalink
Rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
suphero committed Nov 11, 2023
1 parent 4dc57e7 commit 36468e4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# EnvFlex
# Pargali

EnvFlex is an enhanced environment variable loader for Node.js applications. It extends the basic functionality of dotenv with additional features such as type casting and mandatory variable checks, making it easier and safer to work with environment variables.
Pargali is an enhanced environment variable loader for Node.js applications. It extends the basic functionality of dotenv with additional features such as type casting and mandatory variable checks, making it easier and safer to work with environment variables.

## Features

Expand All @@ -10,46 +10,46 @@ EnvFlex is an enhanced environment variable loader for Node.js applications. It

## Installation

Install EnvFlex using npm:
Install Pargali using npm:

```bash
npm install envflex
npm install pargali
```

## Usage

First, require `EnvFlex` at the beginning of your application:
First, require `Pargali` at the beginning of your application:

```javascript
const EnvFlex = require('envflex');
const Pargali = require('pargali');
```

## Accessing Environment Variables

As a String:

```javascript
const someString = EnvFlex.getString('SOME_STRING', 'defaultString');
const someString = Pargali.getString('SOME_STRING', 'defaultString');
```

As a Number:

```javascript
const someNumber = EnvFlex.getNumber('SOME_NUMBER', 123);
const someNumber = Pargali.getNumber('SOME_NUMBER', 123);
```

As a Boolean:

```javascript
const someBoolean = EnvFlex.getBoolean('SOME_BOOLEAN', true);
const someBoolean = Pargali.getBoolean('SOME_BOOLEAN', true);
```

## Mandatory Variable Checks

To ensure that a required environment variable is set:

```javascript
const requiredVar = EnvFlex.require('REQUIRED_VAR');
const requiredVar = Pargali.require('REQUIRED_VAR');
```

If `REQUIRED_VAR` is not set, this will throw an error.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "envflex",
"name": "pargali",
"version": "1.0.2",
"description": "Enhanced environment variable loader for Node.js",
"main": "index.js",
Expand Down
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import dotenv from 'dotenv';
dotenv.config();

export default class EnvFlex {
export default class Pargali {
static _castToString(value: string) {
return String(value).trim();
}

static _castToNumber(value: string) {
const number = Number(value.trim());
if (isNaN(number)) {
throw new Error(`EnvFlex: Value "${value}" is not a valid number.`);
throw new Error(`Pargali: Value "${value}" is not a valid number.`);
}
return number;
}
Expand All @@ -20,17 +20,17 @@ export default class EnvFlex {

static getString(key: string, defaultValue = "") {
const value = process.env[key];
return value === undefined ? defaultValue : EnvFlex._castToString(value);
return value === undefined ? defaultValue : Pargali._castToString(value);
}

static getNumber(key: string, defaultValue = 0) {
const value = process.env[key];
return value === undefined ? defaultValue : EnvFlex._castToNumber(value);
return value === undefined ? defaultValue : Pargali._castToNumber(value);
}

static getBoolean(key: string, defaultValue = false) {
const value = process.env[key];
return value === undefined ? defaultValue : EnvFlex._castToBoolean(value);
return value === undefined ? defaultValue : Pargali._castToBoolean(value);
}

static getStringArray(key: string, defaultValue = [], delimiter = ",") {
Expand All @@ -39,7 +39,7 @@ export default class EnvFlex {
return defaultValue;
}

return value.split(delimiter).map(EnvFlex._castToString);
return value.split(delimiter).map(Pargali._castToString);
}

static getNumberArray(key: string, defaultValue = [], delimiter = ",") {
Expand All @@ -48,7 +48,7 @@ export default class EnvFlex {
return defaultValue;
}

return value.split(delimiter).map(EnvFlex._castToNumber);
return value.split(delimiter).map(Pargali._castToNumber);
}

static getBooleanArray(key: string, defaultValue = [], delimiter = ",") {
Expand All @@ -57,14 +57,14 @@ export default class EnvFlex {
return defaultValue;
}

return value.split(delimiter).map(EnvFlex._castToBoolean);
return value.split(delimiter).map(Pargali._castToBoolean);
}

static require(key: string) {
const value = process.env[key];
if (value === undefined) {
throw new Error(
`EnvFlex: Required environment variable "${key}" is not set.`
`Pargali: Required environment variable "${key}" is not set.`
);
}

Expand Down
18 changes: 9 additions & 9 deletions test/envflex.test.ts → test/pargali.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EnvFlex from '../src/index';
import Pargali from '../src/index';

describe('Value', () => {
beforeAll(() => {
Expand All @@ -9,23 +9,23 @@ describe('Value', () => {
});

test('should retrieve a string environment variable', () => {
expect(EnvFlex.getString('TEST_STRING')).toBe("Hello");
expect(Pargali.getString('TEST_STRING')).toBe("Hello");
});

test('should retrieve a number environment variable', () => {
expect(EnvFlex.getNumber('TEST_NUMBER')).toBe(123);
expect(Pargali.getNumber('TEST_NUMBER')).toBe(123);
});

test('should retrieve a boolean environment variable (true)', () => {
expect(EnvFlex.getBoolean('TEST_BOOLEAN_TRUE')).toBe(true);
expect(Pargali.getBoolean('TEST_BOOLEAN_TRUE')).toBe(true);
});

test('should retrieve a boolean environment variable (false)', () => {
expect(EnvFlex.getBoolean('TEST_BOOLEAN_FALSE')).toBe(false);
expect(Pargali.getBoolean('TEST_BOOLEAN_FALSE')).toBe(false);
});

test('should throw an error for undefined required variable', () => {
expect(() => EnvFlex.require('UNDEFINED_VAR')).toThrow();
expect(() => Pargali.require('UNDEFINED_VAR')).toThrow();
});
});

Expand All @@ -37,15 +37,15 @@ describe('Array', () => {
});

test('should retrieve a string array from an environment variable', () => {
expect(EnvFlex.getStringArray('TEST_STRING_ARRAY')).toEqual(['apple', 'orange', 'banana']);
expect(Pargali.getStringArray('TEST_STRING_ARRAY')).toEqual(['apple', 'orange', 'banana']);
});

test('should retrieve a number array from an environment variable', () => {
expect(EnvFlex.getNumberArray('TEST_NUMBER_ARRAY')).toEqual([1, 2, 3]);
expect(Pargali.getNumberArray('TEST_NUMBER_ARRAY')).toEqual([1, 2, 3]);
});

test('should retrieve a boolean array from an environment variable', () => {
expect(EnvFlex.getBooleanArray('TEST_BOOLEAN_ARRAY')).toEqual([true, false, true, false]);
expect(Pargali.getBooleanArray('TEST_BOOLEAN_ARRAY')).toEqual([true, false, true, false]);
});
});

0 comments on commit 36468e4

Please sign in to comment.