|
| 1 | +# Sourcebin |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/sourcebin) |
| 4 | +[](https://ghostdev.xyz) |
| 5 | +[](https://github.com/ghostdevv/sourcebin) |
| 6 | + |
| 7 | +Fast and simple package to get and create bins from [sourcebin](https://sourceb.in/) |
| 8 | + |
| 9 | +# Requirements |
| 10 | + |
| 11 | +``` |
| 12 | +NodeJS >= 14.x |
| 13 | +``` |
| 14 | + |
| 15 | +# Install |
| 16 | + |
| 17 | +``` |
| 18 | +npm install sourcebin |
| 19 | +``` |
| 20 | + |
| 21 | +# Docs |
| 22 | + |
| 23 | +This README is the best place to learn how to use this package, you can also [take a look at our API docs](https://ghostdevv.github.io/sourcebin/index.html) |
| 24 | + |
| 25 | +# Setup |
| 26 | + |
| 27 | +```js |
| 28 | +// Import individual methods |
| 29 | +import { create, get, url } from 'sourcebin'; |
| 30 | + |
| 31 | +// Import all methods |
| 32 | +import * as sourcebin from 'sourcebin'; |
| 33 | + |
| 34 | +// Use required |
| 35 | +const { create, get, url } = require('sourcebin'); |
| 36 | +``` |
| 37 | + |
| 38 | +# Get a bin |
| 39 | + |
| 40 | +`get(options)` |
| 41 | + |
| 42 | +```js |
| 43 | +const bin = await get({ |
| 44 | + key: 'qXO2NVhRc6' |
| 45 | +}); |
| 46 | +``` |
| 47 | + |
| 48 | +## Options |
| 49 | + |
| 50 | +| Option | Description | Default | Required | |
| 51 | +|----------------|-----------------------------------|---------|----------| |
| 52 | +| `key` | The key to get | n/a | ✅ | |
| 53 | +| `fetchContent` | Should the bin content be fetched | `true` | ❌ | |
| 54 | + |
| 55 | +# Create a bin |
| 56 | + |
| 57 | +`create(options)` |
| 58 | + |
| 59 | +```js |
| 60 | +const bin = await create( |
| 61 | + { |
| 62 | + title: 'bin name', |
| 63 | + description: 'test bin', |
| 64 | + files: [ |
| 65 | + { |
| 66 | + content: 'Hello World', |
| 67 | + language: 'text', |
| 68 | + }, |
| 69 | + ], |
| 70 | + }, |
| 71 | +); |
| 72 | +``` |
| 73 | + |
| 74 | +## Options |
| 75 | + |
| 76 | +| Option | Description | Required | |
| 77 | +|----------------|------------------------|----------| |
| 78 | +| `title` | Title of the bin | ❌ | |
| 79 | +| `description` | Description of the bin | ❌ | |
| 80 | +| `files` | Bin files - see below | ✅ | |
| 81 | + |
| 82 | +### File Options |
| 83 | + |
| 84 | +| Option | Description | Default | Required | |
| 85 | +|----------------|----------------------------------|---------|----------| |
| 86 | +| `content` | Contents of the file | n/a | ✅ | |
| 87 | +| `language` | What language should the file be | `text` | ❌ | |
| 88 | + |
| 89 | +# Url Helper |
| 90 | + |
| 91 | +If you want to get information about a bin try the `url` function. |
| 92 | + |
| 93 | +```js |
| 94 | +const urlData = url('iQznILdZRP'); |
| 95 | + |
| 96 | +// or |
| 97 | + |
| 98 | +const urlData = url('https://sourceb.in/iQznILdZRP'); |
| 99 | +``` |
| 100 | + |
| 101 | +This returns an object that looks like: |
| 102 | + |
| 103 | +```js |
| 104 | +{ |
| 105 | + key: 'iQznILdZRP', |
| 106 | + url: 'https://sourceb.in/iQznILdZRP', |
| 107 | + short: 'http://srcb.in/iQznILdZRP' |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +# FAQ |
| 112 | + |
| 113 | +- ## Multiple files in one bin |
| 114 | + |
| 115 | + This is not currently possible with this wrapper as sourcebin doesn't have a token system for authentication, only pro users are able to have multiple files in one bin. This may come in the future |
| 116 | + |
| 117 | +- ## Migrate from v4 to v5 |
| 118 | + |
| 119 | + v5 is a overhaull of `sourcebin` so we changed some apis. |
| 120 | + |
| 121 | + ### Get a bin |
| 122 | + |
| 123 | + Instead of passing the `key` then `options` it's now one object. |
| 124 | + |
| 125 | + ```diff |
| 126 | + - const bin = await get('qXO2NVhRc6'); |
| 127 | + + const bin = await get({ key: 'qXO2NVhRc6' }); |
| 128 | + |
| 129 | + - const bin = await get('qXO2NVhRc6', { fetchContent: false }); |
| 130 | + + const bin = await get({ key: 'qXO2NVhRc6', fetchContent: false }); |
| 131 | + ``` |
| 132 | + |
| 133 | + ### Create a bin |
| 134 | + |
| 135 | + We also unified the options for this function: |
| 136 | + |
| 137 | + ```diff |
| 138 | + - const bin = await create( |
| 139 | + - [ |
| 140 | + - { |
| 141 | + - content: 'Hello World', |
| 142 | + - language: 'text', |
| 143 | + - }, |
| 144 | + - ], |
| 145 | + - { |
| 146 | + - title: 'bin name', |
| 147 | + - description: 'test bin', |
| 148 | + - }, |
| 149 | + - ); |
| 150 | + |
| 151 | + + const bin = await create( |
| 152 | + + { |
| 153 | + + title: 'bin name', |
| 154 | + + description: 'test bin', |
| 155 | + + files: [ |
| 156 | + + { |
| 157 | + + content: 'Hello World', |
| 158 | + + language: 'text', |
| 159 | + + }, |
| 160 | + + ], |
| 161 | + + } |
| 162 | + + ); |
| 163 | + ``` |
| 164 | + |
| 165 | +# Support |
| 166 | + |
| 167 | +- Join the [discord](https://discord.gg/2Vd4wAjJnm) |
| 168 | +- Create a issue on the [github](https://github.com/ghostdevv/sourcebin) |
0 commit comments