{"version":3,"file":"truncate.cjs","names":[],"sources":["../../src/string/truncate.ts"],"sourcesContent":["/**\n * Truncates string if it's longer than the given maximum string length.\n *\n * @param str - The string to truncate\n * @param options - The options object\n * @param options.length - The maximum string length (default: 30)\n * @param options.omission - The string to indicate text is omitted (default: '...')\n * @returns The truncated string\n *\n * @example\n * truncate('Hi-Diddly-Ho there, Flanders!') // => 'Hi-Diddly-Ho there, Flanders!'\n * truncate('Hi-Diddly-Ho there, Flanders!', { length: 20 }) // => 'Hi-Diddly-Ho ther...'\n * truncate('Hi-Diddly-Ho there, Flanders!', { length: 20, omission: ' [...]' }) // => 'Hi-Diddly-Ho [...]'\n */\nexport function truncate(\n  str: string,\n  options?: {\n    length?: number;\n    omission?: string;\n  },\n): string {\n  if (typeof str !== 'string') {\n    return '';\n  }\n\n  const length = options?.length ?? 30;\n  const omission = options?.omission ?? '...';\n\n  if (str.length <= length) {\n    return str;\n  }\n\n  // Calculate how many characters we can keep\n  const truncateLength = Math.max(length - omission.length, 0);\n  return str.slice(0, truncateLength) + omission;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,SAAgB,SACd,KACA,SAIQ;CACR,IAAI,OAAO,QAAQ,UACjB,OAAO;CAGT,MAAM,SAAS,SAAS,UAAU;CAClC,MAAM,WAAW,SAAS,YAAY;CAEtC,IAAI,IAAI,UAAU,QAChB,OAAO;CAIT,MAAM,iBAAiB,KAAK,IAAI,SAAS,SAAS,QAAQ,CAAC;CAC3D,OAAO,IAAI,MAAM,GAAG,cAAc,IAAI;AACxC"}