UNPKG

apphouse

Version:

Component library for React that uses observable state management and theme-able components.

24 lines (21 loc) 508 B
import { isEmpty } from './isEmpty'; /** * Get keys from an object * @example * ```ts * const myObj = { a: 1, b: 2, c: 3 }; * console.log(keys(myObj)); * // Output: ['a', 'b', 'c'] * ``` * @param obj object with string keys * @returns the keys of the object passed as parameter */ export function keys<T>(obj?: T): string[] { if (isEmpty(obj)) { return []; } if (typeof obj !== 'object' || obj === null) { throw new TypeError('Expected an object'); } return Object.keys(obj); }