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

find-global-deps-souretype

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-global-deps-souretype

Find what global variables are used in js code

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

添加了sourceType设置,老外果然不靠谱,相信中国人

find-global-deps

Find what global variables are used in js code.

Purpose

For this module, a "global dependency" is a global variable used by your code that is not provided by the environment.

Maybe you want to find these and do something with webpack's imports-loader.

Install

npm install find-global-deps

Requires node 6 or later

Usage

var findGlobalDeps = require('find-global-deps');

var code = 'let a = foo';
var result = findGlobalDeps(code);

result // Set { 'foo' }

API

var findGlobalDeps = require('find-global-deps');

findGlobalDeps(code[, options])

Returns a Set<string> of names of global dependencies found.

code

String of js code.

options.environment

Optional array of strings. Defaults to ['es6', 'browser'].

Specifies what environment code is written for. Any use of globals that come with these environments (e.g. process in node) will not be reported.

Can contain any top-level property names of the object exported by the globals module.

Examples

// node
findGlobalDeps(code, {
  environment: ['es6', 'node']
});

// commonjs in browser
findGlobalDeps(code, {
  environment: ['es6', 'browser', 'commonjs']
});

Gotchas

Does not detect (yet)

  • window.foo in browser
  • this.foo at top level in browser
  • global.foo in node

License

MIT

Keywords

FAQs

Package last updated on 12 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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