UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

14 lines (13 loc) 337 B
export const strCnt = (needle, haystack, offset = 0) => { let cnt = 0; const needleLen = needle.length; if (needleLen === 0) return 0; while (true) { const index = haystack.indexOf(needle, offset); if (index < 0) return cnt; cnt++; offset = index + needleLen; } };