MCPcopy Index your code
hub / github.com/TruthHun/BookStack / arrayIndexOf

Function arrayIndexOf

static/word2md/mammoth.browser.js:10407–10461  ·  view source on GitHub ↗
(arr, val, byteOffset, encoding, dir)

Source from the content-addressed store, hash-verified

10405}
10406
10407function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
10408 var indexSize = 1
10409 var arrLength = arr.length
10410 var valLength = val.length
10411
10412 if (encoding !== undefined) {
10413 encoding = String(encoding).toLowerCase()
10414 if (encoding === 'ucs2' || encoding === 'ucs-2' ||
10415 encoding === 'utf16le' || encoding === 'utf-16le') {
10416 if (arr.length < 2 || val.length < 2) {
10417 return -1
10418 }
10419 indexSize = 2
10420 arrLength /= 2
10421 valLength /= 2
10422 byteOffset /= 2
10423 }
10424 }
10425
10426 function read (buf, i) {
10427 if (indexSize === 1) {
10428 return buf[i]
10429 } else {
10430 return buf.readUInt16BE(i * indexSize)
10431 }
10432 }
10433
10434 var i
10435 if (dir) {
10436 var foundIndex = -1
10437 for (i = byteOffset; i < arrLength; i++) {
10438 if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
10439 if (foundIndex === -1) foundIndex = i
10440 if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
10441 } else {
10442 if (foundIndex !== -1) i -= i - foundIndex
10443 foundIndex = -1
10444 }
10445 }
10446 } else {
10447 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
10448 for (i = byteOffset; i >= 0; i--) {
10449 var found = true
10450 for (var j = 0; j < valLength; j++) {
10451 if (read(arr, i + j) !== read(val, j)) {
10452 found = false
10453 break
10454 }
10455 }
10456 if (found) return i
10457 }
10458 }
10459
10460 return -1
10461}
10462
10463Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
10464 return this.indexOf(val, byteOffset, encoding) !== -1

Callers 1

bidirectionalIndexOfFunction · 0.70

Calls 1

readFunction · 0.70

Tested by

no test coverage detected