Refresh documentation (#39)

* minor documentation fixes

* fix Hugo warnings

* add openssf badge
This commit is contained in:
Ruidy 2024-11-21 05:23:00 +01:00
parent fbbd0398c9
commit fbf58eff42
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
15 changed files with 22 additions and 15 deletions

View file

@ -4,6 +4,7 @@
[![Go version](https://img.shields.io/github/go-mod/go-version/rjNemo/underscore?style=for-the-badge&logo=go)](https://pkg.go.dev/github.com/rjNemo/underscore) [![Go version](https://img.shields.io/github/go-mod/go-version/rjNemo/underscore?style=for-the-badge&logo=go)](https://pkg.go.dev/github.com/rjNemo/underscore)
![Go report](https://goreportcard.com/badge/github.com/rjNemo/underscore?style=for-the-badge) ![Go report](https://goreportcard.com/badge/github.com/rjNemo/underscore?style=for-the-badge)
![test coverage](https://img.shields.io/codecov/c/github/rjNemo/underscore?style=for-the-badge&logo=codecov) ![test coverage](https://img.shields.io/codecov/c/github/rjNemo/underscore?style=for-the-badge&logo=codecov)
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/9726/badge?style=for-the-badge)](https://www.bestpractices.dev/projects/9726)
![underscore](https://socialify.git.ci/rjNemo/underscore/image?description=1&font=KoHo&language=1&logo=https%3A%2F%2Fraw.githubusercontent.com%2FrjNemo%2Funderscore%2Fmain%2Fdocs%2Fstatic%2Flogo.png&owner=1&pattern=Floating%20Cogs&stargazers=1&theme=Dark) ![underscore](https://socialify.git.ci/rjNemo/underscore/image?description=1&font=KoHo&language=1&logo=https%3A%2F%2Fraw.githubusercontent.com%2FrjNemo%2Funderscore%2Fmain%2Fdocs%2Fstatic%2Flogo.png&owner=1&pattern=Floating%20Cogs&stargazers=1&theme=Dark)

View file

@ -1,4 +1,4 @@
{{ if .Site.IsMultiLingual }} {{ if hugo.IsMultilingual }}
<span class="gdoc-language"> <span class="gdoc-language">
<ul class="gdoc-language__selector" role="button" aria-pressed="false" tabindex="0"> <ul class="gdoc-language__selector" role="button" aria-pressed="false" tabindex="0">
<li> <li>

View file

@ -63,6 +63,6 @@
{{- end }} {{- end }}
{{- /* Facebook Page Admin ID for Domain Insights */}} {{- /* Facebook Page Admin ID for Domain Insights */}}
{{- with .Site.Social.facebook_admin }} {{- with .Site.Params.facebook.adminID }}
<meta property="fb:admins" content="{{ . }}" /> <meta property="fb:admins" content="{{ . }}" />
{{- end }} {{- end }}

View file

@ -10,6 +10,6 @@
{{- with partial "utils/description" . }} {{- with partial "utils/description" . }}
<meta name="twitter:description" content="{{ . | plainify | htmlUnescape | chomp }}" /> <meta name="twitter:description" content="{{ . | plainify | htmlUnescape | chomp }}" />
{{- end }} {{- end }}
{{- with .Site.Social.twitter -}} {{- with .Site.Params.twitter -}}
<meta name="twitter:site" content="@{{ . }}" /> <meta name="twitter:site" content="@{{ . }}" />
{{- end }} {{- end }}

2
go.mod
View file

@ -1,6 +1,6 @@
module github.com/rjNemo/underscore module github.com/rjNemo/underscore
go 1.23 go 1.23.3
require ( require (
github.com/stretchr/testify v1.8.4 github.com/stretchr/testify v1.8.4

View file

@ -1,6 +1,6 @@
package underscore package underscore
// Joins two slices together and returns a Tuple of [T, []P], the selectors allow you to pick the // Join joins two slices together and returns a Tuple of [T, []P], the selectors allow you to pick the
// keys you want to use from your struct's to join the sets together // keys you want to use from your struct's to join the sets together
func Join[T, P any, S comparable]( func Join[T, P any, S comparable](
left []T, left []T,
@ -18,7 +18,7 @@ func Join[T, P any, S comparable](
return results return results
} }
// Joins two slices together and returns a []O where O is defined by the output // JoinProject joins two slices together and returns a []O where O is defined by the output
// of your projection function // of your projection function
// The selectors allow you to pick the keys from your structure to use as the join keys // The selectors allow you to pick the keys from your structure to use as the join keys
// While the projection functions allows you to reformat joined datasets // While the projection functions allows you to reformat joined datasets

View file

@ -1,8 +1,9 @@
package underscore package underscore
// Orders a slice by a field value within a struct, the predicate allows you // OrderBy orders a slice by a field value within a struct, the predicate allows you
// to pick the fields you want to orderBy. Use > for ASC or < for DESC // to pick the fields you want to orderBy. Use > for ASC or < for DESC
// func (left Person, right Person) bool { return left.Age > right.Age } //
// func (left Person, right Person) bool { return left.Age > right.Age }
func OrderBy[T any](list []T, predicate func(T, T) bool) []T { func OrderBy[T any](list []T, predicate func(T, T) bool) []T {
swaps := true swaps := true
var tmp T var tmp T

View file

@ -1,6 +1,6 @@
package underscore package underscore
// Convert values to pointers // ToPointer Convert values to pointers
// //
// Instead of: // Instead of:
// v := "value" // v := "value"

View file

@ -1,6 +1,6 @@
package underscore package underscore
// Creates a sequence of numbers, i.e. u.Range(0, 3) = [0 1 2 3], while u.Range(3, 0) = [3 2 1 0] // Range creates a sequence of numbers, i.e. u.Range(0, 3) = [0 1 2 3], while u.Range(3, 0) = [3 2 1 0]
func Range(start int, end int) (result []int) { func Range(start int, end int) (result []int) {
if start < end { if start < end {
for i := start; i <= end; i++ { for i := start; i <= end; i++ {

View file

@ -6,14 +6,14 @@ import (
"golang.org/x/exp/constraints" "golang.org/x/exp/constraints"
) )
// sort any slice ASENDING // SortSliceASC sorts any slice ASCENDING
func SortSliceASC[T constraints.Ordered](s []T) { func SortSliceASC[T constraints.Ordered](s []T) {
sort.SliceStable(s, func(i, j int) bool { sort.SliceStable(s, func(i, j int) bool {
return s[i] < s[j] return s[i] < s[j]
}) })
} }
// sort any slice DESCENDING // SortSliceDESC sorts any slice DESCENDING
func SortSliceDESC[T constraints.Ordered](s []T) { func SortSliceDESC[T constraints.Ordered](s []T) {
sort.SliceStable(s, func(i, j int) bool { sort.SliceStable(s, func(i, j int) bool {
return s[i] > s[j] return s[i] > s[j]

4
sum.go
View file

@ -10,8 +10,8 @@ func Sum[T constraints.Ordered](values []T) (sum T) {
return sum return sum
} }
// Sums the values you select from your struct, basically a sort cut instead of // SumMap sums the values you select from your struct, basically a sort cut instead of
// having to perform a u.Map followed by a u.Sum // having to perform a [Map] followed by a [Sum].
func SumMap[T any, R constraints.Ordered](list []T, selector func(T) R) (sum R) { func SumMap[T any, R constraints.Ordered](list []T, selector func(T) R) (sum R) {
for _, v := range list { for _, v := range list {
sum += selector(v) sum += selector(v)

View file

@ -1,5 +1,7 @@
package underscore package underscore
// Ternary returns the first argument if the condition is true, otherwise the second argument.
// Ternary is a special form of the if statement. It allows you to write code that is more concise and less verbose.
func Ternary[T any](condition bool, pos, neg T) T { func Ternary[T any](condition bool, pos, neg T) T {
if condition { if condition {
return pos return pos

View file

@ -1,5 +1,7 @@
package underscore package underscore
// Tuple is a generic tuple type.
// It is used to return multiple values from a function.
type Tuple[L, R any] struct { type Tuple[L, R any] struct {
Left L Left L
Right R Right R

View file

@ -1,5 +1,6 @@
package underscore package underscore
// Unique returns a slice of unique values from the given slice.
func Unique[T comparable](values []T) (uniques []T) { func Unique[T comparable](values []T) (uniques []T) {
seen := make(map[T]bool, 0) seen := make(map[T]bool, 0)
for _, v := range values { for _, v := range values {

2
zip.go
View file

@ -1,6 +1,6 @@
package underscore package underscore
// Zips two slices togther so all the elements of left slice are attached to the corresponding // Zip joins two slices together so all the elements of left slice are attached to the corresponding
// elements of the right slice, i.e. [one two three] [1 2 3 4] = [{one, 1} {two, 2} {three, 3}] // elements of the right slice, i.e. [one two three] [1 2 3 4] = [{one, 1} {two, 2} {three, 3}]
// the returned data will be the size of the smallest slice // the returned data will be the size of the smallest slice
func Zip[L any, R any](left []L, right []R) []Tuple[L, R] { func Zip[L any, R any](left []L, right []R) []Tuple[L, R] {