@dotenvx/dotenvx 1.25.2 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -1
- package/README.md +51 -0
- package/package.json +1 -1
- package/src/lib/main.js +10 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.26.0...main)
|
|
6
|
+
|
|
7
|
+
## [1.26.0](https://github.com/dotenvx/dotenvx/compare/v1.25.2...v1.26.0)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* add `privateKey` option to `main.parse` method ([#474](https://github.com/dotenvx/dotenvx/pull/474))
|
|
6
12
|
|
|
7
13
|
## [1.25.2](https://github.com/dotenvx/dotenvx/compare/v1.25.1...v1.25.2)
|
|
8
14
|
|
package/README.md
CHANGED
|
@@ -1859,8 +1859,59 @@ More examples
|
|
|
1859
1859
|
```
|
|
1860
1860
|
|
|
1861
1861
|
</details>
|
|
1862
|
+
* <details><summary>`parse(src)`</summary><br>
|
|
1862
1863
|
|
|
1864
|
+
Parse a `.env` string directly in node.js code.
|
|
1863
1865
|
|
|
1866
|
+
```js
|
|
1867
|
+
// index.js
|
|
1868
|
+
const dotenvx = require('@dotenvx/dotenvx')
|
|
1869
|
+
const src = 'HELLO=World'
|
|
1870
|
+
const parsed = dotenvx.parse(src)
|
|
1871
|
+
console.log(`Hello ${parsed.HELLO}`)
|
|
1872
|
+
```
|
|
1873
|
+
|
|
1874
|
+
```sh
|
|
1875
|
+
$ node index.js
|
|
1876
|
+
Hello World
|
|
1877
|
+
```
|
|
1878
|
+
|
|
1879
|
+
</details>
|
|
1880
|
+
* <details><summary>`parse(src, {processEnv:})`</summary><br>
|
|
1881
|
+
|
|
1882
|
+
Sometimes, you want to run `parse` without it accessing `process.env`. (You can pass a fake processEnv this way as well - sometimes useful.)
|
|
1883
|
+
|
|
1884
|
+
```js
|
|
1885
|
+
// index.js
|
|
1886
|
+
const dotenvx = require('@dotenvx/dotenvx')
|
|
1887
|
+
const src = 'USER=Me'
|
|
1888
|
+
const parsed = dotenvx.parse(src, { processEnv: {} })
|
|
1889
|
+
console.log(`Hello ${parsed.USER}`)
|
|
1890
|
+
```
|
|
1891
|
+
|
|
1892
|
+
```sh
|
|
1893
|
+
$ node index.js
|
|
1894
|
+
Hello Me
|
|
1895
|
+
```
|
|
1896
|
+
|
|
1897
|
+
</details>
|
|
1898
|
+
* <details><summary>`parse(src, {privateKey:})`</summary><br>
|
|
1899
|
+
|
|
1900
|
+
Decrypt an encrypted `.env` string with `privateKey`.
|
|
1901
|
+
|
|
1902
|
+
```js
|
|
1903
|
+
// index.js
|
|
1904
|
+
const dotenvx = require('@dotenvx/dotenvx')
|
|
1905
|
+
const src = 'HELLO="encrypted:BE9Y7LKANx77X1pv1HnEoil93fPa5c9rpL/1ps48uaRT9zM8VR6mHx9yM+HktKdsPGIZELuZ7rr2mn1gScsmWitppAgE/1lVprNYBCqiYeaTcKXjDUXU5LfsEsflnAsDhT/kWG1l"'
|
|
1906
|
+
const parsed = dotenvx.parse(src, { privateKey: 'a4547dcd9d3429615a3649bb79e87edb62ee6a74b007075e9141ae44f5fb412c' })
|
|
1907
|
+
console.log(`Hello ${parsed.HELLO}`)
|
|
1908
|
+
```
|
|
1909
|
+
|
|
1910
|
+
```sh
|
|
1911
|
+
$ node index.js
|
|
1912
|
+
Hello World
|
|
1913
|
+
```
|
|
1914
|
+
</details>
|
|
1864
1915
|
|
|
1865
1916
|
|
|
1866
1917
|
|
package/package.json
CHANGED
package/src/lib/main.js
CHANGED
|
@@ -154,12 +154,20 @@ const parse = function (src, options = {}) {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
// private decryption key
|
|
157
|
-
const privateKey =
|
|
157
|
+
const privateKey = options.privateKey || null
|
|
158
158
|
|
|
159
159
|
// overload
|
|
160
160
|
const overload = options.overload || options.override
|
|
161
161
|
|
|
162
|
-
const { parsed } = new Parse(src, privateKey, processEnv, overload).run()
|
|
162
|
+
const { parsed, errors } = new Parse(src, privateKey, processEnv, overload).run()
|
|
163
|
+
|
|
164
|
+
// display any errors
|
|
165
|
+
for (const error of errors) {
|
|
166
|
+
console.error(error.message)
|
|
167
|
+
if (error.help) {
|
|
168
|
+
console.error(error.help)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
163
171
|
|
|
164
172
|
return parsed
|
|
165
173
|
}
|