shaharkazaz / ts-safe-access

🍭 It's Like Lodash get with the πŸ’ͺ of Typescript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🍭 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]) - Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
const data = {its: {really: {really: {really: {nested : undefined}}}}, b: {}};
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);

About

🍭 It's Like Lodash get with the πŸ’ͺ of Typescript


Languages

Language:HTML 49.1%Language:JavaScript 23.7%Language:CSS 23.1%Language:TypeScript 4.1%