@stompbox/tape-delay 0.0.9 → 0.0.10
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/README.md +20 -0
- package/dist/index.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,4 +37,24 @@ const aInstance = container.instance('A')
|
|
|
37
37
|
console.log(aInstance.hello())
|
|
38
38
|
const bInstance = container.instance('B')
|
|
39
39
|
console.log(bInstance.method())
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Environment detection
|
|
43
|
+
|
|
44
|
+
Environment variable `process.env.NODE_ENV` is used by default. This behaviour can be redefined with optional second parameter in `TapeDelay` constructor.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { TapeDelay, EnvironmentDetector } from '@stompbox/tape-delay'
|
|
48
|
+
|
|
49
|
+
const randomEnvDetector: EnvironmentDetector = () => {
|
|
50
|
+
if (Math.random() > 0.5) {
|
|
51
|
+
return 'test'
|
|
52
|
+
}
|
|
53
|
+
if (Math.random() > 0.5) {
|
|
54
|
+
return 'development'
|
|
55
|
+
}
|
|
56
|
+
return 'production'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const container = new TapeDelay({}, randomEnvDetector)
|
|
40
60
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ type PublicFields<T> = {
|
|
|
11
11
|
type EntryDescription<T> = ClassEntry<T> | ConstantValueEntry<T> | [ClassEntry<T>, (x: BindInWhenOnFluentSyntax<unknown>) => any];
|
|
12
12
|
type Entry<T> = [EntryDescription<T>, EntryDescription<T>, EntryDescription<T>] | EntryDescription<T>;
|
|
13
13
|
export type Entries = Record<string, Entry<unknown>>;
|
|
14
|
+
export type EnvironmentDetector = () => Environment;
|
|
14
15
|
type EntryType<T> = T extends Entry<infer G> ? PublicFields<G> : never;
|
|
15
16
|
export declare const Lifespans: {
|
|
16
17
|
Singleton: <T>(EntryClass: ClassEntry<T>) => EntryDescription<T>;
|
|
@@ -22,7 +23,7 @@ export declare class TapeDelay<T extends Entries> {
|
|
|
22
23
|
private readonly entries;
|
|
23
24
|
private readonly getEnvironment?;
|
|
24
25
|
private readonly key;
|
|
25
|
-
constructor(entries: T, getEnvironment?:
|
|
26
|
+
constructor(entries: T, getEnvironment?: EnvironmentDetector | undefined);
|
|
26
27
|
private container;
|
|
27
28
|
instance: <E extends keyof T>(entryName: E) => EntryType<T[E]>;
|
|
28
29
|
}
|