Skip to content

Instantly share code, notes, and snippets.

View langpavel's full-sized avatar

Pavel Lang langpavel

View GitHub Profile
@langpavel
langpavel / graphql-ast.ts
Created December 1, 2020 17:10
GraphQL AST Type Definitions converted to data structures from `graphql/language/ast.d.ts`
/**
* Types as data from 'graphql/language/ast.d.ts'
*/
import type { ASTNode } from 'graphql/language/ast';
export interface ASTNodeFieldInfo {
readonly optional?: boolean;
readonly isArray?: boolean;
readonly type: string;
@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 {