Skip to content

Instantly share code, notes, and snippets.

View sagarpanchal's full-sized avatar

Sagar Panchal sagarpanchal

View GitHub Profile
@sagarpanchal
sagarpanchal / isUrl.ts
Created October 5, 2023 12:23
TS is-url
const rURL =
/^((https?|ftp):)?\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!$&'()*+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!$&'()*+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!$&'()*+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2}
@sagarpanchal
sagarpanchal / isEmpty.ts
Last active October 5, 2023 12:23
TS is-empty
export interface IsEmptyOptions {
isEmpty?: any[]
isNotEmpty?: any[]
}
export function isEmpty(input: any, options: IsEmptyOptions = {}): boolean {
options = { isEmpty: [], isNotEmpty: [], ...options } as IsEmptyOptions
if (options.isEmpty?.includes?.(input)) return true
if (options.isNotEmpty?.includes?.(input)) return false
@sagarpanchal
sagarpanchal / chain.ts
Created October 5, 2023 12:21
TS Chain
export function chain<T>(object: T) {
const call =
<V>(previousResult: V) =>
<U>(callback: (object: T, result: V) => U) => {
const result = callback(object, previousResult)
return { call: call(result), result: () => result, object: () => object }
}
return { call: call(undefined), result: () => undefined, object: () => object }
}
@sagarpanchal
sagarpanchal / map-files.ts
Created October 5, 2023 12:20
Find files
import path from "path"
import fs from "fs-extra"
import ignore from "ignore"
import type { Ignore } from "ignore"
import { minimatch } from "minimatch"
import type { SetOptional } from "type-fest"
const ignoreDirectories = [".*", ".git", ".idea", ".venv", ".vscode", "bin", "node_modules", "obj", "vendor"]
const ignoreBuildDirectories = ["build", "dist", "out", "public"]
@sagarpanchal
sagarpanchal / pick.ts
Last active October 5, 2023 12:24
TS pick/omit
function pick<T, K extends keyof T>(obj: T, ...keys: K[]) {
return Object.fromEntries(keys.map((key) => [key, obj[key]])) as Pick<T, K>
}
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';