main.js (1863B)
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 propertyNames = require( './../../property-names' ); 24 var propertySymbols = require( './../../property-symbols' ); 25 var isNonEnumerable = require( '@stdlib/assert/is-nonenumerable-property' ); 26 27 28 // MAIN // 29 30 /** 31 * Returns an array of an object's own non-enumerable property names and symbols. 32 * 33 * @param {*} value - input object 34 * @returns {Array} a list of own non-enumerable property names and symbols 35 * 36 * @example 37 * var defineProperty = require( '@stdlib/utils/define-property' ); 38 * 39 * var obj = {}; 40 * 41 * obj.a = 'a'; 42 * defineProperty( obj, 'b', { 43 * 'configurable': false, 44 * 'enumerable': false, 45 * 'writable': false, 46 * 'value': 'b' 47 * }); 48 * 49 * var props = nonEnumerableProperties( obj ); 50 * // returns [ 'b' ] 51 */ 52 function nonEnumerableProperties( value ) { 53 var out; 54 var tmp; 55 var n; 56 var i; 57 58 out = propertyNames( value ); 59 n = 0; 60 for ( i = 0; i < out.length; i++ ) { 61 if ( isNonEnumerable( value, out[ i ] ) ) { 62 out[ n ] = out[ i ]; 63 n += 1; 64 } 65 } 66 out.length = n; 67 68 tmp = propertySymbols( value ); 69 for ( i = 0; i < tmp.length; i++ ) { 70 if ( isNonEnumerable( value, tmp[ i ] ) ) { 71 out.push( tmp[ i ] ); 72 } 73 } 74 return out; 75 } 76 77 78 // EXPORTS // 79 80 module.exports = nonEnumerableProperties;