Skip to content

Commit

Permalink
feat(micro-dash): reduce size of functions()
Browse files Browse the repository at this point in the history
  • Loading branch information
ersimont committed Nov 14, 2020
1 parent 145f301 commit e9efb9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
10 changes: 5 additions & 5 deletions projects/micro-dash/src/lib/object/functions.ts
@@ -1,17 +1,17 @@
import { isFunction, keys } from '../../public-api';
import { isFunction } from '../../public-api';
import { StringifiedKey } from '../interfaces';

/**
* Creates an array of function property names from own enumerable properties of `object`.
*
* Contribution to minified bundle size, when it is the only function imported:
* - Lodash: 3,504 bytes
* - Micro-dash: 310 bytes
* - Micro-dash: 143 bytes
*/
export function functions<T extends object>(obj: T): Array<StringifiedKey<T>> {
return keys(obj).filter(
return Object.getOwnPropertyNames(obj).filter(
(key) =>
key !== 'constructor' &&
isFunction(Object.getOwnPropertyDescriptor(obj, key)?.value),
);
isFunction(Object.getOwnPropertyDescriptor(obj, key)!.value),
) as Array<StringifiedKey<T>>;
}
8 changes: 2 additions & 6 deletions projects/micro-dash/src/lib/object/keys.ts
Expand Up @@ -8,7 +8,7 @@ import { Nil, StringifiedKey } from '../interfaces';
*
* Contribution to minified bundle size, when it is the only function imported:
* - Lodash: 3,326 bytes
* - Micro-dash: 148 bytes
* - Micro-dash: 135 bytes
*/

export function keys<T>(object: T | Nil): Array<StringifiedKey<T>> {
Expand All @@ -21,9 +21,5 @@ export function keys<T>(object: T | Nil): Array<StringifiedKey<T>> {

/** @hidden */
export function keysOfNonArray<T>(object: T | Nil): Array<StringifiedKey<T>> {
let val: string[] = [];
if (object) {
val = Object.getOwnPropertyNames(object);
}
return val as any;
return object ? (Object.getOwnPropertyNames(object) as any) : [];
}

0 comments on commit e9efb9f

Please sign in to comment.