import { toString } from '../util/toString.ts';

/**
 * Splits the input string by the specified `separator`
 * and returns a new array containing the split segments.
 *
 * @param [string=''] The string to split.
 * @param [separator] The separator pattern to split by.
 * @param [limit] The length to truncate results to.
 * @returns Returns the string segments.
 *
 * @example
 * split('a-b-c', '-');
 * // => ['a', 'b', 'c']
 *
 * split('a-b-c', '-', 2);
 * // => ['a', 'b']
 */
export function split(string: string | null | undefined, separator?: RegExp | string, limit?: number): string[];

/**
 * Splits the input string by the specified `separator`
 * and returns a new array containing the split segments.
 *
 * @param [string=''] The string to split.
 * @param [separator] The separator pattern to split by.
 * @param [limit] The length to truncate results to.
 * @returns Returns the string segments.
 *
 * @example
 * split('a-b-c', '-');
 * // => ['a', 'b', 'c']
 *
 * split('a-b-c', '-', 2);
 * // => ['a', 'b']
 */
export function split(string: string | null | undefined, index: string | number, guard: object): string[];

export function split(string: any, separator?: any, limit?: any): string[] {
  return toString(string).split(separator as string, limit);
}
