Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

scalar/snippetz

Repository files navigation

Warning

We moved @scalar/snippetz to https://github.com/scalar/scalar

Snippetz

CI Contributors GitHub License Version Discord

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

Lean usage

You can also just use one specific plugin to keep your bundle size small.

import { undici } from '@scalar/snippetz/plugins/node/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/scalar

Contributors

Contributions are welcome! Read CONTRIBUTING.

hanspagel
hanspagel
marclave
marclave

License

The source code in this repository is licensed under MIT.