List of helpful shortcuts for faster coding
If you have any other helpful shortcuts, feel free to add in the comments of this gist :)
/** | |
* @see https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color | |
* @see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors | |
*/ | |
export const COLOURS = { | |
$: (c: number) => (str: string) => `\x1b[${c}m` + str + '\x1b[0m', | |
gray: (str: string) => COLOURS.$(90)(str), | |
cyan: (str: string) => COLOURS.$(36)(str), | |
yellow: (str: string) => COLOURS.$(33)(str), | |
green: (str: string) => COLOURS.$(32)(str), |
#!/bin/bash | |
# Check if sharp-cli is installed | |
if ! command -v sharp &> /dev/null; then | |
echo "Error: sharp-cli is not installed. Please install it using 'npm install -g sharp-cli'." | |
exit 1 | |
fi | |
# Directories | |
INPUT_DIR="." |
{ | |
"000000": "Black", | |
"000044": "Endless Galaxy", | |
"000066": "Alone in the Dark", | |
"000088": "Midnight in Tokyo", | |
"0000aa": "Bohemian Blue", | |
"0000ee": "Hyperlink Blue", | |
"0000ff": "Blue", | |
"00022e": "Illicit Darkness", | |
"000435": "Oblivion", |
wget -E -H -k -p https://www.example.com/ |
import { readdir } from "node:fs/promises"; | |
import { extname, resolve } from "node:path"; | |
async function* walkDir(dir: string): AsyncGenerator<string> { | |
const entries = await readdir(dir, { withFileTypes: true }); | |
for (const entry of entries) { | |
const name = resolve(dir, entry.name); | |
if (entry.isDirectory()) { | |
yield* walkDir(name); | |
} else if (filterFile(entry.name)) { |
:root { | |
--easeInSine: cubic-bezier(0.12, 0, 0.39, 0); | |
--easeOutSine: cubic-bezier(0.61, 1, 0.88, 1); | |
--easeInOutSine: cubic-bezier(0.37, 0, 0.63, 1); | |
--easeInQuad: cubic-bezier(0.11, 0, 0.5, 0); | |
--easeOutQuad: cubic-bezier(0.5, 1, 0.89, 1); | |
--easeInOutQuad: cubic-bezier(0.45, 0, 0.55, 1); | |
--easeInCubic: cubic-bezier(0.32, 0, 0.67, 0); | |
--easeOutCubic: cubic-bezier(0.33, 1, 0.68, 1); | |
--easeInOutCubic: cubic-bezier(0.65, 0, 0.35, 1); |
/** | |
* Calculate password strength | |
* @param value password | |
* @returns password strength in range between 0 an 1 | |
*/ | |
export const getPasswordStrength = (value: string): number => { | |
// Minimum 8 characters | |
const REGEX_CHARACTER = /^.{8,}$/ | |
// Minimum 2 uppercase, |
describe('arrayToKeyedObject', () => { | |
it('should return empty object if array are empty', () => { | |
type GenericItems = { code: string } | |
const items: GenericItems[] = [] | |
const result = arrayToKeyedObject(items, (item) => item.code) | |
expect(result).toEqual({}) | |
}) | |
it('should return keyed object', () => { |
function fakeRequest(data) { | |
// eslint-disable-next-line unicorn/consistent-function-scoping | |
const random = (min, max) => Math.floor(Math.random() * (max - min) + min) | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
return resolve({ isOk: true, data }) | |
}, random(500, 2000)) | |
}) | |
} |