Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-current-line

Package Overview
Dependencies
Maintainers
1
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-current-line - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0-next.1576089687.0e8bd8e7a00812d457332b9c28677888df5e1d5f

23

edition-browsers/index.js
/**
* Get the information about the line that called this method.
* @param offset set this to the distance of lines between this method and the true caller
* @param offset set this to the distance between this method and the true caller
* @throws if a failure occured creating the line info

@@ -19,5 +19,10 @@ * @example Input

*/
export default function getLineInfo(offset = 0) {
export default function getCurrentLine(offset = {}) {
// Prepare
offset = Math.abs(offset);
if (offset.file == null)
offset.file = __filename;
if (offset.method == null)
offset.method = 'getCurrentLine';
if (offset.line == null)
offset.line = 0;
const result = {

@@ -66,11 +71,11 @@ line: -1,

// Parse our lines
for (let index = 0; index < lines.length; index++) {
const line = lines[index];
if (line.includes(__filename) || line.includes(' at ') === false) {
for (const line of lines) {
// offset
if (line.includes(offset.file) || line.includes(offset.method))
continue;
}
if (offset !== 0) {
--offset;
if (offset.line !== 0) {
--offset.line;
continue;
}
// extract
const parts = line.split(':');

@@ -77,0 +82,0 @@ if (parts.length >= 2) {

@@ -5,3 +5,3 @@ "use strict";

* Get the information about the line that called this method.
* @param offset set this to the distance of lines between this method and the true caller
* @param offset set this to the distance between this method and the true caller
* @throws if a failure occured creating the line info

@@ -22,5 +22,10 @@ * @example Input

*/
function getLineInfo(offset = 0) {
function getCurrentLine(offset = {}) {
// Prepare
offset = Math.abs(offset);
if (offset.file == null)
offset.file = __filename;
if (offset.method == null)
offset.method = 'getCurrentLine';
if (offset.line == null)
offset.line = 0;
const result = {

@@ -69,11 +74,11 @@ line: -1,

// Parse our lines
for (let index = 0; index < lines.length; index++) {
const line = lines[index];
if (line.includes(__filename) || line.includes(' at ') === false) {
for (const line of lines) {
// offset
if (line.includes(offset.file) || line.includes(offset.method))
continue;
}
if (offset !== 0) {
--offset;
if (offset.line !== 0) {
--offset.line;
continue;
}
// extract
const parts = line.split(':');

@@ -102,2 +107,2 @@ if (parts.length >= 2) {

}
exports.default = getLineInfo;
exports.default = getCurrentLine;
# History
## v2.0.0 2019 December 12
- Offset is now an object that supports `file`, `method`, and `line`
## v1.0.0 2019 December 12
- Extracted out from [Caterpillar v4.0.0](https://github.com/bevry/caterpillar/blob/20fde0ae4519f178ef0768e8183b4e413a44fcd1/source/logger.js#L202-L297)
{
"name": "get-current-line",
"version": "1.0.0",
"version": "2.0.0-next.1576089687.0e8bd8e7a00812d457332b9c28677888df5e1d5f",
"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/ -->

[API Documentation.](http://master.get-current-line.bevry.surge.sh/docs/)
[Complete API Documentation.](http://master.get-current-line.bevry.surge.sh/docs/)

@@ -76,3 +76,3 @@ ```javascript

console.log(
getCurrentLine(/* optional offset number of lines to skip if your caller is wrapped */)
getCurrentLine(/* optional offset information in case the caller is wrapped */)
)

@@ -79,0 +79,0 @@ ```

@@ -11,5 +11,7 @@ /** The combination of details about the line that was executing at the time */

export type LineOffset = Partial<LineInfo>
/**
* Get the information about the line that called this method.
* @param offset set this to the distance of lines between this method and the true caller
* @param offset set this to the distance between this method and the true caller
* @throws if a failure occured creating the line info

@@ -30,5 +32,7 @@ * @example Input

*/
export default function getLineInfo(offset: number = 0): LineInfo {
export default function getCurrentLine(offset: LineOffset = {}): LineInfo {
// Prepare
offset = Math.abs(offset)
if (offset.file == null) offset.file = __filename
if (offset.method == null) offset.method = 'getCurrentLine'
if (offset.line == null) offset.line = 0
const result: LineInfo = {

@@ -78,13 +82,11 @@ line: -1,

// Parse our lines
for (let index = 0; index < lines.length; index++) {
const line = lines[index]
if (line.includes(__filename) || line.includes(' at ') === false) {
for (const line of lines) {
// offset
if (line.includes(offset.file) || line.includes(offset.method)) continue
if (offset.line !== 0) {
--offset.line
continue
}
if (offset !== 0) {
--offset
continue
}
// extract
const parts = line.split(':')

@@ -91,0 +93,0 @@ if (parts.length >= 2) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc