-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Namek edited this page Jun 5, 2016
·
9 revisions
To see a full feature list of The Console itself go to main repo page.
The Console looks like a shell which is a little more special because commands can be scripted using JavaScript. There are 2 ways to provide custom commands:
- single-file scripts
- modules
- alias - for command aliasing, e.g.
alias map google_maps Warsaw
- clear - clears output
- exec - executes file of given path
- repl - enables to switch Read-Eval-Print Loop
The main difference is this:
-
single-file script is evaluated as a whole thing every time a command is invoked
-
module is evaluated once (when loaded) and lives inside JavaScript all the time and can provide multiple commands or other things
currency.js
which stands for currency
command
assertInfo(args.length != 0,
"Usages:\n" +
" - currency 12 gbp eur\n" +
" - currency gbp eur"
)
var amount = args.length == 3 ? args[0] : 1.0
var from = args[args.length == 3 ? 1 : 0]
var to = args[args.length == 3 ? 2 : 1]
var url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=' + from.toUpperCase() + to.toUpperCase() + '=X'
var data = Utils.requestUrl(url)
console.log(data.split(',')[1] * amount)
> Read a blogpost about implementation of currency
command
Same currency
command would be implemented this way:
exports.commands = {
currency: function(args) {
// put here some code as for single-file script
}
}
> Read more about Modules on Wiki
> Read this blogpost about filesystem
module to see a more sophisticated example of module