Created
January 17, 2023 08:52
-
-
Save smitroshin/9eeffb8c684a8e833a0f2be128c48052 to your computer and use it in GitHub Desktop.
Generate a list of persons
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
/** | |
* Source: https://github.com/TanStack/table/blob/v7/examples/filtering/src/makeData.js | |
*/ | |
import namor from 'namor' | |
const range = len => { | |
const arr = [] | |
for (let i = 0; i < len; i++) { | |
arr.push(i) | |
} | |
return arr | |
} | |
const newPerson = () => { | |
const statusChance = Math.random() | |
return { | |
firstName: namor.generate({ words: 1, numbers: 0 }), | |
lastName: namor.generate({ words: 1, numbers: 0 }), | |
age: Math.floor(Math.random() * 30), | |
visits: Math.floor(Math.random() * 100), | |
progress: Math.floor(Math.random() * 100), | |
status: | |
statusChance > 0.66 | |
? 'relationship' | |
: statusChance > 0.33 | |
? 'complicated' | |
: 'single', | |
} | |
} | |
export default function makeData(...lens) { | |
const makeDataLevel = (depth = 0) => { | |
const len = lens[depth] | |
return range(len).map(d => { | |
return { | |
...newPerson(), | |
subRows: lens[depth + 1] ? makeDataLevel(depth + 1) : undefined, | |
} | |
}) | |
} | |
return makeDataLevel() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment