This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function doShaHashing(message: string, algorithm: 'SHA-256' | 'SHA-384' | 'SHA-512') { | |
// Check if the specified algorithm is supported | |
const supportedAlgorithms = ['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512']; | |
if (!supportedAlgorithms.includes(algorithm.toLowerCase())) { | |
throw new Error(`Unsupported algorithm: ${algorithm}`); | |
} | |
// Encode the message as a Uint8Array | |
const encoder = new TextEncoder(); | |
const data = encoder.encode(message); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// indexeddb-helper.ts | |
class IndexedDBHelper { | |
private readonly dbName: string; | |
private readonly storeName: string; | |
constructor(dbName: string, storeName: string) { | |
this.dbName = dbName; | |
this.storeName = storeName; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const data = new FormData(ev.target); | |
const dataObj = Object.fromEntries(data.entries()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Location } from "history"; | |
import React, { useEffect, useState } from "react"; | |
import { Prompt } from "react-router-dom"; | |
import { SubmitDialogComponent } from "./Modal"; | |
interface Props { | |
when?: boolean | undefined; // just use true | |
navigate: (path: string) => void; // (path) => history.push(path) | |
shouldBlockNavigation: (location: Location) => boolean; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Call fn not more often but and not less then ms | |
* @param {function} fn - function what need to call not often but and not less then ms | |
* @param {number} ms - time in milliseconds | |
* @return (any[]) => void | |
*/ | |
export const throttle = (fn: (...args: any[]) => void, ms: number = 0) => { | |
let timeoutId = null; | |
let lastCall = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
// 1 | |
function smartJoin(arrA, arrB) { | |
let aIndex = 0; | |
let bIndex = 0; | |
const result = []; | |
while (aIndex < arrA.length || bIndex < arrB.length) { | |
const itemA = arrA[aIndex]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* example: | |
* const aObj = { | |
* b: () => 42, | |
* c: () => "hello" | |
* } | |
* type ObjExample = ReturnedValueFromObjectMethodByKey<typeof aObj>; | |
* ObjExample type will be: {b: number; c: string} | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flatter(arr) { | |
return arr.flat(Infinity); | |
} | |
flatter( | |
[1, 2, [3, 4, [5]], 6, [[7, [8]], 9]], | |
); | |
function flatter2(arr) { | |
const arrCopy = arr.slice(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function find2(str) { | |
let _helper = []; | |
return str | |
.split('') | |
.reduce((acum, item, i, originalArr) => { | |
if (_helper.some(char => char === item)) { | |
acum.push(_helper); | |
_helper = []; | |
} | |
_helper.push(item); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getBoundingClientRect(el) { | |
return new Promise((res, rej) => { | |
requestAnimationFrame(() => { | |
res(el.getBoundingClientRect()); | |
}); | |
}); | |
} |
NewerOlder