Skip to content

Instantly share code, notes, and snippets.

View sagarpanchal's full-sized avatar

Sagar Panchal sagarpanchal

View GitHub Profile
export function mapListByProp<T extends object, K extends keyof T>(list: T[], key: K) {
const output = new Map<T[K], T[]>()
for (const item of list) {
if (!(key in item)) continue
const existingList = (output.has(item[key]) && output.get(item[key])) || []
const updatedList = [...existingList, item]
output.set(item[key], updatedList)
}
@sagarpanchal
sagarpanchal / .js
Created January 6, 2023 06:38
make column sticky
export const freezeColumns = (table, options = {}) => {
options = { index: 5, offset: -0, ignoreClasses: ['groupingTableAmount', 'activebg'], ...options };
const stickyIndex = options.index;
const rows = table?.querySelectorAll?.('tr');
const testRow = table?.querySelectorAll?.('tbody tr')?.[0] ?? rows?.[0];
const cellSlice = Array.prototype.slice.call(testRow.children, 0, stickyIndex);
const widthList = Array.prototype.map.call(cellSlice, (cell) => cell?.getBoundingClientRect()?.width);
const leftOffsetList = widthList.map((_, index) => {
@sagarpanchal
sagarpanchal / extensions.txt
Last active November 10, 2023 12:49
VS CODE
adam-bender.commit-message-editor
alefragnani.project-manager
arcsine.chronicler
Asuka.insertnumbers
bierner.emojisense
bodil.prettier-toml
bradlc.vscode-tailwindcss
bwildeman.tabulous
csstools.postcss
DavidAnson.vscode-markdownlint

Branch Types

  • 🚑 hotfix/ - for urgent bug fixes that merge directly into production
  • 🐛 bugfix/ - for bug fixes that merges to staging and then production
  • feature/- to implement new feature
  • 🛠️ changes/ - to improve existing feature/code/algorithm
  • 📃 document/ - add/update documentation
  • 📦 deps/ - add/update dependencies

Branch Names

@sagarpanchal
sagarpanchal / utils.js
Created January 6, 2022 08:22
ES Utils
import cloneDeep from 'lodash/cloneDeep';
import forOwn from 'lodash/forOwn';
import isEqual from 'lodash/isEqual';
import memoize from 'lodash/memoize';
import xorWith from 'lodash/xorWith';
import { DateTime, Duration } from 'luxon';
export const LOCALE = 'en-US';
export const CURRENCY = 'USD';
export const TIMEZONE_IANA = 'Asia/Kolkata';
@sagarpanchal
sagarpanchal / stickTableColumns.js
Created November 24, 2021 12:39
Stick Table Columns
const stickyIndex = 5;
const rows = document.querySelectorAll("table tr");
const cellSlice = Array.prototype.slice.call(rows[0].children, 0, stickyIndex);
const widthList = Array.prototype.map.call(cellSlice, (cell) => cell.offsetWidth);
const leftOffsetList = widthList.map((_, index) => {
const output = -10;
for (let i = 0; i < index; i++) output = output + (widthList[i] - 1);
return output;
});
@sagarpanchal
sagarpanchal / number.proto.js
Created September 30, 2021 07:20
number.proto.js
Object.defineProperty(Number.prototype, 'decimal', {
get: function decimal() {
Number.precision = 'precision' in Number ? Number.precision : 3;
const f = Math.pow(10, Number.precision);
return Math.round(this * f) / f;
},
});
export class Action {
constructor(type) {
this.type = type;
}
emit(detail) {
const event = new CustomEvent(this.type, { detail });
window.dispatchEvent(event);
}
@sagarpanchal
sagarpanchal / ajaxCall.ts
Created November 13, 2019 12:38
JS Commons
interface IAjaxCall {
error: boolean;
status: number;
data: any;
}
/**
* async api call helper
* @param func function that'll return promise
*/
@sagarpanchal
sagarpanchal / phoneGap.sh
Created October 21, 2018 20:59
Run phoneGap on Ubuntu
#!/bin/bash
# cd to a directory where you want to install phoneGap
# and run following commands (or just download run this file with bash)
# https://github.com/phonegap/phonegap-app-desktop/commit/7a121fb96aef856cca36c6191778081e9d6317e5
# https://github.com/phonegap/phonegap-app-desktop/commit/5ad750815ddf51e6cc8e557f46afb455e288b92e
sudo apt-get install libgconf-2-4 &&
npm install -g grunt-cli &&