UNPKG

str-indexes-of-plus

Version:

Like indexOf but returns array and counts per-grapheme

11 lines (9 loc) 1.08 kB
/** * @name str-indexes-of-plus * @fileoverview Like indexOf but returns array and counts per-grapheme * @version 5.0.9 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/str-indexes-of-plus/} */ var o="5.0.9";var f=o;function g(p,l,e=0){if(typeof p!="string")throw new TypeError(`str-indexes-of-plus/strIndexesOfPlus(): first input argument must be a string! Currently it's: ${typeof p}`);if(typeof l!="string")throw new TypeError(`str-indexes-of-plus/strIndexesOfPlus(): second input argument must be a string! Currently it's: ${typeof l}`);if(isNaN(+e)||typeof e=="string"&&!/^\d*$/.test(e))throw new TypeError(`str-indexes-of-plus/strIndexesOfPlus(): third input argument must be a natural number! Currently it's: ${e}`);let s=Array.from(p),r=Array.from(l);if(s.length===0||r.length===0||e!=null&&+e>=s.length)return[];e||(e=0);let u=[],i=!1,n;for(let t=e,d=s.length;t<d;t++)i&&(s[t]===r[t-+n]?t-+n+1===r.length&&u.push(+n):(n=null,i=!1)),i||s[t]===r[0]&&(r.length===1?u.push(t):(i=!0,n=t));return u}export{g as strIndexesOfPlus,f as version};