Skip to content

Commit

Permalink
fix(findValueBetween): return null if either start or end is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited authored Aug 31, 2024
1 parent 372ca78 commit 5e64b4d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { splitCookiesString } from "set-cookie-parser";

export const findValueBetween = (plain: string, start: string, end: string): string => {
const startIndex = plain.indexOf(start) + start.length;
export const findValueBetween = (plain: string, start: string, end: string): string | null => {
let startIndex = plain.indexOf(start);
if (startIndex === -1) return null;
startIndex = startIndex + start.length;

const endIndex = plain.indexOf(end, startIndex);
if (endIndex === -1) return null;

return plain.slice(startIndex, endIndex);
};

Expand Down

0 comments on commit 5e64b4d

Please sign in to comment.