ES6 Class to get query params in string url or array of string urls

Size
3,158 Kb
Views
34,408

How do I make an es6 class to get query params in string url or array of string urls?

What is a es6 class to get query params in string url or array of string urls? How do you make a es6 class to get query params in string url or array of string urls? This script and codes were developed by Sébastien Lombard on 16 September 2022, Friday.

ES6 Class to get query params in string url or array of string urls Previews

ES6 Class to get query params in string url or array of string urls - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>ES6 Class to get query params in string url or array of string urls</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>ES6 Class to get query params in string url or array of string urls</h1>
<p> - string url as input = query params object <br />
- array of string urls as input = array of query params objects
</p>
Open your console. <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

ES6 Class to get query params in string url or array of string urls - Script Codes CSS Codes

body { text-align: center; font-family: sans-serif; padding: 2rem;
}
h1 { font-size: 2rem; margin-bottom: 2rem;
}
p { font-size: 1.2rem;
}

ES6 Class to get query params in string url or array of string urls - Script Codes JS Codes

'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var myUrl = 'https://codepen.io/pen/?editors=001&token=mamamama&myqueryvar=2342323';
var myUrlArray = ['https://codepen.io/pen/?editors=001&token=mamamama&myqueryvar=2342323', 'https://codepen.io/pen/?editors=001&token=mam2&myqueryvar=3'];
// JS ES6 CLASS
// ---------------------------
var getQueryParams = function () { // Constructor function getQueryParams(url) { _classCallCheck(this, getQueryParams); this.params = this.processRouter(url, url instanceof Array); } // Handle if string type or array of strings getQueryParams.prototype.processRouter = function processRouter(url, isArray) { if (isArray) { var finalArray = []; url.forEach(function (singleUrl) { finalArray.push(this.processUrl(singleUrl)); }, this); return finalArray; } else { return this.processUrl(url); } }; // Process urls getQueryParams.prototype.processUrl = function processUrl(singleUrl) { var paramsArray = singleUrl.split('?')[1].split('&'); var finalObj = {}; paramsArray.forEach(function (param) { finalObj[param.split('=')[0]] = param.split('=')[1]; }); return finalObj; }; return getQueryParams;
}();
console.info('String Input', new getQueryParams(myUrl).params, '\n\n');
console.info('Array Input', new getQueryParams(myUrlArray).params, '\n\n');
ES6 Class to get query params in string url or array of string urls - Script Codes
ES6 Class to get query params in string url or array of string urls - Script Codes
Home Page Home
Developer Sébastien Lombard
Username SebL
Uploaded September 16, 2022
Rating 3
Size 3,158 Kb
Views 34,408
Do you need developer help for ES6 Class to get query params in string url or array of string urls?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Sébastien Lombard (SebL) Script Codes
Create amazing Facebook ads with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!