remeda
Version:
A utility library for JavaScript and Typescript.
1 lines • 2.39 kB
Source Map (JSON)
{"version":3,"file":"sliceString.cjs","names":[],"sources":["../src/sliceString.ts"],"sourcesContent":["/**\n * Extracts a section of a string between two indices.\n *\n * This function is a wrapper around the built-in [`String.prototype.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)\n * method.\n *\n * @param data - The string to extract from.\n * @param indexStart - The index of the first character to include in the\n * returned substring.\n * @param indexEnd - The index of the first character to exclude from the\n * returned substring.\n * @returns A new string containing the extracted section of the string.\n * @signature\n * R.sliceString(data, indexStart, indexEnd)\n * @example\n * R.sliceString(\"abcdefghijkl\", 1) // => `bcdefghijkl`\n * R.sliceString(\"abcdefghijkl\", 4, 7) // => `efg`\n * @dataFirst\n * @category String\n */\nexport function sliceString(\n data: string,\n indexStart: number,\n indexEnd?: number,\n): string;\n\n/**\n * Extracts a section of a string between two indices.\n *\n * This function is a wrapper around the built-in [`String.prototype.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)\n * method.\n *\n * @param indexStart - The index of the first character to include in the\n * returned substring.\n * @param indexEnd - The index of the first character to exclude from the\n * returned substring, or `undefined` for the rest of the string.\n * @returns A new string containing the extracted section of the string.\n * @signature\n * R.sliceString(indexStart, indexEnd)(string)\n * @example\n * R.sliceString(1)(\"abcdefghijkl\") // => `bcdefghijkl`\n * R.sliceString(4, 7)(\"abcdefghijkl\") // => `efg`\n * @dataLast\n * @category String\n */\nexport function sliceString(\n indexStart: number,\n indexEnd?: number,\n): (data: string) => string;\n\nexport function sliceString(\n dataOrIndexStart: number | string,\n indexStartOrIndexEnd?: number,\n indexEnd?: number,\n): unknown {\n return typeof dataOrIndexStart === \"string\"\n ? dataOrIndexStart.slice(indexStartOrIndexEnd, indexEnd)\n : (data: string) => data.slice(dataOrIndexStart, indexStartOrIndexEnd);\n}\n"],"mappings":"AAkDA,SAAgB,EACd,EACA,EACA,EACS,CACT,OAAO,OAAO,GAAqB,SAC/B,EAAiB,MAAM,EAAsB,EAAS,CACrD,GAAiB,EAAK,MAAM,EAAkB,EAAqB"}