import fs from 'fs'

export const formats = {
  base (message) {
    const results = message.split('\n').map((line, i) => {
      if (i === 0 && line.length >= 51) throw new Error('Subject must be 50 characters or less')
      if (i === 0 && line.match(/\.$/)) throw new Error('Subject should not end with a period')
      if (i === 0 && line.length >= 51) throw new Error('Subject must be 50 characters or less')
      if (i === 1 && line.length > 0) throw new Error('Subject must be followed by a blank line')
      if (i > 1 && line.length >= 73) throw new Error('Description must be 72 characters or less')

      return true
    })

    return results.every(result => result)
  }
}

export default {
  check (format='base', file='./.git/COMMIT_EDITMSG') {
    if (!formats[format]) throw new Error('Requested format does not exist.')

    return formats[format](fs.readFileSync(file))
  }
}

@@ -148,32 +148,42 @@
 ne.length %3E= 51)
+ %7B%0A       
  throw new Error
@@ -216,32 +216,41 @@
 cters or less')%0A
+      %7D%0A%0A
       if (i === 
@@ -272,16 +272,26 @@
 (/%5C.$/))
+ %7B%0A       
  throw n
@@ -339,16 +339,25 @@
 eriod')%0A
+      %7D%0A%0A
       if
@@ -387,16 +387,26 @@
 h %3E= 51)
+ %7B%0A       
  throw n
@@ -451,24 +451,33 @@
 s or less')%0A
+      %7D%0A%0A
       if (i 
@@ -501,16 +501,26 @@
 gth %3E 0)
+ %7B%0A       
  throw n
@@ -572,16 +572,25 @@
  line')%0A
+      %7D%0A%0A
       if
@@ -618,16 +618,26 @@
 h %3E= 73)
+ %7B%0A       
  throw n
@@ -689,16 +689,24 @@
 r less')
+%0A      %7D
 %0A%0A      
@@ -873,16 +873,24 @@
 format%5D)
+ %7B%0A     
  throw n
@@ -933,16 +933,22 @@
 exist.')
+%0A    %7D
 %0A%0A    re

Break when lines are long