Skip to content

mfellner/typelens

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

TypeLens

Travis Codecov codebeat license

TypeLens is a typesafe lensing library for JavaScript and TypeScript.

Introduction

TypeLens is inspired by and borrows ideas from Ramda and Fantasy Land. It is made to safely access properties in unknown objects.

Usage

import { lensKey } from 'typelens';

// Fetch some unsafe data.
const data = await fetch(url).then(r => t.json());

// Define a lens for a nested property.
const nameLens = lensKey(['user', 'profile', 'name']);

// Read the value at the focused property using `view`.
// Accessing a value with a lens returns a `Maybe` type.
const nameMaybe = lensKey.view(data);

// Safely resolve the value to a string. If the value is
// undefined, 'anonymous' used used as fallback.
const name: string = nameMaybe.getString('anonymous');

Articles on functional lenses

About

Work in progress.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published