Skip to content

Commit

Permalink
Add support for 'a'
Browse files Browse the repository at this point in the history
  • Loading branch information
rautio committed Oct 15, 2023
1 parent 58b4b09 commit dbc27aa
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions __tests__/parseText/suites/smoke.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ Tomorrow
In 3 days
0 9 4 * *

in a day
0 9 2 * *

In twenty days
0 9 21 * *

Expand Down
1 change: 1 addition & 0 deletions src/tokens/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('Number token should', () => {
const re = new RegExp(tokens[TokenType.NUMBER].test);
test('match on different formats', () => {
expect(re.test('1')).toBe(true);
expect(re.test('a')).toBe(true);
expect(re.test('30')).toBe(true);
expect(re.test('100')).toBe(true);
expect(re.test('60')).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion src/tokens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const tokens = {
test: '^(tomorrow)$',
},
[TokenType.NUMBER]: {
test: `^(\\d+|${numberStringRegexOptions})$`,
test: `^(\\d+|${numberStringRegexOptions})$|^a$`,
},
[TokenType.FREQUENCY]: {
test: '^(every|each|every other|at|on|next)$',
Expand Down
1 change: 1 addition & 0 deletions src/tokens/number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('Number token getNumber() should', () => {
expect(getNumber('ninety-nine')).toEqual(99);
expect(getNumber('twenty three')).toEqual(23);
expect(getNumber('sixty-seven')).toEqual(67);
expect(getNumber('a')).toEqual(1);
});
test('return the same number as literally written', () => {
expect(getNumber('2')).toEqual(2);
Expand Down
1 change: 1 addition & 0 deletions src/tokens/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const numberMap: Record<string, number> = { ...digits, ...ten, ...tens };
* @param str
*/
export const getNumber = (str: string): number => {
if (str === 'a') return 1;
const isLiteral = !isNaN(Number(str));
// If its a literal number like '2' - just return that
if (isLiteral) {
Expand Down

0 comments on commit dbc27aa

Please sign in to comment.