Skip to content

Instantly share code, notes, and snippets.

@fliptopbox
Last active June 13, 2020 14:58
Show Gist options
  • Select an option

  • Save fliptopbox/d89e34d5a7d7a908f0b2beb899f1f814 to your computer and use it in GitHub Desktop.

Select an option

Save fliptopbox/d89e34d5a7d7a908f0b2beb899f1f814 to your computer and use it in GitHub Desktop.

Revisions

  1. fliptopbox revised this gist Jun 13, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion loremdatum
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    export default function getRandomPayload() {
    function getRandomPayload() {
    return {
    ts: new Date().valueOf(),
    date: {
  2. fliptopbox created this gist Jun 13, 2020.
    52 changes: 52 additions & 0 deletions loremdatum
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    export default 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;
    }