Skip to content

Instantly share code, notes, and snippets.

View i-havr's full-sized avatar
👋
Hi there!

Ihor Havrylov i-havr

👋
Hi there!
View GitHub Profile
@i-havr
i-havr / checkDuplicate.js
Created May 30, 2023 20:03
Функція перевіряє, чи дублюється новий об'єкт при додаванні в масив (по конкретному ключу-значенню). Повертає Boolean.
const checkDuplicate = (array, newObject) => {
const isDuplicate = array.some((obj) => obj.key === newObject.key);
return isDuplicate;
};
@i-havr
i-havr / endStringWithThreeDots.js
Created June 9, 2023 10:49
Функція повертає скорочений до заданої кількості символів рядок із трьома крапками у кінці.
const LIMIT = 30;
const endStringWithThreeDots = (str) => {
if (str.length <= LIMIT) {
return str;
} else {
const updatedString = str.slice(0, LIMIT - 3) + "...";
return updatedString;
}
};
@i-havr
i-havr / useWindowWidth.ts
Last active September 5, 2023 06:35
Custom React.js hook which returns the current width of the window. Also the current state of mobile/tablet/desktop screen is returned.
'use client';
import { useState, useEffect } from 'react';
// const SCREEN_MOBILE = 320;
const LARGE_SCREEN_MOBILE = 480;
const SCREEN_TABLET = 768;
const SCREEN_DESKTOP = 1280;
const LARGE_SCREEN_DESKTOP = 1440;
@i-havr
i-havr / SomePage.jsx
Last active August 26, 2023 17:16
This code allows you to create auto-expanding textarea field without un ugly expanding-corner :)
import { onExpandableTextareaInput } from "./auto-expanding-textarea";
import "./index.css";
document.addEventListener("input", onExpandableTextareaInput);
export default function SomePage() {
const handleChange = () => {
console.log("The value was changed!")}
return (
<form>
@i-havr
i-havr / index.css
Last active July 11, 2023 17:39
Create a cool animated avatar for your portfolio (only CSS).
img {
--s: 300px; /* image size */
--b: 6px; /* border thickness */
--c: #ae3ec9; /* border color */
--cb: #e9ecef; /* background color */
--f: 1; /* initial scale */
width: var(--s);
aspect-ratio: 1;
padding-top: calc(var(--s) / 5);