Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

district0x/district-validation

Repository files navigation

district-validation

CircleCI

Set of functions helpful for input validation. Validation functions always return boolean.

Installation

Add Clojars Project into your project.clj
Include [district.validation] in your CLJS file

API Overview

district.validation

True if passed instance of js/Date.

(valid/js-date? (js/Date.))
;; => true

True if passed instance of cljs-time

(valid/cljs-time? (t/now))
;; => true

length? [x min-length max-length]

True if given string is in a range of lengths.

(valid/length? "a" 1)
;; => true
(valid/length? "aa" 1)
;; => false
(valid/length? "aaaa" 1 3)
;; => false

True for valid email.

(valid/email? "[email protected]")
;; => true
(valid/email? "" {:allow-empty? true})
;; => true

True if given valid web3 address.

(valid/web3-address? "0x48e69c07bc7b9b953b07c45dc8adbd78e12f10fa")
;; => true

True if string is a sha3 hash.

(valid/sha3? "0x10e176b8986f2cfd620a941952c6b3b245a5ae4b276552d6909a88c610eccd66")
;; => true

True if number is not negative number.

(valid/not-neg? 1)
;; => true

True if parameter is not nil.

(valid/not-nil? 1)
;; => true

True if given valid http url

(valid/http-url? "https://district0x.io")
;; => true
(valid/http-url? "" {:allow-empty? true})
;; => true

True if given valid ether (as a unit, not currency) value, that is convertible to wei.

(valid/eth-value? "1.1")
;; => true
(valid/eth-value? "1a")
;; => false
(valid/eth-value? nil {:allow-empty? true})
;; => true

True if given valid non negative ether (as a unit, not currency) value, that is convertible to wei.

(valid/not-neg-eth-value? "1,1")
;; => true
(valid/not-neg-eth-value? 0)
;; => true
(valid/not-neg-eth-value? "-1")
;; => false

True if given valid positive ether (as a unit, not currency) value, that is convertible to wei.

(valid/pos-eth-value? "1,1")
;; => true
(valid/pos-eth-value? 0)
;; => false

Development

  1. Run test suite:
  • Browser
    • npx shadow-cljs watch test-browser
    • open https://d0x-vm:6502
    • tests refresh automatically on code change
  • CI (Headless Chrome, Karma)
    • npx shadow-cljs compile test-ci
    • CHROME_BIN=`which chromium-browser` npx karma start karma.conf.js --single-run
  1. Build
  • on merging pull request to master on GitHub, CI builds & publishes new version automatically
  • update version in build.clj
  • to build: clj -T:build jar
  • to release: clj -T:build deploy (needs CLOJARS_USERNAME and CLOJARS_PASSWORD env vars to be set)

Releases

No releases published

Packages

No packages published