Skip to content

Instantly share code, notes, and snippets.

View dkhrunov's full-sized avatar
📭
Searching for a job

Denis Khrunov dkhrunov

📭
Searching for a job
  • Russia, Penza
View GitHub Profile
@dkhrunov
dkhrunov / HttpStatusCode.ts
Created November 2, 2023 10:08 — forked from scokmen/HttpStatusCode.ts
Typescript Http Status Codes Enum
"use strict";
/**
* Hypertext Transfer Protocol (HTTP) response status codes.
* @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
*/
enum HttpStatusCode {
/**
* The server has received the request headers and the client should proceed to send the request body

Conventional Commit Messages

See how a minor change to your commit message style can make a difference. Examples

Have a look at CLI util git-conventional-commits to ensure this conventions and generate changelogs

Commit Formats

Default

@dkhrunov
dkhrunov / get-nested-value.ts
Last active November 3, 2022 09:46
Recursively traverse by object and return value by nested key
import { isObject, isUndefined } from '../types';
export const getNestedValue = <T>(
object: Record<string | number, T>,
key: string
): T | undefined => {
const getRecursive = (
obj: T | Record<string | number, T>,
keys: string[]
): T | undefined => {
@dkhrunov
dkhrunov / coercion.decorator.ts
Created September 13, 2022 08:41
Сoercion Decorators
import {
coerceArray,
coerceBooleanProperty,
coerceCssPixelValue,
coerceElement,
coerceNumberProperty,
coerceStringArray,
} from '@angular/cdk/coercion';
function propDecoratorFactory<T, D>(
@dkhrunov
dkhrunov / utility-type-guards.ts
Last active September 11, 2022 22:59
Type Gruards
export const isUndefined = (obj: any): obj is undefined =>
typeof obj === 'undefined';
export const isObject = (fn: any): fn is object =>
!isNil(fn) && typeof fn === 'object';
export const isPlainObject = (fn: any): fn is object => {
if (!isObject(fn)) {
return false;
}
@dkhrunov
dkhrunov / is-type-of.ts
Created August 9, 2022 22:09
Universal type guard
export declare interface Type<T> extends Function {
new (...args: any[]): T;
}
export function isTypeOf<T>(type: Type<T>, instance: any): instance is T {
const typeProperties = Object.getOwnPropertyNames(type.prototype);
const instanceProperties = Object.getOwnPropertyNames(
instance.constructor.prototype
);
@dkhrunov
dkhrunov / takeUntilAngular14.ts
Created August 5, 2022 21:38
New takeUntil with Angular v14
export function takeUntilDestroy$<T>(): UnaryFunction<Observable<T>, Observable<T>> {
const viewRef = inject(ChangeDetectorRef) as ViewRef;
const destroyer$ = new ReplaySubject<void>(1);
viewRef.onDestroy(() => destroyer$.next())
return (observable: Observable<T>) => observable.pipe(takeUntil(destroyer$));
}
@dkhrunov
dkhrunov / debounce.decorator.ts
Created July 27, 2022 22:37
Debounce decorator
export function Debounce(timeout: number) {
let timeoutRef: NodeJS.Timer | null = null;
return function (
_target: any,
_propertyKey: string | symbol,
descriptor: PropertyDescriptor
): TypedPropertyDescriptor<any> {
const original = descriptor.value;
@dkhrunov
dkhrunov / what-forces-layout.md
Created July 16, 2022 15:32 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@dkhrunov
dkhrunov / query-params-tracker-builder.interface.ts
Last active July 14, 2022 13:29
Angular QueryParamsTracker - allows to react on changes in the source Observable and sets this value to URL queryParams and also in the opposite direction
import { ActivatedRoute, Router } from '@angular/router';
import { QueryParamsTracker } from './query-params-tracker';
import {
QueryParamsMapper,
SourceValueMapper,
} from './query-params-tracker.types';
export interface IQueryParamsTrackerBuilder<
TValue,
TParams = TValue,