function transform(file, { j }) {
const ast = j(file.source);
const leftPadImport = ast.find(j.ImportDeclaration, {
source: { value: 'left-pad' }
});
const leftPadLocalName = '';
leftPadImport.remove();
ast
.find(j.CallExpression, { callee: { name: leftPadLocalName } })
.forEach(callPath => {
const args = callPath.node.arguments;
if (args.length >= 2) {
const stringArg = args[0];
const targetLength = args[1];
const padString = args.length > 2 ? args[2] : j.literal(' ');
j(callPath).replaceWith(
j.callExpression(
j.memberExpression(stringArg, j.identifier('padStart')),
[targetLength, padString]
)
);
}
});
return ast.toSource();
}
export default transform;