Skip to content

mk-pmb/getown-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published