god-bless-your-code
Version:
Bless your code with ASCII gods, monsters, and mystical powers — your last line of defense against bugs and angry PMs.
116 lines (112 loc) • 7.6 kB
JavaScript
/*
:-==+++++++++++++==-
-=++++++++++++++++++++++++++=-
==++++=== ==+++++++++++++++++++++++++++++++++++==
-=++++++++++++++++++++++++++++++++++++++++++++++++++++++++-:--
=+++*%@@%%#**++++++++++++++++++++++++++++++++++++++++++++++++*++*+-
+++*%@@@@@@%*++++++++++++++++++++++++++++++++++++++++++++++++***##*=
=+++*%@%%%#*+++++++++++++++++++++++++++++++++++++++++++++++++++***%%*-
+*++#%%%*++++++++++++++++++++++++++++++++++++++++++++++++++++*****#*+:
:=**+*#*+++++++++++++++++++=:..........:=++++++++++++++++++*+=-:--=++:
-+**++++++++++++++++++=:................:-+++++++++++++*+=-...........
++*++++++++++++++++=:....................:-+++++++++++++:............:.
++++++++++++++++++:......................::-+++++++++++-............::::
+++++++++++++++++-.....................:::::-++++++++*+-..........:::::::
-++++++++++++++++-:..............:=*###+-:::::=+++*****+-.......:::-=-:::::
+++++++++++++++++::::...........-##:=%%%%=::::-+++**+**+-::::::::-%#+%%+::::
=**++++++++++++++=:::::::::.....:#%+:-#%%%%::::-+**+*++*+=::::::::#%*:+%%+:::
+++++++++++++++++=:::::::::::::::%%%%%%%%%%-:---+**+*****+-:::::::#%%%%%%#:-::
+***+++++++++++++=:::::::::::::::+@%%%%%%@+----=***+******=:::::::=%@%%%%*---:
=+****+++++++++++++-:::::::::::::::=#%%%%#=----=+***********=---::::=%%@%*----:
=+*****++++++++++++=--::::::::::::------------=+*************=----------------
++*****++++++++++*++=----------------------===+***************=----------===-:
++*******************+========--============+**********%%%%%#**+===========-:
+*********************++================+++******++==*%%%%%%%%#**+====+++=-.
+*************************++++++++++++++*******+=====+#@@@@@@#++***+++++*=:
+*********************************************+++======++++=+++++********=
+**********************************************++++++++++++++++++********-
+************************************************+++++******************+:
++*****************************************************+=-+*###*********=
++************************************************#+--------*#**********-
++************************************************#+---==---***********+:
++**************************************************+==++=+************=
++++++*****************************************************************-
=++++++**++****************+*+******************************************-
=++++++++++++++++++++++++++++++++++**************************************-
=+++++++++++++++++++++++++++++++++++++++**********************************=
+++++++++++++++++++++++++++++++++++++++++++++*******************************+-
++++++*****++++++++++++++++++++++++++++++++++++******************************+=:
+++++++******++++++++++++++++++++++++++++++++++++*****************************+=
++======+****+++++++++++++++++++++++++++++++++++++****************************+++=
.+=======+*****+++++++++++++++++++++++++++++++++++++++**************************+++=
========+*****++++++++++++++++++++++++++++++++++++++++*************************++++-
-========++***+++++++++++++++++++++++++++++++++++++++++**************************+++=
-=========++***+++++++++++++++++++++++++++++++++++++++++***************************+=:
==++++=+=++**++++++++++++++++++++++++++++++++++++++++++**************************=:
-+++++++++***++++++++++++++++++++++++++++++++++++++++++**************************=
=++++******++++++++++++++++++++++++++++++++++++++++++++*************************+:
++*********++++++++++++++++++++++++++++++++++++++++++++**************************:
++********+++++++++++++++++++++++++++++++++++++++++++++**************************-
++*********+++++++++++++++++++++++++++++++++++++++++++***************************=
++********++++++++++++++++++++++++++++++++++++++++++++***************************=
++**********++++++++++++++++++++++++++++++++++++++*******************************=
++**********++++++++++++++++++++++++++++++++++++*********************************-
+********+*+++++++++++++++++++++++++++++++++++**********************************:
+********+*++++++++++++++++++++++++++******++**********************************+.
+************+*****+++++******++++++*******************************************-
+******************************+++++*******************************************:
-*****************************************************************************+
+****************************************************************************=
=***************************************************************************+:
=*********************************************************************####+:
+*******************************************************************####+:
=*****************************************************************#####+-
+*************************************************************#######+-
-+***********************************************************#######+:
=********************************************************########*++==
+***************************************************###########+++++++-
-***********************************************############*++++++++++-
+#####*************************************#############**++++++++++++-
=+++++++***########################################*+=-: -=====++++=-:
=++++++++++++*********########################**+=::
-+++++++++++++***- ::---=========--:
=++=++++++++**+-
=++++++++*+-.
:::
*/
import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defaultBlessings } from './constants.mjs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const blessingNameToTextMap = {};
const blessingTextsDirPath = join(__dirname, 'blessing-texts');
function godBlessYourCode(code, codeType, options = {}) {
const { blessings = defaultBlessings } = options;
const chosenBlessingName = Array.isArray(blessings)
? blessings[Math.floor(Math.random() * blessings.length)]
: blessings;
if (!chosenBlessingName)
return;
let blessingText = loadBlessingText(chosenBlessingName);
if (!blessingText)
return;
const wrap = (content) => {
switch (codeType) {
case 'css':
case 'js':
case 'ts': return `/*\n${content}\n*/`;
case 'html': return `<!--\n${content}\n-->`;
default: return `/*\n${content}\n*/`;
}
};
blessingText = wrap(blessingText);
return options.position === 'bottom' ? `${code}\n\n${blessingText}` : `${blessingText}\n\n${code}`;
}
function loadBlessingText(name) {
if (blessingNameToTextMap[name])
return blessingNameToTextMap[name];
return blessingNameToTextMap[name] = readFileSync(join(blessingTextsDirPath, `${name}.txt`), 'utf-8').trimEnd();
}
export { godBlessYourCode, loadBlessingText };
//# sourceMappingURL=index.mjs.map