{"version":3,"file":"index.mjs","sources":["../src/string/stringUtils.ts"],"sourcesContent":["export function formatCamelStr(str = ''): string {\r\n  return str\r\n    .replace(/^\\w/, c => c.toUpperCase())\r\n    .replace(/([a-z0-9])([A-Z])/g, '$1 $2')\r\n    .replace(/_/g, ' ');\r\n}\r\n\r\nexport function replaceAll(text: string, searchValue: string, replaceValue = ''): string {\r\n  return text.replace(new RegExp(searchValue, 'g'), replaceValue || '');\r\n}\r\n\r\n/**\r\n * trims characters from the left\r\n * @param text text to trim\r\n * @param characters character to trim\r\n * @returns trimmed string\r\n */\r\nexport function trimStart(text: string, characters = ' \\n\\t\\r'): string {\r\n  if (!text) {\r\n    return text;\r\n  }\r\n  \r\n  let startIndex = 0;\r\n  while (characters.indexOf(text.charAt(startIndex)) >= 0) {\r\n    startIndex++;\r\n  }\r\n  return text.substring(startIndex);\r\n}\r\n\r\n/**\r\n * trims characters from the right\r\n * @param text text to trim\r\n * @param characters character to trim\r\n * @returns trimmed string\r\n */\r\nexport function trimEnd(text: string, characters = ' \\n\\t\\r'): string {\r\n  if (!text) {\r\n    return text;\r\n  }\r\n\r\n  let endIndex = text.length;\r\n  while (characters.indexOf(text.charAt(endIndex - 1)) >= 0) {\r\n    endIndex--;\r\n  }\r\n  return text.substring(0, endIndex);\r\n}\r\n\r\n/**\r\n * trims characters from both sides\r\n * @param text text to trim\r\n * @param characters character to trim\r\n * @returns trimmed string\r\n */\r\nexport function trim(text: string, characters = ' \\n\\t\\r'): string {\r\n  return trimStart(trimEnd(text, characters), characters);\r\n}\r\n\r\n/**\r\n * Splits string into array of tokens based on a separator(one or many).\r\n * Also, you can define open close brackets.\r\n * e.g. split('field1=func(a,b,c),field2=4', ',', ['()'])\r\n * // result = [\"field1=func(a,b,c)\", \"field2=4\"]\r\n * @param text Text to split\r\n * @param separator\r\n * @param openClose\r\n * @returns\r\n */\r\nexport function split(text: string, separator = ',', openClose?: string[]): string[] {\r\n  const res: string[] = [];\r\n\r\n  if (!text) {\r\n    return res;\r\n  }\r\n\r\n  openClose = openClose || [];\r\n  let index = -1;\r\n\r\n  let token = '';\r\n  while (++index < text.length) {\r\n    let currentChar = text[index];\r\n\r\n    const oIndex = openClose.findIndex(s => s[0] === currentChar);\r\n    if (oIndex >= 0) {\r\n      token += text[index];\r\n      let innerBrackets = 0;\r\n      while (text[++index] !== openClose[oIndex][1] || innerBrackets) {\r\n        currentChar = text[index];\r\n        token += currentChar;\r\n\r\n        if (currentChar === openClose[oIndex][0]) {\r\n          innerBrackets++;\r\n        }\r\n\r\n        if (currentChar === openClose[oIndex][1]) {\r\n          innerBrackets--;\r\n        }\r\n\r\n        if (index + 1 === text.length) {\r\n          throw new Error(`Closing bracket is missing`);\r\n        }\r\n      }\r\n      token += text[index];\r\n      continue;\r\n    }\r\n\r\n    if (separator.includes(currentChar)) {\r\n      res.push(token);\r\n      token = '';\r\n    } else {\r\n      token += currentChar;\r\n    }\r\n  }\r\n\r\n  res.push(token);\r\n\r\n  return res;\r\n}\r\n"],"names":[],"mappings":"SAAgB,cAAc,CAAC,GAAG,GAAG,EAAE;IACrC,OAAO,GAAG;SACP,OAAO,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;SACpC,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC;SACtC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACxB,CAAC;SAEe,UAAU,CAAC,IAAY,EAAE,WAAmB,EAAE,YAAY,GAAG,EAAE;IAC7E,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,YAAY,IAAI,EAAE,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;SAMgB,SAAS,CAAC,IAAY,EAAE,UAAU,GAAG,SAAS;IAC5D,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,IAAI,CAAC;KACb;IAED,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,OAAO,UAAU,CAAC,OA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