{"id":16718694,"url":"https://github.com/planeshifter/node-wandbox-api","last_synced_at":"2025-04-10T08:54:06.966Z","repository":{"id":50982759,"uuid":"52640301","full_name":"Planeshifter/node-wandbox-api","owner":"Planeshifter","description":"Node.js bindings to the Wandbox API.","archived":false,"fork":false,"pushed_at":"2021-05-26T11:53:11.000Z","size":43,"stargazers_count":6,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-25T14:21:24.477Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Planeshifter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-26T23:47:01.000Z","updated_at":"2023-03-04T06:33:40.000Z","dependencies_parsed_at":"2022-09-11T19:21:45.392Z","dependency_job_id":null,"html_url":"https://github.com/Planeshifter/node-wandbox-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Planeshifter%2Fnode-wandbox-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Planeshifter%2Fnode-wandbox-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Planeshifter%2Fnode-wandbox-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Planeshifter%2Fnode-wandbox-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Planeshifter","download_url":"https://codeload.github.com/Planeshifter/node-wandbox-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248190407,"owners_count":21062277,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T21:38:10.874Z","updated_at":"2025-04-10T08:54:06.940Z","avatar_url":"https://github.com/Planeshifter.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Node Wandbox API\n===\n[![NPM version][npm-image]][npm-url] [![Build Status][build-image]][build-url] [![Coverage Status][coverage-image]][coverage-url] [![Dependencies][dependencies-image]][dependencies-url]\n\n\u003e Access Social Compilation Service [Wandbox][wandbox] via API from Node.js.\n\n\n## Installation\n\n``` bash\n$ npm install wandbox-api\n```\n\n\n## Usage\n\n``` javascript\nvar runWandbox = require( 'wandbox-api' );\n```\n\n#### runWandbox( [dest,] src[, opts], clbk )\n\nCompile and run programs on [Wandbox][wandbox]. `src` has to be the path of the source file that Wandbox should compile. Results of API call are passed to `clbk`, a callback function which\nhas an `error` and `result` parameter, and optionally saved to the file specified in `dest`. To change the default compiler options, an options object can be supplied (`opts`).\n\n``` javascript\n/* FILE: code.cpp\n\t#include \u003ciostream\u003e\n\tint main() {\n\t\tstd::cout \u003c\u003c \"All is well\" \u003c\u003c std::endl;\n\t}\n*/\n\n// Pass results to callback function...\nrunWandbox( './code.cpp', clbk );\n\n// Save results to JSON file...\nrunWandbox( './output.json', '/code.cpp', clbk );\n\nfunction clbk( error, results ) {\n\tif ( error ) {\n\t\tthrow new Error( error.message );\n\t}\n\tvar out = results;\n\t/* OUTPUT:\n\t\t{\n\t\t\tprogram_message: 'All is well\\n',\n\t\t\tprogram_output: 'All is well\\n',\n\t\t\tstatus: '0'\n\t\t}\n\t*/\n}\n```\n\nPer Node.js convention, the callback function receives two arguments: `err` and `res`. `err` will be an `error` object in case the GET request is not successful and `null` otherwise,\nin which case `res` will hold the results from running the code on Wandbox. According to the [Wandbox API documentation][wandbox-api-docs], the result `object` might have the following key-value pairs:\n\n*\t__status__: Exit code\n*\t__signal__: Signal message\n*\t__compiler_output__: stdout at compiling\n*\t__compiler_error__:  stderr at compiling\n*\t__compiler_message__: merged messages compiler_output and compiler_error\n*\t__program_output__: stdout at runtime\n*\t__program_error__: stderr at runtime\n*\t__program_message__: merged messages program_output and program_error\n\nIf `save` option is set to true, the result in addition have the following key-value pairs:\n\n*\t__permlink__: permlink you can pass to GET /permlink/:link.\n*\t__url__ URL to display on browser.\n\n#### runWandbox.fromString( [dest,] code[, opts], clbk )\n\nDirectly compile and execute code in a source code `string`.\n\n```javascript\nrunWandbox.fromString( '#include \u003ciostream\u003e\\nint main() {\\n\\tstd::cout \u003c\u003c \"All is well\" \u003c\u003c std::endl;}', clbk );\n\nfunction clbk( error, results ) {\n\tif ( error ) {\n\t\tthrow new Error( error.message );\n\t}\n\tvar out = results;\n}\n```\n\nThe two exported `functions` accept the following `options`:\n*\t__compiler__: name of used compiler. Default: `'gcc-head'`.\n*\t__codes__: additional codes, objects with `file` and `code` keys. Default: `[]`.\n*\t__options__: used options for a compiler joined by comma. Default: `''`.\n*\t__stdin__: standard input. Default: `''`.\n*\t__compiler-option-raw__: additional compile-time options joined by line-break. Default: `''`.\n*\t__runtime-option-raw__: additional run-time options joined by line-break. Default: `''`.\n*\t__save__: boolean indicating whether permanent link should be generated. Default: `false`.\n\nTo specify which compiler to use, set the `compiler` option.\n\n```javascript\nvar code = 'print(\"I can also run Python.\")';\n\nrunWandbox.fromString( code, { 'compiler': 'python-3.5.0' }, function clbk( errror, results ) {\n\tvar out = results;\n\t/*\n\t\t{\n\t\t\tprogram_message: 'I can also run Python.\\n',\n\t\t\tprogram_output: 'I can also run Python.\\n',\n\t\t\tstatus: '0'\n\t\t}\n\t*/\n});\n```\n\nTo specify compile options, supply a comma-separated list to `options`.\n\n```javascript\nvar code = '#include \u003ciostream\u003e\\r\\n int main() { int x = 0; std::cout \u003c\u003c \"hoge\" \u003c\u003c std::endl; }';\n\nrunWandbox.fromString( code, { 'options': 'warning,gnu++1y' }, function clbk( error, results ) {\n\tvar out = res;\n\t/*\n\t\t{ compiler_error: 'prog.cc: In function \\'int main()\\':\\nprog.cc:2:19: warning: unused variable \\'x\\' [-Wunused-variable]\\n  int main() { int x = 0; std::cout \u003c\u003c \"hoge\" \u003c\u003c std::endl; }\\n                   ^\\n',\n\t\t  compiler_message: 'prog.cc: In function \\'int main()\\':\\nprog.cc:2:19: warning: unused variable \\'x\\' [-Wunused-variable]\\n  int main() { int x = 0; std::cout \u003c\u003c \"hoge\" \u003c\u003c std::endl; }\\n                   ^\\n',\n\t\t  program_message: 'hoge\\n',\n\t\t  program_output: 'hoge\\n',\n\t\t  status: '0' }\n\t*/\n});\n```\n\nTo generate a permanent link to the compiled program, set `save` to `true`.\n\n```javascript\nvar code = 'print(\"I can also run Python.\")';\nrunWandbox.fromString( code, {\n\t'compiler': 'python-3.5.0',\n\t'save': true\n}, function clbk( error, results ) {\n\tvar out = results;\n\t/*\n\t\t{\n\t\t\tpermlink: 'hcx4qh0WIkX2YDps',\n\t\t\tprogram_message: 'I can also run Python.\\n',\n\t\t\tprogram_output: 'I can also run Python.\\n',\n\t\t\tstatus: '0',\n\t\t\turl: 'http://melpon.org/wandbox/permlink/hcx4qh0WIkX2YDps'\n\t\t}\n\t*/\n});\n```\n\n---\n## Examples\n\n``` javascript\nvar runWandbox = require( 'wandbox-api' );\n\n// String:\n\nvar code = '#include \u003ciostream\u003e\\nint main() {\\n\\tstd::cout \u003c\u003c \"All is well\" \u003c\u003c std::endl;}';\nrunWandbox.fromString( code, clbk );\n\n// File:\n\n// Pass result to callback function...\nrunWandbox( './examples/fixtures/code.cpp', clbk );\n\n// Save output to file...\nrunWandbox( './examples/fixtures/output.json', './examples/fixtures/code.cpp', clbk );\n\nfunction clbk( error, results ) {\n\tif ( error ) {\n\t\tthrow new Error( error.message );\n\t}\n\tconsole.log( results );\n}\n```\n\nTo run the example code from the top-level application directory,\n\n``` bash\n$ DEBUG=* node ./examples/index.js\n```\n\n\n---\n## CLI\n\n### Installation\n\nTo use the module as a general utility, install the module globally\n\n``` bash\n$ npm install -g wandbox-api\n```\n\n\n### Usage\n\n``` bash\nUsage: runWandbox [options] src\n\nOptions:\n\n  -h,  --help                Print this message.\n  -V,  --version             Print the package version.\n       --file                Boolean indicating whether src is a file path or code to be evaluated. Default: false.\n       --compiler            Name of used compiler. Default: gcc-head.\n       --options             Used options for a compiler joined by comma. Default: boost-1.60,warning,gnu++1y.\n       --codes               Additional codes, objects with `file` and `code` keys. Default: [].\n       --save                Boolean indicating whether permanent link should be generated. Default: false.\n       --stdin               Standard input.\n       --compiler-option-raw Additional compile-time options joined by line-break. Default: \"\".\n       --runtime-option-raw  Additional run-time options joined by line-break. Default: \"\".\n  -o,  --output file          Output file path.\n```\n\n\n### Examples\n\nSetting the compiler using the command-line option:\n\n``` bash\n$ DEBUG=* runWandbox --compiler \u003ccompiler\u003e \u003ccode comes here\u003e\n# =\u003e '[{...},{...},...]'\n```\n\nFor local installations, modify the command to point to the local installation directory; e.g.,\n\n``` bash\n$ DEBUG=* ./node_modules/.bin/runWandbox --file --compiler \u003ccompiler\u003e \u003cfile_path comes here\u003e\n# =\u003e '[{...},{...},...]'\n```\n\nOr, if you have cloned this repository and run `npm install`, modify the command to point to the executable; e.g.,\n\n``` bash\n$ DEBUG=* node ./bin/cli --compiler \u003ccompiler\u003e \u003ccode comes here\u003e\n# =\u003e '[{...},{...},...]'\n```\n\n\n---\n## Tests\n\n### Unit\n\nThis repository uses [tape][tape] for unit tests. To run the tests, execute the following command in the top-level application directory:\n\n``` bash\n$ make test\n```\n\nAll new feature development should have corresponding unit tests to validate correct functionality.\n\n\n### Test Coverage\n\nThis repository uses [Istanbul][istanbul] as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:\n\n``` bash\n$ make test-cov\n```\n\nIstanbul creates a `./reports/coverage` directory. To access an HTML version of the report,\n\n``` bash\n$ make view-cov\n```\n\n\n### Browser Support\n\nThis repository uses [Testling][testling] for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:\n\n``` bash\n$ make test-browsers\n```\n\nTo view the tests in a local web browser,\n\n``` bash\n$ make view-browser-tests\n```\n\n\u003c!-- [![browser support][browsers-image]][browsers-url] --\u003e\n\n\n---\n## License\n\n[MIT license](http://opensource.org/licenses/MIT).\n\n\n## Copyright\n\nCopyright \u0026copy; 2016. Philipp Burckhardt.\n\n\n[npm-image]: http://img.shields.io/npm/v/wandbox-api.svg\n[npm-url]: https://npmjs.org/package/wandbox-api\n\n[build-image]: http://img.shields.io/travis/Planeshifter/node-wandbox-api/master.svg\n[build-url]: https://travis-ci.org/Planeshifter/node-wandbox-api\n\n[coverage-image]: https://img.shields.io/codecov/c/github/Planeshifter/node-wandbox-api/master.svg\n[coverage-url]: https://codecov.io/github/Planeshifter/node-wandbox-api?branch=master\n\n[dependencies-image]: http://img.shields.io/david/Planeshifter/node-wandbox-api.svg\n[dependencies-url]: https://david-dm.org/Planeshifter/node-wandbox-api\n\n[dev-dependencies-image]: http://img.shields.io/david/dev/Planeshifter/node-wandbox-api.svg\n[dev-dependencies-url]: https://david-dm.org/dev/Planeshifter/node-wandbox-api\n\n[github-issues-image]: http://img.shields.io/github/issues/Planeshifter/node-wandbox-api.svg\n[github-issues-url]: https://github.com/Planeshifter/node-wandbox-api/issues\n\n[tape]: https://github.com/substack/tape\n[istanbul]: https://github.com/gotwarlost/istanbul\n[testling]: https://ci.testling.com\n\n[wandbox]: http://melpon.org/wandbox/\n[wandbox-api-docs]: https://github.com/melpon/wandbox/blob/master/kennel2/API.rst\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplaneshifter%2Fnode-wandbox-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplaneshifter%2Fnode-wandbox-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplaneshifter%2Fnode-wandbox-api/lists"}