1.0.1 • Published 3 years ago

@fibonalabs/utility v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

Installation

npm install @fibonalabs/utility

By default, npm install will install all modules listed as dependencies in package.json.

Number

digitsAfterDecimalPoint

This function converts a number into a string, rounding to a specified number of decimals. The number is rounded if necessary, and the fractional part is padded with zeros if necessary so that it has the specified length.

Usage

import {digitsAfterDecimalPoint} from '@fibonalabs/utility-component'
digitsAfterDecimalPoint(inputValue:number,digits:number)

// example
digitsAfterDecimalPoint(100,3)

currencyFormatter

This function converts a number into a string, using a local language format.This is also used as comma separator based on locale-specific numeric representation.Currency Symbols are also generated based on the locale.

Usage

import {currencyFormatter} from '@fibonalabs/utility-component'
currencyFormatter(inputValue: number,currencySymbol: currency,locale?: string)

// example
currencyFormatter(123456.789,'USD')
currencyFormatter(123456.789,'EUR','fr-FR')

roundingOffDigits

This function is used to format a number into a specified length.The length is specified inside the parentheses after the method's name.This function counts all numbers, not only decimals.

Usage

import {roundingOffDigits} from '@fibonalabs/utility-component'
roundingOffDigits(inputValue: number,precision: number)

// example
roundingOffDigits(13.556,2)

simpleUnits

This function formats a number to given simple units.

Usage

import {simpleUnits} from '@fibonalabs/utility-component'
simpleUnits(inputValue: number,unitValue: unit,locale?: string )

// example
simpleUnits(45,'liter')
simpleUnits(45,'liter','en-IN')

percentageConverter

This function is used for percentage conversion of given number.

Usage

import {percentageConverter} from '@fibonalabs/utility-component'
percentageConverter(inputValue: number,locale?: string)

// example
percentageConverter(5556.7)
percentageConverter(5556.7,'en-IN')

OTP

generateOTP

This function is used to generate OTP within specified digits.

Usage

import {generateOTP} from '@fibonalabs/utility-component'
generateOTP(noOfDigits: number)

// example
generateOTP(6)

DateTime

formatDate

This function is used to format a date in a specified manner.

Usage

import {formatDate} from '@fibonalabs/utility-component'
formatDate(date: string, dateFormat: string)

// example
formatDate('2020-01-13', 'DD/MM/YYYY')

findAge

To predict the age from Date Of Birth.

Usage

import { findAge} from '@fibonalabs/utility-component'
findAge(dob: string)

// example
findAge('1991-10-13')

getAgeToday

To calculate age in years, months and days.

Usage

import { getAgeToday } from '@fibonalabs/utility-component'
getAgeToday(dob: string)

// example
findAgeToday('1991-10-13')

findDiffBetweenDates

To calculate the difference in years,months and days between two dates

Usage

import { findDiffBetweenDates } from '@fibonalabs/utility-component'
findDiffBetweenDates(finalDate:string,initialDate:string)

// example
findDiffBetweenDates('2011-10-13','2014-10-13')

getDiffInDays

This function is used to find the difference in days between two dates.

Usage

import { getDiffInDays} from '@fibonalabs/utility-component'
getDiffInDays(finalDate: string, initialDate: string)

// example
getDiffInDays('2019-01-25', '2018-06-05')

getDiffInHours

This function is used to find the difference in hours between two dates.

Usage

import { getDiffInHours } from '@fibonalabs/utility-component'
getDiffInHours(finalDate: string, initialDate: string)

// example
getDiffInHours('2019-01-25', '2018-06-05')

getDiffInMinutes

This function is used to find the difference in minutes between two dates.

Usage

import { getDiffInMinutes } from '@fibonalabs/utility-component'
getDiffInMinutes(finalDate: string, initialDate: string)

// example
getDiffInMinutes('2019-01-25', '2018-06-05')

getDiffInSeconds

This function is used to find the difference in minutes between two dates.

Usage

import { getDiffInSeconds } from '@fibonalabs/utility-component'
getDiffInSeconds(finalDate: string, initialDate: string)

// example
getDiffInSeconds('2019-01-25', '2018-06-05')

getDiffInMonths

This function is used to find the difference in months between two dates.

Usage

import { getDiffInMonths } from '@fibonalabs/utility-component'
getDiffInMonths(finalDate: string, initialDate: string)

// example
getDiffInMonths('2019-01-25', '2018-06-05')

findTotalDaysInMonth

This function is used to find the total number of days in a month.

Usage

import { findTotalDaysInMonth } from '@fibonalabs/utility-component'
findTotalDaysInMonth(date: string)

// example
findTotalDaysInMonth('2019-01-25')

utcToLocalConverter

This function is used to convert UTC to Local Time.

Usage

import { utcToLocalConverter } from '@fibonalabs/utility-component'
utcToLocalConverter(date: string, formatType: string)

// example
utcToLocalConverter('August 19, 1975 23:15:30 GMT+00:00', 'hh:mm:ss A')

userTimeZone

This function is used to find the current time and date in different timezone.

Usage

import { userTimeZone } from '@fibonalabs/utility-component'
userTimeZone(userzone: string, formatType: string)

// example
userTimeZone('America/New_York', 'DD/MM/YYYY hh:mm:ss A z')

guessUserZone

This function is used to Predict the user timezone and finds the current time and date.

Usage

import { guessUserZone } from '@fibonalabs/utility-component'
guessUserZone(formatType: string)

// example
guessUserZone('DD/MM/YYYY hh:mm:ss A z')

timeDiff

This function is used to calculate the difference in time w.r.t days,hours,minutes and seconds.

Usage

import { timeDiff } from '@fibonalabs/utility-component'
timeDiff(startTime: string, endTime: string)

// example
timeDiff('March 1, 2002 11:10:00', 'March 1,2002 12:10:01')

timeDiffFromNow

This function is used to calculate the difference in time w.r.t days,hours,minutes and seconds from current.

Usage

import { timeDiffFromNow } from '@fibonalabs/utility-component'
timeDiffFromNow(startTime: string)

// example
timeDiffFromNow('September 27, 2021 11:10:00')

Array

removeDuplicates

This function is used to remove duplicate values from an array of objects.

Usage

import { removeDuplicates } from '@fibonalabs/utility-component'
removeDuplicates(arr: any,key: string)

// example
removeDuplicates(cars, 'color')

findOcc

This function is used to find the occurence of given key value in an array of objects.

Usage

import { findOcc } from '@fibonalabs/utility-component'
findOcc(arr: any,key: string)

// example
findOcc(cars, 'color')

onlyUnique

This function is used to list the unique values in the array.

Usage

import { onlyUnique } from '@fibonalabs/utility-component'
onlyUnique(arr: any)

// example
onlyUnique(num)

sortArrayAsc

This function is used to sort the given array in ascending order.

Usage

import { sortArrayAsc } from '@fibonalabs/utility-component'
sortArrayAsc(arr: any)

// example
sortArrayAsc(num)

sortArrayDesc

This function is used to sort the given array in descending order.

Usage

import { sortArrayDesc } from '@fibonalabs/utility-component'
sortArrayDesc(arr: any)

// example
sortArrayDesc(num)

valueExist

This function is used to check if a value is present in an array of objects.

Usage

import { valueExist } from '@fibonalabs/utility-component'
valueExist(arr: any, key: string,value: string)

// example
valueExist(cars, 'color', 'red')
1.0.1

3 years ago

1.0.0

3 years ago