@phothin/tsoptions
v0.1.2
Published
Get TypeScript compiler options from a config file, and manipulate them programmatically.
Readme
tsoptions
Get TypeScript compiler options from a config file, and manipulate them programmatically.
Install
npm i -D @phothin/tsoptionsUsage
CommonJS
const TsOptions = require('@phothin/tsoptions');
const tsoptions = new TsOptions(); // Uses tsconfig.json from project root
console.log(tsoptions.options); // Get parsed compiler options
// With custom config path
const custom = new TsOptions('path/to/tsconfig.json');
console.log(custom.options);ES Module
import TsOptions from '@phothin/tsoptions';
const tsoptions = new TsOptions();
console.log(tsoptions.options);API
Constructor
new TsOptions(configPath?)configPath(optional): Path to a TypeScript config file. If omitted, uses the roottsconfig.json.
Methods
add(opts): Add new options (only if they don’t already exist).remove(opt): Remove an option by key.overwrite(opts): Overwrite existing options with provided values.overwriteAll(opts): Replace all options with the provided object.options: Get the current compiler options.
Example
const tsoptions = new TsOptions();
tsoptions.add({ emitDeclarationOnly: true });
console.log(tsoptions.options);