包详细信息

get-current-line

bevry44.6kArtistic-2.07.4.0

Get the current line number of the executing file and method

browser, debug, debugging, deno

自述文件

get-current-line

Status of the GitHub Workflow: bevry NPM version NPM downloads
GitHub Sponsors donate button ThanksDev donate button Patreon donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button
Discord server badge Twitch community badge

Get the current line number of the executing file and method

Usage

Complete API Documentation.

import getCurrentLine from 'get-current-line'
console.log(
    getCurrentLine(/* optional offset information in case the caller is wrapped */)
)
{
    "line": "3",
    "method": "Object.<anonymous>",
    "file": "location/to/the/calling/file.js"
}

If you wish to have something that fetches the current file and directory paths, such as a cross-enviroment compatible __filename and __dirname you can use the filedirname package..

Install

npm

  • Install: npm install --save get-current-line
  • Import: import pkg from ('get-current-line')
  • Require: const pkg = require('get-current-line').default

Deno

import pkg from 'https://unpkg.com/get-current-line@^7.4.0/edition-deno/index.ts'

Skypack

<script type="module">
    import pkg from '//cdn.skypack.dev/get-current-line@^7.4.0'
</script>

unpkg

<script type="module">
    import pkg from '//unpkg.com/get-current-line@^7.4.0'
</script>

jspm

<script type="module">
    import pkg from '//dev.jspm.io/get-current-line@7.4.0'
</script>

Editions

This package is published with the following editions:

  • get-current-line aliases get-current-line/index.cjs which uses the Editions Autoloader to automatically select the correct edition for the consumer's environment
  • get-current-line/source/index.ts is TypeScript source code with Import for modules
  • get-current-line/edition-browsers/index.js is TypeScript compiled against ES2022 for web browsers with Import for modules
  • get-current-line/edition-es2022/index.js is TypeScript compiled against ES2022 for Node.js 6 || 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with Require for modules
  • get-current-line/edition-es5/index.js is TypeScript compiled against ES5 for Node.js 4 || 6 || 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with Require for modules
  • get-current-line/edition-es2022-esm/index.js is TypeScript compiled against ES2022 for Node.js 12 || 14 || 16 || 18 || 20 || 21 with Import for modules
  • get-current-line/edition-types/index.d.ts is TypeScript compiled Types with Import for modules
  • get-current-line/edition-deno/index.ts is TypeScript source code made to be compatible with Deno

History

Discover the release history by heading on over to the HISTORY.md file.

Backers

Code

Discover how to contribute via the CONTRIBUTING.md file.

Authors

Maintainers

Contributors

Finances

GitHub Sponsors donate button ThanksDev donate button Patreon donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button

Sponsors

  • Andrew Nesbitt — Software engineer and researcher
  • Balsa — We're Balsa, and we're building tools for builders.
  • Codecov — Empower developers with tools to improve code quality and testing.
  • Poonacha Medappa
  • Rob Morris
  • Sentry — Real-time crash reporting for your web apps, mobile apps, and games.
  • Syntax — Syntax Podcast

Donors

License

Unless stated otherwise all works are:

and licensed under:

更新日志

History

v7.4.0 2023 December 30

v7.3.0 2023 December 27

v7.2.0 2023 December 6

v7.1.0 2023 November 25

v7.0.0 2023 November 24

  • Updated dependencies, base files, and editions using boundation
  • Minimum required Node.js version changed from node: >=10 to node: >=4 adapting to ecosystem changes

v6.10.0 2023 November 21

v6.9.0 2023 November 15

v6.8.0 2023 November 13

v6.7.0 2023 November 1

v6.6.0 2021 July 30

v6.5.0 2021 July 29

v6.4.0 2021 July 28

v6.3.0 2020 October 29

v6.2.0 2020 September 4

v6.1.0 2020 September 4

v6.0.0 2020 September 3

  • Now compatible with a wider range of environments, including web browsers
  • Optimised the fetching of location information from frames
  • Introduced getFileFromError and getLocationFromError for a wider range of compatibility and usability
  • Introduced immediate property to the offset interface
  • Possible Breaking Changes:
    • Introduced char property to the location interface
    • Renamed LineInfo to Location
    • Rneamed LineOffset to Offset
  • Updated dependencies, base files, and editions using boundation

v5.16.0 2020 August 18

v5.15.0 2020 August 18

v5.14.0 2020 August 4

v5.13.0 2020 July 22

v5.12.0 2020 July 22

v5.11.0 2020 July 22

v5.10.0 2020 June 25

v5.9.0 2020 June 21

v5.8.0 2020 June 21

v5.7.0 2020 June 20

v5.6.0 2020 June 10

v5.5.0 2020 June 10

v5.4.0 2020 May 22

v5.3.0 2020 May 21

v5.2.0 2020 May 13

v5.1.0 2020 May 8

  • Add support for Regular Expressions for file and method offsets, to support such things as case insentitivity

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.

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, and editions using boundation

v3.1.0 2020 May 4

v3.0.0 2020 March 26

  • Updated dependencies, base files, and editions using boundation
  • Minimum required node version changed from node: >=8 to node: >=10 to keep up with mandatory ecosystem changes

v2.0.0 2019 December 12

  • Offset is now an object that supports file, method, and line

v1.0.0 2019 December 12