remeda
Version:
A utility library for JavaScript and Typescript.
1 lines • 550 B
JavaScript
const e=`...`;function t(e,t,r){return typeof e==`string`?n(e,t,r):r=>n(r,e,t)}function n(e,t,{omission:n=`...`,separator:r}={}){if(e.length<=t)return e;if(t<=0)return``;if(t<n.length)return n.slice(0,t);let i=t-n.length;if(typeof r==`string`){let t=e.lastIndexOf(r,i);t!==-1&&(i=t)}else if(r!==void 0){let t=r.flags.includes(`g`)?r:new RegExp(r.source,`${r.flags}g`),n;for(let{index:r}of e.matchAll(t)){if(r>i)break;n=r}n!==void 0&&(i=n)}return`${e.slice(0,i)}${n}`}Object.defineProperty(exports,`truncate`,{enumerable:!0,get:function(){return t}});