Socket
Socket
Sign inDemoInstall

kodemods

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kodemods

some codemods


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

kodemods

just some code mod things

usage

General usage is like this:

import {someCodemod} from 'kodemods';

/**
 * This is the api of a JSCodeshift transform.
 */
export default function(file, api) {
  const {jscodeshift} = api;
  const root = jscodeshift(file.source);

  /**
   * Use my codemods within your script like this:
   */
  const result = someCodemod(api, root, additionalArguments);
}

api docs

findClassesWithSuperClass

This is a helper that will return an array of node paths to classes that extend whatever query is given.

import {findClassesWithSuperClass} from 'kodemods';

// Finds all classes that `extend Foo`
const resultFoo = findClassesWithSuperClass(api, root, {
  type: 'Identifier',
  name: 'Foo',
});

// Finds all classes that `extend bar()`
const resultBar = findClassesWithSuperClass(api, root, {
  type: 'CallExpression',
  callee: {
    type: 'Identifier',
    name: 'bar',
  },
});

// Since we have the actual Node paths we can do things with them. This will
// remove all classes that `extend bar()`
resultBar.forEach(path => path.replace());

findNameForDefaultImport

This helper finds the name of the identifier that corresponds to a particular default import or requires. This returns a string.

import {findNameForDefaultImport} from 'kodemods';

const root = jscodeshift(`
  import bar from 'foo';
  import baz, {buz} from 'boz';
`);

findNameForDefaultImport(api, root, 'foo'); // bar
findNameForDefaultImport(api, root, 'boz'); // baz
findNameForDefaultImport(api, root, 'baz'); // undefined

The basic idea is that this will enable you to more safely track how something is used after being imported. It is now easy to identify anything using NamespaceBaseClass even though in code it is always just used as BaseClass:

const BaseClass = require('NamespaceBaseClass');

class Foo extends BaseClass {
  // ...
}

Keywords

FAQs

Package last updated on 16 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc