UNPKG

sat-utils

Version:
68 lines (67 loc) 3.21 kB
type IOptions = { numbers?: boolean; letters?: boolean; lettersAndNumbers?: boolean; symbols?: boolean; lettersNumbersAndSymbols?: boolean; lowerCase?: boolean; }; /** * Get a random substring of a given string. * * @param {string} str - The input string. * @param {number} length - The length of the random substring. * @returns {string} The random substring. * @throws {TypeError} If the input arguments are not of the expected types. */ declare function getRandomSubString(str: any, length: any): string; /** * Options for generating a random string. * * @typedef {Object} IOptions * @property {boolean} [numbers] - Include numbers. * @property {boolean} [letters] - Include letters. * @property {boolean} [lettersAndNumbers] - Include letters and numbers. * @property {boolean} [symbols] - Include symbols. * @property {boolean} [lettersNumbersAndSymbols] - Include letters, numbers, and symbols. * @property {boolean} [lowerCase] - Convert the result to lowercase. */ /** * Get a random string of a specified length and options. * * @param {number} length - The length of the random string. * @param {IOptions} [opts] - Options for generating the random string. * @returns {string} The random string. * @throws {TypeError} If the input arguments are not of the expected types. */ declare function getRandomString(length: any, opts?: IOptions): string; /** * Get a random item from an array or an array of random items. * * @param {T[]} itemsList - The array of items. * @param {number} [quaintity] - The quantity of random items to get. * @returns {T|T[]} A random item or an array of random items. * @throws {TypeError} If the input arguments are not of the expected types. * @throws {RangeError} If the input arguments are out of range or invalid. */ declare function getRandomArrayItem<T>(t: T[]): T; declare function getRandomArrayItem<T>(t: T[], quaintity: number): T[]; /** * Retrieves unique items from the given array based on specified fields. * @template T - The type of items in the array. * @param {T[]} itemsList - The array of items to be processed. * @param {symbol | string | string[]} [uniqByFields] - Optional. The field(s) based on which uniqueness is determined. * @returns {T[]} The array containing unique items based on the specified fields. * @throws {TypeError} If the first argument is not an array. */ declare function getUniqItems<T>(itemsList: T[], uniqByFields?: symbol | string | string[] | ((currentItems: T[], initalArrItem: any) => boolean)): T[]; /** * Retrieves unique items from the given array based on specified fields. * @template T - The type of items in the array. * @param {T[]} itemsList - The array of items to be processed. * @param {symbol | string | string[]} [uniqByFields] - Optional. The field(s) based on which uniqueness is determined. * @returns {T[]} The array containing unique items based on the specified fields. * @throws {TypeError} If the first argument is not an array. */ declare function getNotUniqItems<T>(itemsList: T[], uniqByFields?: symbol | string | string[]): T[]; export { getRandomString, getRandomSubString, getRandomArrayItem, getUniqItems, getNotUniqItems };