sourcebin-wrapper
v1.6.0
Published
Create and get bins from https://sourceb.in/
Downloads
19
Maintainers
Readme
SourceBin Wrapper
With this wrapper you can create and get bins from https://sourceb.in/
Install
npm i sourcebin-wrapper --save
Initialize
// typescript
import * as SourceBin from 'sourcebin-wrapper';
// Node/JavaScript
const SourceBin = require('sourcebin-wrapper');
Methods
create([BinFile], BinOptions?)
SourceBin.create([
new SourceBin.BinFile({
name: 'index.js',
content: 'This was created using the wrapper\n\nlanguageId: "js"',
languageId: 'js'
})
], {
title: 'Some test',
description: 'This is awesome'
})
.then(console.log)
.catch(console.error);
Language defaults to Text, if invalid or no language provided.
upload(path, BinOptions?)
// Upload single file
SourceBin.upload('path/to/file', { title: 'Upload file' })
.then(console.log)
.catch(console.error);
// Upload entire folder
SourceBin.upload('path/to/folder', { title: 'Upload folder' })
.then(console.log)
.catch(console.error);
Language is detected by the file extension, and name as well.
newBin(contents, lang?, name?, BinOptions?)
SourceBin.newBin('Using wrapper', 'txt', 'wrapper', {
title: 'Some test',
description: 'This is awesome'
})
.then(console.log)
.catch(console.error);
get(url | key)
// Get bin using its key
SourceBin.get("d4ad855543").then(console.log);
// Get bin using its url
SourceBin.get("https://sourceb.in/d4ad855543").then(console.log);
Sample Output
Output for both create and get
{
"key": "d4ad855543",
"url": "https://sourceb.in/d4ad855543",
"shortened": "https://srcb.in/d4ad855543",
"created": "2020-03-17T21:12:30.549Z",
"files": [
{
"raw": "https://sourceb.in/raw/d4ad855543/0",
"content": "This was created using the wrapper\n\nlanguageId: \"js\"",
"languageId": 183,
"language": {
"name": "JavaScript",
"extension": "js",
"aliases": [
"js",
"node"
],
"aceMode": "javascript"
}
}
]
}
Options
BinFileOptions:
This is for creating BinFiles
content
: The contents of what you're uploadingname
<optional>: The name of the file to be uploadedlanguageId
<optional>: Language of the contents you're uploading
BinOptions:
This is for creating Bins
title
<optional>: The title of the bindescription
<optional>: The description of the bin
Note: BinFile is for the contents of each Bin. A Bin can contain multiple BinFiles