{"_id":"typescript.api","_rev":"242-38846ca47639f77f8c69d8e2786092ee","name":"typescript.api","dist-tags":{"latest":"0.7.7"},"versions":{"0.2.0":{"name":"typescript.api","version":"0.2.0","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"license":"Apache License, Version 2.0","_id":"typescript.api@0.2.0","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"dist":{"shasum":"bf6de7c224fb8f79449f6bd9eacd49c264500b45","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.2.0.tgz","integrity":"sha512-HM3NuIAQkGypn+1JqsxWAhmeKJ2DR/EmnJnUN6sZcg12LW98HyVsiIFcnrIXWOO7pUJmgVtqL8vP0YOxdGheaQ==","signatures":[{"sig":"MEUCIBodQDjkYDJ5QxMJTVdrfJ7d4hT5xEVdQ0lHJ84ztuHmAiEAoXs1difJ0QFRUpU055sptU46U3QH59Sj4JPX8Fv8e/4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9 alpha\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(units) {\r\n\t\r\n\tif(!typescript.check(units)) {\r\n\t\r\n\t\tshow_diagnostics(units);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(units, function(compilation) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compilation)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compilation);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compilation, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(units) { \r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tconsole.log( units[n].path );\r\n\t\t\r\n\t\tconsole.log( units[n].content );\r\n\t\t\r\n\t\tfor(var m in units[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(units) { \r\n\r\n\tif(typescript.check (units)) {\r\n\t\t\r\n\t\ttypescript.compile(units, function(compilation) {\r\n\t\t\r\n\t\t\tif( typescript.check (compilation) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compilation, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar unit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([unit], function(compilation) {\r\n\r\n\ttypescript.run(compilation, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar unit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([unit], function(compilation) {\r\n\r\n\tfor(var n in compilation){\r\n\t\r\n\t\tconsole.log(compilation[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(units){\r\n\r\n\ttypescript.compile(units, function(compilation) {\r\n\t\t\r\n\t\ttypescript.reflect(compilation, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar unit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([unit], function(compilation) {\r\n\r\n\ttypescript.run(compilation, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.1.65","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.2.1":{"name":"typescript.api","version":"0.2.1","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"license":"Apache License, Version 2.0","_id":"typescript.api@0.2.1","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"dist":{"shasum":"b03f37a2e877e40864a0d7d008cfa78dad2e6a5a","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.2.1.tgz","integrity":"sha512-QpP4HElnGQMuyGfmfJ0pYTNZqPu0GyXtG+DzGGUCv41Uq/0MnHV4gKun2OE8rPTm5c2M46GvrkjX1q768cW8aA==","signatures":[{"sig":"MEUCIQDJWiFLw3EbtdFgBDcjpRI2HDYvk4o70HG7ScB3IMPBaAIgMtgI4qMwHdfE/QqZUk7v3Mir8mDzYjIz+KCP10vUA8A=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9 alpha\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\t\r\n\t\tconsole.log( resolved[n].path );\r\n\t\t\r\n\t\tconsole.log( resolved[n].content );\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(resolved){\r\n\r\n\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\ttypescript.reflect(compiled, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.1.65","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.2.2":{"name":"typescript.api","version":"0.2.2","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"license":"Apache License, Version 2.0","_id":"typescript.api@0.2.2","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"f73898ac68cf158174d6c3cbdb6cd31cb318fd6f","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.2.2.tgz","integrity":"sha512-1+kSRQpXliOq2aYsRP0RipYbkhs6OQOpGYB/L8znAJVRRkGcA46PwYxlAOCd0fhsM5W6V5eRi75JNDGrZyPIVw==","signatures":[{"sig":"MEYCIQC0F6ey57mK2cBMlG/AAV0p0j8M5DFkG4QkVq8ROWg9+wIhAJVJsFs2SOBV+OXHActyd58+WAUoH58U4Qp/qdx1Ww26","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9 alpha\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\t\r\n\t\tconsole.log( resolved[n].path );\r\n\t\t\r\n\t\tconsole.log( resolved[n].content );\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(resolved){\r\n\r\n\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\ttypescript.reflect(compiled, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.2.3":{"name":"typescript.api","version":"0.2.3","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"license":"Apache License, Version 2.0","_id":"typescript.api@0.2.3","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"ddabbd883a673a9db7101e33a9a2f4338dc613f9","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.2.3.tgz","integrity":"sha512-FFDwqUiextiY8F3yKq+8Jp4suuCQHFZn5vR2NsNbcjEulG/00X3cM3iGPlMzJKtsUd2N//NAJV32kpe4Py9SeQ==","signatures":[{"sig":"MEUCIA9cu/MeExIu6KTZN4yPIMH+lG2oYZM1juynf/0C07ERAiEAnis2qgaOEP1BlOxZUkfmgJ897VDiuBkf+dJq/0a0kt8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9 alpha\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\t\r\n\t\tconsole.log( resolved[n].path );\r\n\t\t\r\n\t\tconsole.log( resolved[n].content );\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(resolved){\r\n\r\n\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\ttypescript.reflect(compiled, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.2.4":{"name":"typescript.api","version":"0.2.4","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"license":"Apache License, Version 2.0","_id":"typescript.api@0.2.4","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"6e967724527bd07e64f3a1ab7c7201f53a9b196a","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.2.4.tgz","integrity":"sha512-qOks7fPVpJExnECoT1GLsq6Ju/CmjOf+jHC1XTT/V2oD0bzoipZepw+pZKYmoTAR7u2OA35T9Kx2Mi7JwSzgdA==","signatures":[{"sig":"MEQCIBlxaTRuMxbts75tkMwmE1ti9M+tzCwk3RhEpflEtetCAiBaLwoCwDlmrrSy78I9NOBTWMgFZgeTQDd3wfOMfyEv6A==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9 alpha\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\t\r\n\t\tconsole.log( resolved[n].path );\r\n\t\t\r\n\t\tconsole.log( resolved[n].content );\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(resolved){\r\n\r\n\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\ttypescript.reflect(compiled, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.2.5":{"name":"typescript.api","version":"0.2.5","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"license":"Apache License, Version 2.0","_id":"typescript.api@0.2.5","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"e26857219a9ab7e710243386f306f1ff84eed2d3","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.2.5.tgz","integrity":"sha512-7BCvHtFu8ipLSlyuoeSBmSIPPt+icY3SP91eJOXLH7TA2+hZXZlnruIJgUfVkJNb7kOe8/rnf6H1+0svAu6CxA==","signatures":[{"sig":"MEYCIQCoN0DIFDUOu/bm20d4PJBcWm4wn5q11xCUDYcKsnMhbQIhAL3il2BRPyQxkb0F4SjPY7Hewe6OW/Hn5hu9HIh81+I4","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9 alpha\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\t\r\n\t\tconsole.log( resolved[n].path );\r\n\t\t\r\n\t\tconsole.log( resolved[n].content );\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(resolved){\r\n\r\n\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\ttypescript.reflect(compiled, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.2.6":{"name":"typescript.api","version":"0.2.6","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"license":"Apache License, Version 2.0","_id":"typescript.api@0.2.6","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"40ddf9a01fa498bcf0c0428cfe0b9629d28123bd","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.2.6.tgz","integrity":"sha512-rJw5kETyKKhjr1N5wV3DcbNSCg6+KyZXzlFBrpSiktyu90HaSs7CTX5Ir42c+IAi6f1DBT30aBtn+u7GqZUT9A==","signatures":[{"sig":"MEUCIC85dXPPFMj/1cFDeOnJh1i8U1tJH/vjz7emXAfLay2HAiEAhC+FTGr2aM/fdPxXH/bmmNQLC21cChbq+QEzAjYQxE8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9 alpha\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\t\r\n\t\tconsole.log( resolved[n].path );\r\n\t\t\r\n\t\tconsole.log( resolved[n].content );\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(resolved){\r\n\r\n\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\ttypescript.reflect(compiled, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.3.0":{"name":"typescript.api","version":"0.3.0","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"license":"Apache License, Version 2.0","_id":"typescript.api@0.3.0","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"7a8af38b5cf534797689379e25ab6ccdf7dbf076","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.3.0.tgz","integrity":"sha512-RbGZiTMOVOhbzJ9grkocJ/apqPnBOogF9GPubAsp9AZT8x8EONjd5/fYk+vfwg02PQH4K+ZfvhCkNdjh0dS/HA==","signatures":[{"sig":"MEQCIHOLCc25ngaIb2wqEW08bQiHuTNFol1I1HgA773gyWFPAiAC9o3C5Hvxl1joNZ4glTqja/HeO7wL6FEWVbrUeWTTHg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9 - (6/6/2013)\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\t\r\n\t\tconsole.log( resolved[n].path );\r\n\t\t\r\n\t\tconsole.log( resolved[n].content );\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(resolved){\r\n\r\n\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\ttypescript.reflect(compiled, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.3.1":{"name":"typescript.api","version":"0.3.1","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"license":"Apache License, Version 2.0","_id":"typescript.api@0.3.1","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"703c4f927984bfa014e06660f964945fb07a7017","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.3.1.tgz","integrity":"sha512-8kboaGzgfiISKnOGntj4ouY65SnugEh6ihELTF5Hxtv0HxfERoGiK1aGzGIP7+OMYP+/AIUFiCKJjqP8UX/zdQ==","signatures":[{"sig":"MEYCIQDxv4ZagdnKoCxI8y2nj/sb0ms8/zeRuVHLL/PASufPfQIhAPyhxuqRahvzZGHsBVTwD/A1vqVyuP7FX1hC/Lbfox1N","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9 beta 6-6-2013\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\t\r\n\t\tconsole.log( resolved[n].path );\r\n\t\t\r\n\t\tconsole.log( resolved[n].content );\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(resolved){\r\n\r\n\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\ttypescript.reflect(compiled, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.3.2":{"name":"typescript.api","version":"0.3.2","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"_id":"typescript.api@0.3.2","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"7d685ac9c38f9bf7929e26a847cfd377bf7d2952","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.3.2.tgz","integrity":"sha512-DMXwmhzrfdoXSBRWvfnIGr6rf+ITZmnq6vulz2zcfjaUgKfDssBrtC9EAxI3hC1DOJm83bE15h4a57crvrLvUA==","signatures":[{"sig":"MEUCIFxWSflcU8jcFm4etIdnarI70787FHUrhcYwPCkfFb/AAiEAoMd0HDpg1FlXegG5c7MY4f9xTJ+nxQ/iBY/xJJ+dtyM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9 beta 6-6-2013\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\t\r\n\t\tconsole.log( resolved[n].path );\r\n\t\t\r\n\t\tconsole.log( resolved[n].content );\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(resolved){\r\n\r\n\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\ttypescript.reflect(compiled, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.build ( sources, callback )\r\n\r\nBuilds the supplied source files. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build(['program.ts'], function(errors, output) {\r\n\t\r\n\tif(errors) {\r\n\t\t// iterate each error.\r\n\t}\r\n\telse {\r\n\t\tconsole.log(output);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.3.3":{"name":"typescript.api","version":"0.3.3","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"_id":"typescript.api@0.3.3","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"75bd75278ef881c40c3eca1bd9412cbf1641d700","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.3.3.tgz","integrity":"sha512-G2ViOv3RU5BA4JJ3ptu1A+feirOgw9eSAyiv49dIaj+QmSlKvbzHzCizESttXhd5sZ4b6eRcVd3jd8iitV9z5A==","signatures":[{"sig":"MEUCIAxRBvgIliZnBREmN3w4DdqUoc8PVIG2D5dMFySKUt0zAiEA2B1/WO8DOyqgb5Ff7l6tFt7QihsBXS432TQV5oLvo/o=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9 beta 6-6-2013\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\t\r\n\t\tconsole.log( resolved[n].path );\r\n\t\t\r\n\t\tconsole.log( resolved[n].content );\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(resolved){\r\n\r\n\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\ttypescript.reflect(compiled, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.3.4":{"name":"typescript.api","version":"0.3.4","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"_id":"typescript.api@0.3.4","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"7602a0160e8e21d6991ab1e14a2c46207e90617d","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.3.4.tgz","integrity":"sha512-/dp//FVmAT+9JIjH88PGLQZc8Tm6WLb/yC4JcA6QRe3g52E4a0XJQcgbaHaFf/qUy6i2RX4rAYXhTOOv7PDoWw==","signatures":[{"sig":"MEYCIQCoxMUPXSZJy6zRSqNASGzXctPsSIaULrNjG+Q+kn5cvQIhAKzKGF5pH8FqTnILV2bZXk/BgRc71XZx2Wmvr0BPzizg","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9 beta 6-6-2013\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\t\r\n\t\tconsole.log( resolved[n].path );\r\n\t\t\r\n\t\tconsole.log( resolved[n].content );\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(resolved){\r\n\r\n\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\ttypescript.reflect(compiled, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.4.0":{"name":"typescript.api","version":"0.4.0","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"_id":"typescript.api@0.4.0","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"9332d0c34b16081ba916d606705030d305b41784","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.4.0.tgz","integrity":"sha512-9kMced5u/KnBeUPjJ9zNRvWDiEHJwjTjejLPbaZLPvQgR1boP7HZSXvL1B2gTNowG2dLWtNbzGh2GsspSvNqWQ==","signatures":[{"sig":"MEQCIH1P7J5L9KfPc502yehe5I+h4LyQu/guDxv+Ld4eJp0WAiBRmM1mSuhD+MQsahnIfB1HwW64/dKbl0oKTewivZP1NQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\t\r\n\t\tconsole.log( resolved[n].path );\r\n\t\t\r\n\t\tconsole.log( resolved[n].content );\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(resolved){\r\n\r\n\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\ttypescript.reflect(compiled, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.4.1":{"name":"typescript.api","version":"0.4.1","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"_id":"typescript.api@0.4.1","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"fde4afc10f541cfbc89916ccf1d65ac4ff93ce6e","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.4.1.tgz","integrity":"sha512-arpZrU9NichkstWL7qQMjIT4Ph9qUEJBGuXt8je3uwb7ijOh+yB0hPDZDgttjrPWU48lUYlXYL3dBliJRYsVHQ==","signatures":[{"sig":"MEUCIGwq2Zohpnla5pUmo/OZoz34zeThbssAQRNEg+k2LXxqAiEA3nruCdn6PXqYQ+uGrrwE1duaqpTdVww3sbPnehxBY3Y=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n## reference\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.4.2":{"name":"typescript.api","version":"0.4.2","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"_id":"typescript.api@0.4.2","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"3b967689c85c797f703874e531cfb204d4d1a80f","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.4.2.tgz","integrity":"sha512-fVN6i2bfpJAJD75pEy+IS8F2/NSAKHsaSXL3vf1WzjQAy2An8whnrv7LGZyLEpRHdvSDFMoV7GfZBEgd/c2dLg==","signatures":[{"sig":"MEYCIQC4MyMGjLbGu3UwgZ7N8U6g6+vCTFL/+T793Jaf84eVagIhAId2IRc85VjCS7g8wSGSE4KTULVX1w0+nXIKnUC98nL+","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n## reference\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.4.3":{"name":"typescript.api","version":"0.4.3","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"_id":"typescript.api@0.4.3","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"c600dd97ebf570cfa70dae4e2d2e2d235656c732","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.4.3.tgz","integrity":"sha512-zz63YdQPQEdw9izp/PH7JwrtW1N6oWpY7yZ7ock7CWGggyVSNY8SmRYfwISuLhlh3HXZpYwp0FyQlh65+LuDVw==","signatures":[{"sig":"MEUCIQD3RnyFHNTU8gx4P6aHbjo7DFTqQ7IyPkEUgrMji1kK7gIgcGnfxN+g2mGh0BhKnxUo3xfO9em411n2lDgca2OtBow=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n## reference\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.4.4":{"name":"typescript.api","version":"0.4.4","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"_id":"typescript.api@0.4.4","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"12f641f67901a785ab0f9ef33eb461c0bf7ec2aa","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.4.4.tgz","integrity":"sha512-ShH099BTCvRJGiOPlb9bdH+ZdgbBjt0ou5OlDlLiLg1k5hEz6sHfgAV39MXw0SgbsLMdExQkMM0/IqJTiNyR0A==","signatures":[{"sig":"MEUCIE1Qp/72BoWnNPvMiLh4VLyGH0QTmZKyZyt/bNZCrySoAiEAi2/uBXy0A2TwUkmEcTsQCzQ5jSf61iYOkQl62ML9MYA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor other additional declarations, see https://github.com/borisyankov/DefinitelyTyped.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : Function  // (public) returns an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tdeclaration   : string,   // (public) The declaration source for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.4.5":{"name":"typescript.api","version":"0.4.5","keywords":["typescript","compiler","require"],"author":{"name":"sinclair"},"_id":"typescript.api@0.4.5","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"4ef458a015bf4ab074f07ab09cae07181c556149","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.4.5.tgz","integrity":"sha512-v0lFqg2QACs2HKQYqIyUtZPen2rJ/OyKZ24dIIIZNyoWdi8qdArGOf4Eg6aFuy5oMOyg/tTscYCl8NcbO+2qVg==","signatures":[{"sig":"MEYCIQDpMcuMCJYnCLrhvJVjDdATHXgvCcA4+vd8rMZ9BlUpNgIhAMdjNjq0nIKSwcsrEdqQ4785ULxXfPtrlatpMC5XpIyo","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : Function  // (public) returns an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tdeclaration   : string,   // (public) The declaration source for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.4.6":{"name":"typescript.api","version":"0.4.6","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.4.6","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"0d0da2de9f079a136dc8879e9b79448e4ee123ef","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.4.6.tgz","integrity":"sha512-VI/pWslnGkIZBbN96vtwuZJbtlB5A6KO3j7dmCSmgED5PvJgyTnB3yhUy5LhId34LIkhlV4rvKHTQtuEQZtkDQ==","signatures":[{"sig":"MEQCIAYDJ8VQaRzKHxGK8vYtt7ILz3xwQCZlhT8AszWayxxPAiBpUA+aiBgJ0zvoKN3e7xEuCyufSYQif9qhaCJbMU3rAg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : Function  // (public) returns an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tdeclaration   : string,   // (public) The declaration source for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.4.7":{"name":"typescript.api","version":"0.4.7","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.4.7","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"356f4c9a825e163b24311a9dd437906bf9e7280d","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.4.7.tgz","integrity":"sha512-/mfdz7fbkFtRq0JNYasyJIj8IpeIr3YY7P7Op4rJzJ4xL5Da0QPjiTJnbHkQw61hiDgDjbF6VtcVl6+jrmLwLg==","signatures":[{"sig":"MEYCIQDKR4qewlhVDLq/r+XUqVktr+UUJTM4U+zxtcZqrv4z5QIhAP6BKkGKAXro7EFmID6Pi7m9XcNOg/vN+N0L3fa5kzT9","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : Function  // (public) returns an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tdeclaration   : string,   // (public) The declaration source for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.5.0":{"name":"typescript.api","version":"0.5.0","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.5.0","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"d7208122e186c5a90f30cd8ff97cea3174969608","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.5.0.tgz","integrity":"sha512-ztwxemihyeuPN0En0g57d+IqAQuSXNAgcDBMfVeRxnB8/v7KGat+t4qDXDAeD4B6xryQrgXaW3YopKX117YKJA==","signatures":[{"sig":"MEQCIA1B9PxT3/9HLrRNDJH7//gEES563+rPJo563pnfPJBYAiBoIzkXjqw23wcVBU0OjbAZcOpzQAdK+Va/u823QOuftw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : Function  // (public) returns an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tdeclaration   : string,   // (public) The declaration source for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.5.1":{"name":"typescript.api","version":"0.5.1","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.5.1","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"747adfb098b6a064d2b7cd47825978bf7de48d6d","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.5.1.tgz","integrity":"sha512-psF6Kz91wFTi8Vngjb9yy/QSQUDJfLb+loXQtfYUzH9MesVu6AUqi4B0PDNfJQNdxYsMrHU6yeHOH70UQrH+XA==","signatures":[{"sig":"MEUCIQCHAiJgdCDQ1d/Hgk769cs5Gj01xzyl216rihsW39J06gIgBeLg/NPj0PuXzXzKxDhCcM9AW6FQtXTYww7nH33mQUk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : Function  // (public) returns an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tdeclaration   : string,   // (public) The declaration source for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.5.2":{"name":"typescript.api","version":"0.5.2","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.5.2","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"8db0d8b90165456ee670443e70658c97c1299d53","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.5.2.tgz","integrity":"sha512-+Rqfy43ceFRmjZHnPm+fSwoMXHn9dfCu3gw8/IWwikYphRIkEl4OIcv3J0btUOec0XWqp4u2qJxWsyNX5nUhVg==","signatures":[{"sig":"MEQCIG7k3DPHnjnC0j7GuWa+Gm+aJzO6KJTxePUj9kK2WmlNAiByy2rIi4A78pnFM2lXbD/irVPntHgi0hgqmZPMwnQ1Nw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : Function  // (public) returns an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tdeclaration   : string,   // (public) The declaration source for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.5.3":{"name":"typescript.api","version":"0.5.3","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.5.3","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"21150fef168f443647b94c92809c92767b2d2492","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.5.3.tgz","integrity":"sha512-Wx8v7p/yhdiwfvcwuJryCbNPGDELbO8m4BchOqjQaWaRaTokvK71Bod52UKOrlX0UNTMzowjA2q3Fi2mxr7E5A==","signatures":[{"sig":"MEUCIFUNa1OIs6x9fk/xsjOxZhkMCfh2frHR2PmRM+aWqL7xAiEA3yYXHBpssk+aZrSM2tU8KiBWv9BSz7vAxakuqP/uJqo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : Function  // (public) returns an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tdeclaration   : string,   // (public) The declaration source for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{"typescript":"0.9.0-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.5.4":{"name":"typescript.api","version":"0.5.4","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.5.4","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"53362388db9c203f864711b5cd253372bdbbd58e","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.5.4.tgz","integrity":"sha512-roziWhkO4QcYg4EOwLTKYJRH+CSL1hVN1y1xiv0oqADJA6dGyMZo5HpHL4Rsuz2UqiOKbJMUynR2pLTEwmzsRw==","signatures":[{"sig":"MEUCIAxGo12asi9UYODjDh27OheXqp2S/te7rMWDZ9gooRVvAiEA1EoK4qm2YsVUG3B9jekV1Fnhk8zIIb5f/+9TTg9f/Ko=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.0-1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : Function  // (public) returns an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tdeclaration   : string,   // (public) The declaration source for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{"typescript":"0.9.0-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.5.5":{"name":"typescript.api","version":"0.5.5","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.5.5","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"0d2dbc37d567fc13b6839c1504a3039d28e6cde5","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.5.5.tgz","integrity":"sha512-XRA+wWBLxMa+5VIz+mFUC8F+FHDjabp6CS2mOjSYD8W6Y9xwZUTGA8cnhpf2zmF+QWjkYGcnPXZkxBMXMeT0zQ==","signatures":[{"sig":"MEUCIFdu3a12FFzY6A/7nJFVxLnr+kv6f2gZ1GIDp/V32NRxAiEAk2WHvXFRoaCemUchKrkvQX78Xh/urWQS6CIHSxFasCk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.0-1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{"typescript":"0.9.0-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.5.6":{"name":"typescript.api","version":"0.5.6","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.5.6","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"265e4ca7b39c709b6c8a33f3f7945fd7a1359a97","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.5.6.tgz","integrity":"sha512-WSg8KhTjVXxweaIEbnNMitTGo020LLZGj8xKsKsejtzlFzBw+VOz7H3Kmbtlhd58lUwKnrhY5+5Z5cC8gYt7vg==","signatures":[{"sig":"MEYCIQCrS8HQbZsgj+9sYomuh9gbtcS4qsj+hLXtW65FGUfUMAIhAIm/cB3fMi6kXf4gWfjQcIhwT9KB7r/pkoA1dxO7SEaX","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.0-1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{"typescript":"0.9.0-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.5.7":{"name":"typescript.api","version":"0.5.7","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.5.7","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"fc8d1363db99444d8b19c55bce8f251424e50e3f","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.5.7.tgz","integrity":"sha512-qEXum2wCLraJoGvk////uUOxT9RxqDlnkl/XlP6WeEyJr4HHfVfN4eFaQr7C5L2WnNnZ+P5Vm+eWXYz+foOxPA==","signatures":[{"sig":"MEUCIQCTALDdMV+V8ynTqJvhTiFDURjgoY6Fuy/B748maDLOlwIgPZlKUNY5ayG5hz+9QhRLHE/UByapS7VVijEaQzjNrVw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.0-1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{"typescript":"0.9.0-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.5.8":{"name":"typescript.api","version":"0.5.8","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.5.8","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"58a45f302e5edc073e24dc10f650d3c2ebe4d19d","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.5.8.tgz","integrity":"sha512-GHy5D6QdIrBML0oeOF6S3dqnEAja9bA68J5fFATrKH5TXeqeDUcTOrrl7687/T0EpjdWnXc68nyWbGHENbNJWA==","signatures":[{"sig":"MEUCIAe2ciFMb8WlWfWx/KOZodbhavcSPr/TlMeAfrNRGuOYAiEAhpiFyGvGD0PEiv4TtuVIW5Hr7ic4JVs3erIi2S3ROhs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.0-1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{"typescript":"0.9.0-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.5.9":{"name":"typescript.api","version":"0.5.9","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.5.9","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"a6825795121ff0aa904c497b2db1c627d19e9c46","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.5.9.tgz","integrity":"sha512-GT5v3irLw7vQOaHzU461dYy+vF0KPIRUtxtH2g3u3dGU9EJDfBnqNi1Y/J9V/kfkHYU5jBUIBZgiFX6YuEI2tA==","signatures":[{"sig":"MEYCIQD/wrr1rDkl9/cMHPpPL/wV+pfq0zRlKrBX5AsWjdgvgQIhAPbQLQ8Qfm6gHDzkWramOtJ4gCUAhjvobEyiqaPwt2bi","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.0-1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [build](#build)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\tpath          : string,   // (public) the path of this unit.\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\tast           : object,   // (public) AST for this unit.\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element. The result will be an \r\nordered (in order of dependancy) array of source units. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nUtility method to check if a source or compiled unit has errors.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif(typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n<a name=\"build\" />\r\n### typescript.build ( sources, callback )\r\n\r\nA quick means of building a typescript source file(s) and producing the compiled\r\nsource code as a string. \r\n\r\n__arguments__\r\n\r\n* sources  - an array of input source filenames.\r\n* callback - a callback containing errors and the compiled source code and declaration.\r\n\r\n__example__\r\n\r\nThe following will build the source file 'program.ts' and write the compiled\r\ncode and declaration output to the console.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.build_source(['program.ts'], function(errors, sourcecode, declaration) {\r\n\t\r\n\tif(errors) {\r\n\r\n\t\tfor(var n in errors) {\r\n\r\n\t\t\tconsole.log( errors[n].toString() );\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\tconsole.log(declaration);\r\n\t\t\r\n\t\tconsole.log(sourcecode);\r\n\t    \r\n\t}\r\n});\r\n```\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units.\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler. \r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{"typescript":"0.9.0-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.6.0":{"name":"typescript.api","version":"0.6.0","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.6.0","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"693d27ffd1a3a6ed70b4b412e27a3f3b08aa04ff","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.6.0.tgz","integrity":"sha512-/XEN0cBmU1MDV1QIq/q5cGnBqc3KIrCfnmMU2AIQN/Tsnh+Qt5/VQtMSA9EZvHmoGuixaD9SBZifBcP5rFzEBQ==","signatures":[{"sig":"MEUCIANox3wejjlWmmUUcZQUVLDXKrYdRJDW+oTgfwJq7wwIAiEA9rojzeUZ3xpB6nbIB/jLmQNksV2yf2hjv5cyxfOQILs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.0-1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [register](#register)\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this unit.\r\n\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\r\n\tast           : object,   // (public) AST for this unit.\r\n\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n\r\n<a name=\"register\" />\r\n### typescript.register ()\r\n\r\nThe register() method will register the typescript file extension with nodejs require(). When using this \r\nmethod, the api will automatically JIT compile your typescript source code on first request and cache \r\nfor subsequent requests. \r\n\r\n```javascript\r\n\r\n//---------------------------------\r\n// program.ts\r\n//---------------------------------\r\n\r\nexport var message:string = 'hello world';\r\n\r\n//---------------------------------\r\n// app.js\r\n//---------------------------------\r\n\r\nrequire('typescript.api').register();\r\n\r\nvar program = require('./program.ts');\r\n\r\nconsole.log(program.message); // hello world\r\n```\r\n\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nThe typescript.api resolve function will resolve source units needed for compilation and return them\r\nin order of dependancy, it does this by scanning each files reference element. \r\n\r\nspecial note: the resolve method will be unable to resolve source units if your code contains circular \r\nreferences. for example, if file0.ts references file1.ts, and file1.ts references file0.ts, then this would\r\nbe considered a circular reference. in these instances, the resolve() method will return the source units \r\nfound in order of discovery, and no additional dependency resolution will occur. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nA utility method to check for errors in either resolved or compiled units.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif( typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\ncompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nexecutes compiled units within a nodejs vm and returns a context containing exported members.\r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units - (obtained from a call to compile)\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{"typescript":"0.9.0-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.6.1":{"name":"typescript.api","version":"0.6.1","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.6.1","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"abe3775e11e85e936f108c498f1e0a5caa88ab05","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.6.1.tgz","integrity":"sha512-+3ilYNBnnYxIIt+XEgBIWJUZLg25Irm4C8nHNdIKVbwxAtrBSojysYiivleBkbzCre86K0MUu4fRrDTWyNEkkA==","signatures":[{"sig":"MEUCIGCUMnHK3UPojXZ8ajcFYKaX1ojbiJg5TSURzegs3bDGAiEA5rtc8Yn3wwIVuNTHn7MMD+5kNRBTXRpVPPva4nXaI3I=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.0-1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [compiler options](#options)\r\n* [declarations](#declarations)\r\n\r\n### objects\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [register](#register)\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(resolved) {\r\n\t\r\n\tif(!typescript.check(resolved)) {\r\n\t\r\n\t\tshow_diagnostics(resolved);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compiled)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"options\" />\r\n### compiler options\r\n\r\nThe following are options available on the typescript compiler.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// enables remote resolution of source files over http. false by default.\r\ntypescript.allowRemote     = false;         \r\n\r\n// the javascript language version to target. EcmaScript3 | EcmaScript5\r\ntypescript.languageVersion = \"EcmaScript5\"; \r\n\r\n// CommonJS or AMD module profiles, Synchronous | Asynchronous. Synchronous is the default.\r\ntypescript.moduleTarget    = \"Synchronous\"; \r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --nolib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resx/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## objects\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this unit.\r\n\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\r\n\tast           : object,   // (public) AST for this unit.\r\n\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n\r\n<a name=\"register\" />\r\n### typescript.register ()\r\n\r\nThe register() method will register the typescript file extension with nodejs require(). When using this \r\nmethod, the api will automatically JIT compile your typescript source code on first request and cache \r\nfor subsequent requests. \r\n\r\n```javascript\r\n\r\n//---------------------------------\r\n// program.ts\r\n//---------------------------------\r\n\r\nexport var message:string = 'hello world';\r\n\r\n//---------------------------------\r\n// app.js\r\n//---------------------------------\r\n\r\nrequire('typescript.api').register();\r\n\r\nvar program = require('./program.ts');\r\n\r\nconsole.log(program.message); // hello world\r\n```\r\n\r\n\r\n<a name=\"resolve\" />\r\n### typescript.resolve (sources, callback)\r\n\r\nThe typescript.api resolve function will resolve source units needed for compilation and return them\r\nin order of dependancy, it does this by scanning each files reference element. \r\n\r\nspecial note: the resolve method will be unable to resolve source units if your code contains circular \r\nreferences. for example, if file0.ts references file1.ts, and file1.ts references file0.ts, then this would\r\nbe considered a circular reference. in these instances, the resolve() method will return the source units \r\nfound in order of discovery, and no additional dependency resolution will occur. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### typescript.check (units)\r\n\r\nA utility method to check for errors in either resolved or compiled units.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif( typescript.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttypescript.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( typescript.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"create\" />\r\n### typescript.create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n<a name=\"compile\" />\r\n### typescript.compile ( units, callback )\r\n\r\ncompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"run\" />\r\n### typescript.run ( compiledUnits, sandbox, callback )\r\n\r\nexecutes compiled units within a nodejs vm and returns a context containing exported members.\r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units - (obtained from a call to compile)\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([sourceUnit], function(compiled) {\r\n\r\n\ttypescript.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value); // outputs 123\r\n\t\t\r\n\t});\r\n});\r\n```\r\n<a name=\"reset\" />\r\n### typescript.reset ()\r\n\r\nResets the compiler.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\ntypescript.reset();\r\n```\r\n\r\n<a name=\"sort\" />\r\n### typescript.sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar units = [\r\n    typescript.create(\"a.ts\", \"\"),\r\n\r\n    typescript.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    \r\n    typescript.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    \r\n    typescript.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    \r\n    typescript.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = typescript.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.","directories":{},"dependencies":{"typescript":"0.9.0-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.7.0":{"name":"typescript.api","version":"0.7.0","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.7.0","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"6f5ba5153547c459fe5220fedffdc37237289795","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.7.0.tgz","integrity":"sha512-XKKKDmwNiTGaUEb7l7Oy5h2DX6uytBG6vxPXyQgKWuNv5YyfIh7MCjXWqPiCccpfRWd4dtER5WNNpFR7Nm5Lmg==","signatures":[{"sig":"MEUCIQDSzISS1DfxZfEGjoljaco0i5ofw0tz8GdOVU0mf5RszgIgaptwXC/dDtfEuU1t2Vw4K3EGiLOgbh1Imk2HlEarVSc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [declarations](#declarations)\r\n\r\n### units\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [register](#register)\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [run](#run)\r\n* [reset](#reset)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntsapi.resolve(['./program.ts'], function(resolved) {\r\n\r\n\tif(!tsapi.check(resolved)) {\r\n\r\n\t\tshow_diagnostics(resolved);\r\n\r\n\t}\r\n\telse {\r\n\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\r\n\t\t\tif(!tsapi.check(compiled)) {\r\n\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --noLib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resources/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## units\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this unit.\r\n\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\r\n\tast           : object,   // (public) AST for this unit.\r\n\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n\r\n<a name=\"register\" />\r\n### typescript.register ()\r\n\r\nThe register() method will register the typescript file extension with nodejs require(). When using this \r\nmethod, the api will automatically JIT compile your typescript source code on first request and cache \r\nfor subsequent requests. \r\n\r\n```javascript\r\n\r\n//---------------------------------\r\n// program.ts\r\n//---------------------------------\r\n\r\nexport var message:string = 'hello world';\r\n\r\n//---------------------------------\r\n// app.js\r\n//---------------------------------\r\n\r\nrequire('typescript.api').register();\r\n\r\nvar program = require('./program.ts');\r\n\r\nconsole.log(program.message); // hello world\r\n```\r\n\r\n\r\n<a name=\"resolve\" />\r\n### resolve (sources, callback)\r\n\r\nThe typescript.api resolve function will resolve source units needed for compilation and return them\r\nin order of dependancy, it does this by scanning each files reference element. \r\n\r\nspecial note: the resolve method will be unable to resolve source units if your code contains circular \r\nreferences. for example, if file0.ts references file1.ts, and file1.ts references file0.ts, then this would\r\nbe considered a circular reference. in these instances, the resolve() method will return the source units \r\nfound in order of discovery, and no additional dependency resolution will occur. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### check (units)\r\n\r\nA utility method to check for errors in either resolved or compiled units.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif( tsapi.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( tsapi.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"create\" />\r\n### create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t})\r\n})\r\n\r\n```\r\n\r\n<a name=\"compile\" />\r\n### compile ( units, callback )\r\n\r\ncompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"run\" />\r\n### run ( compiledUnits, sandbox, callback )\r\n\r\nexecutes compiled units within a nodejs vm and returns a context containing exported members.\r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units - (obtained from a call to compile)\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var value:number = 123\")\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value) // outputs 123\r\n\r\n\t})\r\n})\r\n```\r\n<a name=\"reset\" />\r\n### reset (options)\r\n\r\nResets the compiler.  \r\n\r\n```javascript\t\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset()\r\n```\r\n\r\nAdditionally, It is possible to specify reset with the following options.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset({\r\n\r\n    languageVersion : \"EcmaScript5\", // EcmaScript5 | EcmaScript3\r\n\r\n    moduleGenTarget : \"Synchronous\", // Synchronous | ASynchronous\r\n\r\n    removeComments  : true\r\n})\r\n\r\n```\r\n\r\n<a name=\"sort\" />\r\n### sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\nvar units = [\r\n    tsapi.create(\"a.ts\", \"\"),\r\n    tsapi.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    tsapi.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    tsapi.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = tsapi.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.","directories":{},"dependencies":{"typescript":"0.9.1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.7.1":{"name":"typescript.api","version":"0.7.1","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.7.1","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"e412ada96bd0aaabcf8f204b9a1e9de34f4a4ca4","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.7.1.tgz","integrity":"sha512-1DtyrH4hcRWxERtw/F7UX6Th/8fKf5NxVUg3ggSDcOziAqhvivO3WDkKgWK7FaF2ImYJmooT0D8eTvtHL7voVw==","signatures":[{"sig":"MEQCIErj783l3VPg0y+6/9YLYGTnx3jW/kIh0/VTAroMzAF5AiB3m4hyCVjncpPLlroMKZGPjt3Reit6g9Kg9uNdR76kpw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [declarations](#declarations)\r\n\r\n### units\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [reset](#reset)\r\n* [register](#register)\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [run](#run)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntsapi.resolve(['./program.ts'], function(resolved) {\r\n\r\n\tif(!tsapi.check(resolved)) {\r\n\r\n\t\tshow_diagnostics(resolved);\r\n\r\n\t}\r\n\telse {\r\n\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\r\n\t\t\tif(!tsapi.check(compiled)) {\r\n\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --noLib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resources/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## units\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this unit.\r\n\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\r\n\tast           : object,   // (public) AST for this unit.\r\n\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\r\n\tdeclaration   : string,   // (public) The declaration file for this unit.\r\n\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"reset\" />\r\n### reset (options)\r\n\r\nResets the compiler. Optionally allows the caller to set compiler options.  \r\n\r\n```javascript\t\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset()\r\n```\r\n\r\nAdditionally, It is possible to specify reset with the following options.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset({\r\n\r\n    languageVersion          : \"EcmaScript5\", // (default)EcmaScript5 | EcmaScript3\r\n\r\n    moduleGenTarget\t\t\t : \"Synchronous\", // (default)Synchronous | ASynchronous\r\n\r\n    removeComments\t\t\t : true,          // (default) true\r\n\r\n    generateDeclarationFiles : false,\t\t  // (default) false\r\n\r\n    mapSourceFiles           : false          // (default) false\r\n\r\n})\r\n\r\n```\r\n\r\n<a name=\"register\" />\r\n### typescript.register ()\r\n\r\nThe register() method will register the typescript file extension with nodejs require(). When using this \r\nmethod, the api will automatically JIT compile your typescript source code on first request and cache \r\nfor subsequent requests. \r\n\r\n```javascript\r\n\r\n//---------------------------------\r\n// program.ts\r\n//---------------------------------\r\n\r\nexport var message:string = 'hello world';\r\n\r\n//---------------------------------\r\n// app.js\r\n//---------------------------------\r\n\r\nrequire('typescript.api').register();\r\n\r\nvar program = require('./program.ts');\r\n\r\nconsole.log(program.message); // hello world\r\n```\r\n\r\n\r\n<a name=\"resolve\" />\r\n### resolve (sources, callback)\r\n\r\nThe typescript.api resolve function will resolve source units needed for compilation and return them\r\nin order of dependancy, it does this by scanning each files reference element. \r\n\r\nspecial note: the resolve method will be unable to resolve source units if your code contains circular \r\nreferences. for example, if file0.ts references file1.ts, and file1.ts references file0.ts, then this would\r\nbe considered a circular reference. in these instances, the resolve() method will return the source units \r\nfound in order of discovery, and no additional dependency resolution will occur. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### check (units)\r\n\r\nA utility method to check for errors in either resolved or compiled units.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif( tsapi.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( tsapi.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"create\" />\r\n### create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t})\r\n})\r\n\r\n```\r\n\r\n<a name=\"compile\" />\r\n### compile ( units, callback )\r\n\r\ncompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"run\" />\r\n### run ( compiledUnits, sandbox, callback )\r\n\r\nexecutes compiled units within a nodejs vm and returns a context containing exported members.\r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units - (obtained from a call to compile)\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var value:number = 123\")\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value) // outputs 123\r\n\r\n\t})\r\n})\r\n```\r\n\r\n<a name=\"sort\" />\r\n### sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\nvar units = [\r\n    tsapi.create(\"a.ts\", \"\"),\r\n    tsapi.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    tsapi.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    tsapi.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = tsapi.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.","directories":{},"dependencies":{"typescript":"0.9.1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.7.2":{"name":"typescript.api","version":"0.7.2","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.7.2","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"c2f1190630c372c62c89755542d991dd0bf13195","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.7.2.tgz","integrity":"sha512-Mb87U96AIJLITFVnZr58HbFBzeu8aRCUwQptJ+4QkE7kCyzhW8HiSeE1PSS/6cqNGiIWAXNTw/7IfxTSbY50AA==","signatures":[{"sig":"MEYCIQDxxkOR26AEjeyjEJ4BrTeCBz5Z9Hn0WLfX4VkToR13ZAIhAPJ20aNs2wQKToEcX9fa26KU/FEt6szskCiR3ZQjvoZZ","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [declarations](#declarations)\r\n\r\n### units\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [reset](#reset)\r\n* [register](#register)\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [run](#run)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntsapi.resolve(['./program.ts'], function(resolved) {\r\n\r\n\tif(!tsapi.check(resolved)) {\r\n\r\n\t\tshow_diagnostics(resolved);\r\n\r\n\t}\r\n\telse {\r\n\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\r\n\t\t\tif(!tsapi.check(compiled)) {\r\n\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --noLib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resources/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## units\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this unit.\r\n\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\r\n\tast           : object,   // (public) AST for this unit.\r\n\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\r\n\tdeclaration   : string,   // (public) The declaration file for this unit.\r\n\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"reset\" />\r\n### reset (options)\r\n\r\nResets the compiler. Optionally allows the caller to set compiler options.  \r\n\r\n```javascript\t\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset()\r\n```\r\n\r\nAdditionally, It is possible to specify reset with the following options.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset({\r\n\r\n    languageVersion          : \"EcmaScript5\", // (default)EcmaScript5 | EcmaScript3\r\n\r\n    moduleGenTarget\t\t\t : \"Synchronous\", // (default)Synchronous | ASynchronous\r\n\r\n    removeComments\t\t\t : true,          // (default) true\r\n\r\n    generateDeclarationFiles : false,\t\t  // (default) false\r\n\r\n    mapSourceFiles           : false          // (default) false\r\n\r\n})\r\n\r\n```\r\n\r\n<a name=\"register\" />\r\n### typescript.register ()\r\n\r\nThe register() method will register the typescript file extension with nodejs require(). When using this \r\nmethod, the api will automatically JIT compile your typescript source code on first request and cache \r\nfor subsequent requests. \r\n\r\n```javascript\r\n\r\n//---------------------------------\r\n// program.ts\r\n//---------------------------------\r\n\r\nexport var message:string = 'hello world';\r\n\r\n//---------------------------------\r\n// app.js\r\n//---------------------------------\r\n\r\nrequire('typescript.api').register();\r\n\r\nvar program = require('./program.ts');\r\n\r\nconsole.log(program.message); // hello world\r\n```\r\n\r\n\r\n<a name=\"resolve\" />\r\n### resolve (sources, callback)\r\n\r\nThe typescript.api resolve function will resolve source units needed for compilation and return them\r\nin order of dependancy, it does this by scanning each files reference element. \r\n\r\nspecial note: the resolve method will be unable to resolve source units if your code contains circular \r\nreferences. for example, if file0.ts references file1.ts, and file1.ts references file0.ts, then this would\r\nbe considered a circular reference. in these instances, the resolve() method will return the source units \r\nfound in order of discovery, and no additional dependency resolution will occur. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### check (units)\r\n\r\nA utility method to check for errors in either resolved or compiled units.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif( tsapi.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( tsapi.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"create\" />\r\n### create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t})\r\n})\r\n\r\n```\r\n\r\n<a name=\"compile\" />\r\n### compile ( units, callback )\r\n\r\ncompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"run\" />\r\n### run ( compiledUnits, sandbox, callback )\r\n\r\nexecutes compiled units within a nodejs vm and returns a context containing exported members.\r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units - (obtained from a call to compile)\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var value:number = 123\")\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value) // outputs 123\r\n\r\n\t})\r\n})\r\n```\r\n\r\n<a name=\"sort\" />\r\n### sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\nvar units = [\r\n    tsapi.create(\"a.ts\", \"\"),\r\n    tsapi.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    tsapi.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    tsapi.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = tsapi.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.","directories":{},"dependencies":{"typescript":"0.9.1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.7.3":{"name":"typescript.api","version":"0.7.3","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.7.3","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"82b835652221c518f866e9ad2e63696eba777a1e","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.7.3.tgz","integrity":"sha512-kj64ouqD40XhdrqkMlxmJG1+2DM6X9LgQk37RBLmhFl5IxtPymAkvvrke9+pyoeH2QGnCRLuM2IT0mHhkJyxUQ==","signatures":[{"sig":"MEUCIQCVhu1Z21QFbPSHvAkQtdtNfixA/xQy3no5TYYfLprzYQIgMFvXekudSfSzLh5d8PO/GcL5gneL/fSYL8ghWWkwGww=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.1-1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [declarations](#declarations)\r\n\r\n### units\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [reset](#reset)\r\n* [register](#register)\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [run](#run)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntsapi.resolve(['./program.ts'], function(resolved) {\r\n\r\n\tif(!tsapi.check(resolved)) {\r\n\r\n\t\tshow_diagnostics(resolved);\r\n\r\n\t}\r\n\telse {\r\n\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\r\n\t\t\tif(!tsapi.check(compiled)) {\r\n\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --noLib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resources/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## units\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this unit.\r\n\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\r\n\tast           : object,   // (public) AST for this unit.\r\n\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\r\n\tdeclaration   : string,   // (public) The declaration file for this unit.\r\n\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"reset\" />\r\n### reset (options)\r\n\r\nResets the compiler. Optionally allows the caller to set compiler options.  \r\n\r\n```javascript\t\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset()\r\n```\r\n\r\nAdditionally, It is possible to specify reset with the following options.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset({\r\n\r\n    languageVersion          : \"EcmaScript5\", // (default)EcmaScript5 | EcmaScript3\r\n\r\n    moduleGenTarget\t\t\t : \"Synchronous\", // (default)Synchronous | ASynchronous\r\n\r\n    removeComments\t\t\t : true,          // (default) true\r\n\r\n    generateDeclarationFiles : false,\t\t  // (default) false\r\n\r\n    mapSourceFiles           : false          // (default) false\r\n\r\n})\r\n\r\n```\r\n\r\n<a name=\"register\" />\r\n### typescript.register ()\r\n\r\nThe register() method will register the typescript file extension with nodejs require(). When using this \r\nmethod, the api will automatically JIT compile your typescript source code on first request and cache \r\nfor subsequent requests. \r\n\r\n```javascript\r\n\r\n//---------------------------------\r\n// program.ts\r\n//---------------------------------\r\n\r\nexport var message:string = 'hello world';\r\n\r\n//---------------------------------\r\n// app.js\r\n//---------------------------------\r\n\r\nrequire('typescript.api').register();\r\n\r\nvar program = require('./program.ts');\r\n\r\nconsole.log(program.message); // hello world\r\n```\r\n\r\n\r\n<a name=\"resolve\" />\r\n### resolve (sources, callback)\r\n\r\nThe typescript.api resolve function will resolve source units needed for compilation and return them\r\nin order of dependancy, it does this by scanning each files reference element. \r\n\r\nspecial note: the resolve method will be unable to resolve source units if your code contains circular \r\nreferences. for example, if file0.ts references file1.ts, and file1.ts references file0.ts, then this would\r\nbe considered a circular reference. in these instances, the resolve() method will return the source units \r\nfound in order of discovery, and no additional dependency resolution will occur. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### check (units)\r\n\r\nA utility method to check for errors in either resolved or compiled units.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif( tsapi.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( tsapi.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"create\" />\r\n### create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t})\r\n})\r\n\r\n```\r\n\r\n<a name=\"compile\" />\r\n### compile ( units, callback )\r\n\r\ncompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"run\" />\r\n### run ( compiledUnits, sandbox, callback )\r\n\r\nexecutes compiled units within a nodejs vm and returns a context containing exported members.\r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units - (obtained from a call to compile)\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var value:number = 123\")\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value) // outputs 123\r\n\r\n\t})\r\n})\r\n```\r\n\r\n<a name=\"sort\" />\r\n### sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\nvar units = [\r\n    tsapi.create(\"a.ts\", \"\"),\r\n    tsapi.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    tsapi.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    tsapi.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = tsapi.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.","directories":{},"dependencies":{"typescript":"0.9.1-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.7.4":{"name":"typescript.api","version":"0.7.4","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.7.4","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"30f8717dd2be3c198acd4e26c0c2e21cadab3792","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.7.4.tgz","integrity":"sha512-hwCBB4KbvYDOhqXzB5ATaYR/Fa13Xr/tCvSneDz3QntI5KhMZ9qtIj7QQ8Vee+7L+uTALv54SlqRWsfb4/Fvwg==","signatures":[{"sig":"MEQCIAwlx0zQTHQe6PV40WZV6JmjASqD0+FiEoT2+qSeuj6XAiAWRMU6T29UMLzJ7zEfLTb2aE2mcxGPtJqbhkgxZgTIOg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.1-1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [declarations](#declarations)\r\n\r\n### units\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [reset](#reset)\r\n* [register](#register)\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [run](#run)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntsapi.resolve(['./program.ts'], function(resolved) {\r\n\r\n\tif(!tsapi.check(resolved)) {\r\n\r\n\t\tshow_diagnostics(resolved);\r\n\r\n\t}\r\n\telse {\r\n\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\r\n\t\t\tif(!tsapi.check(compiled)) {\r\n\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --noLib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resources/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## units\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this unit.\r\n\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\r\n\tast           : object,   // (public) AST for this unit.\r\n\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\r\n\tdeclaration   : string,   // (public) The declaration file for this unit.\r\n\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"reset\" />\r\n### reset (options)\r\n\r\nResets the compiler. Optionally allows the caller to set compiler options.  \r\n\r\n```javascript\t\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset()\r\n```\r\n\r\nAdditionally, It is possible to specify reset with the following options.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset({\r\n\r\n    languageVersion          : \"EcmaScript5\", // (default)EcmaScript5 | EcmaScript3\r\n\r\n    moduleGenTarget\t\t\t : \"Synchronous\", // (default)Synchronous | ASynchronous\r\n\r\n    removeComments\t\t\t : true,          // (default) true\r\n\r\n    generateDeclarationFiles : false,\t\t  // (default) false\r\n\r\n    mapSourceFiles           : false          // (default) false\r\n\r\n})\r\n\r\n```\r\n\r\n<a name=\"register\" />\r\n### typescript.register ()\r\n\r\nThe register() method will register the typescript file extension with nodejs require(). When using this \r\nmethod, the api will automatically JIT compile your typescript source code on first request and cache \r\nfor subsequent requests. \r\n\r\n```javascript\r\n\r\n//---------------------------------\r\n// program.ts\r\n//---------------------------------\r\n\r\nexport var message:string = 'hello world';\r\n\r\n//---------------------------------\r\n// app.js\r\n//---------------------------------\r\n\r\nrequire('typescript.api').register();\r\n\r\nvar program = require('./program.ts');\r\n\r\nconsole.log(program.message); // hello world\r\n```\r\n\r\n\r\n<a name=\"resolve\" />\r\n### resolve (sources, callback)\r\n\r\nThe typescript.api resolve function will resolve source units needed for compilation and return them\r\nin order of dependancy, it does this by scanning each files reference element. \r\n\r\nspecial note: the resolve method will be unable to resolve source units if your code contains circular \r\nreferences. for example, if file0.ts references file1.ts, and file1.ts references file0.ts, then this would\r\nbe considered a circular reference. in these instances, the resolve() method will return the source units \r\nfound in order of discovery, and no additional dependency resolution will occur. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### check (units)\r\n\r\nA utility method to check for errors in either resolved or compiled units.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif( tsapi.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( tsapi.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"create\" />\r\n### create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t})\r\n})\r\n\r\n```\r\n\r\n<a name=\"compile\" />\r\n### compile ( units, callback )\r\n\r\ncompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"run\" />\r\n### run ( compiledUnits, sandbox, callback )\r\n\r\nexecutes compiled units within a nodejs vm and returns a context containing exported members.\r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units - (obtained from a call to compile)\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var value:number = 123\")\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value) // outputs 123\r\n\r\n\t})\r\n})\r\n```\r\n\r\n<a name=\"sort\" />\r\n### sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\nvar units = [\r\n    tsapi.create(\"a.ts\", \"\"),\r\n    tsapi.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    tsapi.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    tsapi.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = tsapi.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.","directories":{},"dependencies":{"typescript":"0.9.1-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.7.5":{"name":"typescript.api","version":"0.7.5","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.7.5","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"cc11c18c51f5289c7b6e97d013a5e4e417150664","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.7.5.tgz","integrity":"sha512-aez32NmX4PJZnbBFzK1onvvKI3GV1Nvze/zqR4oMHXTWTHJbWJOdS7b53dV3jXJf1F+y/LXsTUUAKlUJjQVj8Q==","signatures":[{"sig":"MEYCIQCFGlR+kQcdGWA6vpAEOEpRVUYzm0b5cFWVRQ52dAlZDwIhAIC5A57gU0e5Px2EBavUez/4vu1kc2D7AvQsoy7lGsZt","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.1-1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [declarations](#declarations)\r\n\r\n### units\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [reset](#reset)\r\n* [register](#register)\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [run](#run)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntsapi.resolve(['./program.ts'], function(resolved) {\r\n\r\n\tif(!tsapi.check(resolved)) {\r\n\r\n\t\tshow_diagnostics(resolved);\r\n\r\n\t}\r\n\telse {\r\n\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\r\n\t\t\tif(!tsapi.check(compiled)) {\r\n\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --noLib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resources/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## units\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this unit.\r\n\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\r\n\tast           : object,   // (public) AST for this unit.\r\n\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\r\n\tdeclaration   : string,   // (public) The declaration file for this unit.\r\n\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"reset\" />\r\n### reset (options)\r\n\r\nResets the compiler. Optionally allows the caller to set compiler options.  \r\n\r\n```javascript\t\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset()\r\n```\r\n\r\nAdditionally, It is possible to specify reset with the following options. all of which are optional.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset({\r\n\r\n    languageVersion          : \"EcmaScript5\", // (default)EcmaScript5 | EcmaScript3\r\n\r\n    moduleGenTarget\t\t\t : \"Synchronous\", // (default)Synchronous | ASynchronous\r\n\r\n    removeComments\t\t\t : true,          // (default) true\r\n\r\n    generateDeclarationFiles : false,\t\t  // (default) false\r\n\r\n    mapSourceFiles           : false,         // (default) false\r\n\r\n\tnoImplicitAny            : false,         // (default) false\r\n\r\n\tallowBool                : false          // (default) false\r\n\r\n})\r\n\r\n```\r\n\r\n<a name=\"register\" />\r\n### typescript.register ()\r\n\r\nThe register() method will register the typescript file extension with nodejs require(). When using this \r\nmethod, the api will automatically JIT compile your typescript source code on first request and cache \r\nfor subsequent requests. \r\n\r\n```javascript\r\n\r\n//---------------------------------\r\n// program.ts\r\n//---------------------------------\r\n\r\nexport var message:string = 'hello world';\r\n\r\n//---------------------------------\r\n// app.js\r\n//---------------------------------\r\n\r\nrequire('typescript.api').register();\r\n\r\nvar program = require('./program.ts');\r\n\r\nconsole.log(program.message); // hello world\r\n```\r\n\r\n\r\n<a name=\"resolve\" />\r\n### resolve (sources, callback)\r\n\r\nThe typescript.api resolve function will resolve source units needed for compilation and return them\r\nin order of dependancy, it does this by scanning each files reference element. \r\n\r\nspecial note: the resolve method will be unable to resolve source units if your code contains circular \r\nreferences. for example, if file0.ts references file1.ts, and file1.ts references file0.ts, then this would\r\nbe considered a circular reference. in these instances, the resolve() method will return the source units \r\nfound in order of discovery, and no additional dependency resolution will occur. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### check (units)\r\n\r\nA utility method to check for errors in either resolved or compiled units.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif( tsapi.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( tsapi.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"create\" />\r\n### create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t})\r\n})\r\n\r\n```\r\n\r\n<a name=\"compile\" />\r\n### compile ( units, callback )\r\n\r\ncompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"run\" />\r\n### run ( compiledUnits, sandbox, callback )\r\n\r\nexecutes compiled units within a nodejs vm and returns a context containing exported members.\r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units - (obtained from a call to compile)\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var value:number = 123\")\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value) // outputs 123\r\n\r\n\t})\r\n})\r\n```\r\n\r\n<a name=\"sort\" />\r\n### sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\nvar units = [\r\n    tsapi.create(\"a.ts\", \"\"),\r\n    tsapi.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    tsapi.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    tsapi.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = tsapi.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.","directories":{},"dependencies":{"typescript":"0.9.1-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.7.6":{"name":"typescript.api","version":"0.7.6","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.7.6","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"624d608e7012d69035e012da3257df3770c626b1","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.7.6.tgz","integrity":"sha512-Tx430CAFGZGDb6P/T3qqPbsPAjZluwv2d8pwIvf8KkL7oaJcnSophcvZF0gLJc6/yVe1SFPDZvw2fiPDVJgVSg==","signatures":[{"sig":"MEUCIC7+z2l7jR4vufJPgDpT3oAWimNZ7uuSTE22iX8ryXxoAiEA3irdgI7AP9R9r3SDV5Ce0X6mqSfKX/Rn38LytW1EaMc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.1-1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [declarations](#declarations)\r\n\r\n### units\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [reset](#reset)\r\n* [register](#register)\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [run](#run)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntsapi.resolve(['./program.ts'], function(resolved) {\r\n\r\n\tif(!tsapi.check(resolved)) {\r\n\r\n\t\tshow_diagnostics(resolved);\r\n\r\n\t}\r\n\telse {\r\n\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\r\n\t\t\tif(!tsapi.check(compiled)) {\r\n\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --noLib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resources/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## units\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this unit.\r\n\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\r\n\tast           : object,   // (public) AST for this unit.\r\n\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\r\n\tdeclaration   : string,   // (public) The declaration file for this unit.\r\n\r\n\treflection    : object,   // (public) The units reflected members.  \r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"reset\" />\r\n### reset (options)\r\n\r\nResets the compiler. Optionally allows the caller to set compiler options.  \r\n\r\n```javascript\t\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset()\r\n```\r\n\r\nAdditionally, It is possible to specify reset with the following options. all of which are optional.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset({\r\n\r\n    languageVersion          : \"EcmaScript5\", // (default)EcmaScript5 | EcmaScript3\r\n\r\n    moduleGenTarget\t\t\t : \"Synchronous\", // (default)Synchronous | ASynchronous\r\n\r\n    removeComments\t\t\t : true,          // (default) true\r\n\r\n    generateDeclarationFiles : false,\t\t  // (default) false\r\n\r\n    mapSourceFiles           : false,         // (default) false\r\n\r\n\tnoImplicitAny            : false,         // (default) false\r\n\r\n\tallowBool                : false,         // (default) false\r\n\r\n\toutputMany               : true           // (default) true\r\n\r\n})\r\n\r\n```\r\n\r\n<a name=\"register\" />\r\n### typescript.register ()\r\n\r\nThe register() method will register the typescript file extension with nodejs require(). When using this \r\nmethod, the api will automatically JIT compile your typescript source code on first request and cache \r\nfor subsequent requests. \r\n\r\n```javascript\r\n\r\n//---------------------------------\r\n// program.ts\r\n//---------------------------------\r\n\r\nexport var message:string = 'hello world';\r\n\r\n//---------------------------------\r\n// app.js\r\n//---------------------------------\r\n\r\nrequire('typescript.api').register();\r\n\r\nvar program = require('./program.ts');\r\n\r\nconsole.log(program.message); // hello world\r\n```\r\n\r\n\r\n<a name=\"resolve\" />\r\n### resolve (sources, callback)\r\n\r\nThe typescript.api resolve function will resolve source units needed for compilation and return them\r\nin order of dependancy, it does this by scanning each files reference element. \r\n\r\nspecial note: the resolve method will be unable to resolve source units if your code contains circular \r\nreferences. for example, if file0.ts references file1.ts, and file1.ts references file0.ts, then this would\r\nbe considered a circular reference. in these instances, the resolve() method will return the source units \r\nfound in order of discovery, and no additional dependency resolution will occur. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### check (units)\r\n\r\nA utility method to check for errors in either resolved or compiled units.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif( tsapi.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( tsapi.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"create\" />\r\n### create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t})\r\n})\r\n\r\n```\r\n\r\n<a name=\"compile\" />\r\n### compile ( units, callback )\r\n\r\ncompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"run\" />\r\n### run ( compiledUnits, sandbox, callback )\r\n\r\nexecutes compiled units within a nodejs vm and returns a context containing exported members.\r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units - (obtained from a call to compile)\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var value:number = 123\")\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value) // outputs 123\r\n\r\n\t})\r\n})\r\n```\r\n\r\n<a name=\"sort\" />\r\n### sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\nvar units = [\r\n    tsapi.create(\"a.ts\", \"\"),\r\n    tsapi.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    tsapi.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    tsapi.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = tsapi.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.2.21","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.","directories":{},"dependencies":{"typescript":"0.9.1-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"},"0.7.7":{"name":"typescript.api","version":"0.7.7","keywords":["typescript","compiler","require","reflect"],"author":{"name":"sinclair"},"_id":"typescript.api@0.7.7","maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"dist":{"shasum":"b361c58ce4388e673112273d2746ff771245c3e1","tarball":"https://registry.npmjs.org/typescript.api/-/typescript.api-0.7.7.tgz","integrity":"sha512-/Z1duLYkmi4cL8sH1WpMbLyFI8dtFsk5x8/AR3/fOp1BtMFaAYOmU1gAxhUL480W7wDgpKI2Mt76nSxL9JyXZg==","signatures":[{"sig":"MEUCIQCQZYvUA6E84pFnu1sWxD5Z0IL9iXcFPDUHvFMFcpyVrgIgP5raZozKeL6ESNpCvyj/SRcBxPq5p1aUbAdh3Pk4AgE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9.1-1\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n### overview\r\n\r\n* [manual compilation](#manual_compilation)\r\n* [declarations](#declarations)\r\n\r\n### units\r\n\r\n* [source unit](#source_unit)\r\n* [compiled unit](#compiled_unit)\r\n\r\n### methods\r\n\r\n* [reset](#reset)\r\n* [register](#register)\r\n* [create](#create)\r\n* [resolve](#resolve)\r\n* [compile](#compile)\r\n* [check](#check)\r\n* [run](#run)\r\n* [sort](#sort)\r\n\r\n<a name=\"manual_compilation\" />\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources array (resolved) are then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntsapi.resolve(['./program.ts'], function(resolved) {\r\n\r\n\tif(!tsapi.check(resolved)) {\r\n\r\n\t\tshow_diagnostics(resolved);\r\n\r\n\t}\r\n\telse {\r\n\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\r\n\t\t\tif(!tsapi.check(compiled)) {\r\n\r\n\t\t\t\tshow_diagnostics (compiled);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"declarations\" />\r\n### declarations\r\n\r\nIt is important to note that the typescript.api does not automatically reference any declarations (such as lib.d.ts) for compilation. \r\nBecause of this, you will need to reference the appropriate *.d.ts required by your application for compilation. This is unlike the \r\ntsc command line compiler which will, by default reference the lib.d.ts declaration if not stated otherwise. (see --noLib option). \r\n\r\nIn the context of nodejs, the dom declarations declared in lib.d.ts are unnessasary and dramatically slow compilation times. The\r\ntypescript.api splits these declarations out to provide suitable environment declarations that you can reference in your project.\r\n\r\nThe typescript.api comes bundled with following declarations:\r\n\r\n```javascript\r\n// ecma api + html dom declarations (suitable for browser development)\r\n[node_modules]/typescript.api/decl/lib.d.ts \r\n\r\n// ecma api + node.d.ts declarations (suitable for nodejs development)\r\n[node_modules]/typescript.api/decl/node.d.ts\r\n\r\n// ecma api only.\r\n[node_modules]/typescript.api/decl/ecma.d.ts \r\n\r\n// typescript.api declarations.\r\n[node_modules]/typescript.api/decl/typescript.api.d.ts\r\n```\r\n\r\nIt is recommended that developers copy the appropriate declarations suitable for their environment into their project structure and\r\nreference them accordingly. \r\n\r\nFor a full definition of this api, see  [typescript.api.d.ts](https://github.com/sinclairzx81/typescript.api/blob/master/src/resources/typescript.api.d.ts)\r\n\r\nFor other additional declarations, see the [definitely typed](https://github.com/borisyankov/DefinitelyTyped) project.\r\n\r\n## units\r\n\r\n<a name=\"source_unit\" />\r\n### source unit\r\n\r\nThe typescript.api accepts source units for compilation. A source unit consists of the following properties: \r\n\r\n```javascript\r\n\r\nsourceUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this source unit.\r\n\r\n\tcontent       : string,   // (public) the typescript source of this unit.\r\n\r\n\tremote        : boolean,  // (public) if this source file is loaded over http.\r\n\r\n\treferences    : Function  // (public) returns an array of references for this source unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n};\r\n\r\n```\r\n\r\nnote: For manually creating source units, see [create](#create)\r\n\r\nnote: For loading source units from disk. see [resolve](#resolve)\r\n\r\n<a name=\"compiled_unit\" />\r\n### compiled unit\r\n\r\nA compiled unit is the output from a [compilation](#compile). A compiled unit consists of the following properties:\r\n\r\n```javascript\r\n\r\ncompiledUnit = {\r\n\r\n\tpath          : string,   // (public) the path of this unit.\r\n\r\n\tcontent       : string,   // (public) the javascript source of this unit.\r\n\r\n\treferences    : string[], // (public) an array of references for this unit.\r\n\r\n\tdiagnostics   : [object], // (public) compilation errors for this unit. 0 length if none.\r\n\r\n\tast           : object,   // (public) AST for this unit.\r\n\r\n\tsourcemap     : string,   // (public) The sourcemap for this unit.\r\n\r\n\tdeclaration   : string,   // (public) The declaration file for this unit.\r\n\r\n\tscript        : object,   // (public) reflected metadata for this unit.\r\n};\r\n\r\n```\r\n\r\n## methods\r\n\r\n<a name=\"reset\" />\r\n### reset (options)\r\n\r\nResets the compiler. Optionally allows the caller to set compiler options.  \r\n\r\n```javascript\t\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset()\r\n```\r\n\r\nAdditionally, It is possible to specify reset with the following options. all of which are optional.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\ntsapi.reset({\r\n\r\n    languageVersion          : \"EcmaScript5\", // (default)EcmaScript5 | EcmaScript3\r\n\r\n    moduleGenTarget\t\t\t : \"Synchronous\", // (default)Synchronous | ASynchronous\r\n\r\n    removeComments\t\t\t : true,          // (default) true\r\n\r\n    generateDeclarationFiles : false,\t\t  // (default) false\r\n\r\n    mapSourceFiles           : false,         // (default) false\r\n\r\n\tnoImplicitAny            : false,         // (default) false\r\n\r\n\tallowBool                : false,         // (default) false\r\n\r\n\toutputMany               : true           // (default) true\r\n\r\n})\r\n\r\n```\r\n\r\n<a name=\"register\" />\r\n### typescript.register ()\r\n\r\nThe register() method will register the typescript file extension with nodejs require(). When using this \r\nmethod, the api will automatically JIT compile your typescript source code on first request and cache \r\nfor subsequent requests. \r\n\r\n```javascript\r\n\r\n//---------------------------------\r\n// program.ts\r\n//---------------------------------\r\n\r\nexport var message:string = 'hello world';\r\n\r\n//---------------------------------\r\n// app.js\r\n//---------------------------------\r\n\r\nrequire('typescript.api').register();\r\n\r\nvar program = require('./program.ts');\r\n\r\nconsole.log(program.message); // hello world\r\n```\r\n\r\n\r\n<a name=\"resolve\" />\r\n### resolve (sources, callback)\r\n\r\nThe typescript.api resolve function will resolve source units needed for compilation and return them\r\nin order of dependancy, it does this by scanning each files reference element. \r\n\r\nspecial note: the resolve method will be unable to resolve source units if your code contains circular \r\nreferences. for example, if file0.ts references file1.ts, and file1.ts references file0.ts, then this would\r\nbe considered a circular reference. in these instances, the resolve() method will return the source units \r\nfound in order of discovery, and no additional dependency resolution will occur. \r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback which passes the resolved source units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tfor(var n in resolved) {\r\n\r\n\t\tconsole.log( resolved[n].path ); // the source files path\r\n\t\t\r\n\t\tconsole.log( resolved[n].content ); // the source files content (typescript)\r\n\t\t\r\n\t\tfor(var m in resolved[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( resolved[n].references[m] ) // paths to referenced source files.\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n<a name=\"check\" />\r\n### check (units)\r\n\r\nA utility method to check for errors in either resolved or compiled units.\r\n\r\n__arguments__\r\n\r\n* units   - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\ntsapi.resolve([\"program.ts\"], function(resolved) { \r\n\r\n\tif( tsapi.check (resolved)) { // check here for reference errors.\r\n\t\t\r\n\t\ttsapi.compile(resolved, function(compiled) {\r\n\t\t\r\n\t\t\tif( tsapi.check (compiled) ) { // check here for syntax and type errors.\r\n\t\t\t\r\n\t\t\t\ttsapi.run(compiled, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"create\" />\r\n### create ( filename, code )\r\n\r\nCreates a source unit from a string. \r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units may reference.\r\n* code\t   - The source code for this unit.\r\n\r\n__returns__\r\n\r\n* unit\t   - A source unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var message = 'hello world'\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\t\r\n\t\tconsole.log(context.message); // outputs hello world\r\n\t})\r\n})\r\n\r\n```\r\n\r\n<a name=\"compile\" />\r\n### compile ( units, callback )\r\n\r\ncompiles source units. \r\n\r\n__arguments__\r\n\r\n* units\t   - An array of source units. \r\n* callback - A callback that passed the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\tfor(var n in compiled) {\r\n\t\r\n\t\tconsole.log(compiled[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n<a name=\"run\" />\r\n### run ( compiledUnits, sandbox, callback )\r\n\r\nexecutes compiled units within a nodejs vm and returns a context containing exported members.\r\n\r\n__arguments__\r\n\r\n* compiledUnits - compiled source units - (obtained from a call to compile)\r\n* sandbox\t    - A sandbox. pass null to inherit the current sandbox. code in executed in nodejs vm.\r\n* callback      - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\r\n\r\nvar tsapi = require(\"typescript.api\");\t\r\n\r\nvar sourceUnit = tsapi.create(\"temp.ts\", \"export var value:number = 123\")\r\n\r\ntsapi.compile([sourceUnit], function(compiled) {\r\n\r\n\ttsapi.run(compiled, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value) // outputs 123\r\n\r\n\t})\r\n})\r\n```\r\n\r\n<a name=\"sort\" />\r\n### sort ( units )\r\n\r\nWill attempt to sort source units in order of dependency. If cyclic referencing\r\noccurs, the sort will return the units in order in which they are received.\r\n\r\n__arguments__\r\n\r\n* units - An array of source units to be sorted.\r\n* returns - the sorted units in order of dependency.\r\n\r\n__example__\r\n\r\nThe following will create a series of source units which reference each other\r\nas in the following graph. The units are first randomized and then sorted. The \r\nresulting sort will be the order of a, b, c, d, e, f. \r\n\r\n```javascript\r\n/*\r\n         [a]\r\n        /   \\\r\n      [b]   [c]\r\n     /   \\ /   \\\r\n   [d]   [e]   [f]\r\n*/\r\nfunction shuffle(o) {  \r\n    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);\r\n    return o;\r\n};\r\n\r\nvar tsapi = require(\"typescript.api\")\r\n\r\nvar units = [\r\n    tsapi.create(\"a.ts\", \"\"),\r\n    tsapi.create(\"b.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"c.ts\", \"/// <reference path='a.ts' />\"),\r\n    tsapi.create(\"d.ts\", \"/// <reference path='b.ts' />\"),\r\n    tsapi.create(\"e.ts\", \"/// <reference path='b.ts' />\\n/// <reference path='c.ts' />\\n\"),\r\n    tsapi.create(\"f.ts\", \"/// <reference path='c.ts' />\"),\r\n];\r\n\r\n// shuffle\r\nunits = shuffle(units);\r\n\r\n// sort\r\nunits = tsapi.sort(units);\r\n\r\n// display\r\nfor (var n in units)  {\r\n\r\n    console.log(units[n].path);\r\n}\r\n```\r\n","scripts":{},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"licenses":[{"url":"http://www.apache.org/licenses/LICENSE-2.0.html","type":"Apache 2.0"}],"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"_npmVersion":"1.3.8","description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.","directories":{},"dependencies":{"typescript":"0.9.1-1"},"readmeFilename":"readme.md","devDependencies":{},"deprecated":"Deprecated"}},"time":{"created":"2013-05-09T23:05:53.754Z","modified":"2026-04-15T10:52:23.185Z","0.2.0":"2013-05-09T23:05:57.200Z","0.2.1":"2013-05-12T17:06:17.987Z","0.2.2":"2013-05-28T13:58:21.856Z","0.2.3":"2013-05-28T14:25:03.800Z","0.2.4":"2013-06-04T16:48:14.743Z","0.2.5":"2013-06-06T17:40:59.310Z","0.2.6":"2013-06-06T19:32:54.773Z","0.3.0":"2013-06-08T09:51:48.792Z","0.3.1":"2013-06-08T11:20:26.079Z","0.3.2":"2013-06-11T00:21:38.256Z","0.3.3":"2013-06-12T22:17:40.698Z","0.3.4":"2013-06-12T23:04:21.241Z","0.4.0":"2013-06-21T14:06:46.416Z","0.4.1":"2013-06-22T08:32:35.843Z","0.4.2":"2013-06-23T04:56:34.184Z","0.4.3":"2013-06-25T06:34:34.310Z","0.4.4":"2013-06-27T18:31:20.184Z","0.4.5":"2013-07-01T13:43:56.504Z","0.4.6":"2013-07-01T20:33:10.468Z","0.4.7":"2013-07-02T02:08:20.925Z","0.5.0":"2013-07-03T22:14:35.150Z","0.5.1":"2013-07-03T23:48:02.451Z","0.5.2":"2013-07-08T07:40:16.605Z","0.5.3":"2013-07-10T05:35:24.402Z","0.5.4":"2013-07-10T10:18:43.666Z","0.5.5":"2013-07-12T02:22:23.094Z","0.5.6":"2013-07-14T12:16:01.458Z","0.5.7":"2013-07-15T15:24:00.465Z","0.5.8":"2013-07-16T06:09:36.687Z","0.5.9":"2013-07-16T13:55:46.072Z","0.6.0":"2013-07-21T14:14:00.741Z","0.6.1":"2013-07-27T11:19:30.915Z","0.7.0":"2013-08-13T03:44:30.069Z","0.7.1":"2013-08-18T15:52:53.088Z","0.7.2":"2013-08-21T12:46:16.543Z","0.7.3":"2013-08-21T18:39:23.562Z","0.7.4":"2013-08-28T02:45:52.540Z","0.7.5":"2013-08-29T17:37:17.332Z","0.7.6":"2013-09-01T05:35:58.324Z","0.7.7":"2013-10-02T05:19:41.840Z"},"author":{"name":"sinclair"},"repository":{"url":"https://github.com/sinclairzx81/typescript.api.git","type":"git"},"description":"A compiler as a service api enabling nodejs developers to programatically resolve, compile, reflect and run typescript 0.9 source files in memory.","keywords":["typescript","compiler","require","reflect"],"bugs":{"url":"https://github.com/sinclairzx81/typescript.api/issues"},"maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"readme":"# typescript.api\r\n\r\nA compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.\r\n\r\n## install\r\n\r\n```javascript\r\nnpm install typescript.api\r\n```\r\n\r\n## compiler version\r\n\r\nTypeScript 0.9 alpha\r\n\r\n## quick start\r\n\r\n### registering typescript extension\r\n\r\nThe following will register the *.ts extension with require(). When calls to require() are made\r\nto *.ts files, any source resolution and/or compilation errors will be written out to the console\r\nby default.\r\n\r\nIf resolution or compilation errors do exist, the call to require() will return an empty object.\r\n\r\n```javascript\r\nrequire(\"typescript.api\").register();\r\n\r\nvar program = require(\"./program.ts\");\r\n```\r\n\r\n### manual compilation\r\n\r\nThe following is an example of using the api to compile a source file named 'program.ts'. \r\n\r\nThe process will first resolve 'program.ts' and all its referenced sources files. The resolved \r\nsources (units) then checked prior to being sent to the compiler for compilation. Once compiled,\r\nthe compilation is checked again for problems prior to being run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\n// show diagnostic errors.\r\nfunction show_diagnostics (units) {\r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tfor(var m in units[n].diagnostics) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].diagnostics[m].toString() );\r\n\t\t}\r\n\t}\r\n}\r\n\r\ntypescript.resolve(['./program.ts'], function(units) {\r\n\t\r\n\tif(!typescript.check(units)) {\r\n\t\r\n\t\tshow_diagnostics(units);\r\n\t}\r\n\telse {\r\n\t\t\r\n\t\ttypescript.compile(units, function(compilation) {\r\n\t\t\t\r\n\t\t\tif(!typescript.check(compilation)) {\r\n\t\t\t\r\n\t\t\t\tshow_diagnostics (compilation);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\t\t\t\r\n\t\t\t\ttypescript.run(compilation, null, function(context) {\r\n\t\t\t\t\r\n\t\t\t\t\t // exports are available on the context...\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n## reference\r\n\r\n### typescript.resolve (sources, callback)\r\n\r\nWill resolve source units by traversing each source files reference element.\r\n\r\n__arguments__\r\n\r\n* sources - A filename, or a array of filenames to resolve. \r\n* callback(units) - A callback with the resolved units.\r\n\r\n__example__\r\n\r\nThe following will resolve 'program.ts' and log each referenced source file to \r\nthe console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(units) { \r\n\r\n\tfor(var n in units) {\r\n\t\r\n\t\tconsole.log( units[n].path );\r\n\t\t\r\n\t\tconsole.log( units[n].content );\r\n\t\t\r\n\t\tfor(var m in units[n].references) {\r\n\t\t\r\n\t\t\tconsole.log( units[n].references[m] )\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.check (units)\r\n\r\nChecks source units for diagnostic errors. \r\n\r\n__arguments__\r\n\r\n* units - units to be checked. \r\n* returns - true if ok. \r\n\r\n__example__\r\n\r\nThe following example will check if both a resolve() and compile() is successful.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve([\"program.ts\"], function(units) { \r\n\r\n\tif(typescript.check (units)) {\r\n\t\t\r\n\t\ttypescript.compile(units, function(compilation) {\r\n\t\t\r\n\t\t\tif( typescript.check (compilation) ) {\r\n\t\t\t\r\n\t\t\t\ttypescript.run(compilation, null, function(context) {\r\n\t\t\t\t\t\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.create ( filename, code )\r\n\r\nWill create a unit from the supplied filename and source code.\r\n\r\n__arguments__\r\n\r\n* filename - A filename that other units can reference.\r\n* code - The source code for this unit.\r\n\r\n__example__\r\n\r\nThe following will create a unit. and send to the compiler for compilation. \r\nThe compilation is then run.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar unit = typescript.create(\"temp.ts\", \"console.log('hello world');\");\r\n\r\ntypescript.compile([unit], function(compilation) {\r\n\r\n\ttypescript.run(compilation, null, function(context) { \r\n\t\t\r\n\t\t// will output hello world..\r\n\t});\r\n\t\r\n});\r\n```\r\n\r\n### typescript.compile ( units, callback )\r\n\r\nCompiles source units. \r\n\r\n__arguments__\r\n\r\n* units - An array of source units. \r\n* callback - A callback that passes the compiled output.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, and compiled source is\r\nwritten to the console.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\nvar unit = typescript.create(\"temp.ts\", \"var value:number = 123;\");\r\n\r\ntypescript.compile([unit], function(compilation) {\r\n\r\n\tfor(var n in compilation){\r\n\t\r\n\t\tconsole.log(compilation[n].content);\r\n\t}\r\n});\r\n```\r\n\r\n### typescript.reflect ( compilation, callback )\r\n\r\nReflects compilation AST and produces meta data about the modules, classes, \r\nmethods and variables contained within the compilation. \r\n\r\n__arguments__\r\n\r\n* units - The compilation to be reflected. \r\n* callback - A callback that passes the reflected metadata.\r\n\r\n__example__\r\n\r\nThe following will resolve the source file 'program.ts', compile it, then reflect its\r\nmeta data to the console as a JSON string.\r\n\r\n```javascript\r\nvar typescript = require(\"typescript.api\");\r\n\r\ntypescript.resolve(['program.ts'], function(units){\r\n\r\n\ttypescript.compile(units, function(compilation) {\r\n\t\t\r\n\t\ttypescript.reflect(compilation, function(reflection) {\r\n\t\t\t\r\n\t\t\tvar json = JSON.stringify(reflection, null, ' ');\r\n\t\t\t\r\n\t\t\tconsole.log(json);\r\n\t\t});\r\n\t});\r\n});\r\n```\r\n\r\n### typescript.run ( compilation, sandbox, callback )\r\n\r\nRuns a compilation. \r\n\r\n__arguments__\r\n\r\n* compilation - The compilation to be run.\r\n* sandbox - A sandbox. pass null to inherit the current sandbox.\r\n* callback - A callback that passes a context containing any exported variables and function.\r\n\r\n__example__\r\n\r\nThe following will first create and compile a unit, then send it off\r\nfor compilation.\r\n\r\n```javascript\t\r\nvar typescript = require(\"typescript.api\");\t\r\n\r\nvar unit = typescript.create(\"temp.ts\", \"export var value:number = 123;\");\r\n\r\ntypescript.compile([unit], function(compilation) {\r\n\r\n\ttypescript.run(compilation, null, function(context) { \r\n\t\r\n\t\tconsole.log(context.value);\r\n\t\t\r\n\t});\r\n});\r\n```\r\n","users":{"mpinteractiv":true}}