Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tsun

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsun - npm Package Compare versions

Comparing version 0.1.5 to 0.2.0

screenshot/color.png

108

bin/src/repl.js

@@ -0,5 +1,5 @@

"use strict";
/// <reference path='../typings/node.d.ts' />
/// <reference path='../typings/colors.d.ts' />
"use strict";
var readline = require('readline');
var readline = require('node-color-readline');
var util = require('util');

@@ -16,5 +16,2 @@ var vm = require('vm');

var options = require('optimist')
.usage('A TypeScript REPL.\nUsage: $0')
.alias('h', 'help')
.describe('h', 'Print this help message')
.alias('f', 'force')

@@ -24,4 +21,2 @@ .describe('f', 'Force tsun to evaluate code with ts errors.')

.describe('v', 'Print compiled javascript before evaluating.')
.alias('o', 'out')
.describe('o', 'output directory relative to temporary')
.describe('dere', "I-its's not like I'm an option so DON'T GET THE WRONG IDEA!");

@@ -67,2 +62,4 @@ var argv = options.argv;

var dir = dirs_1[_i];
if (!/\.d\.ts$/.test(dir))
continue;
var p = path.join(typings, dir);

@@ -86,2 +83,39 @@ if (fs.statSync(p).isFile()) {

output: process.stdout,
colorize: function (line) {
var colorized = '';
var regex = [
[/\/\//, 'grey'],
[/(['"`\/]).*?(?!<\\)\1/, 'cyan'],
[/[+-]?(\d+\.?\d*|\d*\.\d+)([eE][+-]?\d+)?/, 'cyan'],
[/\b(true|false|null|undefined|NaN|Infinity)\b/, 'blue'],
[/\b(in|if|for|while|var|new|function|do|return|void|else|break)\b/, 'green'],
[/\b(instanceof|with|case|default|try|this|switch|continue|typeof)\b/, 'green'],
[/\b(let|yield|const|class|extends|interface|type)\b/, 'green'],
[/\b(try|catch|finally|Error|delete|throw|import)\b/, 'red'],
[/\b(eval|isFinite|isNaN|parseFloat|parseInt|decodeURI|decodeURIComponent)\b/, 'yellow'],
[/\b(encodeURI|encodeURIComponent|escape|unescape|Object|Function|Boolean|Error)\b/, 'yellow'],
[/\b(Number|Math|Date|String|RegExp|Array|JSON|=>|string|number|boolean)\b/, 'yellow'],
[/\b(console|module|process|require|arguments|fs|global)\b/, 'yellow'],
];
while (line !== '') {
var start = +Infinity;
var color = '';
var length_1 = 0;
for (var _i = 0, regex_1 = regex; _i < regex_1.length; _i++) {
var reg = regex_1[_i];
var match = reg[0].exec(line);
if (match && match.index < start) {
start = match.index;
color = reg[1];
length_1 = match[0].length;
}
}
colorized += line.substring(0, start);
if (color) {
colorized += line.substr(start, length_1)[color];
}
line = line.substr(start + length_1);
}
return colorized;
},
completer: function (line) {

@@ -127,2 +161,57 @@ // append new line to get completions, then revert new line

}
// generate helper, adapted from TypeScript compiler
context['__extends'] = function (d, b) {
for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p];
var __ = function () { this.constructor = d; };
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
context['__assign'] = function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
// emit output for the __decorate helper function
context['__decorate'] = function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
// emit output for the __metadata helper function
context['__metadata'] = function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(k, v);
};
// emit output for the __param helper function
context['__param'] = function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
};
context['__awaiter'] = function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator.throw(value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};
context.console = new console_1.Console(process.stdout);

@@ -179,4 +268,3 @@ context.global = context;

var file = declFiles_1[_i];
var text = fs.readFileSync(file, 'utf8');
declarations[file] = collectDeclaration(ts.createSourceFile(file, text, ts.ScriptTarget.Latest));
declarations[file] = collectDeclaration(service.getSourceFile(file));
}

@@ -186,3 +274,3 @@ return function (cached) {

if (!cached) {
declarations[DUMMY_FILE] = collectDeclaration(ts.createSourceFile(DUMMY_FILE, codes, ts.ScriptTarget.Latest));
declarations[DUMMY_FILE] = collectDeclaration(service.getSourceFile(DUMMY_FILE));
}

@@ -189,0 +277,0 @@ return declarations;

6

bin/tsun.js

@@ -7,9 +7,5 @@ /// <reference path='./typings/node.d.ts' />

var options = require('optimist')
.usage('A TypeScript REPL.\nUsage: $0')
.usage("A TypeScript REPL. Usage:\n " + 'tsun'.blue + " [options] [script.ts]")
.alias('h', 'help')
.describe('h', 'Print this help message')
.alias('f', 'force')
.describe('f', 'Force tsun to evaluate code with ts errors.')
.alias('v', 'verbose')
.describe('v', 'Print compiled javascript before evaluating.')
.alias('o', 'out')

@@ -16,0 +12,0 @@ .describe('o', 'output directory relative to temporary')

{
"name": "tsun",
"version": "0.1.5",
"version": "0.2.0",
"description": "TSUN: a repl for TypeScript Upgraded Node",

@@ -8,5 +8,6 @@ "bin": "./bin/tsun",

"colors": "^1.0.3",
"node-color-readline": "git+https://github.com/HerringtonDarkholme/node-color-readline.git",
"optimist": "^0.6.1",
"temp": "^0.8.1",
"typescript": "1.9.0-dev.20160408"
"typescript": "^1.8.2"
},

@@ -13,0 +14,0 @@ "scripts": {

@@ -10,2 +10,3 @@ # TSUN - TypeScript Upgraded Node

* TS 1.8 support
* Keyword highlight
* Tab-completion support

@@ -40,2 +41,4 @@ * Multiple Line Mode

===
Keyword Highlight
![Keyword Highlight](https://raw.githubusercontent.com/HerringtonDarkholme/typescript-repl/master/screenshot/color.png)

@@ -58,3 +61,5 @@ Tab-completion

===
If you need these, please let me know by making [issues](https://github.com/HerringtonDarkholme/typescript-repl/issues)!
* Add customization
* Add tsun config
/// <reference path='../typings/node.d.ts' />
/// <reference path='../typings/colors.d.ts' />
declare var Reflect: any
declare var Promise: any
import * as readline from 'readline'
import * as readline from 'node-color-readline'
import * as util from 'util'

@@ -21,5 +23,2 @@ import * as vm from 'vm'

var options = require('optimist')
.usage('A TypeScript REPL.\nUsage: $0')
.alias('h', 'help')
.describe('h', 'Print this help message')
.alias('f', 'force')

@@ -29,4 +28,2 @@ .describe('f', 'Force tsun to evaluate code with ts errors.')

.describe('v', 'Print compiled javascript before evaluating.')
.alias('o', 'out')
.describe('o', 'output directory relative to temporary')
.describe('dere', "I-its's not like I'm an option so DON'T GET THE WRONG IDEA!")

@@ -78,2 +75,3 @@

for (let dir of dirs) {
if (!/\.d\.ts$/.test(dir)) continue
let p = path.join(typings, dir)

@@ -95,3 +93,2 @@ if (fs.statSync(p).isFile()) {

function createReadLine() {

@@ -101,2 +98,38 @@ return readline.createInterface({

output: process.stdout,
colorize(line) {
let colorized = ''
let regex: [RegExp, string][] = [
[/\/\//, 'grey'], // comment
[/(['"`\/]).*?(?!<\\)\1/, 'cyan'], // string/regex, not rock solid
[/[+-]?(\d+\.?\d*|\d*\.\d+)([eE][+-]?\d+)?/, 'cyan'], // number
[/\b(true|false|null|undefined|NaN|Infinity)\b/, 'blue'],
[/\b(in|if|for|while|var|new|function|do|return|void|else|break)\b/, 'green'],
[/\b(instanceof|with|case|default|try|this|switch|continue|typeof)\b/, 'green'],
[/\b(let|yield|const|class|extends|interface|type)\b/, 'green'],
[/\b(try|catch|finally|Error|delete|throw|import)\b/, 'red'],
[/\b(eval|isFinite|isNaN|parseFloat|parseInt|decodeURI|decodeURIComponent)\b/, 'yellow'],
[/\b(encodeURI|encodeURIComponent|escape|unescape|Object|Function|Boolean|Error)\b/, 'yellow'],
[/\b(Number|Math|Date|String|RegExp|Array|JSON|=>|string|number|boolean)\b/, 'yellow'],
[/\b(console|module|process|require|arguments|fs|global)\b/, 'yellow'],
]
while (line !== '') {
let start = +Infinity
let color = ''
let length = 0
for (let reg of regex) {
let match = reg[0].exec(line)
if (match && match.index < start) {
start = match.index
color = reg[1]
length = match[0].length
}
}
colorized += line.substring(0, start)
if (color) {
colorized += (<any>line.substr(start, length))[color]
}
line = line.substr(start + length)
}
return colorized
},
completer(line: string) {

@@ -142,2 +175,45 @@ // append new line to get completions, then revert new line

}
// generate helper, adapted from TypeScript compiler
context['__extends'] = function (d: any, b: any) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
let __: any = function () { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
context['__assign'] = function(t: any) {
for (var s: any, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t
}
// emit output for the __decorate helper function
context['__decorate'] = function (decorators: any, target: any, key: any, desc: any) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d: any;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
// emit output for the __metadata helper function
context['__metadata'] = function (k: any, v: any) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
}
// emit output for the __param helper function
context['__param'] = function (paramIndex: any, decorator: any) {
return function (target: any, key: any) { decorator(target, key, paramIndex); }
};
context['__awaiter'] = function (thisArg: any, _arguments: any, P: any, generator: any) {
return new (P || (P = Promise))(function (resolve: any, reject: any) {
function fulfilled(value: any) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value: any) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result: any) { result.done ? resolve(result.value) : new P(function (resolve: any) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};
context.console = new Console(process.stdout);

@@ -196,8 +272,7 @@ context.global = context;

for (let file of declFiles) {
let text = fs.readFileSync(file, 'utf8')
declarations[file] = collectDeclaration(ts.createSourceFile(file, text, ts.ScriptTarget.Latest))
declarations[file] = collectDeclaration(service.getSourceFile(file))
}
return function(cached: boolean = false) {
if (!cached) {
declarations[DUMMY_FILE] = collectDeclaration(ts.createSourceFile(DUMMY_FILE, codes, ts.ScriptTarget.Latest))
declarations[DUMMY_FILE] = collectDeclaration(service.getSourceFile(DUMMY_FILE))
}

@@ -204,0 +279,0 @@ return declarations

@@ -9,9 +9,6 @@ /// <reference path='./typings/node.d.ts' />

var options = require('optimist')
.usage('A TypeScript REPL.\nUsage: $0')
.usage(`A TypeScript REPL. Usage:
${'tsun'.blue} [options] [script.ts]`)
.alias('h', 'help')
.describe('h', 'Print this help message')
.alias('f', 'force')
.describe('f', 'Force tsun to evaluate code with ts errors.')
.alias('v', 'verbose')
.describe('v', 'Print compiled javascript before evaluating.')
.alias('o', 'out')

@@ -18,0 +15,0 @@ .describe('o', 'output directory relative to temporary')

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc