Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

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

README.md

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

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.