export const nGram = ( n ) => { if ( n < 1 || n === Infinity ) { throw new Error ( `${ n } is not a valid argument for n-gram` ) ; } return ( value ) => { const nGrams = [ ] ; let index = 0 ; if ( ! value ) { return nGrams ; } index = value . length - n + 1 ; if ( index < 1 ) { return nGrams ; } while ( index -- ) { nGrams [ index ] = value . slice ( index , index + n ) ; } return nGrams ; } ; } ; export const bigram = nGram ( 2 ) ; export const trigram = nGram ( 3 ) ;