@technobuddha/library
Version:
A large library of useful functions
42 lines (41 loc) • 1.16 kB
TypeScript
/**
* Options for creating a coordinated list with {@link conjoin}
* @group Array
* @category Operations
*/
export type ConjoinOptions = {
/**
* Conjunction to insert in the last position
* @defaultValue 'and'
*/
conjunction?: string;
/**
* If true, use the oxford comma
* @defaultValue true
*/
oxford?: boolean;
/**
* String used to separate values
* @defaultValue ','
*/
separator?: string;
};
/**
* Create a list from an array, separating values and inserting a conjunction
* @param input - Array of values
* @param options - see {@link ConjoinOptions}
* @example
* ```typescript
* const stooges = ['Larry', 'Moe', 'Curly'];
* conjoin(stooges);
* // 'Larry, Moe, and Curly'
* ```
* ```typescript
* const amigos = ['Lucky Day', 'Dusty Bottoms', 'Ned Nederlander'];
* conjoin(amigos, { conjunction: 'or', oxford: false, separator: ';' });
* // 'Lucky Day; Dusty Bottoms or Ned Nederlander'
* ```
* @group Array
* @category Operations
*/
export declare function conjoin<T = unknown>(input: ArrayLike<T>, { conjunction, oxford, separator }?: ConjoinOptions): string;