JavaScript template literal processor with intelligent value interpolation.

Processes template literals with value filtering, array flattening, and whitespace trimming. Core template processor for dynamic JavaScript code generation.

Static template parts.

Dynamic values for interpolation.

Processed JavaScript code.

js`const ${varName} = ${count};`  // "const userCount = 42;"
js`${[1,2,3]}` // "123" (arrays flatten)
js`${null}valid${false}` // "valid" (falsy filtered except 0)
  • Parameters

    • strings: TemplateStringsArray

      Static template parts.

    • Rest...values: any[]

      Interpolated values for processing.

    Returns string

    Processed JavaScript code with trimmed whitespace.

    High-performance JavaScript template literal processor.

    Processes template literals with intelligent value filtering and optimized string building. Performance-optimized with multiple execution paths based on value count.

    • Zero values: Direct string return (fastest path)
    • Single value: Optimized concat operation
    • 2-3 values: StringBuilder pattern
    • 4+ values: Pre-allocated array with exact sizing
    • Extracted validation: Monomorphic function for V8 JIT optimization

    Includes: 0 (zero), truthy values Excludes: null, undefined, false, empty string

    processJSTemplate`let ${'count'} = ${10};`  // "let count = 10;"
    processJSTemplate`${null}${'valid'}` // "valid"
    processJSTemplate`${0}${false}` // "0"