Skip to content

Instantly share code, notes, and snippets.

@satyr
Created February 14, 2009 15:11
Show Gist options
  • Save satyr/64386 to your computer and use it in GitHub Desktop.
Save satyr/64386 to your computer and use it in GitHub Desktop.
#!js
0,function(stream){
var lines = [], line;
while((line = stream.readLine()) !== null) lines.push(line);
var code = lines.join('\n');
if(!code) return print('usage: js {this} < perplexing.js > unperplexed.js');
code = (Function(code.replace(/^#!.*\n?/, '')).toString()
.replace(/^\s*function.*\s+/, '')
.replace(/^ {4}((?: )*)\1/mg, '$1') // halving indentation
.replace(/\s+\}\s*$/, ''));
print(code);
return code;
}(typeof java === 'undefined'
? {readLine: readline}
: new java.io.BufferedReader(
new java.io.InputStreamReader(java.lang.System['in'])));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment