diff options
author | 2022-07-19 01:26:56 -0400 | |
---|---|---|
committer | 2022-07-18 22:26:56 -0700 | |
commit | 6afbf1b16690a9e60ac4d51ddd9c168027512f1b (patch) | |
tree | 3d88dafd5b9dc24d35f96af663db4dae1c2fd7e0 /examples/macros | |
parent | 600929ee6d2c4049a4ccb95c1d4aeab1e9e3b5b9 (diff) | |
download | bun-6afbf1b16690a9e60ac4d51ddd9c168027512f1b.tar.gz bun-6afbf1b16690a9e60ac4d51ddd9c168027512f1b.tar.zst bun-6afbf1b16690a9e60ac4d51ddd9c168027512f1b.zip |
added mystery-box example macro (#787)
Diffstat (limited to 'examples/macros')
-rw-r--r-- | examples/macros/mystery-box.ts | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/examples/macros/mystery-box.ts b/examples/macros/mystery-box.ts new file mode 100644 index 000000000..4dff5d003 --- /dev/null +++ b/examples/macros/mystery-box.ts @@ -0,0 +1,13 @@ +export function mysteryBox(callExpression) { + console.log(callExpression.log); + // get arguments + const [ countNode ] = callExpression.arguments; + const countString: string = countNode.get(); + const count: number = parseInt(countString, 10); + + // validate + if(!(count >= 1 && count <= 1000)) return new Error(`Argument ${countString} is expected to be between 1 and 1000`); + + // return a value + return (Math.random() * count)|0; +} |