Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number of matches #38

Closed
mkaragol64 opened this issue Jan 18, 2018 · 4 comments
Closed

Number of matches #38

mkaragol64 opened this issue Jan 18, 2018 · 4 comments

Comments

@mkaragol64
Copy link

mkaragol64 commented Jan 18, 2018

Hi @adamreisnz

Is it possible to get total number of matches in all files? Or number of total matches file by file? Or both?

@adamreisnz
Copy link
Owner

Hi @mkaragol64, this is not currently possible, but if someone can tame the replace method implementation in this library to report on how many replacements were made then it should be doable.

Will leave this open for PR's, as I don't have the time to look into it myself at the moment.

@jschuman
Copy link

jschuman commented Jun 8, 2018

Is this just a question of using the match method to count and accumulate the number of matches prior to calling replace? A good reference point is here.

@adamreisnz
Copy link
Owner

adamreisnz commented Jun 18, 2018

It would be yes, but I am worried if that might impact performance for large scale replacements. Perhaps it could be enabled and counted only if a flag was passed and set to true.

In addition, currently the library returns an array of files that were changed. If we need to return any other information as well, this would be a breaking change and we'd have to look at returning a result object with various properties, perhaps something like this:

const result = {
  filesChanged: [
    {file: 'foo', numMatches: 10},
    {file: 'bar', numMatches: 13},
  ],
  totalMatches: 23,
};

adamreisnz added a commit that referenced this issue Apr 20, 2019
@adamreisnz
Copy link
Owner

Implemented in 4.0.0

adamreisnz added a commit that referenced this issue Apr 21, 2019
* Bump dependencies

* [feature] #38 Count number of matches

* Update make-replacements.js

* [feature] #42 Differentiate number of matches and number of replacements

* [enhance] #56 Support for CWD parameter

* Default config value

* [enhance] #63 Add --quiet flag to supress console output in CLI

* Update success-handler.js

* Update readme and add change log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants