Back to Functions

isNative

lang

Checks if value is a native function.

Installation

Import
import { isNative } from '@tulx/utils';

Source Code

Implementation
/**
 * Checks if value is a native function.
 *
 * @param value - The value to check.
 * @returns Returns true if value is a native function, else false.
 *
 * @example
 * ```ts
 * isNative(Array.prototype.push); // true
 * isNative(() => {}); // false
 * ```
 */
export function isNative(value: unknown): boolean {
  return (
    typeof value === 'function' &&
    /^\s*function\s+\w+\s*\(/.test(value.toString())
  );
}

Example

import { isNative } from '@tulx/utils';

isNative(Array.prototype.push); // true
isNative(() => {}); // false

Related Functions