{"version":3,"file":"index.cjs","sources":[""],"sourcesContent":["export type TGetStrTruncatedArgs = Parameters<typeof getStrTruncated>;\n\nexport type TGetStrTruncatedReturn = ReturnType<typeof getStrTruncated>;\n\n/**\n * Truncates a string to a maximum number of Unicode code points.\n * The suffix is included in the maximum length.\n * @param {string} str Source string\n * @param {number} maxLength Maximum result length\n * @param {string} [suffix=\"…\"] Suffix for truncated strings\n * @returns {string} Truncated string\n * @throws {TypeError} getStrTruncated: str must be a string\n * @throws {TypeError} getStrTruncated: maxLength must be a non-negative integer\n * @throws {TypeError} getStrTruncated: suffix must be a string\n * @example\n * getStrTruncated(\"Hello world\", 8); // \"Hello w…\"\n * @example\n * // Limit a product title to fit inside a compact card\n * const cardTitle = getStrTruncated(product.title, 48, \"...\");\n */\nexport const getStrTruncated = (str: string, maxLength: number, suffix: string = \"…\"): string => {\n  if (typeof str !== \"string\") {\n    throw new TypeError(\"getStrTruncated: str must be a string\");\n  }\n  if (!Number.isInteger(maxLength) || maxLength < 0) {\n    throw new TypeError(\"getStrTruncated: maxLength must be a non-negative integer\");\n  }\n  if (typeof suffix !== \"string\") {\n    throw new TypeError(\"getStrTruncated: suffix must be a string\");\n  }\n\n  const chars = Array.from(str);\n  if (chars.length <= maxLength) {\n    return str;\n  }\n  const suffixChars = Array.from(suffix);\n  if (suffixChars.length >= maxLength) {\n    return suffixChars.slice(0, maxLength).join(\"\");\n  }\n  return chars.slice(0, maxLength - suffixChars.length).join(\"\") + suffix;\n};\n"],"names":["getStrTruncated","str","maxLength","suffix","TypeError","Number","isInteger","chars","Array","from","length","suffixChars","slice","join"],"mappings":"yDAoBO,MAAMA,gBAAkB,CAACC,IAAaC,UAAmBC,OAAiB,OAC/E,UAAWF,MAAQ,SACjB,MAAM,IAAIG,UAAU,yCAEtB,IAAKC,OAAOC,UAAUJ,YAAcA,UAAY,EAC9C,MAAM,IAAIE,UAAU,6DAEtB,UAAWD,SAAW,SACpB,MAAM,IAAIC,UAAU,4CAGtB,MAAMG,MAAQC,MAAMC,KAAKR,KACzB,GAAIM,MAAMG,QAAUR,UAClB,OAAOD,IAET,MAAMU,YAAcH,MAAMC,KAAKN,QAC/B,GAAIQ,YAAYD,QAAUR,UACxB,OAAOS,YAAYC,MAAM,EAAGV,WAAWW,KAAK,IAE9C,OAAON,MAAMK,MAAM,EAAGV,UAAYS,YAAYD,QAAQG,KAAK,IAAMV"}