Skip to content

No check for the type of 'page' and 'numItems' #5

@HunteRoi

Description

@HunteRoi

Intro

Hey there!

I just went through your lib and src folders and read your scripts. It looks like you don't check for the result of parseInput for the currentPage and the perPage variables. This will then make the library not work properly and could cause issues.

I know that the people using your package could simply check the values before they submit them to your library however I feel like it still needs to make its own place into here.

Steps to reproduce

Step 1

Create a JS file (let's call it index.js) and copy-paste the following code :

const paginate = require('paginate-array');
const array = [1, 2, 3, 4, 5, 6];
console.log(paginate(array, NaN));

or

const paginate = require('paginate-array');
const array = [1, 2, 3, 4, 5, 6];
console.log(paginate(array, 1, NaN));

Step 2

Type node index.js and observe the result

Results

Expected

Uncaught TypeError: page is not a number
or
Uncaught TypeError: numItems is not a number

Received

{ currentPage: NaN,
  perPage: 10,
  total: 6,
  totalPages: 1,
  data: [] 
}

or

{ currentPage: 1,
  perPage: NaN,
  total: 6,
  totalPages: NaN,
  data: [] 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions