diff --git a/package.json b/package.json index 904966a..158d3d4 100644 --- a/package.json +++ b/package.json @@ -1,32 +1,32 @@ { - "name": "c4k-common-cljs", - "description": "Contains predicates and tools for c4k", - "author": "meissa GmbH", - "version": "0.2.0-SNAPSHOT", - "homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-common#readme", - "repository": "https://www.npmjs.com/package/c4k-common", - "license": "APACHE2", - "main": "c4k-common.js", - "bin": { - "c4k-common": "./c4k-common.js" - }, - "keywords": [ - "cljs", - "k8s", - "c4k", - "deployment", - "yaml", - "convention4kubernetes" - ], - "bugs": { - "url": "https://gitlab.com/domaindrivenarchitecture/c4k-common/issues" - }, - "dependencies": { - "js-base64": "^3.6.1", - "js-yaml": "^4.0.0" - }, - "devDependencies": { - "shadow-cljs": "^2.11.18", - "source-map-support": "^0.5.19" - } -} + "name": "c4k-common-cljs", + "description": "Contains predicates and tools for c4k", + "author": "meissa GmbH", + "version": "0.2.0-SNAPSHOT", + "homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-common#readme", + "repository": "https://www.npmjs.com/package/c4k-common", + "license": "APACHE2", + "main": "c4k-common.js", + "bin": { + "c4k-common": "./c4k-common.js" + }, + "keywords": [ + "cljs", + "k8s", + "c4k", + "deployment", + "yaml", + "convention4kubernetes" + ], + "bugs": { + "url": "https://gitlab.com/domaindrivenarchitecture/c4k-common/issues" + }, + "dependencies": { + "js-base64": "^3.7.2", + "js-yaml": "^4.0.0" + }, + "devDependencies": { + "shadow-cljs": "^2.11.18", + "source-map-support": "^0.5.19" + } +} \ No newline at end of file diff --git a/src/main/cljc/dda/c4k_common/predicate.cljc b/src/main/cljc/dda/c4k_common/predicate.cljc index c76e9b5..da55f18 100644 --- a/src/main/cljc/dda/c4k_common/predicate.cljc +++ b/src/main/cljc/dda/c4k_common/predicate.cljc @@ -44,6 +44,12 @@ (fqdn-string? (first split-string)) (port-number? (edn/read-string (second split-string))))))) +(defn integer-string? + [input] + (and (string? input) + (some? (re-matches #"^\d+$" input)) + (integer? (edn/read-string input)))) + (defn string-sequence? [input] (and (sequential? input) diff --git a/src/test/cljc/dda/c4k_common/predicate_test.cljc b/src/test/cljc/dda/c4k_common/predicate_test.cljc index c91bb19..4ae1251 100644 --- a/src/test/cljc/dda/c4k_common/predicate_test.cljc +++ b/src/test/cljc/dda/c4k_common/predicate_test.cljc @@ -51,6 +51,15 @@ (is (false? (cut/host-and-port-string? "test.123:1234"))) (is (false? (cut/host-and-port-string? "test.de:abc")))) +(deftest test-integer-string? + (is (true? (cut/integer-string? "1"))) + (is (true? (cut/integer-string? "42"))) + (is (false? (cut/integer-string? 42))) + (is (false? (cut/integer-string? "42.2"))) + (is (false? (cut/integer-string? "4 2"))) + (is (false? (cut/integer-string? "1e2"))) + (is (false? (cut/integer-string? true)))) + (deftest test-string-sequence? (is (true? (cut/string-sequence? ["hallo" "welt" "!"]))) (is (false? (cut/string-sequence? ["hallo" 1 "welt" "!"])))