View scrollTo.js
function scrollTo(element) {
const bodyRect = document.body.getBoundingClientRect();
const elemRect = element.getBoundingClientRect();
const offset = Math.round(elemRect.top - bodyRect.top);
window.scroll({
top: offset,
left: 0,
behavior: 'smooth'
});
View renameObjectKey.js
function renameObjectKey(oldObj, oldName, newName) {
const newObj = {};
Object.keys(oldObj).forEach(key => {
const value = oldObj[key];
if (key === oldName) {
newObj[newName] = value;
} else {
newObj[key] = value;
View on-resize-end.js
const doSomething = () => { /* Do something */ }
let onResizeEnd;
window.addEventListener('resize', () => {
if (onResizeEnd) {
clearTimeout(onResizeEnd);
}
onResizeEnd = setTimeout(() => doSomething(), 400);
});
View jest-collect-coverage-from-coverage-report.md
jest --collectCoverageFrom='[\"**/*.js\",\"!src/js/vue/**/*.js\"]' --coverage
View i18n-in-aem-and-vue.md

How to do i18n (Internationization) within Vue apps using the :lang prop

JavaScript

import Template from './template.html';

export default {
  template: Template,
  props: {
View git-squash-all-commits-in-master-branch-into-one-commit.md
git checkout --orphan new-squashed-branch master
git commit
View replace-query-string.js
window.history.replaceState(null, null, `${location.pathname}?abcd=1234`);
View Github Master Rebase.md
# Rebase the master branch
git checkout master
git pull --rebase
# Checkout the branch you want to rebase with master
git pull --rebase origin master
View add-event.js
/**
* @param element The element to add the event
* @param type Event type (i.e. 'click')
* @param callback Function to execute when event is triggered
*/
function (element, type, callback) {
try {
element.addEventListener(type, callback, false);
} catch (e) {
element.attachEvent('on' + type, callback);
View typescript-2.x-string-enum.ts
export enum ExampleStringEnum {
PROPERTY_A = 'property-a' as any as ExampleStringEnum,
PROPERTY_B = 'property-b' as any as ExampleStringEnum,
}