-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: implement API exports & minimal docs (#264)
- Loading branch information
Showing
6 changed files
with
134 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# AstAnalyser | ||
|
||
```js | ||
import { AstAnalyser } from "@nodesecure/js-x-ray"; | ||
import { TsSourceParser } from "@nodesecure/ts-source-parser"; | ||
|
||
const scanner = new AstAnalyser({ | ||
customParser: new TsSourceParser() | ||
}); | ||
|
||
const result = scanner.analyse("const x: number = 5;"); | ||
console.log(result); | ||
``` | ||
|
||
AstAnalyser options is described by the following TS interface: | ||
|
||
```ts | ||
interface AstAnalyserOptions { | ||
/** | ||
* @default JsSourceParser | ||
*/ | ||
customParser?: SourceParser; | ||
/** | ||
* @default [] | ||
*/ | ||
customProbes?: Probe[]; | ||
/** | ||
* @default false | ||
*/ | ||
skipDefaultProbes?: boolean; | ||
} | ||
``` | ||
|
||
By default the AstAnalyser class is capable of parsing JavaScript source code using Meriyah. | ||
|
||
## API | ||
|
||
```ts | ||
declare class AstAnalyser { | ||
constructor(options?: AstAnalyserOptions); | ||
analyse: (str: string, options?: RuntimeOptions) => Report; | ||
analyseFile(pathToFile: string, options?: RuntimeFileOptions): Promise<ReportOnFile>; | ||
} | ||
``` | ||
|
||
The `analyseFile` method is a superset of `analyse` with the ability to read the file on the local filesystem with additional features like detecting if the file is ESM or CJS. | ||
|
||
```ts | ||
interface Report { | ||
dependencies: Map<string, Dependency>; | ||
warnings: Warning[]; | ||
idsLengthAvg: number; | ||
stringScore: number; | ||
isOneLineRequire: boolean; | ||
} | ||
|
||
type ReportOnFile = { | ||
ok: true, | ||
warnings: Warning[]; | ||
dependencies: Map<string, Dependency>; | ||
isMinified: boolean; | ||
} | { | ||
ok: false, | ||
warnings: Warning[]; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# EntryFilesAnalyser | ||
|
||
```js | ||
import { EntryFilesAnalyser } from "@nodesecure/js-x-ray"; | ||
|
||
const efa = new EntryFilesAnalyser(); | ||
|
||
// Either a string path or a WHAWG URL | ||
const entryFiles = [ | ||
"./path/to/file.js" | ||
]; | ||
|
||
for await (const report of efa.analyse(entryFiles)) { | ||
console.log(report); | ||
} | ||
``` | ||
|
||
The constructor options is described by the following TS interface | ||
|
||
```ts | ||
interface EntryFilesAnalyserOptions { | ||
astAnalyzer?: AstAnalyser; | ||
loadExtensions?: (defaults: string[]) => string[]; | ||
} | ||
``` | ||
|
||
Default files extensions are `.js`, `.cjs`, `.mjs` and `.node` | ||
|
||
## API | ||
|
||
```ts | ||
declare class EntryFilesAnalyser { | ||
constructor(options?: EntryFilesAnalyserOptions); | ||
analyse(entryFiles: (string | URL)[]): AsyncGenerator<ReportOnFile & { url: string }>; | ||
} | ||
``` | ||
|
||
For more informations about `Report` and `ReportOnFile` interfaces please see [AstAnalyser documentation](./AstAnalyser.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters