1.1.0 • Published 11 months ago

linemod-core v1.1.0

Weekly downloads
397
License
MIT
Repository
github
Last release
11 months ago

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

11 months ago

1.0.0

12 months ago

0.3.0

2 years ago

0.3.1

2 years ago

0.2.0

2 years ago

0.1.1

3 years ago

0.1.0

3 years ago