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-1/

Script Metadata Extractor

Build a utility that extracts interpreter information from script files.

Requirements

Your task is to create a tool that processes script file content and extracts shebang lines when present. The tool should:

  1. Accept script content as a string input
  2. Detect if the content begins with a shebang line (a line starting with #!)
  3. Extract and return the complete shebang line including the #! prefix
  4. Return null or undefined if no shebang is present
  5. Only recognize shebangs at the very beginning of the file (first character position)

The extracted shebang should include everything from #! up to (but not including) the first newline character.

Test Cases

  • Given a script starting with #!/usr/bin/env node\nconsole.log("hello");, the extracted shebang should be #!/usr/bin/env node @test
  • Given a script starting with #!/bin/bash\necho "test", the extracted shebang should be #!/bin/bash @test
  • Given a script with no shebang like console.log("hello");, the function should return null or undefined @test
  • Given a script starting with #!/usr/bin/python3 -u\nprint("hello"), the extracted shebang should include the arguments: #!/usr/bin/python3 -u @test

Implementation

@generates

API

/**
 * Extracts the shebang line from script content
 *
 * @param {string} content - The script file content
 * @returns {string|null} The complete shebang line including #!, or null if not present
 */
function extractShebang(content) {
  // IMPLEMENTATION HERE
}

module.exports = { extractShebang };

Dependencies { .dependencies }

shebang-regex { .dependency }

Provides regular expression pattern for matching shebang lines.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-shebang-regex

tile.json