(lit: string, addParens = true, fallback = "")
| 653 | * @since 4.0.0 |
| 654 | */ |
| 655 | export function join(lit: string, addParens = true, fallback = "") { |
| 656 | const literalStatement = literal(lit) |
| 657 | const fallbackFragment = fragment([literal(fallback)]) |
| 658 | |
| 659 | return (clauses: ReadonlyArray<string | Fragment>): Fragment => { |
| 660 | if (clauses.length === 0) { |
| 661 | return fallbackFragment |
| 662 | } else if (clauses.length === 1) { |
| 663 | return fragment(convertLiteralOrFragment(clauses[0])) |
| 664 | } |
| 665 | |
| 666 | const segments: Array<Segment> = [] |
| 667 | |
| 668 | if (addParens) { |
| 669 | segments.push(literal("(")) |
| 670 | } |
| 671 | |
| 672 | segments.push.apply(segments, convertLiteralOrFragment(clauses[0])) |
| 673 | |
| 674 | for (let i = 1; i < clauses.length; i++) { |
| 675 | segments.push(literalStatement) |
| 676 | segments.push.apply(segments, convertLiteralOrFragment(clauses[i])) |
| 677 | } |
| 678 | |
| 679 | if (addParens) { |
| 680 | segments.push(literal(")")) |
| 681 | } |
| 682 | |
| 683 | return fragment(segments) |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * Combines clauses with `AND`, parenthesizing multiple clauses and returning |
no test coverage detected