UNPKG

@technobuddha/library

Version:
21 lines (20 loc) 772 B
import toString from 'lodash/toString'; import { space, empty } from '../constants'; /** * Create a string from an array, separating values and inserting a conjunction * * @param input Array of values * @param __namedParameters see {@link Options} */ export function coordinate(input, { conjunction = 'and', oxford = true, separator = ',' } = {}) { if (input.length > 0) { let text = toString(input[0]); for (let i = 1; i < input.length - 1; i++) text += separator + space + toString(input[i]); if (input.length > 1) text += (oxford && input.length > 2 ? separator : empty) + space + conjunction + space + toString(input[input.length - 1]); return text; } return empty; } export default coordinate;