mirror of
https://github.com/sasjs/lint.git
synced 2025-12-10 17:34:36 +00:00
27 lines
488 B
TypeScript
27 lines
488 B
TypeScript
export const getIndicesOf = (
|
|
searchStr: string,
|
|
str: string,
|
|
caseSensitive: boolean = true
|
|
) => {
|
|
const searchStrLen = searchStr.length
|
|
if (searchStrLen === 0) {
|
|
return []
|
|
}
|
|
|
|
let startIndex = 0,
|
|
index,
|
|
indices = []
|
|
|
|
if (!caseSensitive) {
|
|
str = str.toLowerCase()
|
|
searchStr = searchStr.toLowerCase()
|
|
}
|
|
|
|
while ((index = str.indexOf(searchStr, startIndex)) > -1) {
|
|
indices.push(index)
|
|
startIndex = index + searchStrLen
|
|
}
|
|
|
|
return indices
|
|
}
|