main.js (1630B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 // MODULES // 22 23 var hasOwnProp = require( './../../has-own-property' ); 24 25 26 // MAIN // 27 28 /** 29 * Tests if an object has an inherited property. 30 * 31 * @param {*} value - value to test 32 * @param {*} property - property to test 33 * @returns {boolean} boolean indicating if an object has an inherited property 34 * 35 * @example 36 * var obj = { 37 * 'boop': true 38 * }; 39 * 40 * var bool = isInheritedProperty( obj, 'toString' ); 41 * // returns true 42 * 43 * @example 44 * var obj = { 45 * 'boop': true 46 * }; 47 * 48 * var bool = isInheritedProperty( obj, 'boop' ); 49 * // returns false 50 * 51 * @example 52 * var obj = { 53 * 'boop': true 54 * }; 55 * 56 * var bool = isInheritedProperty( obj, 'bap' ); 57 * // returns false 58 */ 59 function isInheritedProperty( value, property ) { 60 if ( value === void 0 || value === null || hasOwnProp( value, property ) ) { 61 return false; 62 } 63 if ( typeof property === 'symbol' ) { 64 return property in Object( value ); 65 } 66 return ( String( property ) in Object( value ) ); 67 } 68 69 70 // EXPORTS // 71 72 module.exports = isInheritedProperty;