Heather, I agree that people are unnecessarily rude to you. Don't sob. Your code shows you are already a more capable programmer than most of the ones I interview. No one has given you a clear answer as to why your code is reinventing the wheel, so allow me to do it politely. I took every single example from your README, and show you below how everything can be reimplemented with sed -r (nice extended regex syntax, mostly like js regexs), and find/xargs:<p><pre><code> replace 'var' 'let' *
sed -ri 's,var,let,g' *
replace 'var' 'let' . -r
find . -type f -print0 | xargs -0 sed -ri 's,var,let,g'
replace 'var' 'let' test/file1.js test/file2.js
sed -ri 's,var,let,g' test/file1.js test/file2.js
replace '(\w+)_(\w+)' '$1-$2' *
sed -ri 's,(\w+)_(\w+),\1-\2,g' *
replace 'var' 'let' . -r --include="*.js"
find . -type f -name '*.js' -print0 | xargs -0 sed -ri 's,var,let,g'
replace 'var' 'let' . -r --exclude="*.min.js,*.py"
find . -type f ! -name '*.min.js' ! -name '*.py' -print0 | xargs -0 sed -ri 's,var,let,g'
replace 'var' 'let' . -r --preview
find . -type f -exec sh -c "echo == {}; sed -r 's,var,let,g' {}" \;
(not sure if --preview does exactly that, I echo the filename followed by the modified content)
</code></pre>
There is only one case that justifies reimplementing things: if your tool has the requirement of supporting the <i>exact</i> js regex syntax, then yes you did the right thing to reimplement this in js. I have run into similar situations myself. One time I had to support Perl regexs, and I started by simply using Python's standard regex module, thinking that it would work because both Perl and Python use PCRE. Well as it turned out the regexs I encountered used some advanced features (such as negative/postive look-behind/look-ahead, etc) that Python's regex module plainly did not suppport. So I ended up rewriting part of my implementation in Perl.<p>Edit: I spoke too fast. As a commenter pointed out, other legitimate cases for reimplementing this in js would be when you can't afford to or don't want to fork a process to run find/xargs/sed. It sounds like you were running the tool from the command line, so I didn't think that would be your situation.<p>Edit 2: Yes, the exercise of reinventing the wheel is also useful for learning... I am not going to argue that.<p>Edit 3: If you care about <i>simplicity</i>, I would personally rather write a small shell script wrapping find/xargs/sed and hiding their arcane options, as opposed to writing 173 lines of js.