text: "use strict";
  
  const utils = require("./doc-utils");
  const willBreak = utils.willBreak;
  
  function assertDoc(val) {
    if (
      !(typeof val === "string" || (val != null && typeof val.type === "string"))
    ) {
      throw new Error(
        "Value " + JSON.stringify(val) + " is not a valid document"
      );
    }
  }
  
  function concat(parts) {
    parts.forEach(assertDoc);
  
    // We cannot do this until we change `printJSXElement` to not
    // access the internals of a document directly.
    // if(parts.length === 1) {
    //   // If it's a single document, no need to concat it.
    //   return parts[0];
    // }
    return { type: "concat", parts };
  }
  
  function indent(contents) {
    assertDoc(contents);
  
    return { type: "indent", contents };
  }
  
  function align(n, contents) {
    assertDoc(contents);
  
    return { type: "align", contents, n };
  }
  
  function group(contents, opts) {
    opts = opts || {};
  
    assertDoc(contents);
  
    return {
      type: "group",
      contents: contents,
      break: !!opts.shouldBreak,
      expandedStates: opts.expandedStates
    };
  }
  
  function conditionalGroup(states, opts) {
    return group(
      states[0],
      Object.assign(opts || {}, { expandedStates: states })
    );
  }
  
  function ifBreak(breakContents, flatContents) {
    if (breakContents) {
      assertDoc(breakContents);
    }
    if (flatContents) {
      assertDoc(flatContents);
    }
  
    return { type: "if-break", breakContents, flatContents };
  }
  
  function lineSuffix(contents) {
    assertDoc(contents);
    return { type: "line-suffix", contents };
  }
  
  const lineSuffixBoundary = { type: "line-suffix-boundary" };
  const breakParent = { type: "break-parent" };
  const line = { type: "line" };
  const softline = { type: "line", soft: true };
  const hardline = concat([{ type: "line", hard: true }, breakParent]);
  const literalline = concat([
    { type: "line", hard: true, literal: true },
    breakParent
  ]);
  
  function join(sep, arr) {
    var res = [];
  
    for (var i = 0; i < arr.length; i++) {
      if (i !== 0) {
        res.push(sep);
      }
  
      res.push(arr[i]);
    }
  
    return concat(res);
  }
  
  module.exports = {
    concat,
    join,
    line,
    softline,
    hardline,
    literalline,
    group,
    conditionalGroup,
    lineSuffix,
    lineSuffixBoundary,
    breakParent,
    ifBreak,
    indent,
    align
  };
  