https://github.com/codevideo/syntax-spy
Simultaneously detect and syntax check any code snippet with ease.
https://github.com/codevideo/syntax-spy
Last synced: about 1 year ago
JSON representation
Simultaneously detect and syntax check any code snippet with ease.
- Host: GitHub
- URL: https://github.com/codevideo/syntax-spy
- Owner: codevideo
- Created: 2024-03-05T21:26:07.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-17T09:33:53.000Z (over 2 years ago)
- Last Synced: 2024-03-17T10:39:08.087Z (over 2 years ago)
- Language: TypeScript
- Size: 52.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# syntax-spy
Simultaneously detect and syntax check any code snippet with ease.
`syntax-spy` is a powerful TypeScript / JavaScript tool that combines the powers of [vscode-languagedetection
](https://github.com/microsoft/vscode-languagedetection), [ts-morph](https://github.com/dsherret/ts-morph), and a variety of other AST and linting tools to simultaneously identify and syntax check any snippet of code.
## Installation
```bash
npm install @fullstackcraftllc/syntax-spy
```
## Usage
```typescript
import { identifyAndValidateCode } from '@fullstackcraftllc/syntax-spy';
const code = `
// here's a comment in TypeScript
const testFunction = (someParam: string) => {
const myStringArray: string[] = ['Hello', 'World'];
console.log(someParam);
blahblahsomesyntaxerror
}
`;
async function main() {
try {
const { language, isValid, error } = await identifyAndValidateCode(code);
if (error) {
console.error('Error:', error);
} else {
console.log('Detected language:', language);
console.log('Syntax is valid:', isValid);
}
} catch (error) {
console.error('Error:', error);
}
}
main();
```
## TODOs
- Add support for more programming languages.