adamreisnz / replace-in-file

A simple utility to quickly replace contents in one or more files
580 stars 65 forks source link

Add processor parameter that allows passing custom content processor(s) #142

Closed DVLP closed 2 years ago

DVLP commented 3 years ago

Instead of forking this project and creating a new one to process files I'm adding this PR to allow passing a custom processor function. When providing "processor" parameter it bypasses built-in string replacement functionality("from" and "to" parameters are ignored) to allow processing files with full flexibility of javascript in arbitrary functions.

DVLP commented 3 years ago

Unfortunately I'm too busy to publish another NPM module of my own but what I'd suggest is breaking the project into 2 i.e. process-files and the current project replace-in-file. replace-in-file can load process-files as a dependency and pass string replacement as a processor. Processors can be expanded and return an object instead of a string so counting functionality can be preserved

DVLP commented 3 years ago

Pushed fixes for the problems. The sync version was not plugged in and there were some leftovers after a refactor.

adamreisnz commented 2 years ago

Thank you, released as 6.3.0

DVLP commented 2 years ago

Thanks, great!