Utils (@pim.sk/utils)

line

Registers a global getter __LINE__ on window. Each access returns the current file name and line number by parsing the Error stack. Zero config — just import it once.
import '@pim.sk/utils/line.mjs'
Side-effect only import — no default export. After import, __LINE__ is available globally across the entire page.
Note: place code in a separate .js file — inline scripts report the rendered page line number, not the source file.

Usage

__LINE__

Global getter. Returns the current file name and line number from the Error stack. Use wherever you need to know where in the code execution is at.

// line-tutorial.js

export function exampleBasic(output) {
    output.textContent = __LINE__    // → line-tutorial.js:2
}

Usage in debug logging

Tag every console.log with its exact location. Useful when tracing call flow across multiple functions — no need to manually write file or line info.

function step1() {
    console.log( __LINE__, "step1 start" )
    step2()
    console.log( __LINE__, "step1 end" )
}
function step2() {
    console.log( __LINE__, "step2" )
}
step1()
// line-tutorial.js

export function exampleLog(output) {
    function step1() {
        const a = __LINE__    // → line-tutorial.js:8
        step2()
        const b = __LINE__    // → line-tutorial.js:10
        return [a, b]
    }
    function step2() {
        return __LINE__       // → line-tutorial.js:14
    }
    const [a, b] = step1()
    output.textContent = `step1 start  →  ${a}\n...`
}
v 1.1.2