Skip to content

Commit

Permalink
We already parsed the number
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Apr 7, 2021
1 parent 0eee876 commit dc83904
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions lib/client-api/src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ type ValueType = { name: string; value?: ObjectValueType | ValueType };
type ObjectValueType = Record<string, ValueType>;

const INCOMPATIBLE = Symbol('incompatible');
const NUMBER_REGEXP = /^-?[0-9]+(\.[0-9]+)?$/;

const map = (arg: unknown, type: ValueType): any => {
if (arg === undefined || arg === null || !type) return arg;
switch (type.name) {
Expand All @@ -28,7 +26,7 @@ const map = (arg: unknown, type: ValueType): any => {
return acc;
}, new Array(arg.length));
case 'object':
if (typeof arg === 'string') return NUMBER_REGEXP.test(arg) ? Number(arg) : arg;
if (typeof arg === 'string' || typeof arg === 'number') return arg;
if (!type.value || typeof arg !== 'object') return INCOMPATIBLE;
return Object.entries(arg).reduce((acc, [key, val]) => {
const mapped = map(val, (type.value as ObjectValueType)[key]);
Expand Down

0 comments on commit dc83904

Please sign in to comment.