Skip to content

Instantly share code, notes, and snippets.

const invalidMsg = {
emptyQty: "Qty cannot be empty",
invalidQty: "Invalid Qty input",
zeroQty: "Qty cannot be zero",
decimal: "Qty cannot be decimal",
}
// decimal regex
const regexDecimal = /^\d*\.?\d*$/;
@carsenchan
carsenchan / setup.md
Last active May 30, 2022 05:30
Eslint + Prettier for React Typescript

Project setup

Purpose

To ensure that the coding style is consisitent in the project from different members, for React + Typescript projects, it is recommanded set up ESlint and Prettier.

  1. Install the required dev dependencies:
yarn add eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-react -D
@carsenchan
carsenchan / random-string.ts
Created March 18, 2024 09:48
[Typescript] Random string function
function generateRandomString(length: number): string {
// Define the character set using a regular expression
const characterSet = /[a-zA-Z0-9]/;
let result = '';
for (let i = 0; i < length; i++) {
// Generate a random character from the character set
const randomChar = String.fromCharCode(Math.floor(Math.random() * 62) + 48);
result += randomChar;
}
@carsenchan
carsenchan / gist:07d72c354a3673962f17f7d88275abc3
Created April 9, 2024 02:22
Shows the current `--max-old-space-size` value for NODE_OPTIONS
node -e 'console.log(v8.getHeapStatistics().heap_size_limit/(1024*1024))'