1.1.1 • Published 6 years ago

@datorama/ts-safe-access v1.1.1

Weekly downloads
2,926
License
MIT
Repository
github
Last release
6 years ago

🍭 It's Like Lodash get with the 💪 of Typescript

Build Status License Stars

Installation

npm install @datorama/ts-safe-access --save

Usage

  • get(object, getFn[, defaultValue, excludeNull = false]) - Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.

Options

OptionDescriptionDefault Value
defaultValueIf the resolved value is undefined, the defaultValue is returned in its place.undefined
excludeNullif the resolved value is null, the defaultValue is returned in its place.false
const data = {its: {really: {really: {really: {nested : undefined}}}}, nested: {value: null}};
const result = get(data, data => data.its.really.really.really.nested, 'defaultValue');
  • has(object, getFn) - Checks if path is a direct property of object.
const data = {its: {really: {really: {}}, b: {}};
const result = has(data, data => data.its.really.really.really.nested);

expect(result).toEqual(false);