homebridge-bondbridge
Version:
Plugin to integrate BondBridge units by Bond to Homekit
30 lines (24 loc) • 662 B
JavaScript
;
// Description:
// Create an Object prototype to for getting an index of an enumerated type.
//
module.exports=Object.defineProperty(Object.prototype, "Bb2indexOfEnum", {
value: function( predicate, fromIndex ) {
let length = this == null ? 0 : Object.keys( this ).length;
if ( !length )
return -1;
let index = fromIndex == null ? 0 : fromIndex;
if ( index < 0 )
{
index = Math.max( length + index, 0 );
}
for ( let i=index; i < length; i++)
{
if ( predicate( this[ i ], i, this ) )
{
return i;
}
}
return -1;
}
});