Giter Club home page Giter Club logo

find-dup-values's Introduction

This project recursively navigates a file tree and searches inside files for repeated strings and numbers. This can be useful to find values that should be moved to a constants file. It can be run from the command line, in which case it prints out the list of values as well as the files they were found in. It can also be used as a node.js module so you can handle the results yourself.

Processing all 1.23mloc of JavaScript in Node.js (including lib, tests, benchmarks, all dependencies like v8 and npm as well as their tests) takes approx 4 seconds on a mid-range processor. Most projects will take less than half a second to process.

CLI Usage:

Setup:

  • Clone or download, then navigate to the project directory
  • npm install

Run:

npm run start -- [options]
-p | --path         Path to file or directory to start at
-e | --extensions   Comma-separated list of file extensions to read from
-i | --ignore       Comma-separated list of file/dir names to ignore, compatible with globs
-m | --min          Minimum number of times a value must be repeated to be included
-c | --config       Path to config file which exports the above values

Note:

  • Bold options are required
  • If a config file is provided as well as other CLI arguments, the CLI arguments take precedence
  • For an example of how a config file should be formatted, see the config object in the module example below

Module Usage:

Setup:

  • npm install https://github.com/qualitymanifest/find-dup-values/tarball/master

Run:

const fdv = require("find-dup-values");

const config = {
  path: "../path/to/project", // required
  extensions: [".js", ".jsx", ".ts", ".tsx"], // required
  ignore: [".someDir", "someFile.js", "*test*", "*spec.js"],
  min: 3
};

fdv(config)
  .then(valueJSON => {
    // valueJSON contains a `values` key, which is an array containing the following value objects
    // sorted in ascending order by the total number of occurrences
    valueJSON.values.forEach(value => {
      console.log(value.data); // the string/number value
      console.log(value.total); // the total number of times it was found across the project
      for (let [path, amount] of Object.entries(value.paths)) {
        console.log(`${path}: ${amount}`); // file path and number of occurrences at that path
      }
    });
  })
  .catch(err => /* handle err */);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.