CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-shebang-regex

Regular expression for matching Unix shebang lines at the beginning of files

88

1.54x
Overview
Eval results
Files

task.mdevals/scenario-7/

Script Analyzer

Build a utility that analyzes multiple script files and safely extracts interpreter information, handling files that may or may not contain shebang lines.

Requirements

Your implementation should:

  1. Accept an array of script content strings as input
  2. For each script, safely extract the interpreter path (without the #! prefix) if a shebang exists
  3. Return an array of results where each result contains:
    • hasShebang: boolean indicating if a shebang was found
    • interpreter: the interpreter path if found, or null if not found
  4. Handle edge cases gracefully without throwing errors for scripts without shebangs

Test Cases

  • Given an array with one script containing #!/usr/bin/env node\nconsole.log("test"), returns [{hasShebang: true, interpreter: "/usr/bin/env node"}] @test
  • Given an array with one script containing no shebang console.log("test"), returns [{hasShebang: false, interpreter: null}] @test
  • Given an array with three scripts where only the second has a shebang #!/bin/bash\necho "hi", returns correct results for all three scripts @test
  • Given an empty array, returns an empty array @test

Implementation

@generates

API

/**
 * Analyzes an array of script strings and extracts interpreter information.
 *
 * @param {string[]} scripts - Array of script content strings
 * @returns {Array<{hasShebang: boolean, interpreter: string|null}>} Array of analysis results
 */
function analyzeScripts(scripts) {
  // IMPLEMENTATION HERE
}

module.exports = { analyzeScripts };

Dependencies { .dependencies }

shebang-regex { .dependency }

Provides regular expression for matching shebang lines

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-shebang-regex

tile.json