1.0.6 • Published 3 years ago

hasget v1.0.6

Weekly downloads
15
License
ISC
Repository
github
Last release
3 years ago

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
1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago