amensum / hasget

Home Page:https://npmjs.com/package/hasget

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hasget

version size license downloads

By this library you easy can:

  • Check if the specified nested property of object exists as a direct property of object;
  • Get the specified nested property of object as a direct property of object;

Installing

Using npm:

$ npm install hasget

Using jsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/hasget/dist/hasget.min.js"></script>

Using unpkg CDN:

<script src="https://unpkg.com/hasget/dist/hasget.min.js"></script>

Usage

Import (module):

import { has, get } from 'hasget';

Import (global):

const { has, get } = hasget;

Example:

const obj = { user: { firstname: 'Nik', lastname: null } };

has(obj, 'user'); // true
get(obj, 'user'); // { firstname: 'Nik', lastname: null }

has(obj, 'user.firstname'); // true
get(obj, 'user.firstname'); // 'Nik'

has(obj, 'user.lastname'); // true
get(obj, 'user.lastname'); // null

has(obj, 'user.birthdate'); // false
get(obj, 'user.birthdate'); // undefined

has(obj, 'user.birthdate.year'); // false
get(obj, 'user.birthdate.year'); // undefined

About

https://npmjs.com/package/hasget


Languages

Language:JavaScript 100.0%