Skip to content

Commit

Permalink
feat: support spaces between quantity and unit in convertMany() and ms()
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahsnider committed Jun 4, 2024
1 parent c403802 commit 8f7eb2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/converters/convert-many.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ describe('conversions', () => {
{ from: '-1m', to: [-1, 'm'] },
{ from: '0.1m', to: [0.1, 'm'] },
{ from: '-0.1m', to: [-0.1, 'm'] },

{ from: '1 m', to: [1, 'm'] },
{ from: '-.1 m', to: [-0.1, 'm'] },
{ from: '-1 m', to: [-1, 'm'] },
{ from: '1m 1 m', to: [2, 'm'] },
// Doesn't parse double spaces
{ from: '1m 1 m', to: [1, 'm'] },
])('$from -> $to', ({ from, to }) => {
// biome-ignore lint/suspicious/noExplicitAny:
expect(convertMany(from).to(to[1] as any)).toBe(to[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/converters/convert-many.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { convert } from './convert';

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

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

type ConverterThis = {
_search: RegExpExecArray;
Expand Down

0 comments on commit 8f7eb2d

Please sign in to comment.