├── .gitignore ├── .npmignore ├── docs ├── assets │ ├── widgets.png │ ├── widgets@2x.png │ ├── highlight.css │ └── search.js ├── .nojekyll ├── interfaces │ ├── GetOptions.html │ ├── FileData.html │ ├── FileOptions.html │ ├── CreateOptions.html │ ├── SourcebinLinguistItem.html │ └── BinData.html ├── functions │ ├── get.html │ ├── create.html │ └── url.html ├── modules.html ├── classes │ └── File.html └── index.html ├── .vscode ├── extensions.json └── settings.json ├── src ├── global.d.ts ├── utils │ ├── fetch.ts │ ├── url.ts │ └── languages.ts ├── index.ts ├── methods │ ├── url.ts │ ├── get.ts │ └── create.ts ├── structures │ ├── File.ts │ └── Bin.ts └── types.ts ├── .prettierrc ├── tsup.config.ts ├── tests ├── methods │ ├── url.test.ts │ ├── get.test.ts │ └── create.test.ts ├── utils │ ├── languages.test.ts │ └── url.test.ts └── structures │ ├── file.test.ts │ └── bin.test.ts ├── tsconfig.json ├── .github ├── workflows │ ├── ci.yml │ └── release.yml └── FUNDING.yml ├── LICENSE ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | dev -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .github 3 | .vscode 4 | tests 5 | dev 6 | .prettierrc -------------------------------------------------------------------------------- /docs/assets/widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghostdevv/sourcebin/HEAD/docs/assets/widgets.png -------------------------------------------------------------------------------- /docs/assets/widgets@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghostdevv/sourcebin/HEAD/docs/assets/widgets@2x.png -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "esbenp.prettier-vscode", 4 | "christian-kohler.npm-intellisense" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /src/global.d.ts: -------------------------------------------------------------------------------- 1 | declare module '@sourcebin/linguist' { 2 | const linguist: Record; 3 | const languages: Record; 4 | } 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "quoteProps": "as-needed", 4 | "trailingComma": "all", 5 | "bracketSpacing": true, 6 | "arrowParens": "always", 7 | "semi": true, 8 | "useTabs": false, 9 | "tabWidth": 4 10 | } 11 | -------------------------------------------------------------------------------- /src/utils/fetch.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | export const fetch = axios.create({ 4 | baseURL: 'https://sourceb.in/api', 5 | 6 | headers: { 7 | 'User-Agent': `SourcebinJS https://www.npmjs.com/package/sourcebin`, 8 | }, 9 | }); 10 | -------------------------------------------------------------------------------- /tsup.config.ts: -------------------------------------------------------------------------------- 1 | import type { Options } from 'tsup'; 2 | 3 | export const tsup: Options = { 4 | splitting: false, 5 | sourcemap: false, 6 | clean: false, 7 | dts: true, 8 | keepNames: true, 9 | target: 'esnext', 10 | format: ['esm', 'cjs'], 11 | entryPoints: ['src/index.ts'], 12 | shims: true, 13 | }; 14 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export { type CreateOptions, type FileOptions, create } from './methods/create'; 2 | export { type GetOptions, get } from './methods/get'; 3 | export { url } from './methods/url'; 4 | 5 | export { File } from './structures/File'; 6 | export { Bin } from './structures/Bin'; 7 | 8 | export type { SourcebinLinguistItem, BinData, FileData } from './types'; 9 | -------------------------------------------------------------------------------- /tests/methods/url.test.ts: -------------------------------------------------------------------------------- 1 | import { url } from '../../src/methods/url'; 2 | import assert from 'assert'; 3 | import { test } from 'uvu'; 4 | 5 | test('check url method works as expected', () => { 6 | const key = 'qXO2NVhRc6'; 7 | const data = url(key); 8 | 9 | assert.deepEqual(data, { 10 | key, 11 | url: `https://sourceb.in/${key}`, 12 | short: `http://srcb.in/${key}`, 13 | }); 14 | }); 15 | 16 | test.run(); 17 | -------------------------------------------------------------------------------- /src/methods/url.ts: -------------------------------------------------------------------------------- 1 | import { resolveKey } from '../utils/url'; 2 | 3 | export const url = (keyOrUrl: string) => { 4 | const key = resolveKey(keyOrUrl); 5 | 6 | if (!key) 7 | throw new Error( 8 | 'Invalid item given to url, must be a valid sourcebin url or bin key', 9 | ); 10 | 11 | return { 12 | key, 13 | url: `https://sourceb.in/${key}`, 14 | short: `http://srcb.in/${key}`, 15 | }; 16 | }; 17 | -------------------------------------------------------------------------------- /src/utils/url.ts: -------------------------------------------------------------------------------- 1 | export const getCdnUrl = (key: string, index: number) => { 2 | return `https://cdn.sourceb.in/bins/${key}/${index}`; 3 | }; 4 | 5 | export const resolveKey = (keyOrUrl: string) => { 6 | const sanitised = keyOrUrl.replace( 7 | /http(s)?:\/\/(sourceb.in|srcb.in)\//gi, 8 | '', 9 | ); 10 | 11 | const key = (sanitised.match(/[a-zA-Z0-9]{10}/g) || [])[0]; 12 | return sanitised.length == 10 && key ? key : undefined; 13 | }; 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2019", 4 | "module": "esnext", 5 | "outDir": "dist/esm", 6 | "lib": ["ES2020"], 7 | 8 | "strict": true, 9 | "declaration": true, 10 | "strictNullChecks": true, 11 | "noImplicitReturns": true, 12 | "noImplicitThis": true, 13 | "noImplicitAny": true, 14 | "esModuleInterop": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "moduleResolution": "node" 17 | }, 18 | "include": ["src/**/*.ts"] 19 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.defaultFormatter": "esbenp.prettier-vscode", 4 | "editor.formatOnSave": true 5 | }, 6 | "[typescript]": { 7 | "editor.defaultFormatter": "esbenp.prettier-vscode", 8 | "editor.formatOnSave": true 9 | }, 10 | "[svelte]": { 11 | "editor.defaultFormatter": "svelte.svelte-vscode", 12 | "editor.formatOnSave": true 13 | }, 14 | "[json]": { 15 | "editor.defaultFormatter": "vscode.json-language-features", 16 | "editor.formatOnSave": true 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | 9 | strategy: 10 | matrix: 11 | node-version: [14.x, 16.x, 18.x] 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Setup Node 16 17 | uses: actions/setup-node@v1 18 | with: 19 | node-version: 16 20 | registry-url: https://registry.npmjs.org/ 21 | 22 | - name: Setup PNPM 23 | uses: pnpm/action-setup@v2.0.1 24 | with: 25 | version: 7.0.0 26 | 27 | - name: Install 28 | run: pnpm install 29 | 30 | - name: Test 31 | run: pnpm test 32 | -------------------------------------------------------------------------------- /src/structures/File.ts: -------------------------------------------------------------------------------- 1 | import type { FileData, SourcebinLinguistItem } from '../types'; 2 | import { linguist } from '@sourcebin/linguist'; 3 | 4 | export class File { 5 | public readonly rawUrl: string; 6 | 7 | public readonly name?: string; 8 | public readonly content?: string; 9 | 10 | public readonly languageId: number; 11 | public readonly language: SourcebinLinguistItem; 12 | 13 | constructor(key: string, index: number, data: FileData) { 14 | this.rawUrl = `https://cdn.sourceb.in/bins/${key}/${index}`; 15 | 16 | this.name = data.name; 17 | this.content = data.content; 18 | 19 | this.languageId = data.languageId; 20 | this.language = linguist[data.languageId]; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: ghostdevv # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: onlyspaceghost # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: https://ghostdev.xyz/donate # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | export interface FileData { 2 | name?: string; 3 | content?: string; 4 | languageId: number; 5 | } 6 | 7 | export interface BinData { 8 | hits: number; 9 | key: string; 10 | title?: string; 11 | description?: string; 12 | files: FileData[]; 13 | created: string; 14 | } 15 | 16 | export interface GETBin extends Omit { 17 | files: Omit[]; 18 | } 19 | 20 | export interface POSTBinsBody { 21 | title?: string; 22 | description?: string; 23 | files: FileData[]; 24 | } 25 | 26 | export interface POSTBinsResponse { 27 | key: string; 28 | } 29 | 30 | export interface SourcebinLinguistItem { 31 | name: string; 32 | color: string; 33 | extension: string; 34 | aliases?: string[]; 35 | aceMode: string; 36 | } 37 | -------------------------------------------------------------------------------- /src/utils/languages.ts: -------------------------------------------------------------------------------- 1 | import { languages, linguist } from '@sourcebin/linguist'; 2 | 3 | export function resolveLanguageId(language: string | number) { 4 | if (typeof language == 'number') { 5 | if (!Object.values(languages).includes(language)) 6 | throw new Error(`Unable to find language with id "${language}"`); 7 | 8 | return language; 9 | } 10 | 11 | language = language.toLowerCase(); 12 | 13 | for (const [id, data] of Object.entries(linguist)) { 14 | const hasLanguage = 15 | data.name.toLowerCase() == language || 16 | data.aliases?.map((a) => a.toLowerCase()).includes(language); 17 | 18 | if (hasLanguage) { 19 | return Number(id); 20 | } 21 | } 22 | 23 | // This runs if none of the above checks pass 24 | throw new Error(`Unable to find language "${language}"`); 25 | } 26 | -------------------------------------------------------------------------------- /tests/methods/get.test.ts: -------------------------------------------------------------------------------- 1 | import { get } from '../../src/methods/get'; 2 | import { unreachable } from 'uvu/assert'; 3 | import assert from 'assert'; 4 | import { test } from 'uvu'; 5 | 6 | const key = 'qXO2NVhRc6'; 7 | 8 | test('check that get method returns expected response', async () => { 9 | const res = await get({ key }); 10 | assert.ok(res); 11 | }); 12 | 13 | test('check that get method handles invalid key', async () => { 14 | try { 15 | await get({ key: '123' }); 16 | unreachable("shouldn't work on valid key"); 17 | } catch { 18 | // Ok 19 | } 20 | }); 21 | 22 | test('check that fetchContent option works as expected', async () => { 23 | const res = await get({ key }); 24 | 25 | const withOption = await get({ 26 | key, 27 | fetchContent: false, 28 | }); 29 | 30 | assert.notDeepEqual(res, withOption); 31 | }); 32 | 33 | test.run(); 34 | -------------------------------------------------------------------------------- /src/structures/Bin.ts: -------------------------------------------------------------------------------- 1 | import { File } from '../structures/File'; 2 | import { BinData } from '../types'; 3 | 4 | export class Bin { 5 | public readonly key: string; 6 | 7 | public readonly url: string; 8 | public readonly shortUrl: string; 9 | 10 | public readonly title?: string; 11 | public readonly description?: string; 12 | public readonly views: number; 13 | 14 | public readonly created: Date; 15 | 16 | public readonly files: File[]; 17 | 18 | constructor(data: BinData) { 19 | this.key = data.key; 20 | 21 | this.url = `https://sourceb.in/${data.key}`; 22 | this.shortUrl = `https://srcb.in/${data.key}`; 23 | 24 | this.title = data.title; 25 | this.description = data.description; 26 | this.views = data.hits; 27 | 28 | this.created = new Date(data.created); 29 | 30 | this.files = data.files.map((f, index) => new File(data.key, index, f)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/utils/languages.test.ts: -------------------------------------------------------------------------------- 1 | import { resolveLanguageId } from '../../src/utils/languages'; 2 | import assert from 'assert'; 3 | import { test } from 'uvu'; 4 | 5 | test('returns expected id', () => { 6 | const id = resolveLanguageId('JavaScript'); 7 | assert.equal(id, 183); 8 | }); 9 | 10 | test('is case insensitive', () => { 11 | const id = resolveLanguageId('jAvAsCrIpT'); 12 | assert.equal(id, 183); 13 | }); 14 | 15 | test('works with alias', () => { 16 | const id = resolveLanguageId('js'); 17 | assert.equal(id, 183); 18 | }); 19 | 20 | test('returns undefined if invalid id', () => { 21 | assert.throws(() => resolveLanguageId('madeup language')); 22 | }); 23 | 24 | test("returns id if it's valid number id", () => { 25 | const id = resolveLanguageId(183); 26 | assert.equal(id, 183); 27 | }); 28 | 29 | test("errors if it's a invalid number id", () => { 30 | assert.throws(() => resolveLanguageId(1908881247891)); 31 | }); 32 | 33 | test.run(); 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright © 2022 - Present GHOST 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /tests/structures/file.test.ts: -------------------------------------------------------------------------------- 1 | import { File } from '../../src/structures/File'; 2 | import { getCdnUrl } from '../../src/utils/url'; 3 | import assert from 'assert'; 4 | import { test } from 'uvu'; 5 | 6 | test('can create file', () => { 7 | const file = new File('qXO2NVhRc6', 0, { 8 | languageId: 222, 9 | content: 'test', 10 | name: 'test name', 11 | }); 12 | 13 | assert.ok(file); 14 | }); 15 | 16 | test('has expected fields', () => { 17 | const file = new File('qXO2NVhRc6', 0, { 18 | languageId: 222, 19 | content: 'test', 20 | name: 'test name', 21 | }); 22 | 23 | assert.equal(file.content, 'test'); 24 | assert.equal(file.name, 'test name'); 25 | assert.equal(file.languageId, 222); 26 | }); 27 | 28 | test('has derived fields', () => { 29 | const file = new File('qXO2NVhRc6', 0, { 30 | languageId: 222, 31 | content: 'test', 32 | name: 'test name', 33 | }); 34 | 35 | assert.equal(file.rawUrl, getCdnUrl('qXO2NVhRc6', 0)); 36 | assert.equal(file.language.name, 'Markdown'); 37 | }); 38 | 39 | test.run(); 40 | -------------------------------------------------------------------------------- /src/methods/get.ts: -------------------------------------------------------------------------------- 1 | import type { BinData, FileData, GETBin } from '../types'; 2 | import type { AxiosResponse } from 'axios'; 3 | import { resolveKey } from '../utils/url'; 4 | import { Bin } from '../structures/Bin'; 5 | import { fetch } from '../utils/fetch'; 6 | 7 | export interface GetOptions { 8 | /** 9 | * @default true 10 | */ 11 | fetchContent?: boolean; 12 | 13 | /** 14 | * The key of the bin, can also be a sourcebin url 15 | */ 16 | key: string; 17 | } 18 | 19 | export const get = async (options: GetOptions) => { 20 | const { fetchContent = true } = options; 21 | const key = resolveKey(options.key); 22 | 23 | const { data }: AxiosResponse = await fetch(`/bins/${key}`); 24 | 25 | const parsedFiles: FileData[] = []; 26 | 27 | if (fetchContent) { 28 | for (let i = 0; i < data.files.length; i++) { 29 | const index = i; 30 | 31 | const { data: content } = await fetch({ 32 | baseURL: 'https://cdn.sourceb.in/', 33 | url: `/bins/${key}/${index}`, 34 | responseType: 'text', 35 | }); 36 | 37 | parsedFiles.push({ 38 | ...data.files[index], 39 | content, 40 | }); 41 | } 42 | } 43 | 44 | return new Bin({ 45 | ...data, 46 | files: parsedFiles, 47 | }); 48 | }; 49 | -------------------------------------------------------------------------------- /tests/methods/create.test.ts: -------------------------------------------------------------------------------- 1 | import { create } from '../../src/methods/create'; 2 | import { unreachable } from 'uvu/assert'; 3 | import assert from 'assert'; 4 | import { test } from 'uvu'; 5 | 6 | test('check that create method returns expected response', async () => { 7 | const res = await create({ 8 | files: [ 9 | { 10 | content: 'test', 11 | language: 'text', 12 | }, 13 | ], 14 | }); 15 | 16 | assert.equal(res.files[0].content, 'test'); 17 | assert.equal(res.files[0].language.name, 'Text'); 18 | }); 19 | 20 | test('check that create method can have title and description', async () => { 21 | const res = await create({ 22 | title: 'Test', 23 | description: 'A test desc', 24 | files: [ 25 | { 26 | content: 'test', 27 | language: 'text', 28 | }, 29 | ], 30 | }); 31 | 32 | assert.equal(res.title, 'Test'); 33 | assert.equal(res.description, 'A test desc'); 34 | }); 35 | 36 | test('check that multiple files throws an error', async () => { 37 | try { 38 | await create({ 39 | files: [ 40 | { 41 | content: 'test', 42 | }, 43 | { 44 | content: 'test', 45 | }, 46 | ], 47 | }); 48 | 49 | unreachable("shouldn't work on multiple files"); 50 | } catch { 51 | // Ok 52 | } 53 | }); 54 | 55 | test.run(); 56 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release Package & Test 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | jobs: 8 | test: 9 | runs-on: ubuntu-latest 10 | 11 | strategy: 12 | matrix: 13 | node-version: [14.x, 16.x, 18.x] 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | 18 | - name: Setup Node 16 19 | uses: actions/setup-node@v1 20 | with: 21 | node-version: 16 22 | registry-url: https://registry.npmjs.org/ 23 | 24 | - name: Setup PNPM 25 | uses: pnpm/action-setup@v2.0.1 26 | with: 27 | version: 7.0.0 28 | 29 | - name: Install 30 | run: pnpm install 31 | 32 | - name: Test 33 | run: pnpm test 34 | 35 | publish-npm: 36 | runs-on: ubuntu-latest 37 | steps: 38 | - name: Checkout 39 | uses: actions/checkout@v2 40 | 41 | - name: Setup Node 16 42 | uses: actions/setup-node@v1 43 | with: 44 | node-version: 16 45 | registry-url: https://registry.npmjs.org/ 46 | 47 | - name: Setup PNPM 48 | uses: pnpm/action-setup@v2.0.1 49 | with: 50 | version: 7.0.0 51 | 52 | - name: Install 53 | run: pnpm install 54 | 55 | - name: Build 56 | run: pnpm build 57 | 58 | - name: Publish 59 | run: | 60 | pnpm config set "//registry.npmjs.org/:_authToken" "${NPM_TOKEN}" 61 | pnpm publish --no-git-checks 62 | env: 63 | NPM_TOKEN: ${{secrets.NPM_TOKEN}} -------------------------------------------------------------------------------- /tests/utils/url.test.ts: -------------------------------------------------------------------------------- 1 | import { resolveKey, getCdnUrl } from '../../src/utils/url'; 2 | import assert from 'assert'; 3 | import { test } from 'uvu'; 4 | 5 | test('check cdn url is correct', () => { 6 | const url = getCdnUrl('qXO2NVhRc6', 1); 7 | assert.equal(url, 'https://cdn.sourceb.in/bins/qXO2NVhRc6/1'); 8 | }); 9 | 10 | test('check key is resolved from just a key string', () => { 11 | const key = resolveKey('qXO2NVhRc6'); 12 | assert.equal(key, 'qXO2NVhRc6'); 13 | }); 14 | 15 | test('check key is resolved from full url', () => { 16 | const key = resolveKey('https://sourceb.in/qXO2NVhRc6'); 17 | assert.equal(key, 'qXO2NVhRc6'); 18 | }); 19 | 20 | test('check key is resolved from short url', () => { 21 | const key = resolveKey('http://srcb.in/qXO2NVhRc6'); 22 | assert.equal(key, 'qXO2NVhRc6'); 23 | }); 24 | 25 | test("check that invalid key doesn't result in resolved key", () => { 26 | const key = resolveKey('qXO2NVhRc6a'); 27 | assert.equal(key, undefined); 28 | }); 29 | 30 | test("check that invalid long url doesn't result in resolved key", () => { 31 | const key = resolveKey('https://sourceb.in/qXO2NVhRc6a'); 32 | assert.equal(key, undefined); 33 | }); 34 | 35 | test("check that invalid short url doesn't result in resolved key", () => { 36 | const key = resolveKey('http://srcb.in/qXO2NVhRc6a'); 37 | assert.equal(key, undefined); 38 | }); 39 | 40 | test("check that invalid url doesn't result in resolved key", () => { 41 | const key = resolveKey('http://abc.com/qXO2NVhRc6a'); 42 | assert.equal(key, undefined); 43 | }); 44 | 45 | test.run(); 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sourcebin", 3 | "version": "5.0.0", 4 | "description": "Fast and simple package to get and create bins from https://sourceb.in/", 5 | "main": "dist/index.js", 6 | "module": "dist/index.mjs", 7 | "types": "dist/index.d.ts", 8 | "exports": { 9 | ".": { 10 | "require": "./dist/index.js", 11 | "import": "./dist/index.mjs" 12 | } 13 | }, 14 | "files": [ 15 | "dist", 16 | "LICENSE", 17 | "README.md" 18 | ], 19 | "scripts": { 20 | "test": "tsm node_modules/uvu/bin.js tests \".*\\.test\\.ts\"", 21 | "dev": "nodemon dev/index.js", 22 | "docs": "typedoc src/index.ts", 23 | "build": "tsup-node" 24 | }, 25 | "license": "MIT", 26 | "dependencies": { 27 | "@sourcebin/linguist": "^0.0.3", 28 | "axios": "^0.27.2" 29 | }, 30 | "devDependencies": { 31 | "@types/node": "^18.7.14", 32 | "nodemon": "^2.0.19", 33 | "tsm": "^2.2.2", 34 | "tsup": "^6.2.3", 35 | "typedoc": "^0.23.14", 36 | "typescript": "^4.8.2", 37 | "uvu": "^0.5.6" 38 | }, 39 | "keywords": [ 40 | "sourcebin", 41 | "bin", 42 | "bin wrapper", 43 | "sourcebin wrapper", 44 | "source", 45 | "source bin", 46 | "sourcebin api", 47 | "sourcebin api wrapper", 48 | "sourcebin create", 49 | "sourcebin get" 50 | ], 51 | "author": "GHOST", 52 | "homepage": "https://github.com/ghostdevv/sourcebin", 53 | "repository": { 54 | "type": "git", 55 | "url": "git+https://github.com/ghostdevv/sourcebin" 56 | }, 57 | "bugs": { 58 | "url": "https://github.com/ghostdevv/sourcebin" 59 | } 60 | } -------------------------------------------------------------------------------- /src/methods/create.ts: -------------------------------------------------------------------------------- 1 | import type { POSTBinsBody, POSTBinsResponse } from '../types'; 2 | import { resolveLanguageId } from '../utils/languages'; 3 | import type { AxiosResponse } from 'axios'; 4 | import { fetch } from '../utils/fetch'; 5 | import { get } from './get'; 6 | 7 | export interface FileOptions { 8 | name?: string; 9 | content: string; 10 | 11 | /** 12 | * @default "text" 13 | */ 14 | language?: number | string; 15 | } 16 | 17 | export interface CreateOptions { 18 | title?: string; 19 | description?: string; 20 | files: FileOptions[]; 21 | fetchContent?: boolean; 22 | } 23 | 24 | export const create = async (options: CreateOptions) => { 25 | if (!Array.isArray(options.files) || !options.files.length) 26 | throw new TypeError('Expected an array of one or more files'); 27 | 28 | if (options.files.length > 1) { 29 | throw new Error( 30 | 'You must have Sourcebin pro in order to have multiple files in one bin. This is currently not supported with this library', 31 | ); 32 | } 33 | 34 | const data: POSTBinsBody = { 35 | title: options.title, 36 | description: options.description, 37 | files: [], 38 | }; 39 | 40 | for (const file of options.files) { 41 | const languageId = resolveLanguageId(file.language || 'text'); 42 | 43 | data.files.push({ 44 | languageId, 45 | content: file.content, 46 | name: file.name, 47 | }); 48 | } 49 | 50 | const res: AxiosResponse = await fetch('/bins', { 51 | method: 'POST', 52 | data, 53 | }); 54 | 55 | return await get({ 56 | fetchContent: options.fetchContent || true, 57 | key: res.data.key, 58 | }); 59 | }; 60 | -------------------------------------------------------------------------------- /tests/structures/bin.test.ts: -------------------------------------------------------------------------------- 1 | import { File } from '../../src/structures/File'; 2 | import { Bin } from '../../src/structures/Bin'; 3 | import assert from 'assert'; 4 | import { test } from 'uvu'; 5 | 6 | test('can create bin', () => { 7 | const bin = new Bin({ 8 | key: 'qXO2NVhRc6', 9 | created: '2021-01-31T00:34:35.635Z', 10 | hits: 362, 11 | title: 'test title', 12 | description: 'test description', 13 | files: [ 14 | { 15 | languageId: 222, 16 | content: 'test', 17 | name: 'test name', 18 | }, 19 | ], 20 | }); 21 | 22 | assert.ok(bin); 23 | }); 24 | 25 | test('has expected fields', () => { 26 | const bin = new Bin({ 27 | key: 'qXO2NVhRc6', 28 | created: '2021-01-31T00:34:35.635Z', 29 | hits: 362, 30 | title: 'test title', 31 | description: 'test description', 32 | files: [ 33 | { 34 | languageId: 222, 35 | content: 'test', 36 | name: 'test name', 37 | }, 38 | ], 39 | }); 40 | 41 | assert.equal(bin.key, 'qXO2NVhRc6'); 42 | assert.equal(bin.created.toISOString(), '2021-01-31T00:34:35.635Z'); 43 | assert.equal(bin.views, 362); 44 | assert.equal(bin.title, 'test title'); 45 | assert.equal(bin.description, 'test description'); 46 | }); 47 | 48 | test('has files', () => { 49 | const bin = new Bin({ 50 | key: 'qXO2NVhRc6', 51 | created: '2021-01-31T00:34:35.635Z', 52 | hits: 362, 53 | title: 'test title', 54 | description: 'test description', 55 | files: [ 56 | { 57 | languageId: 222, 58 | content: 'test', 59 | name: 'test name', 60 | }, 61 | ], 62 | }); 63 | 64 | assert.deepEqual( 65 | bin.files[0], 66 | new File('qXO2NVhRc6', 0, { 67 | languageId: 222, 68 | content: 'test', 69 | name: 'test name', 70 | }), 71 | ); 72 | }); 73 | 74 | test.run(); 75 | -------------------------------------------------------------------------------- /docs/assets/highlight.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --light-hl-0: #001080; 3 | --dark-hl-0: #9CDCFE; 4 | --light-hl-1: #000000; 5 | --dark-hl-1: #D4D4D4; 6 | --light-hl-2: #008000; 7 | --dark-hl-2: #6A9955; 8 | --light-hl-3: #AF00DB; 9 | --dark-hl-3: #C586C0; 10 | --light-hl-4: #A31515; 11 | --dark-hl-4: #CE9178; 12 | --light-hl-5: #0000FF; 13 | --dark-hl-5: #569CD6; 14 | --light-hl-6: #0070C1; 15 | --dark-hl-6: #4FC1FF; 16 | --light-hl-7: #795E26; 17 | --dark-hl-7: #DCDCAA; 18 | --light-hl-8: #000000; 19 | --dark-hl-8: #C8C8C8; 20 | --light-hl-9: #098658; 21 | --dark-hl-9: #B5CEA8; 22 | --light-code-background: #FFFFFF; 23 | --dark-code-background: #1E1E1E; 24 | } 25 | 26 | @media (prefers-color-scheme: light) { :root { 27 | --hl-0: var(--light-hl-0); 28 | --hl-1: var(--light-hl-1); 29 | --hl-2: var(--light-hl-2); 30 | --hl-3: var(--light-hl-3); 31 | --hl-4: var(--light-hl-4); 32 | --hl-5: var(--light-hl-5); 33 | --hl-6: var(--light-hl-6); 34 | --hl-7: var(--light-hl-7); 35 | --hl-8: var(--light-hl-8); 36 | --hl-9: var(--light-hl-9); 37 | --code-background: var(--light-code-background); 38 | } } 39 | 40 | @media (prefers-color-scheme: dark) { :root { 41 | --hl-0: var(--dark-hl-0); 42 | --hl-1: var(--dark-hl-1); 43 | --hl-2: var(--dark-hl-2); 44 | --hl-3: var(--dark-hl-3); 45 | --hl-4: var(--dark-hl-4); 46 | --hl-5: var(--dark-hl-5); 47 | --hl-6: var(--dark-hl-6); 48 | --hl-7: var(--dark-hl-7); 49 | --hl-8: var(--dark-hl-8); 50 | --hl-9: var(--dark-hl-9); 51 | --code-background: var(--dark-code-background); 52 | } } 53 | 54 | :root[data-theme='light'] { 55 | --hl-0: var(--light-hl-0); 56 | --hl-1: var(--light-hl-1); 57 | --hl-2: var(--light-hl-2); 58 | --hl-3: var(--light-hl-3); 59 | --hl-4: var(--light-hl-4); 60 | --hl-5: var(--light-hl-5); 61 | --hl-6: var(--light-hl-6); 62 | --hl-7: var(--light-hl-7); 63 | --hl-8: var(--light-hl-8); 64 | --hl-9: var(--light-hl-9); 65 | --code-background: var(--light-code-background); 66 | } 67 | 68 | :root[data-theme='dark'] { 69 | --hl-0: var(--dark-hl-0); 70 | --hl-1: var(--dark-hl-1); 71 | --hl-2: var(--dark-hl-2); 72 | --hl-3: var(--dark-hl-3); 73 | --hl-4: var(--dark-hl-4); 74 | --hl-5: var(--dark-hl-5); 75 | --hl-6: var(--dark-hl-6); 76 | --hl-7: var(--dark-hl-7); 77 | --hl-8: var(--dark-hl-8); 78 | --hl-9: var(--dark-hl-9); 79 | --code-background: var(--dark-code-background); 80 | } 81 | 82 | .hl-0 { color: var(--hl-0); } 83 | .hl-1 { color: var(--hl-1); } 84 | .hl-2 { color: var(--hl-2); } 85 | .hl-3 { color: var(--hl-3); } 86 | .hl-4 { color: var(--hl-4); } 87 | .hl-5 { color: var(--hl-5); } 88 | .hl-6 { color: var(--hl-6); } 89 | .hl-7 { color: var(--hl-7); } 90 | .hl-8 { color: var(--hl-8); } 91 | .hl-9 { color: var(--hl-9); } 92 | pre, code { background: var(--code-background); } 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sourcebin 2 | 3 | [![](https://img.shields.io/npm/v/sourcebin?label=Latest%20Version&style=for-the-badge&logo=npm&color=informational)](https://www.npmjs.com/package/sourcebin) 4 | [![](https://img.shields.io/static/v1?label=Project%20Creator&message=GHOST&color=informational&style=for-the-badge)](https://ghostdev.xyz) 5 | [![](https://img.shields.io/github/workflow/status/ghostdevv/sourcebin/Test%20Suite%20CI?style=for-the-badge)](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) 169 | -------------------------------------------------------------------------------- /docs/interfaces/GetOptions.html: -------------------------------------------------------------------------------- 1 | GetOptions | sourcebin
2 |
3 | 8 |
9 |
10 |
11 |
12 | 15 |

Interface GetOptions

16 |
17 |

Hierarchy

18 |
    19 |
  • GetOptions
22 |
23 |
24 |
25 | 26 |
27 |
28 |

Properties

29 |
fetchContent? 30 | key 31 |
32 |
33 |

Properties

34 |
35 | 36 |
fetchContent?: boolean
37 |
38 |

Default

true

39 |
42 |
43 | 44 |
key: string
45 |

The key of the bin, can also be a sourcebin url

46 |
49 |
76 |
77 |

Generated using TypeDoc

78 |
-------------------------------------------------------------------------------- /docs/functions/get.html: -------------------------------------------------------------------------------- 1 | get | sourcebin
2 |
3 | 8 |
9 |
10 |
11 |
12 | 15 |

Function get

16 |
17 |
28 |
62 |
63 |

Generated using TypeDoc

64 |
-------------------------------------------------------------------------------- /docs/functions/create.html: -------------------------------------------------------------------------------- 1 | create | sourcebin
2 |
3 | 8 |
9 |
10 |
11 |
12 | 15 |

Function create

16 |
17 |
28 |
62 |
63 |

Generated using TypeDoc

64 |
-------------------------------------------------------------------------------- /docs/interfaces/FileData.html: -------------------------------------------------------------------------------- 1 | FileData | sourcebin
2 |
3 | 8 |
9 |
10 |
11 |
12 | 15 |

Interface FileData

16 |
17 |

Hierarchy

18 |
    19 |
  • FileData
22 |
23 |
24 |
25 | 26 |
27 |
28 |

Properties

29 |
content? 30 | languageId 31 | name? 32 |
33 |
34 |

Properties

35 |
36 | 37 |
content?: string
40 |
41 | 42 |
languageId: number
45 |
46 | 47 |
name?: string
50 |
78 |
79 |

Generated using TypeDoc

80 |
-------------------------------------------------------------------------------- /docs/assets/search.js: -------------------------------------------------------------------------------- 1 | window.searchData = JSON.parse("{\"kinds\":{\"64\":\"Function\",\"128\":\"Class\",\"256\":\"Interface\",\"512\":\"Constructor\",\"1024\":\"Property\",\"65536\":\"Type literal\"},\"rows\":[{\"kind\":256,\"name\":\"CreateOptions\",\"url\":\"interfaces/CreateOptions.html\",\"classes\":\"tsd-kind-interface\"},{\"kind\":1024,\"name\":\"title\",\"url\":\"interfaces/CreateOptions.html#title\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"CreateOptions\"},{\"kind\":1024,\"name\":\"description\",\"url\":\"interfaces/CreateOptions.html#description\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"CreateOptions\"},{\"kind\":1024,\"name\":\"files\",\"url\":\"interfaces/CreateOptions.html#files\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"CreateOptions\"},{\"kind\":1024,\"name\":\"fetchContent\",\"url\":\"interfaces/CreateOptions.html#fetchContent\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"CreateOptions\"},{\"kind\":256,\"name\":\"FileOptions\",\"url\":\"interfaces/FileOptions.html\",\"classes\":\"tsd-kind-interface\"},{\"kind\":1024,\"name\":\"name\",\"url\":\"interfaces/FileOptions.html#name\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"FileOptions\"},{\"kind\":1024,\"name\":\"content\",\"url\":\"interfaces/FileOptions.html#content\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"FileOptions\"},{\"kind\":1024,\"name\":\"language\",\"url\":\"interfaces/FileOptions.html#language\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"FileOptions\"},{\"kind\":64,\"name\":\"create\",\"url\":\"functions/create.html\",\"classes\":\"tsd-kind-function\"},{\"kind\":256,\"name\":\"GetOptions\",\"url\":\"interfaces/GetOptions.html\",\"classes\":\"tsd-kind-interface\"},{\"kind\":1024,\"name\":\"fetchContent\",\"url\":\"interfaces/GetOptions.html#fetchContent\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"GetOptions\"},{\"kind\":1024,\"name\":\"key\",\"url\":\"interfaces/GetOptions.html#key\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"GetOptions\"},{\"kind\":64,\"name\":\"get\",\"url\":\"functions/get.html\",\"classes\":\"tsd-kind-function\"},{\"kind\":64,\"name\":\"url\",\"url\":\"functions/url.html\",\"classes\":\"tsd-kind-function\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"functions/url.html#url.__type\",\"classes\":\"tsd-kind-type-literal\",\"parent\":\"url.url\"},{\"kind\":1024,\"name\":\"key\",\"url\":\"functions/url.html#url.__type.key\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"url.url.__type\"},{\"kind\":1024,\"name\":\"url\",\"url\":\"functions/url.html#url.__type.url-1\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"url.url.__type\"},{\"kind\":1024,\"name\":\"short\",\"url\":\"functions/url.html#url.__type.short\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"url.url.__type\"},{\"kind\":128,\"name\":\"File\",\"url\":\"classes/File.html\",\"classes\":\"tsd-kind-class\"},{\"kind\":512,\"name\":\"constructor\",\"url\":\"classes/File.html#constructor\",\"classes\":\"tsd-kind-constructor tsd-parent-kind-class\",\"parent\":\"File\"},{\"kind\":1024,\"name\":\"rawUrl\",\"url\":\"classes/File.html#rawUrl\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"File\"},{\"kind\":1024,\"name\":\"name\",\"url\":\"classes/File.html#name\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"File\"},{\"kind\":1024,\"name\":\"content\",\"url\":\"classes/File.html#content\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"File\"},{\"kind\":1024,\"name\":\"languageId\",\"url\":\"classes/File.html#languageId\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"File\"},{\"kind\":1024,\"name\":\"language\",\"url\":\"classes/File.html#language\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"File\"},{\"kind\":128,\"name\":\"Bin\",\"url\":\"classes/Bin.html\",\"classes\":\"tsd-kind-class\"},{\"kind\":512,\"name\":\"constructor\",\"url\":\"classes/Bin.html#constructor\",\"classes\":\"tsd-kind-constructor tsd-parent-kind-class\",\"parent\":\"Bin\"},{\"kind\":1024,\"name\":\"key\",\"url\":\"classes/Bin.html#key\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"Bin\"},{\"kind\":1024,\"name\":\"url\",\"url\":\"classes/Bin.html#url\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"Bin\"},{\"kind\":1024,\"name\":\"shortUrl\",\"url\":\"classes/Bin.html#shortUrl\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"Bin\"},{\"kind\":1024,\"name\":\"title\",\"url\":\"classes/Bin.html#title\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"Bin\"},{\"kind\":1024,\"name\":\"description\",\"url\":\"classes/Bin.html#description\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"Bin\"},{\"kind\":1024,\"name\":\"views\",\"url\":\"classes/Bin.html#views\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"Bin\"},{\"kind\":1024,\"name\":\"created\",\"url\":\"classes/Bin.html#created\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"Bin\"},{\"kind\":1024,\"name\":\"files\",\"url\":\"classes/Bin.html#files\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"Bin\"},{\"kind\":256,\"name\":\"SourcebinLinguistItem\",\"url\":\"interfaces/SourcebinLinguistItem.html\",\"classes\":\"tsd-kind-interface\"},{\"kind\":1024,\"name\":\"name\",\"url\":\"interfaces/SourcebinLinguistItem.html#name\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"SourcebinLinguistItem\"},{\"kind\":1024,\"name\":\"color\",\"url\":\"interfaces/SourcebinLinguistItem.html#color\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"SourcebinLinguistItem\"},{\"kind\":1024,\"name\":\"extension\",\"url\":\"interfaces/SourcebinLinguistItem.html#extension\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"SourcebinLinguistItem\"},{\"kind\":1024,\"name\":\"aliases\",\"url\":\"interfaces/SourcebinLinguistItem.html#aliases\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"SourcebinLinguistItem\"},{\"kind\":1024,\"name\":\"aceMode\",\"url\":\"interfaces/SourcebinLinguistItem.html#aceMode\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"SourcebinLinguistItem\"},{\"kind\":256,\"name\":\"BinData\",\"url\":\"interfaces/BinData.html\",\"classes\":\"tsd-kind-interface\"},{\"kind\":1024,\"name\":\"hits\",\"url\":\"interfaces/BinData.html#hits\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"BinData\"},{\"kind\":1024,\"name\":\"key\",\"url\":\"interfaces/BinData.html#key\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"BinData\"},{\"kind\":1024,\"name\":\"title\",\"url\":\"interfaces/BinData.html#title\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"BinData\"},{\"kind\":1024,\"name\":\"description\",\"url\":\"interfaces/BinData.html#description\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"BinData\"},{\"kind\":1024,\"name\":\"files\",\"url\":\"interfaces/BinData.html#files\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"BinData\"},{\"kind\":1024,\"name\":\"created\",\"url\":\"interfaces/BinData.html#created\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"BinData\"},{\"kind\":256,\"name\":\"FileData\",\"url\":\"interfaces/FileData.html\",\"classes\":\"tsd-kind-interface\"},{\"kind\":1024,\"name\":\"name\",\"url\":\"interfaces/FileData.html#name\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"FileData\"},{\"kind\":1024,\"name\":\"content\",\"url\":\"interfaces/FileData.html#content\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"FileData\"},{\"kind\":1024,\"name\":\"languageId\",\"url\":\"interfaces/FileData.html#languageId\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"FileData\"}],\"index\":{\"version\":\"2.3.9\",\"fields\":[\"name\",\"comment\"],\"fieldVectors\":[[\"name/0\",[0,35.835]],[\"comment/0\",[]],[\"name/1\",[1,27.362]],[\"comment/1\",[]],[\"name/2\",[2,27.362]],[\"comment/2\",[]],[\"name/3\",[3,27.362]],[\"comment/3\",[]],[\"name/4\",[4,30.727]],[\"comment/4\",[]],[\"name/5\",[5,35.835]],[\"comment/5\",[]],[\"name/6\",[6,24.849]],[\"comment/6\",[]],[\"name/7\",[7,27.362]],[\"comment/7\",[]],[\"name/8\",[8,30.727]],[\"comment/8\",[]],[\"name/9\",[9,35.835]],[\"comment/9\",[]],[\"name/10\",[10,35.835]],[\"comment/10\",[]],[\"name/11\",[4,30.727]],[\"comment/11\",[]],[\"name/12\",[11,24.849]],[\"comment/12\",[]],[\"name/13\",[12,35.835]],[\"comment/13\",[]],[\"name/14\",[13,27.362]],[\"comment/14\",[]],[\"name/15\",[14,35.835]],[\"comment/15\",[]],[\"name/16\",[11,24.849]],[\"comment/16\",[]],[\"name/17\",[13,27.362]],[\"comment/17\",[]],[\"name/18\",[15,35.835]],[\"comment/18\",[]],[\"name/19\",[16,35.835]],[\"comment/19\",[]],[\"name/20\",[17,30.727]],[\"comment/20\",[]],[\"name/21\",[18,35.835]],[\"comment/21\",[]],[\"name/22\",[6,24.849]],[\"comment/22\",[]],[\"name/23\",[7,27.362]],[\"comment/23\",[]],[\"name/24\",[19,30.727]],[\"comment/24\",[]],[\"name/25\",[8,30.727]],[\"comment/25\",[]],[\"name/26\",[20,35.835]],[\"comment/26\",[]],[\"name/27\",[17,30.727]],[\"comment/27\",[]],[\"name/28\",[11,24.849]],[\"comment/28\",[]],[\"name/29\",[13,27.362]],[\"comment/29\",[]],[\"name/30\",[21,35.835]],[\"comment/30\",[]],[\"name/31\",[1,27.362]],[\"comment/31\",[]],[\"name/32\",[2,27.362]],[\"comment/32\",[]],[\"name/33\",[22,35.835]],[\"comment/33\",[]],[\"name/34\",[23,30.727]],[\"comment/34\",[]],[\"name/35\",[3,27.362]],[\"comment/35\",[]],[\"name/36\",[24,35.835]],[\"comment/36\",[]],[\"name/37\",[6,24.849]],[\"comment/37\",[]],[\"name/38\",[25,35.835]],[\"comment/38\",[]],[\"name/39\",[26,35.835]],[\"comment/39\",[]],[\"name/40\",[27,35.835]],[\"comment/40\",[]],[\"name/41\",[28,35.835]],[\"comment/41\",[]],[\"name/42\",[29,35.835]],[\"comment/42\",[]],[\"name/43\",[30,35.835]],[\"comment/43\",[]],[\"name/44\",[11,24.849]],[\"comment/44\",[]],[\"name/45\",[1,27.362]],[\"comment/45\",[]],[\"name/46\",[2,27.362]],[\"comment/46\",[]],[\"name/47\",[3,27.362]],[\"comment/47\",[]],[\"name/48\",[23,30.727]],[\"comment/48\",[]],[\"name/49\",[31,35.835]],[\"comment/49\",[]],[\"name/50\",[6,24.849]],[\"comment/50\",[]],[\"name/51\",[7,27.362]],[\"comment/51\",[]],[\"name/52\",[19,30.727]],[\"comment/52\",[]]],\"invertedIndex\":[[\"__type\",{\"_index\":14,\"name\":{\"15\":{}},\"comment\":{}}],[\"acemode\",{\"_index\":28,\"name\":{\"41\":{}},\"comment\":{}}],[\"aliases\",{\"_index\":27,\"name\":{\"40\":{}},\"comment\":{}}],[\"bin\",{\"_index\":20,\"name\":{\"26\":{}},\"comment\":{}}],[\"bindata\",{\"_index\":29,\"name\":{\"42\":{}},\"comment\":{}}],[\"color\",{\"_index\":25,\"name\":{\"38\":{}},\"comment\":{}}],[\"constructor\",{\"_index\":17,\"name\":{\"20\":{},\"27\":{}},\"comment\":{}}],[\"content\",{\"_index\":7,\"name\":{\"7\":{},\"23\":{},\"51\":{}},\"comment\":{}}],[\"create\",{\"_index\":9,\"name\":{\"9\":{}},\"comment\":{}}],[\"created\",{\"_index\":23,\"name\":{\"34\":{},\"48\":{}},\"comment\":{}}],[\"createoptions\",{\"_index\":0,\"name\":{\"0\":{}},\"comment\":{}}],[\"description\",{\"_index\":2,\"name\":{\"2\":{},\"32\":{},\"46\":{}},\"comment\":{}}],[\"extension\",{\"_index\":26,\"name\":{\"39\":{}},\"comment\":{}}],[\"fetchcontent\",{\"_index\":4,\"name\":{\"4\":{},\"11\":{}},\"comment\":{}}],[\"file\",{\"_index\":16,\"name\":{\"19\":{}},\"comment\":{}}],[\"filedata\",{\"_index\":31,\"name\":{\"49\":{}},\"comment\":{}}],[\"fileoptions\",{\"_index\":5,\"name\":{\"5\":{}},\"comment\":{}}],[\"files\",{\"_index\":3,\"name\":{\"3\":{},\"35\":{},\"47\":{}},\"comment\":{}}],[\"get\",{\"_index\":12,\"name\":{\"13\":{}},\"comment\":{}}],[\"getoptions\",{\"_index\":10,\"name\":{\"10\":{}},\"comment\":{}}],[\"hits\",{\"_index\":30,\"name\":{\"43\":{}},\"comment\":{}}],[\"key\",{\"_index\":11,\"name\":{\"12\":{},\"16\":{},\"28\":{},\"44\":{}},\"comment\":{}}],[\"language\",{\"_index\":8,\"name\":{\"8\":{},\"25\":{}},\"comment\":{}}],[\"languageid\",{\"_index\":19,\"name\":{\"24\":{},\"52\":{}},\"comment\":{}}],[\"name\",{\"_index\":6,\"name\":{\"6\":{},\"22\":{},\"37\":{},\"50\":{}},\"comment\":{}}],[\"rawurl\",{\"_index\":18,\"name\":{\"21\":{}},\"comment\":{}}],[\"short\",{\"_index\":15,\"name\":{\"18\":{}},\"comment\":{}}],[\"shorturl\",{\"_index\":21,\"name\":{\"30\":{}},\"comment\":{}}],[\"sourcebinlinguistitem\",{\"_index\":24,\"name\":{\"36\":{}},\"comment\":{}}],[\"title\",{\"_index\":1,\"name\":{\"1\":{},\"31\":{},\"45\":{}},\"comment\":{}}],[\"url\",{\"_index\":13,\"name\":{\"14\":{},\"17\":{},\"29\":{}},\"comment\":{}}],[\"views\",{\"_index\":22,\"name\":{\"33\":{}},\"comment\":{}}]],\"pipeline\":[]}}"); -------------------------------------------------------------------------------- /docs/functions/url.html: -------------------------------------------------------------------------------- 1 | url | sourcebin
2 |
3 | 8 |
9 |
10 |
11 |
12 | 15 |

Function url

16 |
17 |
    18 | 19 |
  • 20 |
    21 |

    Parameters

    22 |
      23 |
    • 24 |
      keyOrUrl: string
    25 |

    Returns { key: string; short: string; url: string }

    26 |
      27 |
    • 28 |
      key: string
    • 29 |
    • 30 |
      short: string
    • 31 |
    • 32 |
      url: string
35 |
69 |
70 |

Generated using TypeDoc

71 |
-------------------------------------------------------------------------------- /docs/interfaces/FileOptions.html: -------------------------------------------------------------------------------- 1 | FileOptions | sourcebin
2 |
3 | 8 |
9 |
10 |
11 |
12 | 15 |

Interface FileOptions

16 |
17 |

Hierarchy

18 |
    19 |
  • FileOptions
22 |
23 |
24 |
25 | 26 |
27 |
28 |

Properties

29 |
content 30 | language? 31 | name? 32 |
33 |
34 |

Properties

35 |
36 | 37 |
content: string
40 |
41 | 42 |
language?: string | number
43 |
44 |

Default

"text"

45 |
48 |
49 | 50 |
name?: string
53 |
81 |
82 |

Generated using TypeDoc

83 |
-------------------------------------------------------------------------------- /docs/modules.html: -------------------------------------------------------------------------------- 1 | sourcebin
2 |
3 | 8 |
9 |
10 |
11 |
12 |

sourcebin

13 |
14 |
15 |

Index

16 |
17 |

Classes

18 |
Bin 19 | File 20 |
21 |
22 |

Interfaces

23 |
30 |
31 |

Functions

32 |
create 33 | get 34 | url 35 |
36 |
70 |
71 |

Generated using TypeDoc

72 |
-------------------------------------------------------------------------------- /docs/interfaces/CreateOptions.html: -------------------------------------------------------------------------------- 1 | CreateOptions | sourcebin
2 |
3 | 8 |
9 |
10 |
11 |
12 | 15 |

Interface CreateOptions

16 |
17 |

Hierarchy

18 |
    19 |
  • CreateOptions
22 |
23 |
24 |
25 | 26 |
27 |
28 |

Properties

29 |
description? 30 | fetchContent? 31 | files 32 | title? 33 |
34 |
35 |

Properties

36 |
37 | 38 |
description?: string
41 |
42 | 43 |
fetchContent?: boolean
46 |
47 | 48 |
files: FileOptions[]
51 |
52 | 53 |
title?: string
56 |
85 |
86 |

Generated using TypeDoc

87 |
-------------------------------------------------------------------------------- /docs/interfaces/SourcebinLinguistItem.html: -------------------------------------------------------------------------------- 1 | SourcebinLinguistItem | sourcebin
2 |
3 | 8 |
9 |
10 |
11 |
12 | 15 |

Interface SourcebinLinguistItem

16 |
17 |

Hierarchy

18 |
    19 |
  • SourcebinLinguistItem
22 |
23 |
24 |
25 | 26 |
27 |
28 |

Properties

29 |
aceMode 30 | aliases? 31 | color 32 | extension 33 | name 34 |
35 |
36 |

Properties

37 |
38 | 39 |
aceMode: string
42 |
43 | 44 |
aliases?: string[]
47 |
48 | 49 |
color: string
52 |
53 | 54 |
extension: string
57 |
58 | 59 |
name: string
62 |
92 |
93 |

Generated using TypeDoc

94 |
-------------------------------------------------------------------------------- /docs/interfaces/BinData.html: -------------------------------------------------------------------------------- 1 | BinData | sourcebin
2 |
3 | 8 |
9 |
10 |
11 |
12 | 15 |

Interface BinData

16 |
17 |

Hierarchy

18 |
    19 |
  • BinData
22 |
23 |
24 |
25 | 26 |
27 |
28 |

Properties

29 |
created 30 | description? 31 | files 32 | hits 33 | key 34 | title? 35 |
36 |
37 |

Properties

38 |
39 | 40 |
created: string
43 |
44 | 45 |
description?: string
48 |
49 | 50 |
files: FileData[]
53 |
54 | 55 |
hits: number
58 |
59 | 60 |
key: string
63 |
64 | 65 |
title?: string
68 |
99 |
100 |

Generated using TypeDoc

101 |
-------------------------------------------------------------------------------- /docs/classes/File.html: -------------------------------------------------------------------------------- 1 | File | sourcebin
2 |
3 | 8 |
9 |
10 |
11 |
12 | 15 |

Class File

16 |
17 |

Hierarchy

18 |
    19 |
  • File
22 |
23 |
24 |
25 | 26 |
27 |
28 |

Constructors

29 |
31 |
32 |

Properties

33 |
content? 34 | language 35 | languageId 36 | name? 37 | rawUrl 38 |
39 |
40 |

Constructors

41 |
42 | 43 |
    44 | 45 |
  • 46 |
    47 |

    Parameters

    48 |
      49 |
    • 50 |
      key: string
    • 51 |
    • 52 |
      index: number
    • 53 |
    • 54 |
      data: FileData
    55 |

    Returns File

58 |
59 |

Properties

60 |
61 | 62 |
content?: string
65 |
66 | 67 |
70 |
71 | 72 |
languageId: number
75 |
76 | 77 |
name?: string
80 |
81 | 82 |
rawUrl: string
85 |
116 |
117 |

Generated using TypeDoc

118 |
-------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | sourcebin
2 |
3 | 8 |
9 |
10 |
11 |
12 |

sourcebin

13 |
14 | 15 |

Sourcebin

16 |
17 |

18 | 19 |

20 |

Fast and simple package to get and create bins from sourcebin

21 | 22 | 23 |

Requirements

24 |
25 |
NodeJS >= 14.x
 26 | 
27 | 28 | 29 |

Install

30 |
31 |
npm install sourcebin
 32 | 
33 | 34 | 35 |

Docs

36 |
37 |

This README is the best place to learn how to use this package, you can also take a look at our API docs

38 | 39 | 40 |

Setup

41 |
42 |
// Import individual methods
import { create, get, url } from 'sourcebin';

// Import all methods
import * as sourcebin from 'sourcebin';

// Use required
const { create, get, url } = require('sourcebin'); 43 |
44 | 45 | 46 |

Get a bin

47 |
48 |

get(options)

49 |
const bin = await get({
key: 'qXO2NVhRc6'
}); 50 |
51 | 52 | 53 |

Options

54 |
55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 |
OptionDescriptionDefaultRequired
keyThe key to getn/a
fetchContentShould the bin content be fetchedtrue
77 | 78 | 79 |

Create a bin

80 |
81 |

create(options)

82 |
const bin = await create(
{
title: 'bin name',
description: 'test bin',
files: [
{
content: 'Hello World',
language: 'text',
},
],
},
); 83 |
84 | 85 | 86 |

Options

87 |
88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 |
OptionDescriptionRequired
titleTitle of the bin
descriptionDescription of the bin
filesBin files - see below
112 | 113 | 114 |

File Options

115 |
116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 |
OptionDescriptionDefaultRequired
contentContents of the filen/a
languageWhat language should the file betext
138 | 139 | 140 |

Url Helper

141 |
142 |

If you want to get information about a bin try the url function.

143 |
const urlData = url('iQznILdZRP');

// or

const urlData = url('https://sourceb.in/iQznILdZRP'); 144 |
145 |

This returns an object that looks like:

146 |
{
key: 'iQznILdZRP',
url: 'https://sourceb.in/iQznILdZRP',
short: 'http://srcb.in/iQznILdZRP'
} 147 |
148 | 149 | 150 |

FAQ

151 |
152 |
    153 |
  • 154 | 155 |

    Multiple files in one bin

    156 |
    157 |

    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

    158 |
  • 159 |
  • 160 | 161 |

    Migrate from v4 to v5

    162 |
    163 |

    v5 is a overhaull of sourcebin so we changed some apis.

    164 | 165 | 166 |

    Get a bin

    167 |
    168 |

    Instead of passing the key then options it's now one object.

    169 |
    - const bin = await get('qXO2NVhRc6');
    + const bin = await get({ key: 'qXO2NVhRc6' });

    - const bin = await get('qXO2NVhRc6', { fetchContent: false });
    + const bin = await get({ key: 'qXO2NVhRc6', fetchContent: false }); 170 |
    171 | 172 | 173 |

    Create a bin

    174 |
    175 |

    We also unified the options for this function:

    176 |
    - const bin = await create(
    - [
    - {
    - content: 'Hello World',
    - language: 'text',
    - },
    - ],
    - {
    - title: 'bin name',
    - description: 'test bin',
    - },
    - );

    + const bin = await create(
    + {
    + title: 'bin name',
    + description: 'test bin',
    + files: [
    + {
    + content: 'Hello World',
    + language: 'text',
    + },
    + ],
    + }
    + ); 177 |
    178 |
  • 179 |
180 | 181 | 182 |

Support

183 |
184 |
    185 |
  • Join the discord
  • 186 |
  • Create a issue on the github
  • 187 |
188 |
189 |
223 |
224 |

Generated using TypeDoc

225 |
--------------------------------------------------------------------------------