0.2.0-beta.0 • Published 7 years ago

tractor-js-file-transformer v0.2.0-beta.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

tractor-js-file-transformer

A bunch of AST manipulation utilities for tractor.

Greenkeeper badge npm version Coveralls

API:

transformIdentifiers:

Renames an identifier within an AST

Arguments:

  • file:JavaScriptFile - The JavaScript file to manipulate
  • oldName: string - the name of the identifiers that you want to change
  • newName: string - the new name for the identifiers
  • contextName?: string - a context for selecting the elements, which should be a esquery query

Usage:

import { transformIdentifiers } from 'tractor-js-file-transformer';

// Replace all instances of foo with bar transformIdentifiers(file, 'foo', 'bar');

// Replace all instances of var foo with var bar transformIdentifiers(file, 'foo', 'bar', 'VariableDeclarator');

transformMetadata:

Renames an metadata object stored in the first comment of a JS file

Arguments:

  • file:JavaScriptFile - The JavaScript file to manipulate
  • oldName: string - the name of the identifiers that you want to change
  • newName: string - the new name for the identifiers
  • type?: string - the type of the metadata object

Usage:

import { transformMetadata } from 'tractor-js-file-transformer';

// Changes metadata comment from // / { "name": "foo" } / // to // / { "name": "bar" } / transformMetadata(file, 'foo', 'bar');

// Changes metadata comment from // / { "items": { "name": "foo" }, { "name": "baz" } } / // to // / { "items": { "name": "bar" }, { "name": "baz" } } / transformMetadata(file, 'foo', 'bar', 'items');

transformRequirePaths:

Updates the path in a require call when a file moves.

Arguments:

Usage:

import { transformRequirePaths } from 'tractor-js-file-transformer';

// Replace // require('../../../that/goes/to/another/file') // with // require('../../../that/goes/to/a/new/file') transformRequirePaths(file, { fromPath: '/some/path/to/a/file', oldToPath: '/some/path/that/goes/to/another/file', newToPath: '/some/path/that/goes/to/a/new/file' });

Interfaces:

TransformRequireOptions:

interface TransformRequireOptions {
    oldFromPath?: string;
    newFromPath?: string;
    fromPath?: string;
    oldToPath?: string;
    newToPath?: string;
    toPath?: string;
}
0.2.0-beta.0

7 years ago

0.1.1

7 years ago

0.1.1-beta.1

7 years ago

0.1.1-beta.0

7 years ago

0.1.0

7 years ago

0.1.0-beta.5

7 years ago

0.1.0-beta.4

7 years ago

0.1.0-beta.3

7 years ago

0.1.0-beta.2

7 years ago

0.1.0-beta.1

7 years ago

0.1.0-beta.0

7 years ago