0.0.3 • Published 2 years ago
@vault_h4x/csv-gen v0.0.3
CSV-GEN
Create CSVs full of random stuff. That's it.
Usage
ts-node src/main <creator file> <count>
i.e
ts-node src/main vault 100
Creator Files
Creator files allow you to produce 'templates' for creating rows of data.
rowDataFn
- This is an optional method which is called before any of the row columns are populated.
It allows a developer to create variables which can then be used simply as values, or withing
valueFn
s
- This is an optional method which is called before any of the row columns are populated.
It allows a developer to create variables which can then be used simply as values, or withing
fields
- An array of fields to create.
name
The name of the field. This is used to create the CSV header- Value can then be generated in 3 ways
value
is for a static value which wont change between rowsvalueFn
a function that can return a value for the field. It is passed the generatedRowData
from therowDataFn
rowDataKey
is the key to extract from the generatedrowData
- An array of fields to create.
Example
interface RowData {
givenName: string;
familyName: string;
}
export const creator: Creator = {
rowDataFn: (): RowData => {
const gender = Math.round(Math.random());
return {
givenName: Faker.name.firstName(gender),
familyName: Faker.name.lastName(gender),
}
},
fields: [
{
name: 'name', valueFn: (rowData: RowData): string => {
return `${rowData.givenName} ${rowData.familyName}`
}
},
{ name: 'externalId', value: 'external-id' },
{ name: 'givenName', rowDataKey: 'givenName' },
{ name: 'familyName', rowDataKey: 'familyName' },
{
name: 'email',
valueFn: (rowData: RowData): string => {
const email = Faker.internet.email(rowData.familyName, rowData.givenName, 'vaultplatform.com');
return email.toLowerCase();
}
},
]
};