Skip to content

Instantly share code, notes, and snippets.

View langpavel's full-sized avatar

Pavel Lang langpavel

View GitHub Profile
@langpavel
langpavel / cssRulesIterator.js
Created April 12, 2022 11:12
filter all CSS rules
function* cssRulesIterator() {
for(const stylesheet of window.document.styleSheets) {
for (const rule of stylesheet.cssRules) {
yield rule.cssText;
}
}
}
[...cssRulesIterator()].filter(ruleText => true)
@langpavel
langpavel / http-status.ts
Created May 20, 2022 13:29
Type definitions for HTTP status codes
/* eslint-disable @typescript-eslint/no-redeclare */
export function isHttpStatusSuccess(code: number): code is HTTP_STATUS_SUCCESS {
return code >= 200 && code < 300;
}
export function isHttpStatusClientError(code: number): code is HTTP_STATUS_CLIENT_ERROR {
return code >= 400 && code < 500;
}
export function isHttpStatusServerError(code: number): code is HTTP_STATUS_SERVER_ERROR {
@langpavel
langpavel / GraphQLTimestamp.js
Last active July 28, 2023 08:46
GraphQLTimestamp.js
import { Kind } from 'graphql/language';
import { GraphQLScalarType } from 'graphql';
function serializeDate(value) {
if (value instanceof Date) {
return value.getTime();
} else if (typeof value === 'number') {
return Math.trunc(value);
} else if (typeof value === 'string') {
return Date.parse(value);