Files
YouTube.js/docs/api/namespaces/Utils/functions/findFunction.md
2025-07-22 16:53:42 -03:00

1.0 KiB

youtubei.js / Utils / findFunction

Function: findFunction()

findFunction(source, args): ASTLookupResult | undefined

Searches for a function in the given code based on specified criteria.

Parameters

source: string

args: ASTLookupArgs

Returns

ASTLookupResult | undefined

An object containing the function's details if found, undefined otherwise.

Example

const source = '(function() {var foo, bar; foo = function() { console.log("foo"); }; bar = function() { console.log("bar"); }; })();';
const result = findFunction(source, { name: 'bar' });
console.log(result);
// Output: { start: 69, end: 110, name: 'bar', node: { ... }, result: 'bar = function() { console.log("bar"); };' }

Defined in

src/utils/Utils.ts:311