# estree-variable-scopes

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

Latest version **1.0.1** (published 2022-09-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install estree-variable-scopes
pnpm add estree-variable-scopes
yarn add estree-variable-scopes
bun add estree-variable-scopes
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-09-21 |
| First published | 2022-09-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | SpongeBed |
| Maintainers | spongebed |
| Keywords | estree, esprima, acorn, estree-walker, variable-scope, estraverse |

## Links

- npm: https://www.npmjs.com/package/estree-variable-scopes
- npm.io page: https://npm.io/package/estree-variable-scopes

## Recent versions

- 1.0.1 (latest) — 2022-09-21
- 1.0.0 — 2022-09-21

## README

<div align="center">
  
# estree-variable-scopes

**An NPM package that shows the top scope of defined variables and what variable can access to another specific variable**

</div>

# Usage

`Getting all of the variables and it's grandparents`

```js
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```

```js
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
```

---
_Source: https://npm.io/package/estree-variable-scopes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
