__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'
__LINE__ is available globally across the entire page..js file — inline scripts report the rendered page line number, not the source file.
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
}
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...`
}