Modules (original) (raw)

ColaScript supports exits CommonJS modules and have syntax to create them.

With @import command you can import modules:

@import 'sugar' // import all items in current scope @import 'fs' as fs @import dirname from 'path' @import print as echo, prompt as ask, test from 'mylib'

String code = fs.readFileSync(dirname(test) + "/main.cola", "utf8"); echo("hello!");

With @export command you can export and re-export components:

Object hash = {}; Array users = [];

@export hash as _, users @export each as forEach from "underscore" @export "mylib" // re-export all

To associate package names with sources you should create packages.json file. You can generate this file with Dr Package.

{ "underscore": "./components/jashkenas/underscore/1.7.0/underscore.js", "uid": "./components/matthewmueller-uid@0.0.2/index.js", "fmt": "./components/yields-fmt@0.1.0/index.js" }

For browser-cola you can use next code in html:

or