predictype
Version:
PredicType is a library of pre-built and tested predicates for TypeScript, covering various data types and operations.
32 lines (31 loc) • 1.24 kB
TypeScript
import { FunctionStateOper } from '../../enums/functions.js';
/**
* Checks the state of a function (e.g. async, generator, constructor, arrow, anonymous, has name) using the specified
* operation.
*
* @param source The function to check.
* @param oper The state operation to perform (e.g. 'is_async', 'is_arrow').
* @returns True if the state check is valid according to the operator, otherwise false.
*
* @throws {Error} If the operation is not recognized.
*
* @example
* const asyncFn = async function foo() {};
* const genFn = function* gen() {};
*
* functionState(asyncFn, 'is_async'); // true
* functionState(genFn, 'is_generator'); // true
* functionState(() => {}, 'is_arrow'); // true
* functionState(function() {}, 'is_anonymous'); // true
* functionState(function named() {}, 'has_name'); // true
*
* @remarks
* Supported Operators:
* - **HAS_NAME**: Function has a name
* - **IS_ANONYMOUS**: Function is anonymous
* - **IS_ARROW**: Function is an arrow function
* - **IS_ASYNC**: Function is async
* - **IS_CONSTRUCTOR**: Function is a constructor
* - **IS_GENERATOR**: Function is a generator function
*/
export declare function functionState(source: Function, oper: FunctionStateOper): boolean;