Work in progress.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
package.json
tsconfig.json
tslint.json
yarn.lock

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