@ryusei/light
Version:
<div align="center"> <a href="https://light.ryuseijs.com"> <img alt="RyuseiLight" src="https://light.ryuseijs.com/images/svg/logo.svg" width="70"> </a>
18 lines (16 loc) • 559 B
text/typescript
/**
* Iterates over the provided object by own enumerable keys with calling the iteratee function.
*
* @param object - An object to iterate over.
* @param iteratee - An iteratee function that takes the value and key as arguments.
*
* @return A provided object itself.
*/
export function forOwn<T extends object>( object: T, iteratee: ( value: T[ keyof T ], key: string ) => void ) {
if ( object ) {
const keys = Object.keys( object );
for ( let i = 0; i < keys.length; i++ ) {
iteratee( object[ keys[ i ] ], keys[ i ] );
}
}
}