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

get-imported

v0.0.7

Published

The module has JS functions to check all imports or required modules and check if the file is a ES Module or a CJS/ JS Module or Script

Downloads

187

Maintainers

ganeshkbhatganeshkbhat

Keywords

requirecacheuncacheuncachedmodulefreshfetchallimportsrequireses importscjs importcjs requiremjs importcjs importcjs requirejs requirefetch imported packagesfetch required packagesrequire cacherequire-cacheget import cacheget imported cacheget require cacheget required cacheget require modulesget required modulesget import modulesget imported modulesimported modulesimported es modulesimported cjs modulesimported esm modulesimported js modulesimport module listrequired modulesrequired es modulesrequired cjs modulesrequired esm modulesrequired js modulesrequired module listget import cacheget import cacheget import modulesget import modulesget import modulesget imported modulesrequire modulesrequire es modulesrequire cjs modulesrequire esm modulesrequire js modulesrequire module listimport modulesimport es modulesimport cjs modulesimport esm modulesimport js modulesimport module listimported packagesimport es packagesimport cjs packagesimport esm packagesimport js packagesimport packages listimport package listrequire package listrequire-cacheimport-cacherequire cacheimport cacheesmcjspackage.jsonmoduleecmascriptmodulesnativemodulesnativemodules nativeecmascript modulesecmascriptmodulescheck esmcheckesmfind if esmfind file typemodule typetypepackage typefile type.mjs.cjs.jsjsmjsjscjsscriptmoduleeses6commonjsmodulescriptfilepackagescriptis scriptis commonjsis moduleis esmisesmis-esmfind file typefind if es file typecheck if es file typefind if commonjs file typecheck if commonjs file typefind file typecheck file typefile typemodule typepackage typeisesmfind-file-typefind-esmcheck-esmis-file-esmis-esmcheck-esmcheck-typecheck-module-typecheck-module-extcheck module extcheck file extfind-esmfind-typefind-module-typefind-module-extfind module extfind file ext

Readme

get-imported

Module to fetch all required and imported modules in Javascript and NodeJS. The module has JS functions to check all imports or required modules and check if the file is a ES Module or a CJS/ JS Module or Script

Find the demos in the demos folder

Usage

CommonJS example

File example: demos/parser.imports.regex.js


const parser = require("get-imported");
let example_one = parser._importRegex("./demos/src/parser.imports.regex.js");
let example_two = parser._requiresObject();
let example_three = parser._requireRegex("./demos/src/parser.require.regex.js");
let example_four = parser._importRegexExtended("./demos/src/parser.imports.regex.extended.js");

File example: demos/parser.imports.regex.mjs



import * as parser from "get-imported";
const path = import('path');
const someModuleCJS = import('./parser.demo.require.cache.test.file.cjs');
const someModuleJS = import('./parser.demo.require.cache.test.file.js');
const acorn = import("chai");

let arr = parser._importESRegex("./demos/src/parser.imports.regex.mjs");
console.log(arr);


INSTALL

npm install get-imported --save


USAGE

ESM Module

import { _isESCode } from "get-imported";

CommonJS Script/ Module

const checkEsm = require("get-imported");
isESCode("./path/to/file.mjs")

Package APIs

There are other script APIs you may wish to explore that includes the following:

.checkModuleImports

Check if a module can be imported using import()

Usage:

.checkModuleImports(absPath)

.requiresObject

Check require.cache list in code - used in your code's process global context.

Usage:

.requiresObject()

.requireRegex

Check to see if there are require() syntax in code.

Usage:

.requireRegex(absPath, basePath = "", useProcessCwd = false)

.requireRegex(absPath)

.importRegex

Check to see if there are import() syntax in code.

Usage:

.importRegex(absPath, basePath = "", useProcessCwd = false)

.importRegex(absPath)

.importESRegex

Check to see if there are import x from "" syntax in code.

Usage:

.importESRegex(absPath, basePath = "", useProcessCwd = false)

.importESRegex(absPath)

.importRegexExtended

Check to see if there are import() syntax in code.

Usage:

.importRegexExtended(absPath, basePath = "", useProcessCwd = false)

.importRegexExtended(absPath)

.isESMFileExtension

Check to see if the file has .mjs/ .cjs/ .js extension.

Usage:

.isESMFileExtension(absPath)

.isNodeCompatibleFileExtension

Check to see if the file has .mjs/ .cjs/ .js / .node / .wasm extension.

Usage:

.isNodeCompatibleFileExtension(absPath)

.isESMCodeBase

Check to see if the code is ESM Module.

Usage:

.isESMCodeBase(absPath)

isCJSCodeBase

Check to see if the code is CommonJS Script or Module.

Usage:

isCJSCodeBase(absPath)

isModuleInPackageJson

Checks type key's value in package.json.

Usage:

getPackageJsonRoot(startdirectory, options)

isESCode

Multiple checks to check if the code is ESM Module (other than package.json type key's value check in package.json).

Usage:

isModuleInPackageJson(absPath, packagejsonPath, returns)


Contributions

Contributions, Feature Improvements, Bugs, and Issues are invited. raising an issue

License

MIT License