remeda
Version:
A utility library for JavaScript and Typescript.
1 lines • 2.48 kB
Source Map (JSON)
{"version":3,"file":"endsWith.cjs","names":["purry"],"sources":["../src/endsWith.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\n/**\n * Determines whether a string ends with the provided suffix, and refines the\n * output type if possible.\n *\n * This function is a wrapper around the built-in [`String.prototype.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)\n * method, but doesn't expose the `endPosition` parameter. To check only up to a\n * specific position, use `endsWith(sliceString(data, 0, endPosition), suffix)`.\n *\n * @param data - The input string.\n * @param suffix - The string to check for at the end.\n * @signature\n * R.endsWith(data, suffix);\n * @example\n * R.endsWith(\"hello world\", \"hello\"); // false\n * R.endsWith(\"hello world\", \"world\"); // true\n * @dataFirst\n * @category String\n */\nexport function endsWith<T extends string, Suffix extends string>(\n data: T,\n suffix: string extends Suffix ? never : Suffix,\n): data is T & `${string}${Suffix}`;\nexport function endsWith(data: string, suffix: string): boolean;\n\n/**\n * Determines whether a string ends with the provided suffix, and refines the\n * output type if possible.\n *\n * This function is a wrapper around the built-in [`String.prototype.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)\n * method, but doesn't expose the `endPosition` parameter. To check only up to a\n * specific position, use `endsWith(sliceString(data, 0, endPosition), suffix)`.\n *\n * @param suffix - The string to check for at the end.\n * @signature\n * R.endsWith(suffix)(data);\n * @example\n * R.pipe(\"hello world\", R.endsWith(\"hello\")); // false\n * R.pipe(\"hello world\", R.endsWith(\"world\")); // true\n * @dataLast\n * @category String\n */\nexport function endsWith<Suffix extends string>(\n suffix: string extends Suffix ? never : Suffix,\n): <T extends string>(data: T) => data is T & `${string}${Suffix}`;\nexport function endsWith(suffix: string): (data: string) => boolean;\n\nexport function endsWith(...args: ReadonlyArray<unknown>): unknown {\n return purry(endsWithImplementation, args);\n}\n\nconst endsWithImplementation = (data: string, suffix: string): boolean =>\n data.endsWith(suffix);\n"],"mappings":"wCAgDA,SAAgB,EAAS,GAAG,EAAuC,CACjE,OAAOA,EAAAA,EAAM,EAAwB,EAAK,CAG5C,MAAM,GAA0B,EAAc,IAC5C,EAAK,SAAS,EAAO"}