Skip to content

scalar/snippetz

Repository files navigation

Snippetz

CI Release Contributors GitHub License Version Discord

Warning

This package is in early development. Don’t use it in production!

A modern way to generate code examples for different languages.

Installation

npm install @scalar/snippetz

Usage

import { snippetz } from '@scalar/snippetz'

const snippet = snippetz().print('node', 'undici', {
  url: 'https://example.com'
})

/* Output */

// import { request } from 'undici'
//
// const { statusCode, body } = await request(
//   'https://example.com',
// )

API

Get all plugins

import { snippetz } from '@scalar/snippetz'

const snippet = snippetz().plugins()

/* Output */

// [
//   {
//     target: 'node',
//     client: 'undici',
//   }
// ]

Check if a plugin is loaded

import { snippetz } from '@scalar/snippetz'

const snippet = snippetz().hasPlugin('node', 'undici')

/* Output */

// true

Use just one plugin

import { undici } from '@scalar/snippetz-plugin-undici'

const source = undici({
  url: 'https://example.com'
})

console.log(source.code)

// import { request } from 'undici'

// const { statusCode, body } = await request(
//   'url': 'https://example.com',
// )

Community

We are API nerds. You too? Let’s chat on Discord: https://discord.gg/8HeZcRGPFS

Contributors

hanspagel
hanspagel
marclave
marclave

Contributions are welcome! Read CONTRIBUTING.

License

The source code in this repository is licensed under MIT.