time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

main.js (1970B)


      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 isString = require( './../../is-string' );
     24 var isnan = require( './../../is-nan' ).isPrimitive;
     25 var isInteger = require( './../../is-integer' ).isPrimitive;
     26 var isEnum = require( './native.js' );
     27 var hasStringEnumBug = require( './has_string_enumerability_bug.js' );
     28 
     29 
     30 // MAIN //
     31 
     32 /**
     33 * Tests if an object's own property is enumerable.
     34 *
     35 * @param {*} value - value to test
     36 * @param {*} property - property to test
     37 * @returns {boolean} boolean indicating if an object property is enumerable
     38 *
     39 * @example
     40 * var beep = {
     41 *     'boop': true
     42 * };
     43 *
     44 * var bool = isEnumerableProperty( beep, 'boop' );
     45 * // returns true
     46 *
     47 * @example
     48 * var beep = {
     49 *     'boop': true
     50 * };
     51 *
     52 * var bool = isEnumerableProperty( beep, 'hasOwnProperty' );
     53 * // returns false
     54 */
     55 function isEnumerableProperty( value, property ) {
     56 	var bool;
     57 	if (
     58 		value === void 0 ||
     59 		value === null
     60 	) {
     61 		return false;
     62 	}
     63 	bool = isEnum.call( value, property );
     64 	if ( !bool && hasStringEnumBug && isString( value ) ) {
     65 		// Note: we only check for indices, as properties attached to a `String` object are properly detected as enumerable above.
     66 		property = +property;
     67 		return (
     68 			!isnan( property ) &&
     69 			isInteger( property ) &&
     70 			property >= 0 &&
     71 			property < value.length
     72 		);
     73 	}
     74 	return bool;
     75 }
     76 
     77 
     78 // EXPORTS //
     79 
     80 module.exports = isEnumerableProperty;