mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-16 19:12:24 +00:00
1.1 KiB
1.1 KiB
youtubei.js / Utils / findVariable
Function: findVariable()
findVariable(
code,options):ASTLookupResult|undefined
Searches for a variable declaration in the given code based on specified criteria.
Parameters
• code: string
• options: ASTLookupArgs
Returns
ASTLookupResult | undefined
An object containing the variable's details if found, undefined otherwise.
Example
// Find a variable by name
const code = 'const x = 5; let y = "hello";';
const a = findVariable(code, { name: 'y' });
console.log(a?.result);
// Find a variable containing specific text
const b = findVariable(code, { includes: 'hello' });
console.log(b?.result);
// Find a variable matching a pattern
const c = findVariable(code, { regexp: /y\s*=\s*"hello"/ });
console.log(c?.result);