linemod-core
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Linemod Core

Comment driven line modifications

npm version npm downloads Module type: ESM Types in JS js-semistandard-style Follow @voxpelli

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 = () => {};

Readme

Keywords

none

Package Sidebar

Install

npm i linemod-core

Weekly Downloads

15

Version

1.1.0

License

MIT

Unpacked Size

9.09 kB

Total Files

9

Last publish

Collaborators

  • voxpelli