@stompbox/tape-delay 1.0.10 → 1.0.11
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/dist/index.cjs +3 -3
- package/dist/index.d.ts +27 -2
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -52,9 +52,9 @@ const Scope = {
|
|
|
52
52
|
ConstantValue
|
|
53
53
|
};
|
|
54
54
|
class TapeDelay {
|
|
55
|
-
constructor(entries,
|
|
55
|
+
constructor(entries, environmentDetector){
|
|
56
56
|
this.entries = entries;
|
|
57
|
-
this.
|
|
57
|
+
this.environmentDetector = environmentDetector;
|
|
58
58
|
this.key = Math.random().toString();
|
|
59
59
|
this.container = (environment)=>{
|
|
60
60
|
const globalContainer = globalThis;
|
|
@@ -96,7 +96,7 @@ class TapeDelay {
|
|
|
96
96
|
return container;
|
|
97
97
|
};
|
|
98
98
|
this.instance = (entryName)=>{
|
|
99
|
-
const environment = this.
|
|
99
|
+
const environment = this.environmentDetector ? this.environmentDetector() : process.env.NODE_ENV;
|
|
100
100
|
const container = this.container(environment);
|
|
101
101
|
return container.get(entryName.toString());
|
|
102
102
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -57,7 +57,19 @@ export declare class TapeDelay<T extends Entries> {
|
|
|
57
57
|
* ```
|
|
58
58
|
*/
|
|
59
59
|
private readonly entries;
|
|
60
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Optional environment detector. `process.env.NODE_ENV` is used by default.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const randomEnvDetector: EnvironmentDetector = () => {
|
|
66
|
+
* if (Math.random() > 0.5) { return 'test' }
|
|
67
|
+
* if (Math.random() > 0.5) { return 'development' }
|
|
68
|
+
* return 'production'
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
private readonly environmentDetector?;
|
|
61
73
|
private readonly key;
|
|
62
74
|
constructor(
|
|
63
75
|
/**
|
|
@@ -83,7 +95,20 @@ export declare class TapeDelay<T extends Entries> {
|
|
|
83
95
|
* }
|
|
84
96
|
* ```
|
|
85
97
|
*/
|
|
86
|
-
entries: T,
|
|
98
|
+
entries: T,
|
|
99
|
+
/**
|
|
100
|
+
* Optional environment detector. `process.env.NODE_ENV` is used by default.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* const randomEnvDetector: EnvironmentDetector = () => {
|
|
105
|
+
* if (Math.random() > 0.5) { return 'test' }
|
|
106
|
+
* if (Math.random() > 0.5) { return 'development' }
|
|
107
|
+
* return 'production'
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
environmentDetector?: EnvironmentDetector | undefined);
|
|
87
112
|
private container;
|
|
88
113
|
instance: <E extends keyof T>(entryName: E) => EntryType<T[E]>;
|
|
89
114
|
}
|
package/dist/index.js
CHANGED
|
@@ -21,9 +21,9 @@ const Scope = {
|
|
|
21
21
|
ConstantValue: ConstantValue
|
|
22
22
|
};
|
|
23
23
|
class TapeDelay {
|
|
24
|
-
constructor(entries,
|
|
24
|
+
constructor(entries, environmentDetector){
|
|
25
25
|
this.entries = entries;
|
|
26
|
-
this.
|
|
26
|
+
this.environmentDetector = environmentDetector;
|
|
27
27
|
this.key = Math.random().toString();
|
|
28
28
|
this.container = (environment)=>{
|
|
29
29
|
const globalContainer = globalThis;
|
|
@@ -65,7 +65,7 @@ class TapeDelay {
|
|
|
65
65
|
return container;
|
|
66
66
|
};
|
|
67
67
|
this.instance = (entryName)=>{
|
|
68
|
-
const environment = this.
|
|
68
|
+
const environment = this.environmentDetector ? this.environmentDetector() : process.env.NODE_ENV;
|
|
69
69
|
const container = this.container(environment);
|
|
70
70
|
return container.get(entryName.toString());
|
|
71
71
|
};
|