adamreisnz / replace-in-file

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

.doc file support #174

Closed waltergpc closed 8 months ago

waltergpc commented 10 months ago

I want to know if this library has functionality with .doc and .docx files. I am trying to do a basic example with the options given in the README, but the changed flag of the file is false at the end. the path to file will be just a placeholder to show as example how it is being used

pathName = 'path/to/file/file.docx'

const options = {
    files: pathName,
    from: /case/g,
    to: 'testing'
}

Replacement results: [
  {
    file: 'path/to/file/file.docx',
    hasChanged: false
  }
]
adamreisnz commented 8 months ago

Doc files I believe are a proprietary microsoft format, and I am not familiar with how the contents in them are stored. I think Docx is an open format and might be text readable. However, it is beyond the scope of this library to parse those files if needed, as it is mainly intended for plain text.

You can consider using a custom processor though if you need to pre-parse the contents that is fed into the library:

https://github.com/adamreisnz/replace-in-file?tab=readme-ov-file#specify-glob-configuration