get-current-line
Advanced tools
Comparing version 3.1.0 to 4.0.0-next.1588911746.8d29f145b0115d6ab097f90f65279de94526b727
@@ -19,7 +19,6 @@ /** | ||
*/ | ||
export default function getCurrentLine(offset = {}) { | ||
// Prepare | ||
if (offset.file == null) offset.file = __filename | ||
if (offset.method == null) offset.method = 'getCurrentLine' | ||
if (offset.line == null) offset.line = 0 | ||
export default function getCurrentLine( | ||
offset = { file: __filename, method: 'getCurrentLine', frames: 1 } | ||
) { | ||
// prepare | ||
const result = { | ||
@@ -63,9 +62,19 @@ line: -1, | ||
.filter((line) => line.length !== 0) | ||
// Continue | ||
let foundFile = !offset.file | ||
let foundMethod = !offset.method | ||
// Parse our lines | ||
for (const line of lines) { | ||
// offset | ||
if (line.includes(offset.file) || line.includes(offset.method)) continue | ||
if (offset.line !== 0) { | ||
--offset.line | ||
if (!foundFile && line.includes(offset.file)) { | ||
foundFile = true | ||
} | ||
if (!foundMethod && line.includes(offset.method)) { | ||
foundMethod = true | ||
} | ||
if (!foundFile || !foundMethod) { | ||
continue | ||
} else if (offset.frames) { | ||
--offset.frames | ||
continue | ||
} | ||
@@ -72,0 +81,0 @@ // extract |
@@ -21,7 +21,6 @@ 'use strict' | ||
*/ | ||
function getCurrentLine(offset = {}) { | ||
// Prepare | ||
if (offset.file == null) offset.file = __filename | ||
if (offset.method == null) offset.method = 'getCurrentLine' | ||
if (offset.line == null) offset.line = 0 | ||
function getCurrentLine( | ||
offset = { file: __filename, method: 'getCurrentLine', frames: 1 } | ||
) { | ||
// prepare | ||
const result = { | ||
@@ -65,9 +64,19 @@ line: -1, | ||
.filter((line) => line.length !== 0) | ||
// Continue | ||
let foundFile = !offset.file | ||
let foundMethod = !offset.method | ||
// Parse our lines | ||
for (const line of lines) { | ||
// offset | ||
if (line.includes(offset.file) || line.includes(offset.method)) continue | ||
if (offset.line !== 0) { | ||
--offset.line | ||
if (!foundFile && line.includes(offset.file)) { | ||
foundFile = true | ||
} | ||
if (!foundMethod && line.includes(offset.method)) { | ||
foundMethod = true | ||
} | ||
if (!foundFile || !foundMethod) { | ||
continue | ||
} else if (offset.frames) { | ||
--offset.frames | ||
continue | ||
} | ||
@@ -74,0 +83,0 @@ // extract |
# History | ||
## v4.0.0 2020 May 8 | ||
- Breaking Change: | ||
Behaviour of the offset has changed, it now continues until the provided file (if any) or method (if any) is found, once found, it will then continue for the specified frames (if any). | ||
This does not affect you if you never passed an offset, however if you did, you probably want to add `frames: 1` so that it continues oen more stack frame to the probable caller, rather than just stopping at the frame of the found method or file. | ||
The `lines` offset parameter has been discarded and replaced by `frames`, however you probably always want to use `frames` with a `file` or `method` be sure to specify it. | ||
The default offset properties now only apply if no properties were specified, rather than just if a particular property was empty. | ||
- Updated dependencies, [base files](https://github.com/bevry/base), and [editions](https://editions.bevry.me) using [boundation](https://github.com/bevry/boundation) | ||
## v3.1.0 2020 May 4 | ||
@@ -4,0 +18,0 @@ |
{ | ||
"name": "get-current-line", | ||
"version": "3.1.0", | ||
"version": "4.0.0-next.1588911746.8d29f145b0115d6ab097f90f65279de94526b727", | ||
"description": "Get the current line number of the executing file and method", | ||
@@ -11,3 +11,2 @@ "homepage": "https://github.com/bevry/get-current-line", | ||
"debugging", | ||
"dom", | ||
"export-default", | ||
@@ -125,4 +124,4 @@ "file", | ||
"@bevry/update-contributors": "^1.0.1", | ||
"@typescript-eslint/eslint-plugin": "^2.30.0", | ||
"@typescript-eslint/parser": "^2.30.0", | ||
"@typescript-eslint/eslint-plugin": "^2.31.0", | ||
"@typescript-eslint/parser": "^2.31.0", | ||
"assert-helpers": "^6.2.0", | ||
@@ -129,0 +128,0 @@ "eslint": "^6.8.0", |
@@ -70,3 +70,3 @@ <!-- TITLE/ --> | ||
<script type="module"> | ||
import pkg from '//cdn.pika.dev/get-current-line/^3.1.0' | ||
import pkg from '//cdn.pika.dev/get-current-line/^4.0.0' | ||
</script> | ||
@@ -79,3 +79,3 @@ ``` | ||
<script type="module"> | ||
import pkg from '//unpkg.com/get-current-line@^3.1.0' | ||
import pkg from '//unpkg.com/get-current-line@^4.0.0' | ||
</script> | ||
@@ -88,3 +88,3 @@ ``` | ||
<script type="module"> | ||
import pkg from '//dev.jspm.io/get-current-line@3.1.0' | ||
import pkg from '//dev.jspm.io/get-current-line@4.0.0' | ||
</script> | ||
@@ -91,0 +91,0 @@ ``` |
@@ -11,3 +11,10 @@ /** The combination of details about the line that was executing at the time */ | ||
export type LineOffset = Partial<LineInfo> | ||
export interface LineOffset { | ||
/** continue skipping frames until we encounter this method */ | ||
method?: string | null | ||
/** continue skipping frames until we encounter this file */ | ||
file?: string | null | ||
/** once we have encountered our first desired frame, continue for this many frames */ | ||
frames?: number | ||
} | ||
@@ -32,7 +39,6 @@ /** | ||
*/ | ||
export default function getCurrentLine(offset: LineOffset = {}): LineInfo { | ||
// Prepare | ||
if (offset.file == null) offset.file = __filename | ||
if (offset.method == null) offset.method = 'getCurrentLine' | ||
if (offset.line == null) offset.line = 0 | ||
export default function getCurrentLine( | ||
offset: LineOffset = { file: __filename, method: 'getCurrentLine', frames: 1 } | ||
): LineInfo { | ||
// prepare | ||
const result: LineInfo = { | ||
@@ -81,9 +87,20 @@ line: -1, | ||
// Continue | ||
let foundFile: boolean = !offset.file | ||
let foundMethod: boolean = !offset.method | ||
// Parse our lines | ||
for (const line of lines) { | ||
// offset | ||
if (line.includes(offset.file) || line.includes(offset.method)) continue | ||
if (offset.line !== 0) { | ||
--offset.line | ||
if (!foundFile && line.includes(offset.file)) { | ||
foundFile = true | ||
} | ||
if (!foundMethod && line.includes(offset.method)) { | ||
foundMethod = true | ||
} | ||
if (!foundFile || !foundMethod) { | ||
continue | ||
} else if (offset.frames) { | ||
--offset.frames | ||
continue | ||
} | ||
@@ -90,0 +107,0 @@ |
@@ -10,5 +10,5 @@ { | ||
"target": "ESNext", | ||
"lib": ["DOM", "DOM.Iterable"] | ||
"lib": [] | ||
}, | ||
"include": ["source"] | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
28497
333
1