should-print-patch.js 511 B

123456789101112131415161718192021
  1. const { basename, extname } = require('path')
  2. const binaryExtensions = require('binary-extensions')
  3. // we should try to print patches as long as the
  4. // extension is not identified as binary files
  5. const shouldPrintPatch = (path, opts = {}) => {
  6. if (opts.diffText)
  7. return true
  8. const filename = basename(path)
  9. const extension = (
  10. filename.startsWith('.')
  11. ? filename
  12. : extname(filename)
  13. ).substr(1)
  14. return !binaryExtensions.includes(extension)
  15. }
  16. module.exports = shouldPrintPatch