Skip to content

Instantly share code, notes, and snippets.

View hyyan's full-sized avatar

Hyyan Abo Fakher hyyan

  • BASIS Europe Distribution GmbH
  • Germany
  • 07:16 (UTC +02:00)
  • LinkedIn in/hyyan
View GitHub Profile
@hyyan
hyyan / format.js
Created July 17, 2018 11:35
Formate date/time in javascript
function format(date, format) {
if (!date || !format) {
return;
}
if (format.toLowerCase() === "short") {
format = "dd-MM-yyyy";
}
if (format.toLowerCase() === "medium") {
format = "dd-MM-yyyy hh:mm:ss";
}
/* Attribution: http://techslides.com/how-to-parse-and-search-json-in-javascript */
//return an array of objects according to key, value, or key and value matching
function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val));
} else
@hyyan
hyyan / history.js
Created September 10, 2024 13:30 — forked from kottenator/history.js
Document title & History API
var button = document.createElement('button');
button.textContent = 'Push';
document.body.appendChild(button);
var x, title;
if (!history.state) {
x = 0;
title = document.title;
// Without this we can loose the initial page's title on browser navigation