
Research
/Security News
9 Malicious NuGet Packages Deliver Time-Delayed Destructive Payloads
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.
typescript-docs-verifier
Advanced tools
Verifies that typescript examples in markdown files actually compile.
typescript-docs-verifierVerifies that typescript examples in markdown files actually compile.
Ever copied a TypeScript code example from a README and found that it didn't even compile? This tool can help by verifying that all of your code examples compile correctly. And yes, the TypeScript code samples in this README are checked using this tool.

Inspired the by the tut documentation compilation tool for scala.
The selected markdown files are searched for TypeScript code blocks marked like this:
```typescript
// Some TypeScript code here
const write = 'some code';
```
These code blocks are extracted and any imports from the current project are replaced with an import of the main or exports from package.json (e.g. import { compileSnippets } from 'typescript-docs-verifier' would be replaced with import { compileSnippets } from './dist/index' for this project).
Each code snippet is compiled (but not run) and any compilation errors are reported. Code snippets must compile independently from any other code snippets in the file.
The library can also be used to type check .tsx files:
```tsx
import React from 'react'
const SomeComponent = () => (
<div>
This is a TSX component!
</div>
)
```
Individual code blocks can be ignored by preceding them with a <!-- ts-docs-verifier:ignore --> comment:
<!-- ts-docs-verifier:ignore -->
```typescript
// This block won't be compiled by typescript-docs-verifier
```
node_modules/.bin/typescript-docs-verifier [--input-files <markdown-files-to-test>] [--project <path-to-tsconfig-file>]
--input-files is optional and defaults to README.md.--project is optional and defaults to the tsconfig.json file in the package root.import { compileSnippets, SnippetCompilationResult } from 'typescript-docs-verifier'
import * as http from 'http'
const markdownFiles = ['README', 'examples.md'] // defaults to 'README.md' if not provided
const tsconfigPath = 'docs-tsconfig.json' // defaults to the 'tsconfig.json' file in the package root
compileSnippets({ markdownFiles, project: tsconfigPath })
.then((results: SnippetCompilationResult[]) => {
results.forEach((result: SnippetCompilationResult) => {
if (result.error) {
console.log(`Error compiling example code block ${result.index} in file ${result.file}`)
console.log(result.error.message)
console.log('Original code:')
console.log(result.snippet)
}
})
})
.catch((error: unknown) => {
console.error('Error compiling TypeScript snippets', error)
})
const { compileSnippets } = require('typescript-docs-verifier')
const markdownFiles = ['README.md', 'examples.md'] // defaults to 'README.md' if not provided
const tsconfigPath = 'docs-tsconfig.json' // defaults to the 'tsconfig.json' file in the package root
compileSnippets({ markdownFiles, project: tsconfigPath })
.then((results) => {
results.forEach((result) => {
if (result.error) {
console.log(`Error compiling example code block ${result.index} in file ${result.file}`)
console.log(result.error.message)
console.log('Original code:')
console.log(result.snippet)
}
})
})
.catch((error) => {
console.error('Error compiling TypeScript snippets', error)
})
Run the tests:
npm install
npm test
See these notes for information for contributors.
typescript-docs-verifier is available to all via the Apache-2.0 license.
Copyright © 2017 BBC
FAQs
Verifies that typescript examples in markdown files actually compile.
The npm package typescript-docs-verifier receives a total of 3,306 weekly downloads. As such, typescript-docs-verifier popularity was classified as popular.
We found that typescript-docs-verifier demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.