UNPKG

@navikt/aksel

Version:

Aksel command line interface. Codemods and other utilities for Aksel users.

20 lines (19 loc) 945 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getImportSpecifier = getImportSpecifier; exports.renameImportSpecifier = renameImportSpecifier; exports.getImportSpecifierName = getImportSpecifierName; function getImportSpecifier(j, source, specifier, sourcePath) { return source .find(j.ImportDeclaration) .filter((path) => path.node.source.value === sourcePath) .find(j.ImportSpecifier) .filter((path) => path.value.imported.name === specifier); } function renameImportSpecifier(j, source, specifier, newSpecifier, sourcePath) { getImportSpecifier(j, source, specifier, sourcePath).replaceWith(j.importSpecifier(j.identifier(newSpecifier))); } function getImportSpecifierName(j, source, specifier, sourcePath) { const specifiers = getImportSpecifier(j, source, specifier, sourcePath); return specifiers.length > 0 ? specifiers.nodes()[0].local.name : null; }