{"version":3,"file":"normalizeSpaces-BVykeu_h.cjs","names":["isNonEmptyString","isPlainObject"],"sources":["../src/strings/sanitizations/normalizeSpaces.ts"],"sourcesContent":["import { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\ntype NormalizeSpacesOptions = {\n  /** If `true`, skips normalization and only trims whitespace from start & end, defaultValue: `false`.\n   *\n   * @default false\n   */\n  trimOnly?: boolean;\n  /** If `false`, skips trimming value, defaultValue: `true`.\n   *\n   * @default true\n   */\n  withTrim?: boolean;\n};\n\n/** ----------------------------------------------------------\n * * ***Utility: `normalizeSpaces`.***\n * -----------------------------------------------------------\n * **Normalizes whitespace in a string by reducing multiple spaces\n * to a single space, optionally trims, or only trims based on options.**\n *\n * ---\n * - **Behavior:**\n *     - Collapses all consecutive whitespace (spaces, tabs, newlines) into a single space.\n *     - Can trim leading/trailing spaces (default behavior), or preserve them with `withTrim: false`.\n *     - Can skip normalization entirely and only trim using `trimOnly: true`.\n *     - Returns an empty string if input is `null` or `undefined`.\n *\n * ---\n * @param {string | null | undefined} value - The input string to be processed. If `null` or `undefined`, returns an empty string.\n * @param {NormalizeSpacesOptions} [options] - Configuration options.\n * @param {NormalizeSpacesOptions[\"trimOnly\"]} [options.trimOnly=false] - If `true`, skips normalization and only trims the string.\n * @param {NormalizeSpacesOptions[\"withTrim\"]} [options.withTrim=true] - If `false`, preserves leading/trailing whitespace.\n *\n * ---\n * @returns {string} The processed string.\n *\n * ---\n * @example\n * normalizeSpaces(\"   Hello    World\\tthis   is\\n\\nok \");\n * // ➔ \"Hello World this is ok\"\n * normalizeSpaces(\"   Hello    World\\tthis   is\\n\\nok \", { trimOnly: true });\n * // ➔ \"Hello    World\tthis   is\\n\\nok\"\n * normalizeSpaces(\"   Hello    World   \", { withTrim: false });\n * // ➔ \" Hello World \"\n * normalizeSpaces(null);\n * // ➔ \"\"\n */\nexport const normalizeSpaces = (\n  value: string | null | undefined,\n  options?: NormalizeSpacesOptions\n): string => {\n  if (!isNonEmptyString(value)) return \"\";\n\n  if (!isPlainObject(options)) options = {};\n\n  const { trimOnly = false, withTrim = true } = options;\n\n  if (trimOnly) return value.trim();\n\n  if (withTrim) {\n    value = value.trim();\n  }\n\n  // Remove all duplicate spaces (including tabs, newlines, etc.)\n  return value.replace(/\\s+/g, \" \");\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAa,mBACX,OACA,YACW;CACX,IAAI,CAACA,gCAAiB,KAAK,GAAG,OAAO;CAErC,IAAI,CAACC,6BAAc,OAAO,GAAG,UAAU,CAAC;CAExC,MAAM,EAAE,WAAW,OAAO,WAAW,SAAS;CAE9C,IAAI,UAAU,OAAO,MAAM,KAAK;CAEhC,IAAI,UACF,QAAQ,MAAM,KAAK;CAIrB,OAAO,MAAM,QAAQ,QAAQ,GAAG;AAClC"}
