Socket
Socket
Sign inDemoInstall

estree-variable-scopes

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

estree-variable-scopes

An NPM package that shows the top scope of defined variables and what variable can access to another specific variable


Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

estree-variable-scopes

An NPM package that shows the top scope of defined variables and what variable can access to another specific variable

Usage

Getting all of the variables and it's grandparents

import { getVariables } from "estree-variable-scopes";

const code = `
let a = "Hello!"
let b = "Hi!"

const goodMorning = () => {
 const str = "Good morning!"
}
`
console.log(getVariables(code)) //will print all of the defined variables and it's grandparents

Checking a variable can access to a specific variable

import { getVariables, canAccess } from "estree-variable-scopes";

const code = `
let a = "Hello!"
let b = "Hi!"

const goodMorning = () => {
 const str = "Good morning!"
}
`

const scopes = getVariables(code)
const a_value = scopes[0].vars[0] //will point to variable "a" in global scope
const str_value = scopes[1].vars[0] //will point to variable "str" in goodMorning function 
console.log(canAccess(str_value, a_value, scopes)) //will print true because "str" can access to variable "a" in global scope

Keywords

FAQs

Package last updated on 21 Sep 2022

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