npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

infactor

v1.0.1

Published

A simple inline code editor

Downloads

5

Readme

  • Infactor

    [[../../actions/workflows/build.yml/badge.svg]]

    A simple inline code editor and refactoring tool to use from the command line.

** Rationale

Ever read a guide that required you to perform manual code changes to multiple source files in an unfamiliar code base? Ever seen people using sed, awk or perl for the same purpose?

Using tools like sed, awk and perl for performing minor changes may work but its hard for users to understand and geeks to maintain. Doing manual changes is error prone and is not a reproducible user experience.

This tool is an experiment to see if performing minor code changes using the CLI can improve the user experience

** Features

  • Add import
  • [[#get-line][Get line]] matching expression
  • [[#add-line][Add line]] matching expression
  • [[#remove-line][Remove line]] matching expression
  • [[#set-value][Set value]]
  • [[#append-value][Append value]] (only for arrays)

** Example usage

*** Get Line **** Usage #+BEGIN_EXAMPLE Usage: infactor get-line [options]

Get the line or number of the last (or optionally the first) line that matches the expression

Arguments: file The file to add the import to expression The regular expression to use for matching

Options: --text Flag to display the actual line instead of the number --first Flag to return the first line matching --in-class Search inside the specified class --in-method Search inside the specified function --in-function Search inside the specified function -h, --help #+END_EXAMPLE **** Examples ***** Get line The following code will get the line number of the last line matching the regular expression ^[ ]conosole.

 #+BEGIN_SRC sh
   infactor.js get-line sample.js "^[ ]*console"
 #+END_SRC

 The output should be something like: `34` close to the end of the file.

***** Get Line in class

  To limit the scode of the search inside a specific function:

  #+BEGIN_SRC sh
    infactor.js get-line sample.js "^[ ]*console" --in-class Op
  #+END_SRC

  The output should be `12` pointing the logging statemtent found inside the `Op` class.

***** Get Line in method

  #+BEGIN_SRC sh
    infactor.js get-line sample.js "^[ ]*console" --in-class Op --in-method exec
  #+END_SRC

  The output should be `12` pointing the logging statemtent found inside the `Op` class (same as above).

***** Get Line in function

  #+BEGIN_SRC sh
    infactor.js get-line sample.js "^[ ]*console" --in-function demo
  #+END_SRC

  In this case the resut should be `-1` as `demo` function contains a logging statement.

*** Add Line **** Usage

 #+BEGIN_EXAMPLE

Usage: infactor add-line [options]

Add a line at the bottom of the block

Arguments: file The file to add the import to code The code to add

Options: --out Write result to stdout instead of saving to the file --top Flag to enable adding the code at the top of the block --before The expression to match the line before which the code will be added --after The expression to match the line after which the code will be added --in-class Search inside the specified class --in-method Search inside the specified method --in-function Search inside the specified function -h, --help display help for command #+END_EXAMPLE **** Example ***** Adding code

 #+BEGIN_SRC sh
   infactor.js add-line sample.js "    console.log('Now demo is also logging!');" --in-function demo
 #+END_SRC


 #+BEGIN_SRC js
   function demo () {
       var a = 2;
       var b = 3
       new Op(a, b, sum).exec();
       new Op(a, b, mul).exec();
       console.log('Now demo is also logging!');
   }
 #+END_SRC

***** Adding code to the top of the function

  Using the `--top` flag it's now possible to add code to the top of a function, method, class etc.

  #+BEGIN_SRC sh
    infactor.js add-line sample.js "    console.log('On top!');" --in-function demo --top
  #+END_SRC


  #+BEGIN_SRC js
    function demo () {
        console.log('On top!');
        var a = 2;
        var b = 3
        new Op(a, b, sum).exec();
        new Op(a, b, mul).exec();
        console.log('Now demo is also logging!');
    }
  #+END_SRC

*** Remove Line **** Usage

 #+BEGIN_EXAMPLE

Usage: infactor remove-line [options]

Remove the line of the last (or optionally the first) line that matches the expression

Arguments: file The file to add the import to expression The regular expression to use for matching

Options: --out Write result to stdout instead of saving to the file --first Flag to return the first line matching --in-class Search inside the specified class --in-method Search inside the specified method --in-function Search inside the specified function -h, --help display help for command #+END_EXAMPLE **** Example

***** Removing a line

  Given the following code contained in the [[./sample.js]] file:

 #+BEGIN_SRC js
   function demo () {
       var a = 2;
       var b = 3;
       var array = [1, 2, 3, 4, 5];
       new Op(a, b, sum).exec();
       new Op(a, b, mul).exec();
   }
 #+END_SRC

 We shall remove the uneeded array declaration using:

 #+BEGIN_SRC sh
   infactor.js remove-line sample.js "^[ ]*var array" --in-function demo --out
 #+END_SRC

 The output should be something like:

 #+BEGIN_SRC js
   function demo () {
       var a = 2;
       var b = 3;
       new Op(a, b, sum).exec();
       new Op(a, b, mul).exec();
   }
 #+END_SRC

*** Set value To set the value of a variable you can use the set subcommand: **** Usage #+BEGIN_EXAMPLE Usage: infactor set [options]

Set the value of a variable

Arguments: file The file to add the import to variable The variable to set value The value to set

Options: --out Write result to stdout instead of saving to the file --in-class Search inside the specified class --in-method Search inside the specified method --in-function Search inside the specified function -h, --help display help for command #+END_EXAMPLE **** Examples ***** Setting the value of a var in a specific class

  #+BEGIN_SRC sh
  infactor set sample.js a "\"bar\"" --in-class Op
  #+END_SRC

***** Setting the value of a var in a specific function

  #+BEGIN_SRC sh
  infactor set sample.js a "\"bar\"" --in-function demo
  #+END_SRC

*** Append value To append the value to an array variable you can use the append subcommand: **** Usage #+BEGIN_EXAMPLE Usage: infactor append [options]

Append the value to a variable (e.g. array)

Arguments: file The file to add the import to variable The variable to append to value The value to append

Options: --out Write result to stdout instead of saving to the file --in-class Search inside the specified class --in-method Search inside the specified method --in-function Search inside the specified function --in-element Search inside the specified element (e.g. jsx etc) -h, --help display help for command #+END_EXAMPLE

**** Examples ***** Appending the value to an array

  #+BEGIN_SRC sh
  infactor set sample.js array 7 --in-class Op
  #+END_SRC