Skip to content

Commit 3e65428

Browse files
committed
feat: rewrite and fixed empty string and function parsing (closes #20, closes #21)
1 parent abd9a9f commit 3e65428

20 files changed

+6939
-2318
lines changed

.babelrc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
2-
"presets": [ "crocodile" ],
3-
"sourceMaps": "inline",
4-
"plugins": [ "add-module-exports" ]
2+
"presets": [
3+
["@babel/env", {
4+
"targets": {
5+
"node": "8"
6+
}
7+
}]
8+
],
9+
"sourceMaps": "inline"
510
}

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"extends": "crocodile"
2+
"extends": ["eslint:recommended", "plugin:node/recommended"],
3+
"rules": {
4+
}
35
}

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
2-
# osx
31
.DS_Store
4-
5-
# project
6-
node_modules/
7-
logs
82
*.log
9-
npm-debug.log*
10-
*.idea
11-
lib
3+
.idea
4+
node_modules
125
coverage
6+
.nyc_output
7+
lib

.npmignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: node_js
2+
node_js:
3+
- '10'
4+
- '12'
5+
- '14'
6+
script:
7+
npm run test-coverage
8+
after_success:
9+
npm run coverage

LICENSE

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
The MIT License
1+
MIT License
22

3-
Copyright (c) 2016- Nick Baugh <niftylettuce@gmail.com>
3+
Copyright (c) 2016 Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com)
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
611

7-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
814

9-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Readme.md renamed to README.md

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
1-
21
# dotenv-parse-variables
32

4-
[![Slack Status][slack-image]][slack-url]
5-
[![NPM version][npm-image]][npm-url]
6-
[![Build Status][build-image]][build-url]
7-
[![Code Coverage][codecoverage-image]][codecoverage-url]
8-
[![Standard JS Style][standard-image]][standard-url]
9-
[![MIT License][license-image]][license-url]
3+
[![build status](https://travis-ci.com/niftylettuce/dotenv-parse-variables.svg)](https://travis-ci.com/niftylettuce/dotenv-parse-variables)
4+
[![code coverage](https://img.shields.io/codecov/c/github/niftylettuce/dotenv-parse-variables.svg)](https://codecov.io/gh/niftylettuce/dotenv-parse-variables)
5+
[![code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
6+
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
7+
[![made with lass](https://img.shields.io/badge/made_with-lass-95CC28.svg)](https://lass.js.org)
8+
[![license](https://img.shields.io/github/license/niftylettuce/dotenv-parse-variables.svg)](LICENSE)
109

11-
> Parse dotenv files for `Boolean`, `Array`, and `Number` variable types, built for [CrocodileJS][crocodile-url].
10+
> Parse dotenv files for `Boolean`, `Array`, and `Number` variable types, built for [Lad][] and [Forward Email][fe].
1211
1312

14-
## Index
13+
## Table of Contents
1514

16-
* [Example](#example)
1715
* [Install](#install)
16+
* [Example](#example)
1817
* [Usage](#usage)
18+
* [Options](#options)
19+
* [Contributors](#contributors)
1920
* [License](#license)
2021

2122

23+
## Install
24+
25+
[npm][]:
26+
27+
```sh
28+
npm install dotenv-parse-variables
29+
```
30+
31+
[yarn][]:
32+
33+
```sh
34+
yarn add dotenv-parse-variables
35+
```
36+
37+
2238
## Example
2339

2440
Imagine you have a configuration file at `.env` with the following:
@@ -58,25 +74,19 @@ And you'll see that it outputs the properly parsed variable types:
5874
BOOP: [ 'some', 'thing', 'that', 'goes', 'wow' ],
5975
// NOTE: this was not parsed due to the * asterisk override above
6076
BLEEP: 'false',
61-
// NOTE: only the `true*` above was opted out through the use of an asterisk
77+
// NOTE: only the "true*" above was opted out through the use of an asterisk
6278
PING: [ 'ping', 'true', 2, 100 ],
6379
// NOTE: this was not parsed because the string was between bacticks
6480
PONG: 'some,thing,that,goes,wow'
6581
}
6682
```
6783

68-
If your configuration line ends in `*` it will not be parsed by this package, which allows you to keep values as the `String` variable type if needed. Also when you encapsulate a value between bacticks e.g. \`value\`, the value won't be parsed and it will return as a `String` variable. This can be used in situations where you for example have a ',' inside your string and it should not be parsed as an array.
69-
70-
## Install
71-
72-
```bash
73-
npm install --save dotenv-parse-variables
74-
```
84+
If your configuration line ends in `*` it will not be parsed by this package, which allows you to keep values as the `String` variable type if needed. Also when you encapsulate a value between bacticks e.g. \`value\`, the value won't be parsed and it will return as a `String` variable. This can be used in situations where you for example have a `,` inside your string and it should not be parsed as an array.
7585

7686

7787
## Usage
7888

79-
This package works just fine with [dotenv][dotenv], however we also recommend to use [dotenv-extended][dotenv-extended] and [dotenv-expand][dotenv-expand] as we do in [CrocodileJS][crocodile-url].
89+
This package works well with [dotenv][dotenv], however we also recommend to use [dotenv-extended][dotenv-extended] and [dotenv-expand][dotenv-expand] as we do in [Lad][]. You could also simply just use [Lad][] or [@ladjs/env][] specifically.
8090

8191
> Example with `dotenv`:
8292
@@ -112,25 +122,45 @@ console.log(env);
112122
If you don't want to use this package to parse variable types, you could also use [getenv][getenv] (but it requires more work).
113123

114124

125+
## Options
126+
127+
A second argument can be provided to `dotenvParseVariables` with an object of options.
128+
129+
The defaults are listed below:
130+
131+
* `assignToProcessEnv` (Boolean) - defaults to `true`, whether or not to assign the parsed values to `process.env`
132+
* `overrideProcessEnv` (Boolean) - defaults to `false`, whether or not to override existing values in `process.env`
133+
* `ignoreFunctions` (Boolean) - defaults to `true`, whether or not to ignore functions in the parsed values returned
134+
135+
136+
## Contributors
137+
138+
| Name | Website |
139+
| -------------- | ------------------------- |
140+
| **Nick Baugh** | <http://niftylettuce.com> |
141+
142+
115143
## License
116144

117-
[MIT][license-url]
145+
[MIT](LICENSE) © Nick Baugh
146+
118147

148+
##
149+
150+
[lad]: https://lad.js.org
151+
152+
[fe]: https://forwardemail.net
153+
154+
[npm]: https://www.npmjs.com/
155+
156+
[yarn]: https://yarnpkg.com/
119157

120-
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg
121-
[license-url]: LICENSE
122-
[npm-image]: https://img.shields.io/npm/v/dotenv-parse-variables.svg
123-
[npm-url]: https://npmjs.org/package/dotenv-parse-variables
124-
[crocodile-url]: https://crocodilejs.com
125-
[standard-image]: https://img.shields.io/badge/code%20style-standard%2Bes7-brightgreen.svg
126-
[standard-url]: https://github.com/crocodilejs/eslint-config-crocodile
127-
[slack-image]: https://img.shields.io/badge/chat-join%20slack-brightgreen
128-
[slack-url]: https://join.slack.com/t/ladjs/shared_invite/zt-fqei6z11-Bq2trhwHQxVc5x~ifiZG0g
129158
[dotenv]: https://github.com/motdotla/dotenv
159+
130160
[dotenv-expand]: https://github.com/motdotla/dotenv-expand
161+
131162
[dotenv-extended]: https://github.com/keithmorris/node-dotenv-extended
163+
132164
[getenv]: https://github.com/ctavan/node-getenv
133-
[build-image]: https://semaphoreci.com/api/v1/niftylettuce/dotenv-parse-variables/branches/master/shields_badge.svg
134-
[build-url]: https://semaphoreci.com/niftylettuce/dotenv-parse-variables
135-
[codecoverage-image]: https://codecov.io/gh/niftylettuce/dotenv-parse-variables/branch/master/graph/badge.svg
136-
[codecoverage-url]: https://codecov.io/gh/niftylettuce/dotenv-parse-variables
165+
166+
[@ladjs/env]: https://github.com/ladjs/env

package.json

Lines changed: 91 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,59 @@
33
"description": "Parse dotenv files for Boolean, Array, and Number variable types, built for CrocodileJS",
44
"version": "0.3.1",
55
"author": "Nick Baugh <niftylettuce@gmail.com>",
6-
"bugs": "https://github.com/niftylettuce/dotenv-parse-variables/issues",
6+
"ava": {
7+
"serial": true
8+
},
9+
"bugs": {
10+
"url": "https://github.com/niftylettuce/dotnenv-parse-variables/issues",
11+
"email": "niftylettuce@gmail.com"
12+
},
13+
"commitlint": {
14+
"extends": [
15+
"@commitlint/config-conventional"
16+
]
17+
},
18+
"contributors": [
19+
"Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com)"
20+
],
721
"dependencies": {
8-
"debug": "^4.1.1"
22+
"debug": "^4.1.1",
23+
"is-string-and-not-blank": "^0.0.2"
924
},
1025
"devDependencies": {
11-
"babel-cli": "^6.26.0",
12-
"babel-plugin-add-module-exports": "^1.0.2",
13-
"babel-preset-crocodile": "^1.0.0",
14-
"chai": "^4.2.0",
15-
"codecov": "^3.6.5",
16-
"dirty-chai": "^2.0.1",
26+
"@babel/cli": "^7.11.6",
27+
"@babel/core": "^7.11.6",
28+
"@babel/preset-env": "^7.11.5",
29+
"@commitlint/cli": "^9.1.2",
30+
"@commitlint/config-conventional": "^9.1.2",
31+
"ava": "^3.12.1",
32+
"codecov": "^3.7.2",
33+
"cross-env": "^7.0.2",
1734
"dotenv": "^8.2.0",
18-
"eslint-config-crocodile": "^1.0.0",
19-
"istanbul": "^1.1.0-alpha.1",
20-
"mocha": "^6.1.4"
35+
"eslint": "^7.8.1",
36+
"eslint-config-xo-lass": "^1.0.3",
37+
"eslint-plugin-node": "^11.1.0",
38+
"fixpack": "^3.0.6",
39+
"husky": "^4.3.0",
40+
"lint-staged": "^10.3.0",
41+
"nyc": "^15.1.0",
42+
"remark-cli": "^8.0.1",
43+
"remark-preset-github": "^3.0.0",
44+
"xo": "^0.33.1"
2145
},
2246
"engines": {
23-
"node": ">= 6.x"
47+
"node": ">= 8.3.0"
2448
},
49+
"files": [
50+
"lib"
51+
],
2552
"homepage": "https://github.com/niftylettuce/dotenv-parse-variables",
53+
"husky": {
54+
"hooks": {
55+
"pre-commit": "npm test",
56+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
57+
}
58+
},
2659
"keywords": [
2760
"array",
2861
"boolean",
@@ -36,15 +69,53 @@
3669
"variables"
3770
],
3871
"license": "MIT",
72+
"lint-staged": {
73+
"linters": {
74+
"*.js": [
75+
"xo --fix",
76+
"git add"
77+
],
78+
"*.md": [
79+
"remark . -qfo",
80+
"git add"
81+
],
82+
"package.json": [
83+
"fixpack",
84+
"git add"
85+
]
86+
}
87+
},
3988
"main": "lib/index.js",
40-
"repository": "niftylettuce/dotenv-parse-variables",
89+
"prettier": {
90+
"singleQuote": true,
91+
"bracketSpacing": true,
92+
"trailingComma": "none"
93+
},
94+
"remarkConfig": {
95+
"plugins": [
96+
"preset-github"
97+
]
98+
},
99+
"repository": {
100+
"type": "git",
101+
"url": "https://github.com/niftylettuce/dotnenv-parse-variables"
102+
},
41103
"scripts": {
42-
"analyze-coverage": "node_modules/.bin/babel-node node_modules/.bin/istanbul cover node_modules/.bin/_mocha",
43-
"check-coverage": "node_modules/.bin/babel-node node_modules/.bin/istanbul check-coverage",
44-
"compile": "rm -rf lib/ && babel -d lib src",
45-
"coverage": "rm -rf coverage/ && npm run analyze-coverage && npm run check-coverage && node_modules/.bin/codecov",
46-
"lint": "eslint .",
47-
"prepublish": "npm run test",
48-
"test": "npm run lint && npm run compile && npm run coverage"
104+
"ava": "cross-env NODE_ENV=test ava",
105+
"build": "npm run build:clean && npm run build:lib",
106+
"build:clean": "rimraf lib",
107+
"build:lib": "babel src --out-dir lib",
108+
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
109+
"lint": "xo && remark . -qfo && eslint lib",
110+
"nyc": "cross-env NODE_ENV=test nyc ava",
111+
"test": "npm run build && npm run lint && npm run ava",
112+
"test-coverage": "npm run build && npm run lint && npm run nyc"
113+
},
114+
"xo": {
115+
"prettier": true,
116+
"space": true,
117+
"extends": [
118+
"xo-lass"
119+
]
49120
}
50121
}

0 commit comments

Comments
 (0)