src/index.js
function getQuery(path = '') {

  const query = {};

  // Check if the path even has a query first
  if(!path.includes('?')) {
    return query;
  }

  const queryString = path.split('?')[1];

  // Check if the query string has any values
  if(!queryString.includes('=')) {
    return query;
  }

  const values = queryString.split('&');

  // Loop over the query string values and add to the query object
  for (let i = values.length - 1; i >= 0; i--) {

    // Check that the current query string section has a value
    if(!values[i].includes('=')) {
      continue;
    }

    // Get the key and value to add to the query object
    const [ key, value ] = values[i].split('=');
    query[key] = value;
  }

  return query;
}
function getQuery(path = '') {

  const query = {};

  // Check if the path even has a query first
  if(!path.includes('?')) {
    return query;
  }

  const queryString = path.split('?')[1];

  // Check if the query string has any values
  if(!queryString.includes('=')) {
    return query;
  }

  const values = queryString.split('&');

  // Loop over the query string values and add to the query object
  for (let i = values.length - 1; i >= 0; i--) {

    // Check that the current query string section has a value
    if(!values[i].includes('=')) {
      continue;
    }

    // Get the key and value to add to the query object
    const [ key, value ] = values[i].split('=');
    query[key] = value;
  }

  return query;
}
function getQuery ( path = '' ) { const query = { } ; // Check if the path even has a query first if ( ! path . includes ( '?' ) ) { return query ; } const queryString = path . split ( '?' ) [ 1 ] ; // Check if the query string has any values if ( ! queryString . includes ( '=' ) ) { return query ; } const values = queryString . split ( '&' ) ; // Loop over the query string values and add to the query object for ( let i = values . length - 1 ; i >= 0 ; i -- ) { // Check that the current query string section has a value if ( ! values [ i ] . includes ( '=' ) ) { continue ; } // Get the key and value to add to the query object const [ key , value ] = values [ i ] . split ( '=' ) ; query [ key ] = value ; } return query ; }
Function to get the query object from a given path
Function to get the query object from a given path