@empathyco/x-get-safe-property-chain

A utility for safely retrieving nested values.

Usage no npm install needed!

<script type="module">
  import empathycoXGetSafePropertyChain from 'https://cdn.skypack.dev/@empathyco/x-get-safe-property-chain';
</script>

README

x-get-safe-property-chain

A utility for safely retrieving nested values.

Installation

You can install the package using npm

npm install @empathyco/x-get-safe-property-chain --save-dev

Usage

import { getSafePropertyChain } from '@empathyco/x-get-safe-property-chain';

const obj = { nestedObject: { anotherNestedObject: { message: 'Hell yeah!' } } }; 
const message = getSafePropertyChain(obj, 'nestedObject.anotherNestedObject.message');
console.log(message); // 'Hell yeah!'