Skip to content

Instantly share code, notes, and snippets.

@fliptopbox
Last active June 13, 2020 14:58
Show Gist options
  • Save fliptopbox/d89e34d5a7d7a908f0b2beb899f1f814 to your computer and use it in GitHub Desktop.
Save fliptopbox/d89e34d5a7d7a908f0b2beb899f1f814 to your computer and use it in GitHub Desktop.
function getRandomPayload() {
return {
ts: new Date().valueOf(),
date: {
epoc: new Date().valueOf(),
iso: new Date().toISOString(),
local: new Date().toString(),
utc: new Date().toUTCString()
},
float: Math.random(),
integer: (Math.random() * 10) >> 0,
array: [Math.random(), Math.random(), Math.random()],
dictionary: {
x: Math.random(),
y: Math.random(),
z: Math.random(),
a: Math.random()
},
word: words(1),
sentence: words(r(8, 3)),
paragraph: `${words(r(8, 3))} ${words(r(16))} ${words(r(24))}`
};
}
function words(count = 3) {
let glossary = `
I you me my mine yours an a am can but it is not with in out here there where
everybody nobody somebody anybody
chastity temperance charity diligence patience gratitude humility
greed pride sloth wrath lust gluttony envy
alpha beta charlie delta echo foxtrot golf hotel indigo
juliet kilo lima mama november oscar papa quebec romeo
sierra tango uniform vienna whiskey xray yanky
zero one two three four five six seven eight nine ten
`
.trim()
.replace(/[\n\s]+/g, " ")
.split(/\s+/);
glossary = [...glossary, ...glossary];
count = Math.min(glossary.length, count);
count = count || 1;
glossary = glossary.sort((a, b) => Math.random() - 0.5);
glossary = glossary.slice(0, count);
glossary = glossary.join(" ");
glossary += count > 1 ? "." : "";
return glossary.replace(/^\w/, (a) => a.toUpperCase());
}
function r(max = 5, min = 1) {
return (Math.random() * max + min) >> 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment