YouTube.js
Guide
Discord
GitHub
Guide
Discord
GitHub

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

Edit this page
Last Updated:: 6/8/25, 5:43 PM
Contributors: Luan