@@ -85,25 +85,45 @@ task with the smallest possible allocation of your machine's resources.
85
85
86
86
### Concat
87
87
88
- Concatenate strings ` s ` to the one string:
88
+ Concatenates strings ` s ` to the one string:
89
89
90
90
``` go
91
91
s1 := " this "
92
92
s2 := " is "
93
93
s3 := " my string"
94
94
95
- s := gosl.Concat (s1, s2, s3)
95
+ s := gosl.Concat (s1, s2, s3) // "this is my string"
96
96
```
97
97
98
98
### ContainsCaseInsensitive
99
99
100
- Report if string ` substr ` is within string ` s ` (case-insensitive by default):
100
+ Reports if string ` substr ` is within string ` s ` (case-insensitive by default):
101
101
102
102
``` go
103
103
s := " Hello, WORLD!"
104
104
substr := " r"
105
105
106
- b := gosl.ContainsCaseInsensitive (s, substr)
106
+ b := gosl.ContainsCaseInsensitive (s, substr) // true
107
+ ```
108
+
109
+ ### IsFileExist
110
+
111
+ Reports whether a file exists on the specified ` path ` :
112
+
113
+ ``` go
114
+ p := filepath.Clean (" ~/Downloads/file.csv" )
115
+
116
+ b := gosl.IsFileExist (p) // true|false
117
+ ```
118
+
119
+ ### IsDirExist
120
+
121
+ Reports whether a dir exists on the specified ` path ` :
122
+
123
+ ``` go
124
+ p := filepath.Clean (" ~/Downloads/my-folder" )
125
+
126
+ b := gosl.IsDirExist (p) // true|false
107
127
```
108
128
109
129
### RandomString
@@ -113,7 +133,7 @@ Generates a (**really**) random string with a given size:
113
133
``` go
114
134
size := 8
115
135
116
- s , err := gosl.RandomString (size)
136
+ s , err := gosl.RandomString (size) // string, like "34f4ey7e"
117
137
if err != nil {
118
138
log.Fatal (err)
119
139
}
@@ -126,33 +146,33 @@ Renders a styled string with a given `lipgloss.Style` template:
126
146
``` go
127
147
tmpl := lipgloss.NewStyle ().Foreground (lipgloss.Color (" 42" )).Margin (1 )
128
148
129
- s := gosl.RenderStyled (" This is a styled text" , tmpl)
149
+ s := gosl.RenderStyled (" This is a styled text" , tmpl) // styled string
130
150
```
131
151
132
152
This function is a more comfortable wrapper for the
133
153
[ charmbracelet/lipgloss] [ charmbracelet_lipgloss_url ] library.
134
154
135
155
### ToString
136
156
137
- Convert byte slice ` b ` to string or error:
157
+ Converts byte slice ` b ` to string or error:
138
158
139
159
``` go
140
160
b := []byte (" Hello, World!" )
141
161
142
- s , err := gosl.ToString (b)
162
+ s , err := gosl.ToString (b) // "Hello, World!"
143
163
if err != nil {
144
164
log.Fatal (err)
145
165
}
146
166
```
147
167
148
168
### ToBytes
149
169
150
- Convert string ` s ` to byte slice or error:
170
+ Converts string ` s ` to byte slice or error:
151
171
152
172
``` go
153
173
s := " Hello, World!"
154
174
155
- b , err := gosl.ToBytes (s)
175
+ b , err := gosl.ToBytes (s) // [48 65 6c ...]
156
176
if err != nil {
157
177
log.Fatal (err)
158
178
}
@@ -171,46 +191,46 @@ resources, but can be applied to a huge number of user types.
171
191
172
192
### Equals
173
193
174
- Compare two values of type ` T ` , return ` true ` if they are equal:
194
+ Compares two values of type ` T ` , return ` true ` if they are equal:
175
195
176
196
``` go
177
197
s1 := " hello"
178
198
s2 := " hello"
179
199
180
- b := gosl.Equals (s1, s2)
200
+ b := gosl.Equals (s1, s2) // true
181
201
```
182
202
183
203
### NotEquals
184
204
185
- Compare two values of type ` T ` , return ` true ` if they are ** not** equal:
205
+ Compares two values of type ` T ` , return ` true ` if they are ** not** equal:
186
206
187
207
``` go
188
208
s1 := 42
189
209
s2 := 64
190
210
191
- b := gosl.NotEquals (s1, s2)
211
+ b := gosl.NotEquals (s1, s2) // true
192
212
```
193
213
194
214
### ContainsInSlice
195
215
196
- Report if value ` v ` is within slice ` s ` :
216
+ Reports if value ` v ` is within slice ` s ` :
197
217
198
218
``` go
199
219
s := []string {" one" , " two" , " three" }
200
220
v := " two"
201
221
202
- b := gosl.ContainsInSlice (s, v)
222
+ b := gosl.ContainsInSlice (s, v) // true
203
223
```
204
224
205
225
### ContainsInMap
206
226
207
- Report if key ` k ` is within map ` m ` :
227
+ Reports if key ` k ` is within map ` m ` :
208
228
209
229
``` go
210
230
m := map [string ]int {" one" : 1 , " two" : 2 , " three" : 3 }
211
231
k := " two"
212
232
213
- b := gosl.ContainsInMap (m, k)
233
+ b := gosl.ContainsInMap (m, k) // true
214
234
```
215
235
216
236
### Marshal
@@ -225,7 +245,7 @@ type user struct {
225
245
226
246
u := &user{}
227
247
228
- j , err := gosl.Marshal (u)
248
+ j , err := gosl.Marshal (u) // {"id": 0, "name": ""}
229
249
if err != nil {
230
250
log.Fatal (err)
231
251
}
@@ -247,7 +267,7 @@ type user struct {
247
267
j := []byte (` {"id":1,"name":"Viktor"}` )
248
268
m := &user{}
249
269
250
- u , err := gosl.Unmarshal (j, m)
270
+ u , err := gosl.Unmarshal (j, m) // [id:1 name:Viktor]
251
271
if err != nil {
252
272
log.Fatal (err)
253
273
}
@@ -300,6 +320,10 @@ BenchmarkContainsCaseInsensitive_LoremIpsum-8 1827114 656.4 ns/op
300
320
BenchmarkContainsInSlice-8 122999034 9.758 ns/op 0 B/op 0 allocs/op
301
321
302
322
BenchmarkContainsInMap-8 19123504 62.61 ns/op 0 B/op 0 allocs/op
323
+
324
+ BenchmarkIsFileExist-8 395916 2941 ns/op 240 B/op 2 allocs/op
325
+
326
+ BenchmarkIsDirExist-8 437505 2696 ns/op 224 B/op 2 allocs/op
303
327
```
304
328
305
329
## 💡 Motivation
@@ -335,29 +359,19 @@ Your PRs & issues are welcome! Thank you 😘
335
359
and robots by [ Vic Shóstak] [ author ] .
336
360
337
361
[ go_version_img ] : https://img.shields.io/badge/Go-1.20+-00ADD8?style=for-the-badge&logo=go
338
-
339
362
[ go_report_img ] : https://img.shields.io/badge/Go_report-A+-success?style=for-the-badge&logo=none
340
-
341
363
[ go_report_url ] : https://goreportcard.com/report/github.com/koddr/gosl
342
364
343
365
[ go_dev_url ] : https://pkg.go.dev/github.com/koddr/gosl
344
366
345
- [ code_coverage_img ] : https://img.shields.io/badge/code_coverage-98 %25-success?style=for-the-badge&logo=none
367
+ [ code_coverage_img ] : https://img.shields.io/badge/code_coverage-99 %25-success?style=for-the-badge&logo=none
346
368
347
369
[ license_img ] : https://img.shields.io/badge/license-Apache_2.0-red?style=for-the-badge&logo=none
348
-
349
370
[ license_url ] : https://github.com/koddr/gosl/blob/main/LICENSE
350
-
351
371
[ repo_url ] : https://github.com/koddr/gosl
352
-
353
372
[ repo_issues_url ] : https://github.com/koddr/gosl/issues
354
-
355
373
[ repo_pull_request_url ] : https://github.com/koddr/gosl/pulls
356
-
357
374
[ encoding_json_url ] : https://pkg.go.dev/encoding/json
358
-
359
375
[ charmbracelet_lipgloss_url ] : https://github.com/charmbracelet/lipgloss
360
-
361
376
[ benchmarks ] : https://github.com/koddr/gosl/tree/main#%EF%B8%8F-benchmarks
362
-
363
377
[ author ] : https://github.com/koddr
0 commit comments