hjfitz / hitcher

πŸ”— Optional chaining, but now

Home Page:https://www.npmjs.com/package/hitcher

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ”— Hitcher

Optional object chaining, but now

Install

yarn add hitcher

Usage

import hitch from 'hitcher'

const myObj = {
	person: {
		name: {
			first: 'Harry',
			last: 'Fitz'
		},
		github: '@hjfitz'
	}
}

const first = hitch(myObj, 'person', 'name', 'first')

API

chain(obj: object, ...keys: string|number)

Follows ...keys in obj, to find the value. Better than doing const foo = obj && obj[key] && obj[key][key2] && obj[key][key2][key3] and so on.

Soon, one can use obj?.key?.key2?.key3.

Inspiration

Optional object chaining - a new feature to land in ES!

About

πŸ”— Optional chaining, but now

https://www.npmjs.com/package/hitcher


Languages

Language:TypeScript 54.2%Language:JavaScript 45.8%