{"size": 1257, "ext": "js", "max_stars_repo_path": "node_modules/parse-latin/lib/plugin/merge-initial-lower-case-letter-sentences.js", "max_stars_repo_name": "ericdmoore/remark-rehype", "max_stars_repo_stars_event_min_datetime": "2015-01-05T09:26:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-23T04:34:22.000Z", "max_issues_repo_path": "node_modules/parse-latin/lib/plugin/merge-initial-lower-case-letter-sentences.js", "max_issues_repo_name": "ericdmoore/remark-rehype", "max_issues_repo_issues_event_min_datetime": "2016-06-29T22:15:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-30T17:49:40.000Z", "max_forks_repo_path": "node_modules/parse-latin/lib/plugin/merge-initial-lower-case-letter-sentences.js", "max_forks_repo_name": "ericdmoore/remark-rehype", "max_forks_repo_forks_event_min_datetime": "2015-01-05T12:04:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-23T07:43:17.000Z"}
{"max_stars_count": 34, "max_issues_count": 6, "max_forks_count": 8, "avg_line_length": 23.2777777778, "max_line_length": 79, "alphanum_fraction": 0.6284805091}
import toString from 'nlcst-to-string'
import modifyChildren from 'unist-util-modify-children'

// Initial lowercase letter.
import {lowerInitial} from '../expressions.js'

// Merge a sentence into its previous sentence, when the sentence starts with a
// lower case letter.
export var mergeInitialLowerCaseLetterSentences = modifyChildren(function (
  child,
  index,
  parent
) {
  var children = child.children
  var position
  var node
  var siblings
  var previous

  if (children && children.length > 0 && index > 0) {
    position = -1

    while (children[++position]) {
      node = children[position]

      if (node.type === 'WordNode') {
        if (!lowerInitial.test(toString(node))) {
          return
        }

        siblings = parent.children

        previous = siblings[index - 1]

        previous.children = previous.children.concat(children)

        siblings.splice(index, 1)

        // Update position.
        if (previous.position && child.position) {
          previous.position.end = child.position.end
        }

        // Next, iterate over the node *now* at the current position.
        return index
      }

      if (node.type === 'SymbolNode' || node.type === 'PunctuationNode') {
        return
      }
    }
  }
})
