typedash
Version:
modern, type-safe collection of utility functions
1 lines • 999 B
Source Map (JSON)
{"version":3,"file":"ensureSuffix-D2sbFKA6.cjs","names":[],"sources":["../src/functions/ensureSuffix/ensureSuffix.ts"],"sourcesContent":["/**\n * Ensures that the string ends with the given suffix.\n * @param string The string to ensure the suffix of.\n * @param suffix The suffix to ensure.\n * @returns The string with the given suffix.\n * @example\n * ```ts\n * ensureSuffix('foo', 'bar'); // 'foobar'\n * ensureSuffix('foobar', 'bar'); // 'foobar'\n * ```\n */\nexport function ensureSuffix<S extends string, Suffix extends string>(\n string: S,\n suffix: Suffix\n): EnsureSuffix<S, Suffix> {\n if (string.endsWith(suffix)) {\n return string as EnsureSuffix<S, Suffix>;\n }\n\n return `${string}${suffix}` as EnsureSuffix<S, Suffix>;\n}\n\ntype EnsureSuffix<\n S extends string,\n Suffix extends string,\n> = S extends `${infer _Prefix}${Suffix}` ? S : `${S}${Suffix}`;\n"],"mappings":";;;;;;;;;;;;;AAWA,SAAgB,aACd,QACA,QACyB;AACzB,KAAI,OAAO,SAAS,OAAO,CACzB,QAAO;AAGT,QAAO,GAAG,SAAS"}