Created
August 26, 2019 22:35
-
-
Save cacheflow/c20aeeae7137221b0df01da1358127e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import isNil from "@unction/isnil"; | |
export default function get(name: any) { | |
return function getProperty(keyedFunctor: any): null | unknown { | |
if (isNil(keyedFunctor)) { | |
return keyedFunctor; | |
} | |
if (keyedFunctor.get) { | |
return keyedFunctor.get(name); | |
} | |
return keyedFunctor[name]; | |
}; | |
} | |
get('hello')(new Map([['hello', 'world']])) | |
get('hello')({ hello: 'world' }) | |
get('hello')({ goodbye: 'world' }) | |
get(0)(['hello world']) | |
get(0)('hello world') | |
get(0)(null) | |
get(0)(undefined) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment