builtin.js (1784B)
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 // VARIABLES // 22 23 var propertyDescriptor = Object.getOwnPropertyDescriptor; 24 25 26 // MAIN // 27 28 /** 29 * Returns a property descriptor for an object's own property. 30 * 31 * ## Notes 32 * 33 * - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error. 34 * - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`. 35 * 36 * @private 37 * @param {*} value - input object 38 * @param {(string|symbol)} property - property 39 * @returns {(Object|null)} property descriptor or null 40 * 41 * @example 42 * var obj = { 43 * 'beep': 'boop', 44 * 'foo': 3.14 45 * }; 46 * 47 * var desc = getOwnPropertyDescriptor( obj, 'foo' ); 48 * // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14} 49 */ 50 function getOwnPropertyDescriptor( value, property ) { 51 var desc; 52 if ( value === null || value === void 0 ) { 53 return null; 54 } 55 desc = propertyDescriptor( value, property ); 56 return ( desc === void 0 ) ? null : desc; 57 } 58 59 60 // EXPORTS // 61 62 module.exports = getOwnPropertyDescriptor;