# @nomicfoundation/solidity-analyzer

> `@nomicfoundation/solidity-analyzer` is an N-API library built in Rust, which exposes a single function, which takes the contents of a Solidity source file and returns its imports and version pragmas.

Latest version **0.1.2** (published 2024-06-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @nomicfoundation/solidity-analyzer
pnpm add @nomicfoundation/solidity-analyzer
yarn add @nomicfoundation/solidity-analyzer
bun add @nomicfoundation/solidity-analyzer
```

## Health

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

Positive: has types; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2024-06-07 |
| First published | 2022-05-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 12 |
| Dependencies | 0 |
| Unpacked size | 41.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 17 |
| Maintainers | alcuadrado, nomic-foundation-publisher |

## Links

- npm: https://www.npmjs.com/package/@nomicfoundation/solidity-analyzer
- Repository: https://github.com/NomicFoundation/solidity-analyzer
- Homepage: https://github.com/NomicFoundation/solidity-analyzer#readme
- Issues: https://github.com/NomicFoundation/solidity-analyzer/issues
- npm.io page: https://npm.io/package/@nomicfoundation/solidity-analyzer

## Recent versions

- 0.1.2 (latest) — 2024-06-07
- 0.1.1 — 2023-03-03
- 0.1.0 — 2022-09-16
- 0.0.4 — 2022-09-15
- 0.0.3 — 2022-05-31
- 0.0.2 — 2022-05-31

## README

# `@nomicfoundation/solidity-analyzer`

`@nomicfoundation/solidity-analyzer` is an N-API library built in Rust, which exposes a single function, which takes the contents of a Solidity source file and returns its imports and version pragmas.

## Installation

```bash
npm install @nomicfoundation/solidity-analyzer
```

## API

```ts
export interface AnalysisResult {
  versionPragmas: Array<string>;
  imports: Array<string>;
}

export function analyze(input: string): AnalysisResult;
```

## Example

```ts
analyze(`
  pragma solidity ^0.8.0;

  import "./file.sol";
`);

// { versionPragmas: [ '^0.8.0' ], imports: [ './file.sol' ] }
```

## Goals

This library has two different goals:

1. Being fast
2. Being error-tolerant

Both are achieved by not parsing the Solidity source but just tokenizing it instead. This allows us to create a simple state machine that only recognizes imports and pragmas, ignoring everything else, and recovering from malformed tokens or expressions.

## Browser support

This library doesn't work in a browser.

## Testing

This project has some JavaScript unit tests in `__test__`, and it's also tested using the entire [`smart-contract-sanctuary`](https://github.com/tintinweb/smart-contract-sanctuary).

You can find the scripts to test with the sanctuary in `test-with-sanctuary/`.

## Regenerating `index.js` and `index.d.ts`

These files have to be committed because of our current Github Actions, yet, they are autogenerated.

You can run `cargo clean`, `yarn clean`, and `yarn build` to recreate them.

---
_Source: https://npm.io/package/@nomicfoundation/solidity-analyzer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
