Ever wonder how true something is? Run this script or send a GET
request to https://api.yodacode.xyz/howtrue/:text
if you want to find out.
Calculate how true something is
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto'); | |
const truths = [ | |
'so true', | |
'undeniably true', | |
'This response is undeniably true;', | |
'So true!', | |
'This is true;', | |
'true', | |
'false', | |
'Untrue' | |
]; | |
function sentenceHash (sentence) { | |
const symbols = sentence | |
.trim() | |
.toLowerCase() | |
.split('') | |
.sort() | |
.filter(char => 'abcdefghijklmnopqrstuvwxyz123456789'.split('').includes(char)) | |
.join(''); | |
return crypto.createHash('md5').update(symbols + process.env.HOWTRUE_SALT).digest('hex'); | |
} | |
function howTrue (text) { | |
return truths[parseInt(sentenceHash(text).substring(0, 5), 16) % truths.length]; | |
} | |
module.exports = async function (req, res, [ text ]) { | |
res.header('Hash-Output', sentenceHash(text)); | |
res.send(howTrue(text)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment