Skip to content

Instantly share code, notes, and snippets.

View The-LukeZ's full-sized avatar
🫤
Getting distracted by sidequests...

LukeZ The-LukeZ

🫤
Getting distracted by sidequests...
View GitHub Profile
@The-LukeZ
The-LukeZ / safeParseInt.js
Created January 22, 2026 13:54
Safe parse function for typescript
/**
* Attempts to parse a string as an integer with validation and clamping.
*
* @param {unknown} str - The string to parse as an integer
* @param {number} defaultValue - The value to return if parsing fails or validation fails
* @param {string} [min=1] - The minimum allowed value (inclusive), defaults to 1
* @param {number} [max] - The maximum allowed value (inclusive)
* @returns {number} The parsed integer clamped to the range [min, max], or the default value if parsing fails
*
* @example
@The-LukeZ
The-LukeZ / README.md
Last active October 30, 2025 10:46
Typesafe NodeCache

NodeCache already has Typescript support, however, you always need to pass your type when using cache.get() for example.

Below you can find an example of a cache factory which provides a full typesafe interface while only providing the type once.

How it works? The type interface for the NodeCache already has dynamic types and I only wrapped it in a wrapper-function and enhanced the JSDoc comments.

@The-LukeZ
The-LukeZ / discord-markup-parser.ts
Last active August 24, 2025 20:38
Discord Markup Parser for better markdown parsing
/** MarkdownParser.ts
*
* Tokenization-first markdown -> HTML implementation
*
* Features:
* - Bold: **bold**
* - Italic: *italic* or _italic_
* - Underline: __underline__
* - Subtext: lines starting with "-# "
* - Strikethrough: ~~strike~~