Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rakannimer/typesafe-get
Safely drill for nested values
https://github.com/rakannimer/typesafe-get
Last synced: 7 days ago
JSON representation
Safely drill for nested values
- Host: GitHub
- URL: https://github.com/rakannimer/typesafe-get
- Owner: rakannimer
- Created: 2019-05-07T09:55:54.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T05:17:14.000Z (about 2 years ago)
- Last Synced: 2024-12-21T23:16:06.843Z (2 months ago)
- Language: TypeScript
- Size: 3.9 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## typesafe-get
Safely drill for nested values
## Install```sh
yarn add typesafe-get
```## Usage
```typescript
import get from "ts-typesafe-get";const obj = { a: 1, b: 2 };
const undef = undefined;
expect(get(() => obj.b, -1)).toEqual(2);
expect(get(() => obj.c, -1)).toEqual(-1);
expect(get(() => obj.a, -1)).toEqual(1);
expect(get(() => undef.a[0].b, -1)).toEqual(-1);
```## API
### Signature :
```typescript
function get(
reducer: () => O,
defaultTo: Exclude
): Exclude;
```