With this wrapper you can create and get bins from https://sourceb.in/
npm i sourcebin-wrapper --save
// typescript
import * as SourceBin from 'sourcebin-wrapper';
// Node/JavaScript
const SourceBin = require('sourcebin-wrapper');
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 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.
SourceBin.newBin('Using wrapper', 'txt', 'wrapper', {
title: 'Some test',
description: 'This is awesome'
})
.then(console.log)
.catch(console.error);
// 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);
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"
}
}
]
}
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
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