code: function validatePage(page, size) {
    page = page && isFinite(page) ? page : 1;
    if (page < 1) {
      return 0;
    }
    return --page * size;
  }
docs: Validate that the requested page is a number and is within correct bounds: page >= 0. Will also calculate the correct "from" value based on requested number of results see: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-from-size.html