Skip to content

hjfitz/hitcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”— 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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published