Skip to main content

JavaScript

Remove URL query

Reference

location.search = '';

Using relative URL (Reference RFC1808)

<a href="?">
location = '?';

URL for browser

https://github.com/medialize/URI.js

Absolute URL for browser

Reference

var getAbsUrl = (function() {
var a;

return function(url) {
if (!a) {
a = document.createElement('a');
}
a.href = url;
return a.href;
};
})();

Metric prefix

Number.prototype.prefix = function (precision, base) {

var units = ' K M G T P E Z Y'.split(' ');

if (typeof precision === 'undefined') {
precision = 2;
}

if (typeof base === 'undefined') {
base = 1000;
}

if (this == 0 || !isFinite(this)) {
return this.toFixed(precision) + units[0];
}

var power = Math.floor(Math.log(Math.abs(this)) / Math.log(base));
// Make sure not larger than max prefix
power = Math.min(power, units.length - 1);

return (this / Math.pow(base, power)).toFixed(precision) + units[power];
};

Performance / Benchmark

function benchmark(run) {
var start = performance.now();
run();
return performance.now() - start;
}

Static Web Server

http-server

npm i -g http-server@13

http-server .

Vercel serve

See serve