UNPKG

@groww-tech/ella

Version:

Ella is a utility-belt library for JavaScript that provides general purpose methods used in day to day programming.

209 lines (205 loc) 6.61 kB
export { NumberFormatter } from './NumberFormatter/index'; /** * @module Number */ /** * This method can be used to add commas as per Indian system to any valid number of type string or number. * * @param {number | string} x - Number that you want to be formatted with commas as per Indian system * * @remarks * It's strongly recommended to pass number only but method can also handle valid string. * * @example * ``` * addingCommasToNumber(1)); // 1 * addingCommasToNumber(11)); // 11 * addingCommasToNumber(111)); // 111 * addingCommasToNumber('-1111')); // -1,111 * addingCommasToNumber('11111')); // 11,111 * addingCommasToNumber(-111111)); // -1,11,111 * ``` */ declare function addingCommasToNumber(x: number | string): string; /** * This method can be used to validate 10 digit mobile number. * * @param {number | string} mobNumber - Mobile number that you want to validate * * @remarks * It's strongly recommended to pass number only but method can also handle valid string. * * @example * ``` * isValidMobileNumber(1234567890) // true * isValidMobileNumber(-1234567890) // false * isValidMobileNumber(123) // false * isValidMobileNumber("123") // false * isValidMobileNumber("1234567890") // true * isValidMobileNumber("-1234567890") // false * ``` */ declare function isValidMobileNumber(mobNumber: number | string): boolean; /** * This method can be used to convert paisa to rupees * * @param {number} value - Number that you want to be converted to rupee * * @remarks * Paise cannot be in decimal, so make sure you pass integer else it will return argument only without any change * * @example * ``` * convertPaisaToRupee(100)); // 1 * ``` */ declare function convertPaisaToRupee(value: number | string): number; /** * This method can be used to convert rupees to paisa * * @param {number} value - Number that you want to be converted to paise * * @example * ``` * convertRupeeToPaisa(1)); // 100 * ``` */ declare function convertRupeeToPaisa(value: number): number; /** * This method can be used to find ordinal suffix of any number. * * @param {number} num - Number that you want to find ordinal suffix of * * @example * ``` * ordinalSuffixOfNumber(1); // 1st * ordinalSuffixOfNumber(11); // 11th * ordinalSuffixOfNumber(21); // 21st * ordinalSuffixOfNumber(101); // 103rd * ``` */ declare function ordinalSuffixOfNumber(num: number): string; /** * This method can be used to add commas as per million format (thousands separator). * * @param {number | string} num - Number that you want to be formatted with commas * * @remarks * It returns the number as it is on error * * @example * * ``` * millionWithCommas(1030120313); // 1,030,120,313 * millionWithCommas(1000001); // 1,000,001 * millionWithCommas(1000001.12432432); // 1,000,001.12432432 * ``` */ declare function millionWithCommas(num: number | string): string | number; /** * This method can be used to get a random integer number between 2 number both inclusive. * * @param {number} min - Starting number * @param {number} max - Ending number * * @example * ``` * getIntegerRandomNoBetweenTwoNo(0,500)); // will return anything between 0 to 500 * ``` */ declare function getIntegerRandomNoBetweenTwoNo(min: number, max: number): number; /** * This method can be used to convert the number in lakhs and crore format. * * @param {number | string} number - Number that you want to format for lakh or crore. * @param {number} toFixed - how much decimal places you need after decimal, default is set as 2. * * @remarks * It returns the number as it is on error ,empty string, null, undefined, NaN is passed. * * @example * * ``` * changeFormatToLakhCrore(103213456); // 10.32Cr * changeFormatToLakhCrore('1034564'); // 10.35L * changeFormatToLakhCrore('1027654',3); // 10.277L * ``` * */ declare function changeFormatToLakhCrore(num: string | number, toFixedDecimals?: number): string | number; /** * This method can be used to convert the number in thousand,million,billion and trillion format. * * @param {number | string} number - Number that you want to format for in billion trillon Intl format. * @param {number} toFixed - how much decimal places you need after decimal, default is set as 2. * * @remarks * It returns the number as it is on error ,empty string, null, undefined, NaN is passed. * * @example * * ``` * convertToBillionTrillionFormat(3098100000); // 3.09B * convertToBillionTrillionFormat(2849537600000); // 2.84T * convertToBillionTrillionFormat(12200000); // 12.20M * convertToBillionTrillionFormat(100232332,3); // 100.232M * convertToBillionTrillionFormat('100232332'); // 100.23M * ``` * */ declare function convertToBillionTrillionFormat(num: string | number, toFixedDecimals?: number): string | number; /** * This method can be used to give the sign of the number : + , - or empty if 0. * * @param {number | string} num - Number that you want to get sign for. * * @remarks * It returns empty (No sign) for 0 value. * * @example * * ``` * getNumberSign(1000); // '+' * getNumberSign('1200'); // '+' * getNumberSign(-12430); // '-' * getNumberSign(0); // '' * ``` * */ declare function getNumberSign(num: string | number): "" | "-" | "+"; /** * This method fixes the decimal part but without round off the value. * * * @param {number | string} num - number entered in input element * @param {number} toFixedDecimal - Number of decimal places you want to fix the decimal part to. * * @example * ``` * toFixedWithoutRounding(1.56789,4) => 1.5678 * ``` */ declare function toFixedWithoutRounding(num: number | string, toFixedDecimal: number): string | number; /** * This function checks for isFinite and converts to number otherwise * returns 0. * * @param {number | string} num - number entered in input element * */ declare function toNumber(num: number | string): number; /** * This function rounds off `value` to the nearest `step`. * * * @param {number} value - number entered in input element * @param {number} step - price multiplier * * @example * ``` * In idea stock on NSE price step will be 0.05 and for BSE it is 0.01 * roundToNearest(2.4,0.5) => 2.5 * ``` */ declare const roundToNearest: (value: number, step?: number) => number; export { addingCommasToNumber, changeFormatToLakhCrore, convertPaisaToRupee, convertRupeeToPaisa, convertToBillionTrillionFormat, getIntegerRandomNoBetweenTwoNo, getNumberSign, isValidMobileNumber, millionWithCommas, ordinalSuffixOfNumber, roundToNearest, toFixedWithoutRounding, toNumber };