Module: Lens
Interfaces
Type Aliases
Get
Ƭ Get<Source, Path>: Source extends Record<string, unknown> ? Path extends `${number}.${infer Right}` ? Get<Source, Right> : Path extends `${infer Left extends keyof Source}.${infer Right}` ? Get<Exclude<Source[Left], undefined>, Right> | Extract<Source[Left], undefined> : Path extends keyof Source ? Source[Path] : never : Source extends any[] ? Path extends `${infer Index extends number}.${infer Right}` ? Get<Exclude<Source[Index], undefined>, Right> | Extract<Source[Index], undefined> : Path extends `${infer Index extends number}` ? Source[Index] : never : never
Gets the value type inside a nested object type Source by provided Path
written in dot-notation.
Type parameters
| Name | Type |
|---|---|
Source | extends Flattenable |
Path | extends string |
Set
Ƭ Set<Source, Path, Value>: Source extends Record<string, unknown> ? Path extends `${number}.${infer Right}` ? Set<Source, Right, Value> : Path extends `${infer Left extends keyof Source}.${infer Right}` ? { [Key in keyof Source]: Key extends Exclude<keyof Source, Left> ? Source[Key] : Set<Exclude<Source[Left], undefined>, Right, Value> } : Path extends keyof Source ? { [Key in keyof Source]: Key extends Exclude<keyof Source, Path> ? Source[Key] : Value } : never : Source extends any[] ? Path extends `${infer Index extends number}.${infer Right}` ? Unshift<Source, Index, Set<Exclude<Source[Index], undefined>, Right, Value>> : Path extends `${infer Index extends number}` ? Unshift<Source, Index, Value> : never : never
Sets the Value type inside a nested object type Source by provided Path
written in dot-notation.
Type parameters
| Name | Type |
|---|---|
Source | extends Flattenable |
Path | extends string |
Value | Value |
Functions
get
▸ get<Source>(source): <Path>(path: Path) => Get<Source, Path>
Gets the value inside a nested source object by provided path
written in dot-notation.
Type parameters
| Name | Type |
|---|---|
Source | extends Flattenable |
Parameters
| Name | Type |
|---|---|
source | Source |
Returns
fn
▸ <Path>(path): Get<Source, Path>
Type parameters
| Name | Type |
|---|---|
Path | extends Flatten<Source> |
Parameters
| Name | Type |
|---|---|
path | Path |
Returns
Get<Source, Path>
▸ get<Source, Path>(path): (source: Source) => Get<Source, Path>
Gets the value inside a nested source object by provided path
written in dot-notation.
Type parameters
| Name | Type |
|---|---|
Source | extends Flattenable |
Path | extends string | number | symbol |
Parameters
| Name | Type |
|---|---|
path | Path |
Returns
fn
▸ (source): Get<Source, Path>
Parameters
| Name | Type |
|---|---|
source | Source |
Returns
Get<Source, Path>
▸ get<Source, Path>(source, path): Get<Source, Path>
Gets the value inside a nested source object by provided path
written in dot-notation.
Type parameters
| Name | Type |
|---|---|
Source | extends Flattenable |
Path | extends string | number | symbol |
Parameters
| Name | Type |
|---|---|
source | Source |
path | Path |
Returns
Get<Source, Path>
lens
▸ lens<Source>(source): Lens<Source>
Creates a wrapper for a given source that provides access to both get and set functionalities for it,
effectively creating a functional lens.
Type parameters
| Name | Type |
|---|---|
Source | extends Flattenable |
Parameters
| Name | Type |
|---|---|
source | Source |
Returns
Lens<Source>
set
▸ set<Source>(source): <Path, Value>(path: Path, value: Value) => Set<Source, Path, Value>
Sets the value inside a nested source object by provided path
written in dot-notation.
Type parameters
| Name | Type |
|---|---|
Source | extends Flattenable |
Parameters
| Name | Type |
|---|---|
source | Source |
Returns
fn
▸ <Path, Value>(path, value): Set<Source, Path, Value>
Type parameters
| Name | Type |
|---|---|
Path | extends Flatten<Source> |
Value | extends Get<Source, Path> |
Parameters
| Name | Type |
|---|---|
path | Path |
value | Value |
Returns
Set<Source, Path, Value>
▸ set<Source, Path, Value>(path, value): (source: Source) => Set<Source, Path, Value>
Sets the value inside a nested source object by provided path
written in dot-notation.
Type parameters
| Name | Type |
|---|---|
Source | extends Flattenable |
Path | extends string | number | symbol |
Value | extends any |
Parameters
| Name | Type |
|---|---|
path | Path |
value | Value |
Returns
fn
▸ (source): Set<Source, Path, Value>
Parameters
| Name | Type |
|---|---|
source | Source |
Returns
Set<Source, Path, Value>
▸ set<Source, Path, Value>(source, path, value): Set<Source, Path, Value>
Sets the value inside a nested source object by provided path
written in dot-notation.
Type parameters
| Name | Type |
|---|---|
Source | extends Flattenable |
Path | extends string | number | symbol |
Value | extends any |
Parameters
| Name | Type |
|---|---|
source | Source |
path | Path |
value | Value |
Returns
Set<Source, Path, Value>