Skip to content

Instantly share code, notes, and snippets.

// from: https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color
const color = {
Reset : "\x1b[0m",
Bright : "\x1b[1m",
Dim : "\x1b[2m",
Underscore : "\x1b[4m",
Blink : "\x1b[5m",
Reverse : "\x1b[7m",
Hidden : "\x1b[8m",
@lot224
lot224 / base64.ts
Created August 24, 2021 13:36
Shortens a guid from 36 characters to (22-24) characters
// Inspired By
// https://stackoverflow.com/questions/6213227/fastest-way-to-convert-a-number-to-radix-64-in-javascript
// Haven't Fully Tested or implemented in a prod environment
// Generate Random Value matching a guid
const Guid = (): string => {
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/gi, () => {
const crypto = require('crypto');
const id = crypto.randomBytes(16).toString("hex")[5];
@lot224
lot224 / fetch.ts
Last active December 20, 2021 20:42
mockFetch - require in setup.js
export const hookFetch = global.fetch;
type collection = {
[key: string]: {
response: {
success?: unknown
error?: unknown
}
headers?: {
[key: string]: string
@lot224
lot224 / converter.js
Created December 7, 2022 17:38
Mongo c# driver ObjectId to Guid converter nodejs
const b64ToGuid = (b64) => {
const bytes = Buffer.from(b64, "base64");
bits = [];
bytes.forEach(byte => {
bits.push(byte.toString(16).padStart(2, '0'));
});
const data = bits.join("");
const parts = [];
parts.push(data.substring(0, 8).split("").reverse().join(""));