diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-10-13 03:37:40 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-10-13 03:37:40 +0200 |
commit | ebce2c4b839c0b2f8be78bc31c1ce12c45a0164c (patch) | |
tree | 7cac3c5449eb8aa398b279d62d9a67ed34fa4115 /src/main/kotlin/pl/treksoft/kvision/utils | |
parent | 470953c78c2509224bb452c16f8bbea54e53b3d7 (diff) | |
download | kvision-ebce2c4b839c0b2f8be78bc31c1ce12c45a0164c.tar.gz kvision-ebce2c4b839c0b2f8be78bc31c1ce12c45a0164c.tar.bz2 kvision-ebce2c4b839c0b2f8be78bc31c1ce12c45a0164c.zip |
Major refactoring of the multi-platform components.
Dependencies upgrade.
A lot of code style fixes.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/utils')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/utils/JSON.kt | 39 | ||||
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt | 24 |
2 files changed, 39 insertions, 24 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/utils/JSON.kt b/src/main/kotlin/pl/treksoft/kvision/utils/JSON.kt new file mode 100644 index 00000000..e47351ac --- /dev/null +++ b/src/main/kotlin/pl/treksoft/kvision/utils/JSON.kt @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package pl.treksoft.kvision.utils + +import kotlinx.serialization.context.SimpleModule +import kotlinx.serialization.json.JSON +import pl.treksoft.kvision.types.DateSerializer +import kotlin.js.Date + +object JSON { + + val plain = JSON().apply { + install(SimpleModule(Date::class, DateSerializer)) + } + + val nonstrict = JSON(strictMode = false).apply { + install(SimpleModule(Date::class, DateSerializer)) + } + +} diff --git a/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt b/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt index e5f608c2..e252d672 100644 --- a/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt +++ b/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt @@ -27,13 +27,11 @@ import com.lightningkite.kotlin.observable.list.ObservableList import kotlinx.coroutines.suspendCancellableCoroutine import org.w3c.files.File import org.w3c.files.FileReader -import pl.treksoft.kvision.KVManager import pl.treksoft.kvision.core.CssSize import pl.treksoft.kvision.core.UNIT import kotlin.browser.window import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException -import kotlin.js.Date /** * Extension property to convert Int to CSS px units. @@ -186,27 +184,6 @@ fun Int.toHexString(): String { } /** - * Extension function to convert String to Date with a given date format. - * @param format date/time format - * @return Date object - */ -@Suppress("UnsafeCastFromDynamic") -fun String.toDateF(format: String = "YYYY-MM-DD HH:mm:ss"): Date? { - val result = KVManager.fecha.parse(this, format) - return if (result) result else null -} - -/** - * Extension function to convert Date to String with a given date format. - * @param format date/time format - * @return String object - */ -@Suppress("UnsafeCastFromDynamic") -fun Date.toStringF(format: String = "YYYY-MM-DD HH:mm:ss"): String { - return KVManager.fecha.format(this, format) -} - -/** * Utility function to detect Internet Explorer 11. * @return true if the current browser is IE11 */ @@ -216,7 +193,6 @@ fun isIE11(): Boolean = window.navigator.userAgent.matches("Trident\\/7\\.") * Suspending extension function to get file content. * @return file content */ -@Suppress("EXPERIMENTAL_FEATURE_WARNING") suspend fun File.getContent(): String = suspendCancellableCoroutine { cont -> val reader = FileReader() reader.onload = { |