(lit: string, addParens = true, fallback = "")
| 787 | * @since 4.0.0 |
| 788 | */ |
| 789 | export function join(lit: string, addParens = true, fallback = "") { |
| 790 | const literalStatement = literal(lit) |
| 791 | const fallbackFragment = fragment([literal(fallback)]) |
| 792 | |
| 793 | return (clauses: ReadonlyArray<string | Fragment>): Fragment => { |
| 794 | if (clauses.length === 0) { |
| 795 | return fallbackFragment |
| 796 | } else if (clauses.length === 1) { |
| 797 | return fragment(convertLiteralOrFragment(clauses[0])) |
| 798 | } |
| 799 | |
| 800 | const segments: Array<Segment> = [] |
| 801 | |
| 802 | if (addParens) { |
| 803 | segments.push(literal("(")) |
| 804 | } |
| 805 | |
| 806 | segments.push.apply(segments, convertLiteralOrFragment(clauses[0])) |
| 807 | |
| 808 | for (let i = 1; i < clauses.length; i++) { |
| 809 | segments.push(literalStatement) |
| 810 | segments.push.apply(segments, convertLiteralOrFragment(clauses[i])) |
| 811 | } |
| 812 | |
| 813 | if (addParens) { |
| 814 | segments.push(literal(")")) |
| 815 | } |
| 816 | |
| 817 | return fragment(segments) |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | /** |
| 822 | * Combines clauses with `AND`, parenthesizing multiple clauses and returning |
no test coverage detected