linemod-core
v2.0.2
Published
Comment driven line modifications
Downloads
316
Readme
Linemod Core
Comment driven line modifications
Usage
import { linemod } from 'linemod-core';
import pathModule from 'node:path';
await linemod(
[pathModule.resolve(__dirname, 'index.js')],
{ outputExtension: '.mjs' }
);
In CommonJS using available import()
expression
const { linemod } = await import('linemod-core');
API
linemod(paths, { outputExtension }) => Promise<void>
Takes an array of string file paths (paths
), applies modifications to them and outputs them to the same destination with the specified extension (outputExtension
)
linemodFile(path, { outputExtension }) => Promise<void>
Same as linemod()
, but takes a single string file path (path
) rather than an array.
linemodApply(content) => string
Applies any modifications on the string input (content
) and returns back the resulting string.
Available modifications
Linemods are added at the end of the line they are supposed to apply to.
linemod-add:
Prefixes the line with whatever is specified after the keyword:
// linemod-add: import escape from 'stringify-entities';
Becomes:
import escape from 'stringify-entities';
linemod-prefix-with:
Prefixes the line with whatever is specified after the keyword:
const exportedMethod = () => {}; // linemod-prefix-with: export
Becomes:
export const exportedMethod = () => {};
linemod-replace-with:
Replaces the line with whatever is specified after the keyword:
const escape = require('stringify-entities'); // linemod-replace-with: import escape from 'stringify-entities';
Becomes:
import escape from 'stringify-entities';
linemod-remove
Simply removes the entire line.
Quite useful when combined with linemod-prefix-with
:
const exportedMethod = () => {}; // linemod-prefix-with: export
module.exports = { exportedMethod }; // linemod-remove
Becomes:
export const exportedMethod = () => {};