-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* forwarr * use more explicit import * update yarn.lock
- Loading branch information
1 parent
9f901f6
commit e16847d
Showing
4 changed files
with
300 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import Hook from 'console-feed/lib/Hook'; | ||
import { Encode } from 'console-feed/lib/Transform'; | ||
|
||
export function hookConsole(output: (log: any) => void) { | ||
Hook(window.console, async (log) => { | ||
output(log); | ||
}); | ||
} | ||
|
||
export function handleEvaluate(command: string): { error: boolean; result: any } | undefined { | ||
let result = null; | ||
let error = false; | ||
|
||
try { | ||
// Attempt to wrap command in parentheses, fixing issues | ||
// where directly returning objects results in unexpected | ||
// behaviour. | ||
if (command && command.charAt(0) === '{') { | ||
try { | ||
const wrapped = `(${command})`; | ||
// `new Function` is used to validate Javascript syntax | ||
// eslint-disable-next-line | ||
const validate = new Function(wrapped); | ||
command = wrapped; | ||
} catch (e) { | ||
// We shouldn't wrap the expression | ||
} | ||
} | ||
|
||
result = (0, eval)(command); // eslint-disable-line no-eval | ||
} catch (e) { | ||
result = e; | ||
error = true; | ||
} | ||
|
||
try { | ||
return { | ||
error, | ||
result: Encode(result), | ||
}; | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} |
Oops, something went wrong.