1.0.0 • Published 4 years ago

getown v1.0.0

Weekly downloads
61
License
ISC
Repository
github
Last release
4 years ago

getown

Lookup an object property only if it's its own property.

API

This module exports one function:

getown(obj, prop, fallback)

Returns obj[prop] if obj is truthy and has an own property prop, otherwise returns fallback.

Usage

from test/usage.mjs:

import getown from 'getown';
const dict = { foo: 'bar' };
same(getown(dict, 'foo'), 'bar');
same(getown(dict, 'bar'), undefined);
same(getown(dict, 'bar', 321), 321);
same(typeof dict.toString, 'function');
same(getown(dict, 'toString'), undefined);

Known issues

  • Needs more/better tests and docs.

 

License

ISC