2021-04-14 16:52:15 +00:00
|
|
|
const DEFAULT_RESULTS_NAME = "results";
|
2021-04-04 12:45:24 +00:00
|
|
|
|
2021-04-14 16:52:15 +00:00
|
|
|
const generateResultsCountText = (
|
|
|
|
name: string = DEFAULT_RESULTS_NAME,
|
|
|
|
pageIndex: number,
|
|
|
|
pageSize: number,
|
2021-10-11 17:27:14 +00:00
|
|
|
resultsCount: number,
|
|
|
|
filteredCount?: number
|
2021-06-10 14:00:03 +00:00
|
|
|
): string => {
|
2021-04-09 10:44:57 +00:00
|
|
|
if (resultsCount === 0) return `No ${name}`;
|
2021-07-26 17:01:58 +00:00
|
|
|
// If there is 1 result and the last 3 letters in the result
|
|
|
|
// name are "ies," we remove the "ies" and add "y"
|
|
|
|
// to make the name singular
|
|
|
|
if (resultsCount === 1 && name.slice(-3) === "ies") {
|
|
|
|
return `${resultsCount} ${name.slice(0, -3)}y`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is 1 result and the last 2 letters in the result
|
|
|
|
// name are "es," we remove the "es" to make the name singular
|
|
|
|
if (resultsCount === 1 && name.slice(-2) === "es") {
|
|
|
|
return `${resultsCount} ${name.slice(0, -2)}y`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is 1 result and the last letter in the result
|
|
|
|
// name is "s," we remove the "s" to make the name singular
|
|
|
|
if (resultsCount === 1 && name[name.length - 1] === "s") {
|
|
|
|
return `${resultsCount} ${name.slice(0, -1)}`;
|
|
|
|
}
|
2021-04-09 10:44:57 +00:00
|
|
|
|
2021-10-11 17:27:14 +00:00
|
|
|
// If there is no filtered count, return pageSize+ name
|
|
|
|
if (pageSize === resultsCount && !filteredCount)
|
|
|
|
return `${pageSize}+ ${name}`;
|
|
|
|
if (pageIndex !== 0 && resultsCount <= pageSize && !filteredCount)
|
2021-04-14 16:52:15 +00:00
|
|
|
return `${pageSize}+ ${name}`;
|
2021-04-04 12:45:24 +00:00
|
|
|
return `${resultsCount} ${name}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default { generateResultsCountText };
|