Skip to content

Commit

Permalink
fix: query param booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraghazra committed Jul 15, 2020
1 parent 00ce9d3 commit 5fce46d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require("dotenv").config();
const { renderError } = require("../src/utils");
const { renderError, parseBoolean } = require("../src/utils");
const fetchStats = require("../src/fetchStats");
const renderStatsCard = require("../src/renderStatsCard");

Expand Down Expand Up @@ -30,9 +30,9 @@ module.exports = async (req, res) => {
res.send(
renderStatsCard(stats, {
hide: JSON.parse(hide || "[]"),
show_icons,
hide_border,
hide_rank,
show_icons: parseBoolean(show_icons),
hide_border: parseBoolean(hide_border),
hide_rank: parseBoolean(hide_rank),
line_height,
title_color,
icon_color,
Expand Down
11 changes: 11 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ function isValidHexColor(hexColor) {
).test(hexColor);
}

function parseBoolean(value) {
if (value === "true") {
return true;
} else if (value === "false") {
return false;
} else {
return value;
}
}

function request(data, headers) {
return new Promise((resolve, reject) => {
axios({
Expand All @@ -54,4 +64,5 @@ module.exports = {
encodeHTML,
isValidHexColor,
request,
parseBoolean,
};

0 comments on commit 5fce46d

Please sign in to comment.