@dotenvx/dotenvx 1.25.2 → 1.26.1

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 CHANGED
@@ -2,7 +2,19 @@
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.25.2...main)
5
+ [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.26.1...main)
6
+
7
+ ## [1.26.1](https://github.com/dotenvx/dotenvx/compare/v1.26.0...v1.26.1)
8
+
9
+ ### Added
10
+
11
+ * add typescript type definitions for `main.parse` method ([#475](https://github.com/dotenvx/dotenvx/pull/475))
12
+
13
+ ## [1.26.0](https://github.com/dotenvx/dotenvx/compare/v1.25.2...v1.26.0)
14
+
15
+ ### Added
16
+
17
+ * add `privateKey` option to `main.parse` method ([#474](https://github.com/dotenvx/dotenvx/pull/474))
6
18
 
7
19
  ## [1.25.2](https://github.com/dotenvx/dotenvx/compare/v1.25.1...v1.25.2)
8
20
 
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
  &nbsp;
1866
1917
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.25.2",
2
+ "version": "1.26.1",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
package/src/lib/main.d.ts CHANGED
@@ -1,5 +1,37 @@
1
1
  import type { URL } from 'url';
2
2
 
3
+ export interface DotenvParseOptions {
4
+ /**
5
+ * Override any environment variables that have already been set on your machine with values from your .env file.
6
+ * @default false
7
+ * @example require('@dotenvx/dotenvx').config({ overload: true })
8
+ * @alias overload
9
+ */
10
+ overload?: boolean;
11
+
12
+ /**
13
+ * @default false
14
+ * @alias override
15
+ */
16
+ override?: boolean;
17
+
18
+ /**
19
+ * Specify an object to read existing environment variables from. Defaults to process.env environment variables.
20
+ *
21
+ * @default process.env
22
+ * @example const processEnv = {}; require('@dotenvx/dotenvx').parse('HELLO=World', { processEnv: processEnv })
23
+ */
24
+ processEnv?: DotenvPopulateInput;
25
+
26
+ /**
27
+ * Specify a privateKey to decrypt any encrypted contents with.
28
+ *
29
+ * @default undefined
30
+ * @example require('@dotenvx/dotenvx').parse('HELLO="encrypted:BE9Y7LKANx77X1pv1HnEoil93fPa5c9rpL/1ps48uaRT9zM8VR6mHx9yM+HktKdsPGIZELuZ7rr2mn1gScsmWitppAgE/1lVprNYBCqiYeaTcKXjDUXU5LfsEsflnAsDhT/kWG1l"', { privateKey: 'a4547dcd9d3429615a3649bb79e87edb62ee6a74b007075e9141ae44f5fb412c' })
31
+ */
32
+ privateKey?: string;
33
+ }
34
+
3
35
  export interface DotenvParseOutput {
4
36
  [name: string]: string;
5
37
  }
@@ -9,14 +41,16 @@ export interface DotenvParseOutput {
9
41
  *
10
42
  * @see https://dotenvx.com/docs
11
43
  * @param src - contents to be parsed. example: `'DB_HOST=localhost'`
44
+ * @param options - additional options. example: `{ prcoessEnv: {}, privateKey: '<privateKey>', overload: false }`
12
45
  * @returns an object with keys and values based on `src`. example: `{ DB_HOST : 'localhost' }`
13
46
  */
14
47
  export function parse<T extends DotenvParseOutput = DotenvParseOutput>(
15
- src: string | Buffer
48
+ src: string | Buffer,
49
+ options?: DotenvParseOptions
16
50
  ): T;
17
51
 
18
52
  export interface DotenvConfigOptions {
19
- /** *
53
+ /**
20
54
  * Specify a custom path if your file containing environment variables is located elsewhere.
21
55
  * Can also be an array of strings, specifying multiple paths.
22
56
  *
@@ -37,16 +71,16 @@ export interface DotenvConfigOptions {
37
71
  /**
38
72
  * Override any environment variables that have already been set on your machine with values from your .env file.
39
73
  * @default false
40
- * @example require('@dotenvx/dotenvx').config({ override: true })
74
+ * @example require('@dotenvx/dotenvx').config({ overload: true })
41
75
  * @alias overload
42
76
  */
43
- override?: boolean;
77
+ overload?: boolean;
44
78
 
45
79
  /**
46
80
  * @default false
47
81
  * @alias override
48
82
  */
49
- overload?: boolean;
83
+ override?: boolean;
50
84
 
51
85
  /**
52
86
  * Specify an object to write your secrets to. Defaults to process.env environment variables.
@@ -118,7 +152,7 @@ export interface DotenvPopulateInput {
118
152
  *
119
153
  * @see https://dotenvx.com/docs
120
154
  *
121
- * @param options - additional options. example: `{ path: './custom/path', encoding: 'latin1', debug: true, override: false }`
155
+ * @param options - additional options. example: `{ path: './custom/path', encoding: 'latin1', debug: true, overload: false }`
122
156
  * @returns an object with a `parsed` key if successful or `error` key if an error occurred. example: { parsed: { KEY: 'value' } }
123
157
  *
124
158
  */
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 = null // implement later
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
  }