cheprop
Checks if the set property exists in the object. Returns boolean or the value of the property
Last updated 3 years ago by hakarapet .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install cheprop 
SYNC missed versions from official npm registry.

cheprop :)

Description

Checks if the object property is existing and/or returns the value.

Syntax

var cheprop = require('cheprop');
cheprop(object,'path.to.object', [proertyType]);

object : object where the property is to be found.
'path.to.object' : string of property path (e.g. 'object.a.b.c' ).
propertyType: (optional) string indicating which type should property have.
Possible variants: 'array', 'null', 'nun', 'object', 'function', 'number', 'string'.

Installation

npm install cheprop

https://npmjs.org/package/cheprop
Source code available at: https://github.com/hakarapet/cheprop

Usage

NodeJS

const obj = {
    aa: {
        bbb: {
            cccc: 'some string',
            dddd: [1, 2, 3, 4, 5, 6],
            eeee: {
                key: 'value'
            },
            ffff: function () {},
            gggg: 12345,
            hhhh: null,
            iiii: NaN
        }
    }
};
cheProp(obj, 'obj.aa.bbb')

Returns the value of the bbb if it exists in obj.aa

cheProp(obj, 'obj.aa.bbb', 'object')

Returns true if the bbb exists in obj.aa and the type is object
All other possible methods of getting the property are available.

'obj.aa.bbb'
'obj["aa"].bbb'
'obj["aa"]["bbb"]'
'obj["aa"]["bbb"].cccc'
'obj.aa["bbb"].cccc'
'obj.aa["bbb"].dddd'
'obj.aa["bbb"].eeee'
'obj.aa["bbb"].ffff'
'obj.aa["bbb"].gggg'
'obj.aa["bbb"].hhhh'
'obj.aa["bbb"].iiii'
'obj.aa["bbb"].eeee.key'
'obj.aa["bbb"].eeee["key"]'
'obj.aa["bbb"]["eeee"]["key"]'
'obj.aa["bbb"]["eeee"].key'

Test

npm test

Author

Hayk Karapetyan
hakarapet@gmail.com

License

MIT License
https://opensource.org/licenses/MIT

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

1 Versions

  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |