@groww-tech/ella
Version:
Ella is a utility-belt library for JavaScript that provides general purpose methods used in day to day programming.
219 lines (217 loc) • 9.54 kB
TypeScript
/**
* @module String
*/
/**
* This method can be used to validate email id given in string.
* Special characters allowed before @ are -+._
*
* @param {emailId} str - String that you want to validate as email
*
* @example
* ```
* isValidEmail('johndoe@gmail.com'); // Output is an array
* isValidEmail('johndoe@gmail'); // Output is null
* isValidEmail('john-doe@gmail.com'); // Output is an array
* isValidEmail('john+doe@gmail.com'); // Output is an array
* isValidEmail('john.doe@gmail.com'); // Output is an array
* isValidEmail('john.doe@mail.in'); // Output is an array
* isValidEmail('john_doe@mail.in'); // Output is an array
*
* @returns boolean if input string matches the email vaildation regex
*/
declare function isValidEmail(emailId: string): RegExpMatchArray | null;
/**
* This method can be used to convert any html string to normal string.
*
* @param {string} htmlString - HTML String that you want to convert to normal text
*
* @example
* ```
* convertHtmlToText('<p>Hello <b>World</b></p>') // Hello World
* ```
*/
declare function convertHtmlToText(htmlString: string): string;
/**
* This method can be used to check if a name is Valid or not
*
* @param {string} name - Name that you want to validate
*
* @remarks
* Valid name - Only alphanumeric with space allowed (no other special chars) and min char should be 2
*/
declare function isValidName(name: string): boolean;
/**
* This method can be used to convert any string to sentence case.
*
* @param {string} str - String that you want to convert to sentence case
*
* @example
* ```
* convertToSentenceCase('Enter investment amount'); // Enter investment amount
* convertToSentenceCase('Enter SIP amount'); // Enter sip amount
* convertToSentenceCase('My NAME Is kHan'); // My name is khan
* convertToSentenceCase('My NAME Is kHan. i am not a terrorist. Understood?'); // My name is khan. I am not a terrorist. Understood?
* ```
*/
declare function convertToSentenceCase(str: string): string;
/**
* This method can be used to capitalize first letter of each work and touch nothing else.
*
* @param {string} str - String that you want to transform
*
* @example
* ```
* capitalizeFirstLetter('Enter investment amount'); // Enter Investment Amount
* capitalizeFirstLetter('Enter SIP amount'); // Enter SIP Amount
* capitalizeFirstLetter('My NAME Is kHan'); // My NAME Is KHan
* capitalizeFirstLetter('My NAME Is kHan. i am not a terrorist. Understood?'); // My NAME Is KHan. I Am Not A Terrorist. Understood?
* ```
*/
declare function capitalizeFirstLetter(str: string): string;
/**
* This method can be used to convert any string to title case.
*
* @param {string} str - String that you want to convert to title case
*
* @example
* ```
* toTitleCase('Enter investment amount'); // Enter Investment Amount
* toTitleCase('Enter SIP amount'); // Enter Sip Amount
* toTitleCase('My NAME Is kHan'); // My Name Is Khan
* toTitleCase('My NAME Is kHan. i am not a terrorist. Understood?'); // My Name Is Khan. I Am Not A Terrorist. Understood?
* ```
*/
declare function toTitleCase(str: string): string | undefined;
/**
* This function masks an input string from the index specified to the number of characters specified to be masked
*
* @param {string} inputString - Input string to be masked
* @param {number} maskStartIndex - Index in the input string from which masking needs to be started
* @param {number} maskCharactersCount - Count of number of charaters to be masked in input string
* @param {number} maskCaracter - Charatcer with which string needs to be masked with
*
* @example
* ```
* maskInputString("maskInputString", 7, 12); // Output is 'maskInpXXXXXXXX'
* maskInputString("maskInputString", 0, 12); // Output is 'XXXXXXXXXXXXing'
* maskInputString("maskInputString", 0, 10); // Output is 'XXXXXXXXXXtring'
* maskInputString("maskInputString", 0, 9); // Output is 'XXXXXXXXXString'
* maskInputString("maskInputString", 2, 9); // Output is 'maXXXXXXXXXring'
* maskInputString("maskInputString", 6, 8); // Output is 'maskInXXXXXXXXg'
* maskInputString("maskInputString", 6, 8, '*'); // Output is 'maskIn********g'
* maskInputString("maskInputString", 6, 13); // Output is 'maskInXXXXXXXXX'
* maskInputString("maskInputString", 6, 16); // Output is 'XXXXXXXXXXXXXXX' as maskCharactersCount is greater than length of inputString
* maskInputString("maskInputString", 13, 1); // Output is 'maskInputStriXg'
* maskInputString("maskInputString", 16, 13); // Output is 'maskInputString' as maskStartIndex is greater than length of inputString
* maskInputString("maskInputString", 16); // Output is ''
* maskInputString("maskInputString", 2); // Output is ''
* maskInputString("maskInputString", undefined, 3); // Output is ''
* maskInputString(); // Output is ''
* maskInputString("maskInputString", -1, 2); // Output is ''
* maskInputString("maskInputString", 1, -2); // Output is ''
* ```
*/
declare function maskInputString(inputString: string, maskStartIndex: number, maskCharactersCount: number, maskCharacter?: string): string;
/**
* This function truncates an input string from the index specified to the number of characters specified to be truncated
*
* @param {string} inputString - Input string to be truncated
* @param {string} truncateStartIndex - Index from which truncation of the string to be started
* @param {number} truncateCharactersCount - Number of characters which should be trucated from the truncateStartIndex
*
* @example
* ```
* truncateInputString('truncateInputString') // Output will be 'InputString'
* truncateInputString('truncateInputString', 0, 8) // Output will be 'InputString'
* truncateInputString('truncateInputString', 4, 9) // Output will be 'trunString'
* truncateInputString('truncateInputString', 20, 9) // Output will be 'truncateInputString', as start index is larger than length of inputString
* truncateInputString('truncateInputString', 10, 20) // Output will be '', aslength of characters to be truncated is large than length of inputString
* truncateInputString('truncateInputString', 0, 0) // Output will be 'truncateInputString'
* truncateInputString('truncateInputString', 10, -1) // Output will be ''
* truncateInputString('truncateInputString', -1, 10) // Output will be ''
* truncateInputString('truncateInputString', -1, -1) // Output will be ''
* ```
*/
declare function truncateInputString(inputString: string, truncateStartIndex?: number, truncateCharactersCount?: number): string;
/**
* This method is used to check if the given string check for characters from a-z, A-Z, 0-9.
*
* @param str - String that you want to check for the above characters
*
* @example
* ```
* isAlphanumericString('aaAa123') // true
* isAlphanumericString('aaAa_98-') // false
* ```
*/
declare function isAlphanumericString(str: string): boolean;
/**
* This method checks for all characters to be number between 0-9 and pincode length to be 6
*
* @param {string | number} pincode - string or number entered in input element
*
* @example
*```
* isValidPincode('123456') // true
* isValidPincode('1234aa') // false
* isValidPincode(110018) // true
* isValidPincode('12345') // false
* ```
*/
declare function isValidPincode(pincode: string | number): boolean;
/**
* The sequential number would always be a subset to "0123456789".
* For instance, 1234, 4567, 2345, etc are all subset of "0123456789".
* To validate, this function uses 'indexOf' method present on String Object.
*
* @param {string | number} digitsPattern - string or number entered in input element
*
* @example
*```
* isSequentialDigitsPattern('1234') //true
* isSequentialDigitsPattern('1235') //false
* isSequentialDigitsPattern('9876') //true
* ```
*/
declare function isSequentialDigitsPattern(digitsPattern: string | number): boolean;
/**
* This function checks if a string has all digits as the same digit
*
* @param {string} str - string entered in input element
*
* @example
* ```
* isSameDigitsString('1111') //true
* isSameDigitsString('2222') //true
* isSameDigitsString('1212') //false
* ```
*
*/
declare function isSameDigitsString(str: string): boolean;
/**
* This function normalizes text to string by using latest price and last price and is used by Ticker component.
* This is useful in case of a negative number where it doesn't behave properly in Ticker component.
*
* @param {number} latestPrice - The current price of the fund/schemes
* @param {number} lastPrice - The last price of the scheme of the fund/schemes
*
* @example
* ```
* <Ticker text={normalizeTickerString(116.27,114.27)} />
* ```
*
*/
declare function normalizeTickerString(latestPrice: number, lastPrice: number): string;
/**
* This function returns Start Case string for a camel case string
* @param {string} str - Input string in camelCase
*
* @example
* ```
* convertToStartCase('retailAndInvestors') // 'Retail And Investors'
* convertToStartCase('foreignInstitutions') // 'Foreign Institutions'
* convertToStartCase('Blackrock Inc.'); // 'Blackrock Inc.'
* convertToStartCase('FMR, LLC'); // F M R, L L C
*/
declare function convertToStartCase(str: string): string;
export { capitalizeFirstLetter, convertHtmlToText, convertToSentenceCase, convertToStartCase, isAlphanumericString, isSameDigitsString, isSequentialDigitsPattern, isValidEmail, isValidName, isValidPincode, maskInputString, normalizeTickerString, toTitleCase, truncateInputString };