index.js
function syllable(value) {
  var count = 0
  var index
  var length
  var singular
  var parts
  var addOne
  var subtractOne

  if (value.length === 0) {
    return count
  }

  // Return early when possible.
  if (value.length < 3) {
    return 1
  }

  // If `value` is a hard to count, it might be in `problematic`.
  if (own.call(problematic, value)) {
    return problematic[value]
  }

  // Additionally, the singular word might be in `problematic`.
  singular = pluralize(value, 1)

  if (own.call(problematic, singular)) {
    return problematic[singular]
  }

  addOne = returnFactory(1)
  subtractOne = returnFactory(-1)

  // Count some prefixes and suffixes, and remove their matched ranges.
  value = value
    .replace(EXPRESSION_TRIPLE, countFactory(3))
    .replace(EXPRESSION_DOUBLE, countFactory(2))
    .replace(EXPRESSION_SINGLE, countFactory(1))

  // Count multiple consonants.
  parts = value.split(/[^aeiouy]+/)
  index = -1
  length = parts.length

  while (++index < length) {
    if (parts[index] !== '') {
      count++
    }
  }

  // Subtract one for occurrences which should be counted as one (but are
  // counted as two).
  value
    .replace(EXPRESSION_MONOSYLLABIC_ONE, subtractOne)
    .replace(EXPRESSION_MONOSYLLABIC_TWO, subtractOne)

  // Add one for occurrences which should be counted as two (but are counted as
  // one).
  value
    .replace(EXPRESSION_DOUBLE_SYLLABIC_ONE, addOne)
    .replace(EXPRESSION_DOUBLE_SYLLABIC_TWO, addOne)
    .replace(EXPRESSION_DOUBLE_SYLLABIC_THREE, addOne)
    .replace(EXPRESSION_DOUBLE_SYLLABIC_FOUR, addOne)

  // Make sure at least on is returned.
  return count || 1

  // Define scoped counters, to be used in `String#replace()` calls.
  // The scoped counter removes the matched value from the input.
  function countFactory(addition) {
    return counter
    function counter() {
      count += addition
      return ''
    }
  }

  // Define scoped counters, to be used in `String#replace()` calls.
  // The scoped counter does not remove the matched value from the input.
  function returnFactory(addition) {
    return returner
    function returner($0) {
      count += addition
      return $0
    }
  }
}
function syllable(value) {
  var count = 0
  var index
  var length
  var singular
  var parts
  var addOne
  var subtractOne

  if (value.length === 0) {
    return count
  }

  // Return early when possible.
  if (value.length < 3) {
    return 1
  }

  // If `value` is a hard to count, it might be in `problematic`.
  if (own.call(problematic, value)) {
    return problematic[value]
  }

  // Additionally, the singular word might be in `problematic`.
  singular = pluralize(value, 1)

  if (own.call(problematic, singular)) {
    return problematic[singular]
  }

  addOne = returnFactory(1)
  subtractOne = returnFactory(-1)

  // Count some prefixes and suffixes, and remove their matched ranges.
  value = value
    .replace(EXPRESSION_TRIPLE, countFactory(3))
    .replace(EXPRESSION_DOUBLE, countFactory(2))
    .replace(EXPRESSION_SINGLE, countFactory(1))

  // Count multiple consonants.
  parts = value.split(/[^aeiouy]+/)
  index = -1
  length = parts.length

  while (++index < length) {
    if (parts[index] !== '') {
      count++
    }
  }

  // Subtract one for occurrences which should be counted as one (but are
  // counted as two).
  value
    .replace(EXPRESSION_MONOSYLLABIC_ONE, subtractOne)
    .replace(EXPRESSION_MONOSYLLABIC_TWO, subtractOne)

  // Add one for occurrences which should be counted as two (but are counted as
  // one).
  value
    .replace(EXPRESSION_DOUBLE_SYLLABIC_ONE, addOne)
    .replace(EXPRESSION_DOUBLE_SYLLABIC_TWO, addOne)
    .replace(EXPRESSION_DOUBLE_SYLLABIC_THREE, addOne)
    .replace(EXPRESSION_DOUBLE_SYLLABIC_FOUR, addOne)

  // Make sure at least on is returned.
  return count || 1

  // Define scoped counters, to be used in `String#replace()` calls.
  // The scoped counter removes the matched value from the input.
  function countFactory(addition) {
    return counter
    function counter() {
      count += addition
      return ''
    }
  }

  // Define scoped counters, to be used in `String#replace()` calls.
  // The scoped counter does not remove the matched value from the input.
  function returnFactory(addition) {
    return returner
    function returner($0) {
      count += addition
      return $0
    }
  }
}
function syllable ( value ) { var count = 0 var index var length var singular var parts var addOne var subtractOne if ( value . length === 0 ) { return count } // Return early when possible. if ( value . length < 3 ) { return 1 } // If `value` is a hard to count, it might be in `problematic`. if ( own . call ( problematic , value ) ) { return problematic [ value ] } // Additionally, the singular word might be in `problematic`. singular = pluralize ( value , 1 ) if ( own . call ( problematic , singular ) ) { return problematic [ singular ] } addOne = returnFactory ( 1 ) subtractOne = returnFactory ( - 1 ) // Count some prefixes and suffixes, and remove their matched ranges. value = value . replace ( EXPRESSION_TRIPLE , countFactory ( 3 ) ) . replace ( EXPRESSION_DOUBLE , countFactory ( 2 ) ) . replace ( EXPRESSION_SINGLE , countFactory ( 1 ) ) // Count multiple consonants. parts = value . split ( / [^aeiouy]+ / ) index = - 1 length = parts . length while ( ++ index < length ) { if ( parts [ index ] !== '' ) { count ++ } } // Subtract one for occurrences which should be counted as one (but are // counted as two). value . replace ( EXPRESSION_MONOSYLLABIC_ONE , subtractOne ) . replace ( EXPRESSION_MONOSYLLABIC_TWO , subtractOne ) // Add one for occurrences which should be counted as two (but are counted as // one). value . replace ( EXPRESSION_DOUBLE_SYLLABIC_ONE , addOne ) . replace ( EXPRESSION_DOUBLE_SYLLABIC_TWO , addOne ) . replace ( EXPRESSION_DOUBLE_SYLLABIC_THREE , addOne ) . replace ( EXPRESSION_DOUBLE_SYLLABIC_FOUR , addOne ) // Make sure at least on is returned. return count || 1 // Define scoped counters, to be used in `String#replace()` calls. // The scoped counter removes the matched value from the input. function countFactory ( addition ) { return counter function counter ( ) { count += addition return '' } } // Define scoped counters, to be used in `String#replace()` calls. // The scoped counter does not remove the matched value from the input. function returnFactory ( addition ) { return returner function returner ( $0 ) { count += addition return $0 } } }
Get syllables in a given value.
Get syllables in a given value .