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
// split by ": " or "; " | |
const splitted = "Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green".split(/: |; /g); | |
// res: ['Game 1', '3 blue, 4 red', '1 red, 2 green, 6 blue', '2 green'] |
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
// https://stackoverflow.com/questions/49744804/how-to-match-an-overlapping-pattern-multiple-times-using-regexp | |
// the problem is that by default regexp cant do overlapping patterns | |
// for example we want: "eighthree" -> ['eight', 'three'] and for "sevenine" -< ['seven', 'nine'] | |
// but with default .match we get "eighthree" -> ['eight'] and for "sevenine" -> ['seven'] | |
const greedyRegex = (str: string) => { | |
let reg = /one|two|three|four|five|six|seven|eight|nine|\d/g, | |
next = reg.exec(str), | |
res = []; |
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
// DEMO: https://codesandbox.io/s/hackathon-jyswt0 | |
const FEATURES_LP_PD = { | |
Skills: { | |
'Show company data': 'cms.pages.skills.content.list.item.showCompanyData', | |
'Search whole company': 'cms.pages.skills.skillsShare.isSearchingWholeCompany', | |
'Knowledge Exchange': 'cms.pages.skills.hasSharedSkillsFeature', | |
'Replace default logo': 'cms.pages.skills.buttonOptions.replaceDefaultLogo', | |
'Logo change on hover': 'cms.pages.skills.buttonOptions.shouldLogoChangeOnHover', | |
}, |
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
// https://mobile.twitter.com/AndaristRake/status/1625130160277028864 | |
// https://twitter.com/GabrielVergnaud/status/1623814585445675008?s=20&t=iG8sUzPLNZNgog-tAttHiw | |
type AllPaths<T> = | |
// if `T` is an object with string keys | |
T extends Record<string, unknown> | |
// Assign the union `keyof T` to a variable `K` | |
? keyof T extends infer K | |
// We distribute K. | |
// For each member in `K`: |
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
https://github.com/typescript-eslint/typescript-eslint/issues/5947 | |
Don't use `{}` as a type. `{}` actually means "any non-nullish value". | |
- If you want a type meaning "any object", you probably want `object` instead. | |
- If you want a type meaning "any value", you probably want `unknown` instead. | |
- If you want a type meaning "empty object", you probably want `Record<string, never>` instead. |
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
// Write to the specific key of the object | |
// pathToWriteTo(['/', 'a'], 'myData') | |
// will write to -> {'/': {'a': 'myData'}} | |
function pathToWriteTo( | |
pathArr: string[], | |
input: { [key: string]: {} }, | |
fs: { [key: string]: {} } | |
) { | |
let level: { [key: string]: {} } = fs; | |
let index = 0; |
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
// https://tsplay.dev/WvaG4m | |
// Source: https://github.com/ghoullier/awesome-template-literal-types#dot-notation-string-type-safe | |
// alternative: https://github.com/g-makarov/dot-path-value | |
type PathImpl<T, Key extends keyof T> = | |
Key extends string | |
? T[Key] extends Record<string, any> | |
? | `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> & string}` |
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
// @ts-check | |
/** | |
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. | |
* This is especially useful for Docker builds. | |
*/ | |
!process.env.SKIP_ENV_VALIDATION && (await import("./src/env/server.mjs")); | |
/** @type {import("next").NextConfig} */ | |
const config = { | |
reactStrictMode: true, |
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
// Timer interview question | |
// https://twitter.com/erikras/status/1560681872002277379 | |
class Timer { | |
q = Promise.resolve() | |
call(cb) { | |
this.q = this.q.then(() => cb()) | |
return this | |
} |
NewerOlder