Skip to content

Commit

Permalink
Merge branch 'main' into fix/csv-file-loader-line-count
Browse files Browse the repository at this point in the history
  • Loading branch information
suityou01 authored Sep 6, 2024
2 parents a2ce657 + cf43003 commit a506852
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 28 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"author": "Charlie Benger-Stevenson",
"license": "OGL-UK-3.0",
"repository": "https://github.com/DEFRA/ffc-pay-etl-framework",
"description": "A framework for creating ETL pipelines in node",
"jest": {
"setupFiles": [
Expand Down
57 changes: 34 additions & 23 deletions src/transformers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,46 @@ Currently supported transformers are :

### Options

| option | description |
| -------------- | ------------------------------------------------------------- |
| columns | Array of column transformations |
| option | description |
| ------- | ------------------------------------------------------------ |
| columns | Array of column transformations |
| locale | See https://fakerjs.dev/guide/localization for valid locales |

### Usage

```js
FakerTransformer(
{
columns: [
{
name: "column2",
faker: "company.name"
}
]
}
)
FakerTransformer({
columns: [
{
name: "column2",
faker: "company.name",
},
],
});
```

faker is a string value that can be any of the currently supported [apis](https://fakerjs.dev/api/)

e.g.
e.g.

- finance.accountName
- person.firstName
- randomizer.next

To create UK post code

```js
FakerTransformer({
columns: [
{
name: "column2",
faker: "location.zipCode",
},
],
locale: "en_GB",
});
```

### Example

src/examples/csv-faker.js
Expand All @@ -46,20 +59,18 @@ src/examples/csv-faker.js

### Options

| option | description |
| -------------- | ------------------------------------------------------------- |
| column | source column to be transformed |
| option | description |
| ------ | ------------------------------- |
| column | source column to be transformed |

### Usage

```js
ToUpperCaseTransformer(
{
column: "column2"
}
)
ToUpperCaseTransformer({
column: "column2",
});
```

### Example

src/examples/csv-to-upper-case.js
src/examples/csv-to-upper-case.js
9 changes: 8 additions & 1 deletion src/transformers/fakerTransformer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { Transform } = require("node:stream")
const { faker } = require("@faker-js/faker")

/**
*
Expand All @@ -12,11 +11,19 @@ const { faker } = require("@faker-js/faker")
* }
* ]
* }
* @param {String} options.locale
* @returns StreamReader
*/
function FakerTransformer(options){
let self = this
self.columns = options.columns
let faker;
if(options.locale){
faker = require(`@faker-js/faker/locale/${options.locale}`).faker
} else {
faker = require('@faker-js/faker').faker
}

function getFaker(fakerType) {
return fakerType.split('.').reduce((a,b) => {
return Object.keys(a).length === 0 ? faker[b] : a[b]
Expand Down
4 changes: 0 additions & 4 deletions test/transformers/fakerTransformer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ describe('fakerTransformer tests', () => {
objectMode: true,
transform(chunk,_,callback){
expect(chunk.errors.length).toEqual(0)
<<<<<<< Updated upstream
expect(chunk[1]).not.toEqual("B")
=======
expect(chunk[1]).not.toEqual("b")
done()
callback(null, chunk)
Expand Down Expand Up @@ -57,7 +54,6 @@ describe('fakerTransformer tests', () => {
expect(chunk[1]).not.toEqual("b")
const regex = /^([A-Za-z]{2}[\d]{1,2}[A-Za-z]?)[\s]+([\d][A-Za-z]{2})$/
expect(chunk[1].match(regex)[0]).toEqual(chunk[1])
>>>>>>> Stashed changes
done()
callback(null, chunk)
}
Expand Down

0 comments on commit a506852

Please sign in to comment.