mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 16:55:23 +00:00
* use parsed options while signing * update project layout to v3 * fix .gitignore * remove example template * misc updates * bump tlsx version * hide template sig warning with env * js: retain value while using log * fix nil pointer derefernce * misc doc update --------- Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
17 lines
389 B
Go
17 lines
389 B
Go
package utils
|
|
|
|
// TransformIndex transforms user given index (start from 1) to array index (start from 0)
|
|
// in safe way without panic i.e negative index or index out of range
|
|
func TransformIndex[T any](arr []T, index int) int {
|
|
if index <= 1 {
|
|
// negative index
|
|
return 0
|
|
}
|
|
if index >= len(arr) {
|
|
// index out of range
|
|
return len(arr) - 1
|
|
}
|
|
// valid index
|
|
return index - 1
|
|
}
|