0.0.3 • Published 2 years ago

@vault_h4x/csv-gen v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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 valueFns
  • 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 rows
        • valueFn a function that can return a value for the field. It is passed the generated RowData from the rowDataFn
        • rowDataKey is the key to extract from the generated rowData

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();
      }
    },
  ]
};
0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago