Number(page)
instead 57
58const getPagingData = (data, page, limit) => {
59 const { count: totalItems, rows: tutorials } = data;
60 const currentPage = page ? +page : 0; 61 const totalPages = Math.ceil(totalItems / limit);
62 return { totalItems, tutorials, totalPages, currentPage };
63};
Number(size)
instead 49};
50
51const getPagination = (page, size) => {
52 const limit = size ? +size : 3; 53 const offset = page ? page * limit : 0;
54
55 return { limit, offset };
Prefer using explicit casts by calling Number
, Boolean
, or String
over using operators like +
, !!
or "" +
.
This is considered best practice as it improves readability.
const b = !!foo;
// The `+` operator does not change the value of its operand
// unless it's already a number.
let n = +foo;
n = 1 * foo;
const s = "" + foo;
const b = Boolean(foo);
const n = Number(foo);
const s = String(foo);