This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Combined Union Type + Array of allowed values */ | |
const ServerEnvironments = ['development', 'test', 'stage', 'production'] as const; | |
// equivalent to `type ServerEnvironments = 'development' | 'test' | 'stage' | 'production' | |
type ServerEnvironments = typeof ServerEnvironments[number]; | |
const serverEnv: ServerEnvironments = 'development'; | |
const isValidServerEnv = (env: string): env is ServerEnvironments => ServerEnvironments.include(env); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const nodeCustomInspect = Symbol.for('nodejs.util.inspect.custom'); | |
const denoCustomInspect = Symbol.for("Deno.customInspect"); | |
const Ctor = () => ({}); | |
Object.assign(Ctor, { | |
prototype: { | |
constructor: Ctor, | |
toString() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export {}; | |
/** @see https://bobbyhadz.com/blog/typescript-process-env-type */ | |
declare global { | |
namespace NodeJS { | |
interface ProcessEnv { | |
// Added keys for process.env | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @see https://stackoverflow.com/a/3561711 | |
*/ | |
RegExp.xEscape = function escape(string) { | |
return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&'); | |
}; | |
Function.prototype.xPartial = function partial(...args) { | |
return this.bind(null, ...args); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { describe } from 'src/utils/testing'; | |
import { renderHook } from '@testing-library/react-hooks'; | |
//////// useConstant.test.ts //////// | |
import useConstant from 'src/hooks/useConstant'; | |
describe('useConstant()', async assert => { | |
const testStateValue = { value: 'abc' }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A function that converts one value of type A to another value or the same or a different type B | |
* | |
* Use with functions like: | |
* - @see Array.prototype.map() | |
* - `pipe()` or `compose()` functions | |
*/ | |
export type Mapper<A = unknown, B = unknown> = (val: A) => B; | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Loop function inspired by Lisp lop macro | |
// @see https://lispcookbook.github.io/cl-cookbook/iteration.html | |
const isStepLoop = config => false; | |
const isIterableLoop = config => false; | |
const isCountedLoop = config => false; | |
const loop = (config, onIter = x => x) => { | |
const { | |
// Loop from `from` to `to` by `step` | |
from, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AL": "Alabama", | |
"AK": "Alaska", | |
"AS": "American Samoa", | |
"AZ": "Arizona", | |
"AR": "Arkansas", | |
"CA": "California", | |
"CO": "Colorado", | |
"CT": "Connecticut", | |
"DE": "Delaware", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zhuLiDoTheThing(args) | |
// Application status codes can come from HTTP 2xx, 4xx, and 5xx responses. This `.then()` will attempt to resolve | |
// to Promise<codeString> or reject with an error if the code is missing from the response body. | |
.then( | |
response => { | |
if (response.code) { | |
// Forward the code from the response | |
return response.code; | |
} | |
NewerOlder