Skip to content

Commit

Permalink
refactor: adjust return statement + reorder checks within parseValue
Browse files Browse the repository at this point in the history
  • Loading branch information
scottenock committed Jul 8, 2024
1 parent 00dce5c commit b890453
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import decodeComponent from 'decode-uri-component';
import splitOnFirst from 'split-on-first';
import {includeKeys} from 'filter-obj';
import splitOnFirst from 'split-on-first';

const isNullOrUndefined = value => value === null || value === undefined;

Expand Down Expand Up @@ -301,18 +301,24 @@ function getHash(url) {
}

function parseValue(value, options, type) {
if (type === 'string' && (typeof value === 'string')) {
if (type === 'string' && typeof value === 'string') {
return value;
}

if (typeof type === 'function' && (typeof value === 'string')) {
value = type(value);
} else if (type === 'number' && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
value = Number(value);
} else if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
value = Number(value);
} else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
value = value.toLowerCase() === 'true';
if (typeof type === 'function' && typeof value === 'string') {
return type(value);
}

if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
return value.toLowerCase() === 'true';
}

if (type === 'number' && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
return Number(value);
}

if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
return Number(value);
}

return value;
Expand Down

0 comments on commit b890453

Please sign in to comment.