str-indexes-of-plus
Version:
Like indexOf but returns array and counts per-grapheme
11 lines (9 loc) • 1.56 kB
JavaScript
/**
* @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 strIndexesOfPlus=(()=>{var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var g=(s,t)=>{for(var e in t)o(s,e,{get:t[e],enumerable:!0})},y=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of m(t))!f.call(s,r)&&r!==e&&o(s,r,{get:()=>t[r],enumerable:!(n=a(t,r))||n.enumerable});return s};var h=s=>y(o({},"__esModule",{value:!0}),s);var j={};g(j,{strIndexesOfPlus:()=>v,version:()=>x});var d="5.0.9";var x=d;function v(s,t,e=0){if(typeof s!="string")throw new TypeError(`str-indexes-of-plus/strIndexesOfPlus(): first input argument must be a string! Currently it's: ${typeof s}`);if(typeof t!="string")throw new TypeError(`str-indexes-of-plus/strIndexesOfPlus(): second input argument must be a string! Currently it's: ${typeof t}`);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 n=Array.from(s),r=Array.from(t);if(n.length===0||r.length===0||e!=null&&+e>=n.length)return[];e||(e=0);let u=[],l=!1,p;for(let i=e,c=n.length;i<c;i++)l&&(n[i]===r[i-+p]?i-+p+1===r.length&&u.push(+p):(p=null,l=!1)),l||n[i]===r[0]&&(r.length===1?u.push(i):(l=!0,p=i));return u}return h(j);})();