Sha256: 15aed4c34b5ec1f470f793ea850ab1d299ed750ef172ea3c8c4a515c4084901b
Contents?: true
Size: 715 Bytes
Versions: 5
Compression:
Stored size: 715 Bytes
Contents
export default function guessIndent ( code ) { const lines = code.split( '\n' ); const tabbed = lines.filter( line => /^\t+/.test( line ) ); const spaced = lines.filter( line => /^ {2,}/.test( line ) ); if ( tabbed.length === 0 && spaced.length === 0 ) { return null; } // More lines tabbed than spaced? Assume tabs, and // default to tabs in the case of a tie (or nothing // to go on) if ( tabbed.length >= spaced.length ) { return '\t'; } // Otherwise, we need to guess the multiple const min = spaced.reduce( ( previous, current ) => { const numSpaces = /^ +/.exec( current )[0].length; return Math.min( numSpaces, previous ); }, Infinity ); return new Array( min + 1 ).join( ' ' ); }
Version data entries
5 entries across 5 versions & 2 rubygems