Skip to content

Commit 61adeca

Browse files
committed
Remove getCharacterLastIndex
1 parent 8176950 commit 61adeca

2 files changed

Lines changed: 1 addition & 31 deletions

File tree

src/utils.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
import { getCharacterIndex, getCharacterLastIndex } from './utils.ts';
1+
import { getCharacterIndex } from './utils.ts';
22

33
test('getCharacterIndex', () => {
44
expect(getCharacterIndex('foobar', /o/, 0)).toBe(1);
55
expect(getCharacterIndex('foobar', /o/, 1)).toBe(1);
66
expect(getCharacterIndex('foobar', 'o', 0)).toBe(1);
77
expect(() => getCharacterIndex('foobar', '_', 0)).toThrow();
88
});
9-
10-
test('getCharacterLastIndex', () => {
11-
expect(getCharacterLastIndex('foobar', /o/, 6)).toBe(2);
12-
expect(getCharacterLastIndex('foobar', /o/, 2)).toBe(2);
13-
expect(getCharacterLastIndex('foobar', 'o', 6)).toBe(2);
14-
expect(() => getCharacterLastIndex('foobar', '_', 6)).toThrow();
15-
});

src/utils.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,6 @@ function getCharacterSearchTestFunction(pattern: RegExp | string) {
88
return (character: string) => pattern.test(character);
99
}
1010

11-
export function getCharacterLastIndex(
12-
text: string,
13-
pattern: RegExp | string,
14-
fromIndex: number,
15-
) {
16-
const test = getCharacterSearchTestFunction(pattern);
17-
18-
for (let index = fromIndex; index >= 0; index--) {
19-
const character = text[index];
20-
21-
if (test(character)) {
22-
return index;
23-
}
24-
}
25-
26-
/* c8 ignore next 4 @preserve */
27-
throw new Error(
28-
`Cannot find front char ${pattern} from index ${fromIndex} in ${JSON.stringify(
29-
text,
30-
)}`,
31-
);
32-
}
33-
3411
export function getCharacterIndex(
3512
text: string,
3613
pattern: RegExp | string,

0 commit comments

Comments
 (0)