ditox 2.2.0 → 2.3.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/docs/README.md DELETED
@@ -1,794 +0,0 @@
1
- ditox
2
-
3
- # ditox
4
-
5
- ## Table of contents
6
-
7
- ### Classes
8
-
9
- - [ResolverError](classes/ResolverError.md)
10
-
11
- ### Type aliases
12
-
13
- - [BindModuleOptions](README.md#bindmoduleoptions)
14
- - [Container](README.md#container)
15
- - [FactoryOptions](README.md#factoryoptions)
16
- - [FactoryScope](README.md#factoryscope)
17
- - [Module](README.md#module)
18
- - [ModuleBindingEntry](README.md#modulebindingentry)
19
- - [ModuleDeclaration](README.md#moduledeclaration)
20
- - [Token](README.md#token)
21
-
22
- ### Functions
23
-
24
- - [bindModule](README.md#bindmodule)
25
- - [bindModules](README.md#bindmodules)
26
- - [bindMultiValue](README.md#bindmultivalue)
27
- - [createContainer](README.md#createcontainer)
28
- - [declareModule](README.md#declaremodule)
29
- - [declareModuleBindings](README.md#declaremodulebindings)
30
- - [injectable](README.md#injectable)
31
- - [injectableClass](README.md#injectableclass)
32
- - [isToken](README.md#istoken)
33
- - [optional](README.md#optional)
34
- - [resolveValue](README.md#resolvevalue)
35
- - [resolveValues](README.md#resolvevalues)
36
- - [token](README.md#token)
37
- - [tryResolveValue](README.md#tryresolvevalue)
38
- - [tryResolveValues](README.md#tryresolvevalues)
39
-
40
- ## Type aliases
41
-
42
- ### BindModuleOptions
43
-
44
- Ƭ **BindModuleOptions**: `Object`
45
-
46
- Options for module binding.
47
-
48
- `scope` types:
49
- - `singleton` - **This is the default**. The module is created and cached by the container which registered the factory.
50
- - `scoped` - The module is created and cached by the container which starts resolving.
51
-
52
- #### Type declaration
53
-
54
- | Name | Type |
55
- | :------ | :------ |
56
- | `scope?` | ``"scoped"`` \| ``"singleton"`` |
57
-
58
- #### Defined in
59
-
60
- [packages/ditox/src/modules.ts:76](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L76)
61
-
62
- ___
63
-
64
- ### Container
65
-
66
- Ƭ **Container**: `Object`
67
-
68
- Dependency container.
69
-
70
- #### Type declaration
71
-
72
- | Name | Type |
73
- | :------ | :------ |
74
- | `bindFactory` | <T\>(`token`: [`Token`](README.md#token)<`T`\>, `factory`: (`container`: [`Container`](README.md#container)) => `T`, `options?`: [`FactoryOptions`](README.md#factoryoptions)<`T`\>) => `void` |
75
- | `bindValue` | <T\>(`token`: [`Token`](README.md#token)<`T`\>, `value`: `T`) => `void` |
76
- | `get` | <T\>(`token`: [`Token`](README.md#token)<`T`\>) => `undefined` \| `T` |
77
- | `hasToken` | (`token`: [`Token`](README.md#token)<`unknown`\>) => `boolean` |
78
- | `remove` | <T\>(`token`: [`Token`](README.md#token)<`T`\>) => `void` |
79
- | `removeAll` | () => `void` |
80
- | `resolve` | <T\>(`token`: [`Token`](README.md#token)<`T`\>) => `T` |
81
-
82
- #### Defined in
83
-
84
- [packages/ditox/src/ditox.ts:95](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L95)
85
-
86
- ___
87
-
88
- ### FactoryOptions
89
-
90
- Ƭ **FactoryOptions**<`T`\>: { `scope?`: ``"scoped"`` \| ``"singleton"`` ; `onRemoved?`: (`value`: `T`) => `void` } \| { `scope`: ``"transient"`` }
91
-
92
- Options for factory binding.
93
-
94
- `scope` types:
95
- - `singleton` - **This is the default**. The value is created and cached by the container which registered the factory.
96
- - `scoped` - The value is created and cached by the container which starts resolving.
97
- - `transient` - The value is created every time it is resolved.
98
-
99
- `scoped` and `singleton` scopes can have `onRemoved` callback. It is called when a token is removed from the container.
100
-
101
- #### Type parameters
102
-
103
- | Name |
104
- | :------ |
105
- | `T` |
106
-
107
- #### Defined in
108
-
109
- [packages/ditox/src/ditox.ts:83](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L83)
110
-
111
- ___
112
-
113
- ### FactoryScope
114
-
115
- Ƭ **FactoryScope**: ``"scoped"`` \| ``"singleton"`` \| ``"transient"``
116
-
117
- **`see`** https://github.com/mnasyrov/ditox#factory-lifetimes
118
-
119
- #### Defined in
120
-
121
- [packages/ditox/src/ditox.ts:71](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L71)
122
-
123
- ___
124
-
125
- ### Module
126
-
127
- Ƭ **Module**<`ModuleProps`\>: `ModuleController` & `ModuleProps`
128
-
129
- Dependency module
130
-
131
- **`example`**
132
- ```ts
133
- type LoggerModule = Module<{
134
- logger: Logger;
135
- }>;
136
- ```
137
-
138
- #### Type parameters
139
-
140
- | Name | Type |
141
- | :------ | :------ |
142
- | `ModuleProps` | extends `AnyObject` = `EmptyObject` |
143
-
144
- #### Defined in
145
-
146
- [packages/ditox/src/modules.ts:22](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L22)
147
-
148
- ___
149
-
150
- ### ModuleBindingEntry
151
-
152
- Ƭ **ModuleBindingEntry**: [`ModuleDeclaration`](README.md#moduledeclaration)<`AnyObject`\> \| { `module`: [`ModuleDeclaration`](README.md#moduledeclaration)<`AnyObject`\> ; `options`: [`BindModuleOptions`](README.md#bindmoduleoptions) }
153
-
154
- #### Defined in
155
-
156
- [packages/ditox/src/modules.ts:80](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L80)
157
-
158
- ___
159
-
160
- ### ModuleDeclaration
161
-
162
- Ƭ **ModuleDeclaration**<`T`\>: `Object`
163
-
164
- Description how to bind the module in declarative way.
165
-
166
- **`example`**
167
- ```ts
168
- const LOGGER_MODULE: ModuleDeclaration<LoggerModule> = {
169
- token: LOGGER_MODULE_TOKEN,
170
- factory: (container) => {
171
- const transport = container.resolve(TRANSPORT_TOKEN).open();
172
- return {
173
- logger: { log: (message) => transport.write(message) },
174
- destroy: () => transport.close(),
175
- }
176
- },
177
- exports: {
178
- logger: LOGGER_TOKEN,
179
- },
180
- };
181
- ```
182
-
183
- #### Type parameters
184
-
185
- | Name | Type |
186
- | :------ | :------ |
187
- | `T` | extends [`Module`](README.md#module)<`AnyObject`\> |
188
-
189
- #### Type declaration
190
-
191
- | Name | Type | Description |
192
- | :------ | :------ | :------ |
193
- | `exports?` | { [K in keyof GetModuleProps<T\>]?: Token<GetModuleProps<T\>[K]\> } | Dictionary of module properties which are bound to tokens. |
194
- | `imports?` | `ReadonlyArray`<[`ModuleBindingEntry`](README.md#modulebindingentry)\> | Modules for binding |
195
- | `token` | [`Token`](README.md#token)<`T`\> | Token for the module |
196
- | `afterBinding?` | (`container`: [`Container`](README.md#container)) => `void` | Callback could be used to export complex dependencies from the module. It is called after binding the module. |
197
- | `beforeBinding?` | (`container`: [`Container`](README.md#container)) => `void` | Callback could be used to prepare an environment. It is called before binding the module. |
198
- | `factory` | (`container`: [`Container`](README.md#container)) => `T` | Factory of the module |
199
-
200
- #### Defined in
201
-
202
- [packages/ditox/src/modules.ts:47](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L47)
203
-
204
- ___
205
-
206
- ### Token
207
-
208
- Ƭ **Token**<`T`\>: `RequiredToken`<`T`\> \| `OptionalToken`<`T`\>
209
-
210
- Binding token.
211
-
212
- #### Type parameters
213
-
214
- | Name |
215
- | :------ |
216
- | `T` |
217
-
218
- #### Defined in
219
-
220
- [packages/ditox/src/ditox.ts:25](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L25)
221
-
222
- ## Functions
223
-
224
- ### bindModule
225
-
226
- ▸ **bindModule**<`T`\>(`container`, `moduleDeclaration`, `options?`): `void`
227
-
228
- Binds the dependency module to the container
229
-
230
- **`example`**
231
- ```ts
232
- bindModule(container, LOGGER_MODULE);
233
- ```
234
-
235
- #### Type parameters
236
-
237
- | Name | Type |
238
- | :------ | :------ |
239
- | `T` | extends [`Module`](README.md#module)<`AnyObject`\> |
240
-
241
- #### Parameters
242
-
243
- | Name | Type | Description |
244
- | :------ | :------ | :------ |
245
- | `container` | [`Container`](README.md#container) | Dependency container. |
246
- | `moduleDeclaration` | [`ModuleDeclaration`](README.md#moduledeclaration)<`T`\> | Declaration of the dependency module. |
247
- | `options?` | [`BindModuleOptions`](README.md#bindmoduleoptions) | Options for module binding. |
248
-
249
- #### Returns
250
-
251
- `void`
252
-
253
- #### Defined in
254
-
255
- [packages/ditox/src/modules.ts:98](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L98)
256
-
257
- ___
258
-
259
- ### bindModules
260
-
261
- ▸ **bindModules**(`container`, `modules`): `void`
262
-
263
- Binds dependency modules to the container
264
-
265
- #### Parameters
266
-
267
- | Name | Type | Description |
268
- | :------ | :------ | :------ |
269
- | `container` | [`Container`](README.md#container) | Dependency container for binding |
270
- | `modules` | readonly [`ModuleBindingEntry`](README.md#modulebindingentry)[] | Array of module binding entries: module declaration or `{module: ModuleDeclaration, options: BindModuleOptions}` objects. |
271
-
272
- #### Returns
273
-
274
- `void`
275
-
276
- #### Defined in
277
-
278
- [packages/ditox/src/modules.ts:159](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L159)
279
-
280
- ___
281
-
282
- ### bindMultiValue
283
-
284
- ▸ **bindMultiValue**<`T`\>(`container`, `token`, `value`): `void`
285
-
286
- Rebinds the array by the token with added new value.
287
-
288
- #### Type parameters
289
-
290
- | Name |
291
- | :------ |
292
- | `T` |
293
-
294
- #### Parameters
295
-
296
- | Name | Type | Description |
297
- | :------ | :------ | :------ |
298
- | `container` | [`Container`](README.md#container) | Dependency container. |
299
- | `token` | [`Token`](README.md#token)<readonly `T`[]\> | Token for an array of values. |
300
- | `value` | `T` | New value which is added to the end of the array. |
301
-
302
- #### Returns
303
-
304
- `void`
305
-
306
- #### Defined in
307
-
308
- [packages/ditox/src/utils.ts:27](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L27)
309
-
310
- ___
311
-
312
- ### createContainer
313
-
314
- ▸ **createContainer**(`parentContainer?`): [`Container`](README.md#container)
315
-
316
- Creates a new dependency container.
317
-
318
- Container can have an optional parent to chain token resolution. The parent is used in case the current container does not have a registered token.
319
-
320
- #### Parameters
321
-
322
- | Name | Type | Description |
323
- | :------ | :------ | :------ |
324
- | `parentContainer?` | [`Container`](README.md#container) | Optional parent container. |
325
-
326
- #### Returns
327
-
328
- [`Container`](README.md#container)
329
-
330
- #### Defined in
331
-
332
- [packages/ditox/src/ditox.ts:204](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L204)
333
-
334
- ___
335
-
336
- ### declareModule
337
-
338
- ▸ **declareModule**<`T`\>(`declaration`): [`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>
339
-
340
- Declares a module binding
341
-
342
- **`example`**
343
- ```ts
344
- const LOGGER_MODULE = declareModule<LoggerModule>({
345
- factory: (container) => {
346
- const transport = container.resolve(TRANSPORT_TOKEN).open();
347
- return {
348
- logger: { log: (message) => transport.write(message) },
349
- destroy: () => transport.close(),
350
- }
351
- },
352
- exports: {
353
- logger: LOGGER_TOKEN,
354
- },
355
- });
356
- ```
357
-
358
- #### Type parameters
359
-
360
- | Name |
361
- | :------ |
362
- | `T` |
363
-
364
- #### Parameters
365
-
366
- | Name | Type | Description |
367
- | :------ | :------ | :------ |
368
- | `declaration` | `Omit`<[`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>, ``"token"``\> & `Partial`<`Pick`<[`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>, ``"token"``\>\> | a module declaration |
369
-
370
- #### Returns
371
-
372
- [`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>
373
-
374
- #### Defined in
375
-
376
- [packages/ditox/src/modules.ts:194](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L194)
377
-
378
- ___
379
-
380
- ### declareModuleBindings
381
-
382
- ▸ **declareModuleBindings**(`modules`): [`ModuleDeclaration`](README.md#moduledeclaration)<[`Module`](README.md#module)\>
383
-
384
- Declares bindings of several modules
385
-
386
- #### Parameters
387
-
388
- | Name | Type | Description |
389
- | :------ | :------ | :------ |
390
- | `modules` | readonly [`ModuleBindingEntry`](README.md#modulebindingentry)[] | module declaration entries |
391
-
392
- #### Returns
393
-
394
- [`ModuleDeclaration`](README.md#moduledeclaration)<[`Module`](README.md#module)\>
395
-
396
- #### Defined in
397
-
398
- [packages/ditox/src/modules.ts:206](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L206)
399
-
400
- ___
401
-
402
- ### injectable
403
-
404
- ▸ **injectable**<`Tokens`, `Values`, `Result`\>(`factory`, ...`tokens`): (`container`: [`Container`](README.md#container)) => `Result`
405
-
406
- Decorates a factory by passing resolved values as factory arguments.
407
-
408
- If an argument is an object which has tokens as its properties,
409
- then returns an object containing resolved values as properties.
410
-
411
- #### Type parameters
412
-
413
- | Name | Type |
414
- | :------ | :------ |
415
- | `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { [key: string]: [`Token`](README.md#token)<`unknown`\>; })[] |
416
- | `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : Tokens[K] extends TokenProps<Props\> ? Props : never } |
417
- | `Result` | `Result` |
418
-
419
- #### Parameters
420
-
421
- | Name | Type | Description |
422
- | :------ | :------ | :------ |
423
- | `factory` | (...`params`: `Values`) => `Result` | A factory. |
424
- | `...tokens` | `Tokens` | Tokens which correspond to factory arguments. |
425
-
426
- #### Returns
427
-
428
- `fn`
429
-
430
- Decorated factory which takes a dependency container as a single argument.
431
-
432
- ▸ (`container`): `Result`
433
-
434
- Decorates a factory by passing resolved values as factory arguments.
435
-
436
- If an argument is an object which has tokens as its properties,
437
- then returns an object containing resolved values as properties.
438
-
439
- ##### Parameters
440
-
441
- | Name | Type |
442
- | :------ | :------ |
443
- | `container` | [`Container`](README.md#container) |
444
-
445
- ##### Returns
446
-
447
- `Result`
448
-
449
- Decorated factory which takes a dependency container as a single argument.
450
-
451
- #### Defined in
452
-
453
- [packages/ditox/src/utils.ts:178](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L178)
454
-
455
- ___
456
-
457
- ### injectableClass
458
-
459
- ▸ **injectableClass**<`Tokens`, `Values`, `Result`\>(`constructor`, ...`tokens`): (`container`: [`Container`](README.md#container)) => `Result`
460
-
461
- Decorates a class by passing resolved values as arguments to its constructor.
462
-
463
- If an argument is an object which has tokens as its properties,
464
- then returns an object containing resolved values as properties.
465
-
466
- #### Type parameters
467
-
468
- | Name | Type |
469
- | :------ | :------ |
470
- | `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { [key: string]: [`Token`](README.md#token)<`unknown`\>; })[] |
471
- | `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : Tokens[K] extends TokenProps<Props\> ? Props : never } |
472
- | `Result` | `Result` |
473
-
474
- #### Parameters
475
-
476
- | Name | Type | Description |
477
- | :------ | :------ | :------ |
478
- | `constructor` | (...`params`: `Values`) => `Result` | Constructor of a class |
479
- | `...tokens` | `Tokens` | Tokens which correspond to constructor arguments |
480
-
481
- #### Returns
482
-
483
- `fn`
484
-
485
- A factory function which takes a dependency container as a single argument
486
- and returns a new created class.
487
-
488
- ▸ (`container`): `Result`
489
-
490
- Decorates a class by passing resolved values as arguments to its constructor.
491
-
492
- If an argument is an object which has tokens as its properties,
493
- then returns an object containing resolved values as properties.
494
-
495
- ##### Parameters
496
-
497
- | Name | Type |
498
- | :------ | :------ |
499
- | `container` | [`Container`](README.md#container) |
500
-
501
- ##### Returns
502
-
503
- `Result`
504
-
505
- A factory function which takes a dependency container as a single argument
506
- and returns a new created class.
507
-
508
- #### Defined in
509
-
510
- [packages/ditox/src/utils.ts:211](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L211)
511
-
512
- ___
513
-
514
- ### isToken
515
-
516
- ▸ **isToken**<`T`\>(`value`): value is Token<T\>
517
-
518
- Checks if a value is the token
519
-
520
- #### Type parameters
521
-
522
- | Name |
523
- | :------ |
524
- | `T` |
525
-
526
- #### Parameters
527
-
528
- | Name | Type |
529
- | :------ | :------ |
530
- | `value` | `unknown` |
531
-
532
- #### Returns
533
-
534
- value is Token<T\>
535
-
536
- #### Defined in
537
-
538
- [packages/ditox/src/utils.ts:11](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L11)
539
-
540
- ___
541
-
542
- ### optional
543
-
544
- ▸ **optional**<`T`\>(`token`, `optionalValue`): `OptionalToken`<`T`\>
545
-
546
- Decorate a token with an optional value.
547
- This value is be used as default value in case a container does not have registered token.
548
-
549
- #### Type parameters
550
-
551
- | Name |
552
- | :------ |
553
- | `T` |
554
-
555
- #### Parameters
556
-
557
- | Name | Type | Description |
558
- | :------ | :------ | :------ |
559
- | `token` | [`Token`](README.md#token)<`T`\> | Existed token. |
560
- | `optionalValue` | `T` | Default value for the resolver. |
561
-
562
- #### Returns
563
-
564
- `OptionalToken`<`T`\>
565
-
566
- #### Defined in
567
-
568
- [packages/ditox/src/ditox.ts:41](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L41)
569
-
570
- ▸ **optional**<`T`\>(`token`): `OptionalToken`<`T` \| `undefined`\>
571
-
572
- #### Type parameters
573
-
574
- | Name |
575
- | :------ |
576
- | `T` |
577
-
578
- #### Parameters
579
-
580
- | Name | Type |
581
- | :------ | :------ |
582
- | `token` | [`Token`](README.md#token)<`T`\> |
583
-
584
- #### Returns
585
-
586
- `OptionalToken`<`T` \| `undefined`\>
587
-
588
- #### Defined in
589
-
590
- [packages/ditox/src/ditox.ts:45](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L45)
591
-
592
- ___
593
-
594
- ### resolveValue
595
-
596
- ▸ **resolveValue**<`Tokens`, `Values`\>(`container`, `token`): `Values`
597
-
598
- Resolves a value by the provided token.
599
-
600
- If an argument is an object which has tokens as its properties,
601
- then returns an object containing resolved values as properties.
602
-
603
- If a value is not found by the token, then `ResolverError` is thrown.
604
-
605
- **`example`**
606
- ```ts
607
- const value = resolveValue(container, tokenA);
608
- console.log(value); // 1
609
-
610
- const props = resolveValue(container, {a: tokenA, b: tokenB});
611
- console.log(props); // {a: 1, b: 2}
612
- ```
613
-
614
- #### Type parameters
615
-
616
- | Name | Type |
617
- | :------ | :------ |
618
- | `Tokens` | extends [`Token`](README.md#token)<`unknown`\> \| { [key: string]: [`Token`](README.md#token)<`unknown`\>; } |
619
- | `Values` | extends `unknown` |
620
-
621
- #### Parameters
622
-
623
- | Name | Type |
624
- | :------ | :------ |
625
- | `container` | [`Container`](README.md#container) |
626
- | `token` | `Tokens` |
627
-
628
- #### Returns
629
-
630
- `Values`
631
-
632
- #### Defined in
633
-
634
- [packages/ditox/src/utils.ts:118](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L118)
635
-
636
- ___
637
-
638
- ### resolveValues
639
-
640
- ▸ **resolveValues**<`Tokens`, `Values`\>(`container`, ...`tokens`): `Values`
641
-
642
- Returns an array of resolved values or objects with resolved values.
643
-
644
- If an item of the array is an object which has tokens as its properties,
645
- then returns an object containing resolved values as properties.
646
-
647
- If a token is not found, then `ResolverError` is thrown.
648
-
649
- **`example`**
650
- ```ts
651
- const items1 = resolveValues(container, tokenA);
652
- console.log(items1); // [1]
653
-
654
- const items2 = resolveValues(container, tokenA, {a: tokenA, b: tokenB});
655
- console.log(items2); // [1, {a: 1, b: 2}]
656
- ```
657
-
658
- #### Type parameters
659
-
660
- | Name | Type |
661
- | :------ | :------ |
662
- | `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { [key: string]: [`Token`](README.md#token)<`unknown`\>; })[] |
663
- | `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : Tokens[K] extends TokenProps<Props\> ? Props : never } |
664
-
665
- #### Parameters
666
-
667
- | Name | Type |
668
- | :------ | :------ |
669
- | `container` | [`Container`](README.md#container) |
670
- | `...tokens` | `Tokens` |
671
-
672
- #### Returns
673
-
674
- `Values`
675
-
676
- #### Defined in
677
-
678
- [packages/ditox/src/utils.ts:154](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L154)
679
-
680
- ___
681
-
682
- ### token
683
-
684
- ▸ **token**<`T`\>(`description?`): [`Token`](README.md#token)<`T`\>
685
-
686
- Creates a new binding token.
687
-
688
- #### Type parameters
689
-
690
- | Name |
691
- | :------ |
692
- | `T` |
693
-
694
- #### Parameters
695
-
696
- | Name | Type | Description |
697
- | :------ | :------ | :------ |
698
- | `description?` | `string` | Token description for better error messages. |
699
-
700
- #### Returns
701
-
702
- [`Token`](README.md#token)<`T`\>
703
-
704
- #### Defined in
705
-
706
- [packages/ditox/src/ditox.ts:31](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L31)
707
-
708
- ___
709
-
710
- ### tryResolveValue
711
-
712
- ▸ **tryResolveValue**<`Tokens`, `Values`\>(`container`, `token`): `Values`
713
-
714
- Tries to resolve a value by the provided token.
715
-
716
- If an argument is an object which has tokens as its properties,
717
- then returns an object containing resolved values as properties.
718
-
719
- If a token is not found, then `undefined` value is used.
720
-
721
- **`example`**
722
- ```ts
723
- const value = tryResolveValue(container, tokenA);
724
- console.log(value); // 1
725
-
726
- const props = tryResolveValue(container, {a: tokenA, b: tokenB});
727
- console.log(props); // {a: 1, b: 2}
728
- ```
729
-
730
- #### Type parameters
731
-
732
- | Name | Type |
733
- | :------ | :------ |
734
- | `Tokens` | extends [`Token`](README.md#token)<`unknown`\> \| { [key: string]: [`Token`](README.md#token)<`unknown`\>; } |
735
- | `Values` | extends `unknown` |
736
-
737
- #### Parameters
738
-
739
- | Name | Type |
740
- | :------ | :------ |
741
- | `container` | [`Container`](README.md#container) |
742
- | `token` | `Tokens` |
743
-
744
- #### Returns
745
-
746
- `Values`
747
-
748
- #### Defined in
749
-
750
- [packages/ditox/src/utils.ts:54](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L54)
751
-
752
- ___
753
-
754
- ### tryResolveValues
755
-
756
- ▸ **tryResolveValues**<`Tokens`, `Values`\>(`container`, ...`tokens`): `Values`
757
-
758
- Returns an array of resolved values or objects with resolved values.
759
-
760
- If an item of the array is an object which has tokens as its properties,
761
- then returns an object containing resolved values as properties.
762
-
763
- If a token is not found, then `undefined` value is used.
764
-
765
- **`example`**
766
- ```ts
767
- const items1 = tryResolveValues(container, tokenA);
768
- console.log(items1); // [1]
769
-
770
- const items2 = tryResolveValues(container, tokenA, {a: tokenA, b: tokenB});
771
- console.log(items2); // [1, {a: 1, b: 2}]
772
- ```
773
-
774
- #### Type parameters
775
-
776
- | Name | Type |
777
- | :------ | :------ |
778
- | `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { [key: string]: [`Token`](README.md#token)<`unknown`\>; })[] |
779
- | `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? undefined \| V : Tokens[K] extends TokenProps<Props\> ? Partial<Props\> : never } |
780
-
781
- #### Parameters
782
-
783
- | Name | Type |
784
- | :------ | :------ |
785
- | `container` | [`Container`](README.md#container) |
786
- | `...tokens` | `Tokens` |
787
-
788
- #### Returns
789
-
790
- `Values`
791
-
792
- #### Defined in
793
-
794
- [packages/ditox/src/utils.ts:88](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L88)