REP.js
This is an extension for generation of code using js code.
Demo
Features
You can just write the code that will generate other code and call 'REP.js: Eval and Print' command of this extension and it will insder generated code right after the code of generator.
Example:
Write this code in your text editor
for (let i = 0; i < 10; i++) {
writeline(i);
}
Select all these lines
Run "REP.js: Eval and Print" command
Result:
for (let i = 0; i < 10; i++) {
writeline(i);
}
0;
1;
2;
3;
4;
5;
6;
7;
8;
9;
Globals
You have to functions: write
and writeline
.
write
will transform it's parameters to string and pushes them
writeline
will do the same as write
but will insert new line character after it's output.
You also can use console.log
and console.warn
and console.error
- it will be rendered as multiline comments.
Also lodash and ramda libraries are available. Use _
to get lodash and R
to get ramda.
Example:
const vars = ["Read", "Eval", "Print"];
writeline(`const ${_.camelCase(vars.join(""))} = 10`);
Will be rendered to
const readEvalPrint = 10;
Example 2:
const RC = _.template(
`
import React from 'react'
import s from './<%= name %>.module.scss'
interface I<%= name %>Props {
// TODO: Add props
}
export default function <%= name %>(props: I<%= name %>Props): JSX.Element {
return <div className={s.wrapper}>Hello</div>
}
`.trim()
);
writeline(RC({ name: "SelectionInput" }));
Will be compiled to
import React from 'react'
import s from './SelectionInput.module.scss'
interface ISelectionInputProps {
// TODO: Add props
}
export default function SelectionInput(props: ISelectionInputProps): JSX.Element {
return <div className={s.wrapper}>Hello</div>
}