Skip to content

Commit

Permalink
fix: 🐛 improve NUMBER transtype operation
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Jan 27, 2022
1 parent 0a01718 commit b33dd88
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
3 changes: 1 addition & 2 deletions packages/analytics/src/upload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { unlink } from 'fs';
import debug from 'debug';
import writeTo from 'stream-write';
import tempy from 'tempy';

/**
Expand Down Expand Up @@ -59,5 +58,5 @@ export default async function upload(data, feed) {
const cbk = () => debug('ezs')('[upload] unlink file.', tmpfile);
return setTimeout(() => unlink(tmpfile, cbk), cleanupDelay * 1000);
}
return writeTo(this.input, data, () => feed.end());
return this.ezs.writeTo(this.input, data, () => feed.end());
}
10 changes: 5 additions & 5 deletions packages/istex/src/istex.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ezs from '@ezs/core';
import { PassThrough } from 'stream';
import os from 'os';
import queue from 'async.queue';
Expand All @@ -12,7 +11,7 @@ const worker = (stream) => (data, done) => {
writeTo(stream, data, () => done());
};

const getAndWriteQueries = (data, options, feed) => new Promise(
const getAndWriteQueries = (ezs, data, options, feed) => new Promise(
(resolve, reject) => {
if (!Array.isArray(data)) {
return reject(new Error('unexpected data. Should be an array.'));
Expand Down Expand Up @@ -43,7 +42,7 @@ const getAndWriteQueries = (data, options, feed) => new Promise(
},
);

const getAndWriteIdentifiers = (data, options, feed) => new Promise(
const getAndWriteIdentifiers = (ezs, data, options, feed) => new Promise(
(resolve, reject) => {
if (!Array.isArray(data)) {
return reject(new Error('unexpected data. Should be an array.'));
Expand Down Expand Up @@ -115,8 +114,9 @@ async function ISTEX(data, feed) {
field,
sid,
};
await getAndWriteQueries(queries, options, feed);
await getAndWriteIdentifiers(identifiers, options, feed);
const { ezs } = this;
await getAndWriteQueries(ezs, queries, options, feed);
await getAndWriteIdentifiers(ezs, identifiers, options, feed);
feed.end();
}

Expand Down
3 changes: 2 additions & 1 deletion packages/transformers/src/operations/NUMBER.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { transformer } from './transformer';

export const valueToNumber = value => {
const number = Number(value);

const number = typeof value === 'number' ? value : Number(String(value).replace(/,/, '.'));

return Number.isNaN(number) ? 0 : number;
};
Expand Down
8 changes: 8 additions & 0 deletions packages/transformers/src/operations/NUMBER.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ describe('NUMBER', () => {
expect(valueToNumber(1234)).toBe(1234);
});

it('should return 12.34', () => {
expect(valueToNumber('12.34')).toBe(12.34);
});

it('should return 12,34', () => {
expect(valueToNumber('12,34')).toBe(12.34);
});

it('should return 0 if value is null', () => {
expect(valueToNumber(null)).toBe(0);
});
Expand Down

0 comments on commit b33dd88

Please sign in to comment.