Giter Site home page Giter Site logo

ghostdevv / sourcebin Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 3.0 734 KB

Fast and simple package to get and create bins from https://sourceb.in/

License: MIT License

TypeScript 100.00%
sourcebin discord typescript language sourcebin-wrapper sourcebinapi sourcebin-api hacktoberfest

sourcebin's Introduction

Sourcebin

Fast and simple package to get and create bins from sourcebin

Requirements

NodeJS >= 14.x

Install

npm install sourcebin

Docs

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

Setup

// 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');

Get a bin

get(options)

const bin = await get({
    key: 'qXO2NVhRc6'
});

Options

Option Description Default Required
key The key to get n/a
fetchContent Should the bin content be fetched true

Create a bin

create(options)

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

Options

Option Description Required
title Title of the bin
description Description of the bin
files Bin files - see below

File Options

Option Description Default Required
content Contents of the file n/a
language What language should the file be text

Url Helper

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

const urlData = url('iQznILdZRP');

// or

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

This returns an object that looks like:

{
  key: 'iQznILdZRP',
  url: 'https://sourceb.in/iQznILdZRP',
  short: 'http://srcb.in/iQznILdZRP'
}

FAQ

  • Multiple files in one bin

    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

  • Migrate from v4 to v5

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

    Get a bin

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

    - 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 });

    Create a bin

    We also unified the options for this function:

    - 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',
    +           },
    +       ],
    +   }
    +  );

Support

sourcebin's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar ghostdevv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sourcebin's Issues

SyntaxError: Invalid key provided - SourceBin#shorten

Upon trying to create a bin using sourcebin#create, I receive an error that an invalid key was provided.

(node:40713) UnhandledPromiseRejectionWarning: SyntaxError: Invalid key provided - SourceBin#shorten
    at Function.shorten (/Users/<omitted>/Desktop/home/<omitted>/node_modules/sourcebin/src/sourcebin-methods.js:148:59)
    at /Users/<omitted>/Desktop/home/<omitted>/node_modules/sourcebin/src/sourcebin-methods.js:132:33
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:40713) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:40713) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Any solution for this?

Switch to axios

Self explanatory, switch to axios since it's more known and preferable

Update error handling

Able to fully catch error (remove console.error's)
Move indepth error checking (e.g. if bin creating fails, why?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.