Skip to content

Commit

Permalink
Merge pull request #134 from mechanik-daniel/133-endswith-startswith-…
Browse files Browse the repository at this point in the history
…undefined

fix: endsWith+startsWith with undefined inputs
  • Loading branch information
mechanik-daniel authored Dec 24, 2024
2 parents a612775 + 7550e96 commit 81af426
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/helpers/stringFunctions/stringFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ import { randomUUID } from 'crypto';
import { sha256 } from 'js-sha256';
import uuidByString from 'uuid-by-string';

export const startsWith = (str: string, startStr: string): boolean => str.startsWith(startStr);
export const startsWith = (str: string | undefined, startStr: string): boolean | undefined => {
// undefined inputs always return undefined
if (typeof str === 'undefined') return undefined;
return str.startsWith(startStr);
};

export const endsWith = (str: string, endStr: string): boolean => str.endsWith(endStr);
export const endsWith = (str: string | undefined, endStr: string): boolean | undefined => {
// undefined inputs always return undefined
if (typeof str === 'undefined') return undefined;
return str.endsWith(endStr);
};

export const initCapOnce = (str: string): string => {
// used for polymorhic element names, where all type names need to
Expand Down

0 comments on commit 81af426

Please sign in to comment.