Skip to content

Commit

Permalink
Merge pull request #519 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 13.10.1
  • Loading branch information
andyone authored Nov 9, 2024
2 parents c3e3a3b + 6d5291a commit 2e7a651
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### [13.10.1](https://kaos.sh/ek/13.10.1)

* `[mathutil]` Added shorthand helper `B`

### [13.10.0](https://kaos.sh/ek/13.10.0)

> [!IMPORTANT]
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require (
github.com/essentialkaos/check v1.4.1
github.com/essentialkaos/depsy v1.3.1
github.com/essentialkaos/go-linenoise/v3 v3.6.1
golang.org/x/crypto v0.28.0
golang.org/x/sys v0.26.0
golang.org/x/crypto v0.29.0
golang.org/x/sys v0.27.0
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
10 changes: 10 additions & 0 deletions mathutil/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ import (

// ////////////////////////////////////////////////////////////////////////////////// //

func ExampleB() {
isRoot := true

fmt.Println(B(isRoot, 0, 1000))
fmt.Println(B(!isRoot, 0, 1000))
// Output:
// 0
// 1000
}

func ExampleIsNumber() {
fmt.Println(IsNumber("test"))
fmt.Println(IsNumber("746131"))
Expand Down
11 changes: 11 additions & 0 deletions mathutil/mathutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ type NumericNeg interface {

// ////////////////////////////////////////////////////////////////////////////////// //

// B is shorthand for choosing value by condition
func B[N Numeric](cond bool, positive, negative N) N {
if cond {
return positive
}

return negative
}

// ////////////////////////////////////////////////////////////////////////////////// //

// IsInt returns true if given string contains int symbols.
//
// Note that this method does not validate the given value.
Expand Down
5 changes: 5 additions & 0 deletions mathutil/mathutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ func (s *MathUtilSuite) TestFromPerc(c *C) {
c.Assert(FromPerc(250, 100), Equals, 250.0)
c.Assert(FromPerc(25.55, -100), Equals, -25.55)
}

func (s *MathUtilSuite) TestB(c *C) {
c.Assert(B(true, 2.3, 3.7), Equals, 2.3)
c.Assert(B(false, 2.3, 3.7), Equals, 3.7)
}
8 changes: 4 additions & 4 deletions terminal/input/input_validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (v isNumberValidator) Validate(input string) (string, error) {
input = strings.TrimSpace(input)

if input == "" {
return input, nil // Empty imput is okay
return input, nil // Empty input is okay
}

_, err := strconv.ParseInt(input, 10, 64)
Expand All @@ -99,7 +99,7 @@ func (v isFloatValidator) Validate(input string) (string, error) {
input = strings.TrimSpace(input)

if input == "" {
return input, nil // Empty imput is okay
return input, nil // Empty input is okay
}

_, err := strconv.ParseFloat(input, 64)
Expand All @@ -116,7 +116,7 @@ func (v isEmailValidator) Validate(input string) (string, error) {
input = strings.TrimSpace(input)

if input == "" {
return input, nil // Empty imput is okay
return input, nil // Empty input is okay
}

name, domain, ok := strings.Cut(input, "@")
Expand All @@ -134,7 +134,7 @@ func (v isURLValidator) Validate(input string) (string, error) {
input = strings.TrimSpace(input)

if input == "" {
return input, nil // Empty imput is okay
return input, nil // Empty input is okay
}

switch {
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ package ek
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "13.10.0"
const VERSION = "13.10.1"

0 comments on commit 2e7a651

Please sign in to comment.