Skip to content

Commit d16a688

Browse files
committed
🐛 fix negative ranges on formatToHiddenDigits
1 parent 041441c commit d16a688

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/models/Range.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const normalizeRange = (
88

99
if (range >= 0) return [0, range];
1010

11-
return [limit - Math.abs(range), limit];
11+
return [limit + 1 - Math.abs(range), limit];
1212
};
1313

1414
export const within = (

src/parsers/parseToCharacters.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,23 @@ export type RootCharacterNode = {
2727
const parseToCharacters = (value: string): RootCharacterNode => {
2828
let digits = 0;
2929

30+
const children = value.split('').map((character: string): DigitCharacterNode | OtherCharacterNode => {
31+
if (DIGIT.test(character))
32+
return {
33+
character,
34+
kind: 'digit',
35+
digit: ++digits, // It returns the incremented value of 'digits'.
36+
};
37+
return {
38+
character,
39+
kind: 'other',
40+
};
41+
});
42+
3043
return {
3144
digits,
45+
children,
3246
kind: 'root',
33-
children: value.split('').map((character, index) =>
34-
DIGIT.test(character)
35-
? {
36-
character,
37-
kind: 'digit',
38-
digit: ++digits, // It returns the incremented value of 'digits'.
39-
}
40-
: {
41-
character,
42-
kind: 'other',
43-
}
44-
),
4547
};
4648
};
4749

0 commit comments

Comments
 (0)