Skip to content

Instantly share code, notes, and snippets.

View erkobridee's full-sized avatar

Erko Bridee erkobridee

View GitHub Profile
/*
based on:
https://sqlpey.com/javascript/top-5-methods-to-generate-a-hash-from-a-string-in-javascript/#generating-a-hash-method-3-using-hexadecimal-output
*/
export const cyrb53Hex = (str: string, seed = 0) => {
let h1 = 0xdeadbeef ^ seed,
h2 = 0x41c6ce57 ^ seed
for (let i = 0, ch; i < str.length; i++) {
export const toObject = <K extends string | number, V>(arr: [K, V][]) =>
arr.reduce((obj, [key, value]) => {
obj[key] = value
return obj
}, {} as Record<K, V>)
export default toObject(
Object.entries(import.meta.glob('./icons/*.svg', { eager: true, import: 'default' })).map(
([n, m]) => [
n.replace('./icons/', '').replace('.svg', ''),
// ref.: https://plainjs.com/javascript/manipulation/unwrap-a-dom-element-35/
/**
* unwrap the content of a given HTMLElement to the parent element at the previous
* position of the given element
*
* @param {HTMLElement} element
* @param {boolean} removeElement
*/
export const unwrap = (element: HTMLElement, removeElement = true) => {
/*
Day.js - format
https://day.js.org/docs/en/display/format
*/
const getLastSundaysOfYear = (year = new Date().getFullYear()) => {
const currentYear = dayjs().year(year);
const lastSundaysOfYearMap = new Map();
for(let i = 0; i < 12; i++) {
const lastSundayOfMonth = currentYear.month(i).endOf('month').day(0);
/*
dynamic sorting an object array
https://dev.to/fpaghar/donesort-an-array-of-objects-ways-in-javascript-48hl
*/
const SortDirection = {
Asc: 1,
Desc: -1
} as const;