This repository has been archived by the owner on Jul 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
docs/.next | ||
docs/node_modules | ||
test/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# lNV | ||
|
||
lNV is a light-weight .eNV file read/write package. | ||
lNV isn't very feature-rich compared to dotENV, but for small projects like Discord bots, all you need is a read function, it's wasted space. | ||
This package also targets to become as easy-to-use as possible! | ||
|
||
The documentation will be available soon, at: | ||
https://lnv.robuxtrex.co.uk | ||
|
||
## Early Access | ||
|
||
As this is my first package, I would like to clarify that some versions may/will not work. Use at your own risk. | ||
Though, you can always help me on GitHub issues :D | ||
https://github.com/RobuxTRex/lnv/issues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "lnv", | ||
"version": "1.0.0-4", | ||
"description": "lNV can read and write to ENV files with little-to-no performance cost!", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"private": "npm publish", | ||
"public": "npm publish --access public", | ||
"start": "node ./src/entry.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/RobuxTRex/lnv.git" | ||
}, | ||
"author": "sulphurdev", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/RobuxTRex/lnv/issues" | ||
}, | ||
"homepage": "https://lnv.robuxtrex.co.uk/link/npm" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const root = process.cwd() | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { parseBuffer } = require('../parse'); | ||
|
||
module.exports = function loadEnv(target) { | ||
|
||
if (!target) return null; | ||
|
||
const envFilePath = path.join(root, '.env'); | ||
const bufferEnv = fs.readFileSync(envFilePath); | ||
const envObject = parseBuffer(bufferEnv); | ||
|
||
let found = Object.entries(envObject) | ||
|
||
if(envObject == null) { | ||
return null; | ||
} else { | ||
for (const [key, value] of Object.entries(envObject)) { | ||
if (key == target) { | ||
return value; | ||
} else { | ||
null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const loadEnv = require('./func/load') | ||
|
||
exports.get = loadEnv | ||
exports.read = loadEnv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const NEWLINES_MATCH = /\r\n|\n|\r/ | ||
const NEWLINE = '\n' | ||
const RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*(.*)?\s*$/ | ||
const RE_NEWLINES = /\\n/g | ||
|
||
const parseBuffer = (src) => { | ||
const obj = {}; | ||
src.toString().split(NEWLINES_MATCH).forEach((line, idx) => { | ||
// matching "KEY" and "VAL" in "KEY=VAL" | ||
const keyValueArr = line.match(RE_INI_KEY_VAL); | ||
// matched? | ||
if(keyValueArr != null){ | ||
const key = keyValueArr[1]; | ||
|
||
// default undefined or missing values to empty string | ||
|
||
let val = (keyValueArr[2] || ''); | ||
const end = val.length -1; | ||
const isDoubleQuoted = val[0] === '"' && val[end] === '"'; | ||
const isSingleQuoted = val[0] === "'" && val[end] === "'"; | ||
|
||
// if single or double quoted, remove quotes | ||
if(isSingleQuoted || isDoubleQuoted) { | ||
val = val.substring(1, end); | ||
|
||
// if double quoted, expand newlines | ||
if(isDoubleQuoted){ | ||
val = val.replace(RE_NEWLINES, NEWLINE); | ||
} | ||
} else { | ||
// remove surrounding whitespace | ||
val = val.trim(); | ||
} | ||
obj[key] = val; | ||
} | ||
}); | ||
return obj; | ||
} | ||
|
||
module.exports = { | ||
parseBuffer | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
USER=xyz | ||
ID=123xyz | ||
USER=SulphurDev | ||
PASSWORD=123xyz | ||
EMAIL=robuxtrex@gmail.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
const lnv = require('lnv') | ||
|
||
console.log(lnv.get('USER')) | ||
console.log(lnv.get('e')) |
cd79f7e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
lnv – ./
lnv.vercel.app
lnv-git-main-robuxtrex.vercel.app
lnv-robuxtrex.vercel.app