npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

current-executing-script

v0.1.3

Published

Get the currently executing script, regardless of its source/trigger/synchronicity. Similar to HTML5's `document.currentScript` but arguably much more useful!

Downloads

14,532

Readme

currentExecutingScript

GitHub Latest Release Build Status Sauce Test Status Dependency Status Dev Dependency Status

Sauce Test Status

Get the currently executing script, regardless of its source/trigger/synchronicity. Similar to HTML5's document.currentScript but arguably much more useful!

Overview

Loose

This utility comprises a set of behaviors for detecting the currently executing script, which does not comply with the HTML spec's concept of document.currentScript. However, personally, I find it much more useful!

It can get the script element that was the source of the nearest (deepest) frame in the call stack (so, the currently executing code), regardless of whether or not said source script is being evaluated synchronously for the first time by the browser.

It also has experimental support for getting the script element that was the source of the farthest (most shallow) frame in the call stack, regardless of whether or not said source script is being evaluated synchronously for the first time by the browser.

Finally, it has experimental support for getting the script element or attribute node (e.g. onclick) responsible for creating the current call stack.

Strict

If you are only interested in getting the currently synchronously evaluating script (i.e. like an HTML spec-compliant polyfill for document.currentScript), take a look at JamesMGreene/document.currentScript instead.

Browser Compatibility

Forthcoming....

Installation

NPM

npm install current-executing-script

GitHub

Alternatively, you can download/clone its GitHub repo: JamesMGreene/currentExecutingScript

Usage

Nearest

To get the nearest (deepest) script for the current call stack:

var scriptEl1 = currentExecutingScript();
var scriptEl2 = currentExecutingScript.near();

Farthest

EXPERIMENTAL!!!

To get the farthest (most shallow) script for the current call stack:

var scriptEl = currentExecutingScript.far();

IMPORTANT: Note that the accuracy of this may be limited by the allowed stack depth of each browser. For example, Chrome defaults to collecting a maximum of the 10 nearest frames but can be configured to collect more (see Error.stackTraceLimit and --stack-trace-limit). This library will automatically configure it to Infinity on your behalf.

Origin

EXPERIMENTAL!!!

To get the script or attribute node (e.g. onclick) responsible for initiating the current call stack:

var scriptElOrAttrNode = currentExecutingScript.origin();

In most situations, the result of .origin() will commonly match the result of .far() unless the current call stack was initiated by something other than a script element (e.g. an onclick attribute node).

IMPORTANT: Note that the accuracy of this may be limited by the allowed stack depth of each browser. For example, Chrome defaults to collecting a maximum of the 10 nearest frames but can be configured to collect more (see Error.stackTraceLimit and --stack-trace-limit). This library will automatically configure it to Infinity on your behalf.

Configuration

skipStackDepth

The stack depth to skip over when analyzing call stack frames (defaults to 1, to ensure it skips over its own functions).

Errata

  • MDN docs for document.currentScript: https://developer.mozilla.org/en-US/docs/Web/API/document.currentScript
  • Demo using old Gist: http://jsfiddle.net/JamesMGreene/9DFc9/
  • Original location, old Gist: https://gist.github.com/JamesMGreene/fb4a71e060da6e26511d