Skip to content

Eldhopj/kotlin-extensions

Repository files navigation

Kotlin-Extenstions

Codacy Badge

This library contains essential Kotlin language extenstions which we use in daily projects

How To

Gradle:

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
	    ...
	    maven { url 'https://jitpack.io' }
    }
}

dependency to your module build.gradle file

dependencies {
    implementation 'com.github.Eldhopj:kotlin-extensions:1.2'
}

For info on using in the maven and others, see the jitpack docs page.

Usage

String Extensions

  • .isValidEmail -> Checks whether the email is valid, returns true if valid else false

  • .isValidName -> Checks whether the name is valid, returns true if valid else false

  • .isValidPhoneNumber -> Checks whether the phone number is valid, returns true if valid else false

  • .capitalizeEachWord -> Capitalize each word

    • eg: hello world -> Hello World
  • .checkRegex -> Checks the regex pattern is valid, returns true if valid else false

      Parameters
      1.pattern -> regex pattern.
    
  • .toHourMinuteSeconds -> Converts the seconds to Hours, Minutes & Seconds as per your pattern.

      Parameters
      1.pattern -> in which pattern we have to convert. Default Pattern is %dh %dm %ds.
    
    • eg: 1h 2m 30s
  • .toHourMinute -> Converts the seconds to Minutes & Seconds as per your pattern.

      Parameters
      1.pattern -> in which pattern we have to convert. Default Pattern is %dm %ds.
    
    • eg: 1hr 2m

Please go thorough the String Extensions code documentation for more information

Number Extensions

  • .shortenString -> Format number into short values.

    • eg: 1000 -> 1k
    • 1000000 -> 1M
      
  • .format -> Returns the string representation of the decimal values

    Parameters 1.pattern -> in which pattern we have to convert. Default Pattern is 0.##. 2.roundingMode -> set the rounding behavour, default behavour is RoundingMode.HALF_EVEN

    • eg: 10.02542 -> 10.03
  • .isNullOrZero -> Returns true if this number is null or zero (0)

Please go thorough the Number Extensions code documentation for more information

Date Extensions

Please go thorough the Date Extension code documentation

Map Extensions

  • .mergeWith -> Merges two maps

Please go thorough the Map Extension code documentation