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

import-meta-ponyfill

v3.1.0

Published

This library implements some standard interfaces of [import.meta](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta) with the aim of resolving the confusion caused by multiple standards in Node.js. It includes unifie

Downloads

662

Readme

import.meta ponyfill

This library implements some standard interfaces of import.meta with the aim of resolving the confusion caused by multiple standards in Node.js. It includes unified support for the following Node.js standards:

How to use

  • commonjs
    const import_meta_ponyfill = require("import-meta-ponyfill");
    const importMeta = import_meta_ponyfill(require, module);
    importMeta.resolve; // function
    importMeta.main; // boolean
    importMeta.url; // string
    importMeta.filename; // string
    importMeta.dirname; // string
  • esmodule
    import import_meta_ponyfill from "import-meta-ponyfill";
    const importMeta = import_meta_ponyfill(import.meta);
    • v20.6.0, v18.19.0

      Unflag import.meta.resolve, with parentURL parameter still flagged.

    • v20.6.0, v18.19.0

      This API no longer throws when targeting file: URLs that do not map to an existing file on the local FS.

    • v20.0.0, v18.19.0

      This API now returns a string synchronously instead of a Promise.

    • v16.2.0, v14.18.0

      Add support for WHATWG URL object to parentURL parameter.

ImportMeta API

  • url: string;

    A string representation of the fully qualified module URL. When the module is loaded locally, the value will be a file URL (e.g. file:///path/module.ts).

    You can also parse the string as a URL to determine more information about how the current module was loaded. For example to determine if a module was local or not:

    const url = new URL(importMeta.url);
    if (url.protocol === "file:") {
      console.log("this module was loaded locally");
    }
  • resolve(specifier: string, parent?: string | URL | undefined): string;

    A function that returns the resolved specifier, see import.meta.resolve(specifier), even attempting to return a result for non-existent paths.

    console.log(importMeta.resolve("./foo.js"));
    // file:///dev/foo.js

    @param specifier The module specifier to resolve relative to parent. @param parent The absolute parent module URL to resolve from. @returns The absolute (file:) URL string for the resolved module.

  • nodeResolve(specifier: string, parent?: string | URL | undefined): string;

    A function that returns resolved specifier as if it would be imported using import.meta.resolve(specifier) or require.resolve(specifier).

    console.log(import.meta.nodeResolve("./foo.js"));
    // file:///dev/foo.js

    @param specifier The module specifier to resolve relative to parent. @param parent The absolute parent module URL to resolve from. @returns The absolute (file:) URL string for the resolved module.

  • main: boolean;

    A flag that indicates if the current module is the main module that was called when starting the program under Deno.

    if (importMeta.main) {
      // this was loaded as the main module, maybe do some bootstrapping
    }
  • filename: string;

    The absolute path of the current module.

    This property is only provided for local modules (ie. using file:// URLs).

    Example:

    // Unix
    console.log(importMeta.filename); // /home/alice/my_module.ts
    
    // Windows
    console.log(importMeta.filename); // C:\alice\my_module.ts
  • dirname: string;

    The absolute path of the directory containing the current module.

    This property is only provided for local modules (ie. using file:// URLs).

    Example:

    // Unix
    console.log(importMeta.dirname); // /home/alice
    
    // Windows
    console.log(importMeta.dirname); // C:\alice