Skip to main content

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

NameType
Sourceextends Flattenable
Pathextends 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

NameType
Sourceextends Flattenable
Pathextends string
ValueValue

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

NameType
Sourceextends Flattenable

Parameters

NameType
sourceSource

Returns

fn

▸ <Path>(path): Get<Source, Path>

Type parameters
NameType
Pathextends Flatten<Source>
Parameters
NameType
pathPath
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

NameType
Sourceextends Flattenable
Pathextends string | number | symbol

Parameters

NameType
pathPath

Returns

fn

▸ (source): Get<Source, Path>

Parameters
NameType
sourceSource
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

NameType
Sourceextends Flattenable
Pathextends string | number | symbol

Parameters

NameType
sourceSource
pathPath

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

NameType
Sourceextends Flattenable

Parameters

NameType
sourceSource

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

NameType
Sourceextends Flattenable

Parameters

NameType
sourceSource

Returns

fn

▸ <Path, Value>(path, value): Set<Source, Path, Value>

Type parameters
NameType
Pathextends Flatten<Source>
Valueextends Get<Source, Path>
Parameters
NameType
pathPath
valueValue
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

NameType
Sourceextends Flattenable
Pathextends string | number | symbol
Valueextends any

Parameters

NameType
pathPath
valueValue

Returns

fn

▸ (source): Set<Source, Path, Value>

Parameters
NameType
sourceSource
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

NameType
Sourceextends Flattenable
Pathextends string | number | symbol
Valueextends any

Parameters

NameType
sourceSource
pathPath
valueValue

Returns

Set<Source, Path, Value>