Fluent Node library for generating code blocks.
npm install codewriterStringBuilder's or StringWriter's in other languages. Instead of using string concatenation to build the generated code, CodeWriter adds support for code-specific concepts like indentation and language-specific comments.
sh
npm install --save-dev codewriter
`
Usage
$3
`js
const CodeWriter = require('codewriter');
const options = { indentSize: 4 };
const writer = new CodeWriter(options);
// Use CodeWriter methods to build the code
const code = writer.toCode();
`
$3
CodeWriter ships with a Typescript definition file, which provides strong-typing and compile-time support.
`ts
import { CodeWriter, CodeWriterOptions } from 'codewriter';
const options: CodeWriterOptions = { indentSize: 4 };
const writer = new CodeWriter(options);
// Use CodeWriter methods to build the code
const code: string = writer.toCode();
`
Options
CodeWriter allows some options to be specified in the constructor to customize how the code is generated.
Options reference
Sample options for generating JavaScript code
Through the OptionsLibrary class, CodeWriter also provides predefined options for certain common languages and language families.
Examples
Generate empty C# console program
API reference
JSDoc Documentation
You can view the source code comments directly from GitHub.
If you are using Typescript, you can install the package locally to get code completion support from supported IDE's and editors.
Building the code
`sh
Clone repo from GitHub
git clone https://github.com/JeevanJames/codewriter.git .
Install dependencies
npm install
Build code
npm run build
Continuously watch for code changes and build
npm run watch
Lint code
npm run lint
The codebase has a test-harness directory that contains an index.ts file.
You can update this file to quickly test code against the framework.
To run the test-harness, run the following command:
npm run test-harness
``