0.0.4 • Published 2 years ago

snipbin.js v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

SnipBin.js

npm NPM npm

An API wrapper for SnipBin, written in TypeScript.

SnipBin is also written by me -- be sure to check it out and leave a ⭐ if you enjoyed the concept!

⚡ Getting Started

💻 Installation

# install snipbin.js@latest
yarn add snipbin.js

# or... 
# npm install snipbin.js

✏ Usage

🔒 Authorization

Set your SnipBin API key to use restricted features of this API.

Note: You don't have to be authenticated to use this library or SnipBin's API.

import { authorize } from 'snipbin.js'

authorize('myApiKey')

🔗 Fetching Snips

Note: You can't fetch encrypted snips.

import { snipbin } from 'snipbin.js'

snipbin.getSnip('abt')

🔗 Creating Snips

Note: In order to link a snip with your account, make sure to set authorize with your API key.

import { snipbin, authorize } from 'snipbin.js'

authorize('myApiKey')
snipbin.createSnip({
  slug: 'test-snip',
  content: "import { snipbin } from 'snipbin.js'",
  language: 'js',
  // password: 'secret'
})

🔗 Editing Snips

Note: Since you can only edit snips on your account, you must set authorize with your API key.

import { snipbin, authorize } from 'snipbin.js'

authorize('myApiKey')
snipbin.editSnip('test-snip', {
  slug: 'test-snip2',
  content: "we're editing this thing, whoa!",
  // password: 'secret'
})

🔗 Deleting Snips

Note: Since you can only delete snips on your account, you must set authorize with your API key. Also, it goes without saying that this action is irreversible.

import { snipbin, authorize } from 'snipbin.js'

authorize('myApiKey')
snipbin.deleteSnip('test-snip')

💡 Detecting Language

Note: This is simply a wrapper around LangMyst, which uses go-enry to detect languages.

import { detect } from 'snipbin.js'

detect.detectLanguage({ snippet: "import { snipbin } from 'snipbin.js'" })

Aside from that, the codebase is also fully documented. If you prefer, you can go through the codebase to better find your way around this project with the different return types and functions.

Additionally, you can find the different endpoints and internals of this API over on SnipBin's API documentation

🔧 Tools Used

🤞 Contributing

After setting up the project, and making changes:

git add .
git commit -m "commit message"
git push YOUR_REPO_URL YOUR_BRANCH

💙 Credits

Since I haven't written a proper API wrapper before, a big round of thanks to Ian Hornik for writing pastemyst.ts, as this library is built around it.