Skip to content

Commit 8f7eb2d

Browse files
committed
feat: support spaces between quantity and unit in convertMany() and ms()
1 parent c403802 commit 8f7eb2d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/converters/convert-many.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ describe('conversions', () => {
1515
{ from: '-1m', to: [-1, 'm'] },
1616
{ from: '0.1m', to: [0.1, 'm'] },
1717
{ from: '-0.1m', to: [-0.1, 'm'] },
18+
19+
{ from: '1 m', to: [1, 'm'] },
20+
{ from: '-.1 m', to: [-0.1, 'm'] },
21+
{ from: '-1 m', to: [-1, 'm'] },
22+
{ from: '1m 1 m', to: [2, 'm'] },
23+
// Doesn't parse double spaces
24+
{ from: '1m 1 m', to: [1, 'm'] },
1825
])('$from -> $to', ({ from, to }) => {
1926
// biome-ignore lint/suspicious/noExplicitAny:
2027
expect(convertMany(from).to(to[1] as any)).toBe(to[0]);

src/converters/convert-many.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { convert } from './convert';
44

55
import type { BestUnits, Unit } from '../types/units';
66

7-
const splitExpression = /(-?(?:\d+)?\.?\d+)(\S+)/g;
7+
const splitExpression = /(-?(?:\d+)?\.?\d+)\s?(\S+)/g;
88

99
type ConverterThis = {
1010
_search: RegExpExecArray;

0 commit comments

Comments
 (0)