Skip to content

Instantly share code, notes, and snippets.

@krobing
krobing / utilities.d.ts
Created March 13, 2025 16:47
TypeScript's Utilities
/**
* Transforms the keys of an object type to uncapitalized versions.
*
* This utility type takes an object type `ObjType` and produces a new type
* where all the keys are uncapitalized. The values associated with the keys
* remain unchanged.
*
* @template ObjType - The object type whose keys are to be uncapitalized.
*
* @example
@krobing
krobing / createReducerCtx.tsx
Last active March 11, 2025 04:38
Custom Hooks for React to create a ReactContext with useState and useReducer built-in React hooks
'use client'
import React from 'react'
// types definition
export type Action = { type: string; [payload: string | number | symbol]: unknown }
export type ReducerCtxType<S = unknown, A = Action> = {
state: S
dispatch: React.Dispatch<A>
@krobing
krobing / api.d.ts
Last active January 25, 2024 20:44
Api middleware to extends redux.js & its definition types file
/* eslint-disable @typescript-eslint/no-explicit-any */
// include types definition from axios's http calls library
import { Method, CancelToken } from 'axios'
//
// Set interface/type definition for api middleware
//
// Constants
// Action key that carries API call info interpreted by this Redux middleware.
@krobing
krobing / bootstrap-styled.d.ts
Last active January 25, 2024 20:38
Type definitions libraries for: bootstrap-styled.d.ts, paginate-this.d.ts, react-imask.d.ts
// Dependencies by bootstrap styled
// --------------------------------
declare module '@bootstrap-styled/css-mixins'
declare module '@bootstrap-styled/provider' {
import { Theme, UserTheme } from 'bootstrap-styled'
import { Component, ReactNode, AnchorHTMLAttributes } from 'react'
import { DefaultTheme as StyledTheme, StyledComponentBase } from 'styled-components/macro'
export type BootstrapProviderProps = {
children: ReactNode
@krobing
krobing / extract-vars.js
Last active August 12, 2022 16:02
Scripts to extract sass/scss files variables to javascript plain object with formats
import styleVariables from '../../scss/bs4-runtime.scss';
import transformVars from './transformVars';
// console.log('styleVariables::', styleVariables);
/**
* Function that transforms and extracts variables from sass/scss files
* into a javascript's plain object
*
* @param options {Object} - {camelCase: boolean, numToStr: boolean}
@krobing
krobing / App.tsx
Last active August 11, 2022 19:40
Custom themes, functions, mixins and AppThemeProvider by styled-components
import React from 'react'
import BootstrapProvider from '@bootstrap-styled/provider'
import { Row, Col } from '@bootstrap-styled/v4'
import makeAppTheme, { utilities } from './styles/app.theme'
import AppThemeProvider from './styles/app.provider'
// app components
import Layout from './components/Layout'
import Comps from './examples/Comps'
import FilterForm from './examples/FilterForm'
@krobing
krobing / .editorconfig
Created August 8, 2022 22:24
proposal by .editorconfig
# editorconfig.org
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
indent_style = tab
@krobing
krobing / .eslintrc.json
Last active August 8, 2022 22:23
eslint/stylelintrc configuration for typescript & javascript & styles formatting with prettier tool
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
@krobing
krobing / .vscode.settings.json
Created August 8, 2022 22:15
vscode editor settings for project's code formatting
{
"editor.renderWhitespace": "boundary",
"editor.wordWrap": "bounded",
"editor.wordWrapColumn": 140,
"indenticator.inner.showHighlight": true,
"editor.formatOnType": false,
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"typescript.validate.enable": false,
"[javascript]": {
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
// "lib": [], /* Specify library files to be included in the compilation: */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */