@akadenia/helpers
Version:
Akadenia helpers
175 lines (174 loc) • 6.93 kB
TypeScript
/**
*
* @function
* @param {T} input - The string, object, or array of objects that needs to have its casing changed
* @param {"toSnakeCase" | "toCamelCase"} type - The type of casing the string, object, or array of objects should be converted to (snake_case or camelCase)
* @returns {T} - A new string, object, or array of objects in the specified casing
*/
export declare const convertKeyCasing: <T extends string | Object | Array<Object>>(input: T, type: "toSnakeCase" | "toCamelCase") => T;
/**
*
* @function
* @returns {string} - A randomly generated string.
*/
export declare const uuidv4: () => string;
/**
*
* @function
* @param {number} position - A position number.
* @returns {string} - A string representing the position with the appropriate suffix (st, nd, rd, or th) e.g "1st", "2nd", "3rd", "4th", etc.
*/
export declare const formatPosition: (position: number) => string;
/**
*
* @function
* @param {string} text - The text to be truncated
* @param {number} characterLimit - The maximum number of characters that the text can have
* @returns {string} - The truncated text with "..." added at the end if the text has exceeded the character limit
*/
export declare const truncateText: (text: string, characterLimit: number) => string;
/**
*
* @function
* @param {string} path - The path of the file
* @returns {string} - The file name
*/
export declare const fileNameFromPath: (path: string) => string;
/**
*
* @function
* @param {string} s - The string that needs to have spaces replaced with underscores
* @returns {string} - The string with spaces replaced with underscores
*/
export declare const replaceSpacesWithUnderscore: (s?: string) => string;
/**
*
* @function
* @param {string} s - The string that needs to have underscores replaced with spaces
* @returns {string} - The string with underscores replaced with spaces
*/
export declare const replaceUnderscoreWithSpaces: (s?: string) => string;
/**
*
* @function
* @param {string} word - The word that needs to be pluralized
* @param {boolean} condition - The condition that determines if the word needs to be pluralized
* @returns {string} - The word with "s" added to the end if the condition is true
*/
export declare const pluralizeOnCondition: (word: string, condition: boolean) => string;
/**
* @function
* @param {Object | Array<Object> | string} data - The object or array of objects to convert key cases
* @returns {Object | Array<Object> | string} - The object or array of objects with the keys in camelCase
*/
export declare const convertSnakeToCamelCase: (data: string | Object | Array<Object>) => string | Object | Object[];
/**
* @function
* @param {Object | Array<Object> | string} data - The object or array of objects to convert key cases
* @returns {Object | Array<Object> | string} - The object or array of objects with the keys in snake_case
*/
export declare const convertCamelToSnakeCase: (data: string | Object | Array<Object>) => string | Object | Object[];
/**
* Convert camel case to kebab case
* @function
* @param {string} word - The word needed to be converted to kebab case from camel case
* @returns {string} - The word returned as kebab case
*/
export declare function convertCamelToKebabCase(word: string): string;
/**
* Convert kebab case to camel case
* @function
* @param {string} word - The word needed to be converted from kebab case to camel case
* @returns {string} - The word returned as camel case
*/
export declare function convertKebabToCamelCase(word: string): string;
/**
* Generate acronym from text
* @param term term to be converted to an acronym
* @returns an acronym generated from the term
*/
export declare function generateAcronym(term: string): string;
/**
* Validate if a word is acronym
* @function
* @param {string} word - The word that is being validated as acronym
* @returns {string} - The boolean value when the condition is met
*/
export declare function isAcronym(word: string): boolean;
/**
* Convert acronym to kebab case
* @function
* @param {string} word - The acronym to be converted to kebab case
* @returns {string} - The word returned as camel case
*/
export declare function acronymToKebabCase(word: string): string;
/**
* @function
* @param value The string to be displayed
* @returns The passed string or the default string if the passed string is null or undefined
*/
export declare const handleNullDisplay: (value: string | null | undefined, defaultValue?: string) => string;
/**
* @function
* @param text The string to be capitalized
* @returns The string in a capitalized form
*/
export declare const capitalizeText: (text: string | undefined) => string;
/**
* Enforces a character limit on a given string.
* @function
* @param {object} options - The options for the function.
* @param {string} options.text - The text to limit.
* @param {number} options.characterLimit - The maximum number of characters allowed.
* @param {function} options.onCharacterLimit - The function to call when the character limit is exceeded.
* @returns {string} The original string if it is shorter than the character limit, or a truncated version of the string if it is longer.
*/
export declare const enforceCharacterLimit: ({ text, characterLimit, onCharacterLimit, }: {
text: string;
characterLimit: number;
onCharacterLimit: () => void;
}) => string;
/**
* Validate email if its a proper email or not
* @function
* @param email The email to be validated
* @returns The boolean value when the condition is met
*/
export declare const isValidEmail: (email: string) => boolean;
/**
* Generate ID from word
* @function
* @param word The word needed to generate ID from
* @returns The generated ID from the word
*/
export declare function generateIDFromWord(text: string): string;
/**
* Get the word from the generated ID
* @function
* @param id The id that is needed to get the word from.
* @param customList The word lists that are used to check the original words from.
* @returns The word that is got from the id
*/
export declare function generateWordFromId(id: string, customList?: Record<string, string>): string;
/**
* Get the slug from words
* @function
* @param id The id that will be in the slug
* @param words The words that will be in the slug
* @returns The slug from the words and it will be url path safe
*/
export declare function generateSlugFromWordsWithID(id: string, ...words: string[]): string;
/**
* Extracts the id from the slug
* @function
* @param slug The slug associated with the id
* @returns The id from the slug
*/
export declare function extractIDfromSlug(slug: string): string | undefined;
/**
* Abbreviate number
* @function
* @param number The number to be abbreviated
* @returns The string representation of the abbreviated number
*/
export declare const abbreviateNumber: (number: number | undefined | null) => string | null;