get-current-line
Advanced tools
Comparing version 4.0.0 to 5.0.0-next.1588915085.6932dd53f9475bf57202af9776b27444739814e7
/** | ||
* Get the information about the line that called this method. | ||
* @param offset set this to the distance between this method and the true caller | ||
* @param offset continue until these offset conditions are met, used to continue to the caller | ||
* @throws if a failure occured creating the line info | ||
@@ -20,3 +20,7 @@ * @example Input | ||
export default function getCurrentLine( | ||
offset = { file: __filename, method: 'getCurrentLine', frames: 1 } | ||
offset = { | ||
file: __filename, | ||
method: 'getCurrentLine', | ||
frames: 0, | ||
} | ||
) { | ||
@@ -63,34 +67,44 @@ // prepare | ||
// Continue | ||
let foundFile = !offset.file | ||
let foundMethod = !offset.method | ||
let found = !offset.file && !offset.method | ||
let exited = found | ||
// Parse our lines | ||
for (const line of lines) { | ||
// offset | ||
if (!foundFile && line.includes(offset.file)) { | ||
foundFile = true | ||
let i = 0 | ||
while (i < lines.length) { | ||
const line = lines[i] | ||
// continue | ||
if (found && exited) { | ||
const parts = line.split(':') | ||
if (parts.length >= 2) { | ||
if (parts[0].indexOf('(') === -1) { | ||
result.method = 'unknown' | ||
result.file = parts[0].replace(/^.+?\s+at\s+/, '') | ||
} else { | ||
result.method = parts[0] | ||
.replace(/^.+?\s+at\s+/, '') | ||
.replace(/\s+\(.+$/, '') | ||
result.file = parts[0].replace(/^.+?\(/, '') | ||
} | ||
result.line = Number(parts[1]) | ||
break | ||
} | ||
// found and exited, but not a valid entry, so continue | ||
++i | ||
continue | ||
} | ||
if (!foundMethod && line.includes(offset.method)) { | ||
foundMethod = true | ||
} | ||
if (!foundFile || !foundMethod) { | ||
// continue until found and exited | ||
if (line.includes(offset.file) || line.includes(offset.method)) { | ||
found = true | ||
// next item | ||
++i | ||
continue | ||
} else if (offset.frames) { | ||
--offset.frames | ||
} else if (found) { | ||
// exited, apply frame offset and call it a day | ||
i += offset.frames || 0 | ||
exited = true | ||
continue | ||
} else { | ||
// nothing found yet, next item | ||
++i | ||
continue | ||
} | ||
// extract | ||
const parts = line.split(':') | ||
if (parts.length >= 2) { | ||
if (parts[0].indexOf('(') === -1) { | ||
result.method = 'unknown' | ||
result.file = parts[0].replace(/^.+?\s+at\s+/, '') | ||
} else { | ||
result.method = parts[0] | ||
.replace(/^.+?\s+at\s+/, '') | ||
.replace(/\s+\(.+$/, '') | ||
result.file = parts[0].replace(/^.+?\(/, '') | ||
} | ||
result.line = Number(parts[1]) | ||
break | ||
} | ||
} | ||
@@ -97,0 +111,0 @@ } catch (err) { |
@@ -5,3 +5,3 @@ 'use strict' | ||
* Get the information about the line that called this method. | ||
* @param offset set this to the distance between this method and the true caller | ||
* @param offset continue until these offset conditions are met, used to continue to the caller | ||
* @throws if a failure occured creating the line info | ||
@@ -23,3 +23,7 @@ * @example Input | ||
function getCurrentLine( | ||
offset = { file: __filename, method: 'getCurrentLine', frames: 1 } | ||
offset = { | ||
file: __filename, | ||
method: 'getCurrentLine', | ||
frames: 0, | ||
} | ||
) { | ||
@@ -66,34 +70,44 @@ // prepare | ||
// Continue | ||
let foundFile = !offset.file | ||
let foundMethod = !offset.method | ||
let found = !offset.file && !offset.method | ||
let exited = found | ||
// Parse our lines | ||
for (const line of lines) { | ||
// offset | ||
if (!foundFile && line.includes(offset.file)) { | ||
foundFile = true | ||
let i = 0 | ||
while (i < lines.length) { | ||
const line = lines[i] | ||
// continue | ||
if (found && exited) { | ||
const parts = line.split(':') | ||
if (parts.length >= 2) { | ||
if (parts[0].indexOf('(') === -1) { | ||
result.method = 'unknown' | ||
result.file = parts[0].replace(/^.+?\s+at\s+/, '') | ||
} else { | ||
result.method = parts[0] | ||
.replace(/^.+?\s+at\s+/, '') | ||
.replace(/\s+\(.+$/, '') | ||
result.file = parts[0].replace(/^.+?\(/, '') | ||
} | ||
result.line = Number(parts[1]) | ||
break | ||
} | ||
// found and exited, but not a valid entry, so continue | ||
++i | ||
continue | ||
} | ||
if (!foundMethod && line.includes(offset.method)) { | ||
foundMethod = true | ||
} | ||
if (!foundFile || !foundMethod) { | ||
// continue until found and exited | ||
if (line.includes(offset.file) || line.includes(offset.method)) { | ||
found = true | ||
// next item | ||
++i | ||
continue | ||
} else if (offset.frames) { | ||
--offset.frames | ||
} else if (found) { | ||
// exited, apply frame offset and call it a day | ||
i += offset.frames || 0 | ||
exited = true | ||
continue | ||
} else { | ||
// nothing found yet, next item | ||
++i | ||
continue | ||
} | ||
// extract | ||
const parts = line.split(':') | ||
if (parts.length >= 2) { | ||
if (parts[0].indexOf('(') === -1) { | ||
result.method = 'unknown' | ||
result.file = parts[0].replace(/^.+?\s+at\s+/, '') | ||
} else { | ||
result.method = parts[0] | ||
.replace(/^.+?\s+at\s+/, '') | ||
.replace(/\s+\(.+$/, '') | ||
result.file = parts[0].replace(/^.+?\(/, '') | ||
} | ||
result.line = Number(parts[1]) | ||
break | ||
} | ||
} | ||
@@ -100,0 +114,0 @@ } catch (err) { |
# History | ||
## v5.0.0 2020 May 8 | ||
- Breaking Change: | ||
Offset intention is now compatible with v3 and below. That is, skipping will continue until: | ||
1. The file or method is found | ||
2. Once found, will continue until neither the file nor method are found anymore | ||
3. Once exited, the frame offset will then apply | ||
If you still wish to capture the method or the file, combine them with `frames: -1`. | ||
- Updated dependencies, [base files](https://github.com/bevry/base), and [editions](https://editions.bevry.me) using [boundation](https://github.com/bevry/boundation) | ||
## v4.0.0 2020 May 8 | ||
@@ -4,0 +18,0 @@ |
{ | ||
"name": "get-current-line", | ||
"version": "4.0.0", | ||
"version": "5.0.0-next.1588915085.6932dd53f9475bf57202af9776b27444739814e7", | ||
"description": "Get the current line number of the executing file and method", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/bevry/get-current-line", |
@@ -70,3 +70,3 @@ <!-- TITLE/ --> | ||
<script type="module"> | ||
import pkg from '//cdn.pika.dev/get-current-line/^4.0.0' | ||
import pkg from '//cdn.pika.dev/get-current-line/^5.0.0' | ||
</script> | ||
@@ -79,3 +79,3 @@ ``` | ||
<script type="module"> | ||
import pkg from '//unpkg.com/get-current-line@^4.0.0' | ||
import pkg from '//unpkg.com/get-current-line@^5.0.0' | ||
</script> | ||
@@ -88,3 +88,3 @@ ``` | ||
<script type="module"> | ||
import pkg from '//dev.jspm.io/get-current-line@4.0.0' | ||
import pkg from '//dev.jspm.io/get-current-line@5.0.0' | ||
</script> | ||
@@ -91,0 +91,0 @@ ``` |
@@ -11,8 +11,31 @@ /** The combination of details about the line that was executing at the time */ | ||
/** | ||
* If provided, continue skipping until: | ||
* | ||
* 1. The file or method is found | ||
* 2. Once found, will continue until neither the file nor method are found anymore | ||
* 3. Once exited, the frame offset will then apply | ||
* | ||
* If you wish to capture the method or the file, combine them with `frames: -1`. | ||
* | ||
* If you wish for more customisation than this, create an issue requesting passing a custom skip handler function, as more variance to this interface is too much customisation complexity. | ||
*/ | ||
export interface LineOffset { | ||
/** continue skipping frames until we encounter this method */ | ||
/** | ||
* if provided, continue until a method containing this string is exited | ||
* if provided alongside a file, will continue until neither the file nor method are found | ||
* this allows file and method to act as fallbacks for each other, such that if one is not found, it doesn't skip everything | ||
*/ | ||
method?: string | null | ||
/** continue skipping frames until we encounter this file */ | ||
/** | ||
* if provided, continue until a file containing this string is exited | ||
* if provided alongside a method, will continue until neither the file nor method are found | ||
* this allows file and method to act as fallbacks for each other, such that if one is not found, it doesn't skip everything | ||
*/ | ||
file?: string | null | ||
/** once we have encountered our first desired frame, continue for this many frames */ | ||
/** | ||
* once we have satisfied the found condition, if any, then apply this index offset to the frames | ||
* e.g. 1 would mean next frame, and -1 would mean the previous frame | ||
* Use -1 to go back to the found method or file | ||
*/ | ||
frames?: number | ||
@@ -23,3 +46,3 @@ } | ||
* Get the information about the line that called this method. | ||
* @param offset set this to the distance between this method and the true caller | ||
* @param offset continue until these offset conditions are met, used to continue to the caller | ||
* @throws if a failure occured creating the line info | ||
@@ -41,3 +64,7 @@ * @example Input | ||
export default function getCurrentLine( | ||
offset: LineOffset = { file: __filename, method: 'getCurrentLine', frames: 1 } | ||
offset: LineOffset = { | ||
file: __filename, | ||
method: 'getCurrentLine', | ||
frames: 0, | ||
} | ||
): LineInfo { | ||
@@ -89,36 +116,47 @@ // prepare | ||
// Continue | ||
let foundFile: boolean = !offset.file | ||
let foundMethod: boolean = !offset.method | ||
let found: boolean = !offset.file && !offset.method | ||
let exited: boolean = found | ||
// Parse our lines | ||
for (const line of lines) { | ||
// offset | ||
if (!foundFile && line.includes(offset.file)) { | ||
foundFile = true | ||
let i = 0 | ||
while (i < lines.length) { | ||
const line = lines[i] | ||
// continue | ||
if (found && exited) { | ||
const parts = line.split(':') | ||
if (parts.length >= 2) { | ||
if (parts[0].indexOf('(') === -1) { | ||
result.method = 'unknown' | ||
result.file = parts[0].replace(/^.+?\s+at\s+/, '') | ||
} else { | ||
result.method = parts[0] | ||
.replace(/^.+?\s+at\s+/, '') | ||
.replace(/\s+\(.+$/, '') | ||
result.file = parts[0].replace(/^.+?\(/, '') | ||
} | ||
result.line = Number(parts[1]) | ||
break | ||
} | ||
// found and exited, but not a valid entry, so continue | ||
++i | ||
continue | ||
} | ||
if (!foundMethod && line.includes(offset.method)) { | ||
foundMethod = true | ||
} | ||
if (!foundFile || !foundMethod) { | ||
// continue until found and exited | ||
if (line.includes(offset.file) || line.includes(offset.method)) { | ||
found = true | ||
// next item | ||
++i | ||
continue | ||
} else if (offset.frames) { | ||
--offset.frames | ||
} else if (found) { | ||
// exited, apply frame offset and call it a day | ||
i += offset.frames || 0 | ||
exited = true | ||
continue | ||
} else { | ||
// nothing found yet, next item | ||
++i | ||
continue | ||
} | ||
// extract | ||
const parts = line.split(':') | ||
if (parts.length >= 2) { | ||
if (parts[0].indexOf('(') === -1) { | ||
result.method = 'unknown' | ||
result.file = parts[0].replace(/^.+?\s+at\s+/, '') | ||
} else { | ||
result.method = parts[0] | ||
.replace(/^.+?\s+at\s+/, '') | ||
.replace(/\s+\(.+$/, '') | ||
result.file = parts[0].replace(/^.+?\(/, '') | ||
} | ||
result.line = Number(parts[1]) | ||
break | ||
} | ||
} | ||
@@ -125,0 +163,0 @@ } catch (err) { |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
30994
398
1