Skip to content

Commit

Permalink
Move common code to jvm
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinTHS committed Jan 23, 2023
1 parent 41a0af8 commit dec7009
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 38 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Project exclude paths
/.gradle/
/.gradle/
/build
/.idea
8 changes: 8 additions & 0 deletions .idea/artifacts/Kava_jvm_1_0_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 3 additions & 26 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ plugins {
}

group = "com.github.merlinths"
version = "1.0.0"

version = "1.0.1"

val coroutineVersion = "1.6.4"

Expand All @@ -23,40 +22,18 @@ kotlin {
useJUnitPlatform()
}
}
js(BOTH) {
browser {
commonWebpackConfig {
cssSupport.enabled = true
}
}
}
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}


sourceSets {
val commonMain by getting {
val jvmMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion")
}
}
val commonTest by getting {
val jvmTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting
val jvmTest by getting
val jsMain by getting
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/jvmMain/kotlin/com/github/merlinths/kava/Example.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.merlinths.kava

import com.github.merlinths.kava.validation.valid
import com.github.merlinths.kava.validator.optional

fun main() = valid {
val (name) = parseName("Hello Kotlin!")

println(name)
}

fun parseName(greeting: String) = optional {
ensure (greeting) {
isNotBlank() and endsWith("!")
}

val (name) = "Hello\\s([^!]*)!"
.toRegex()
.find(greeting)

name.groupValues[1]
}
11 changes: 0 additions & 11 deletions src/jvmMain/kotlin/com/github/merlinths/kava/JvmValidScope.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.merlinths.kava

import java.util.*

interface ValidScope<ScopeType> {
/**
* This method stops execution of the current [ValidScope].
Expand All @@ -20,4 +22,10 @@ interface ValidScope<ScopeType> {
*/
operator fun <Type: Any> Type?.component1(): Type =
this ?: fail()

operator fun <Type: Any> Optional<Type>.component1(): Type =
if (isPresent)
this.get()
else
fail()
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ fun <Type, WrapperType> Validator<Type, WrapperType>.launchValidation(
}
}
}

0 comments on commit dec7009

Please sign in to comment.