diff --git a/packages/analytics/src/upload.js b/packages/analytics/src/upload.js index 73f4f7e2..c3626056 100644 --- a/packages/analytics/src/upload.js +++ b/packages/analytics/src/upload.js @@ -1,6 +1,5 @@ import { unlink } from 'fs'; import debug from 'debug'; -import writeTo from 'stream-write'; import tempy from 'tempy'; /** @@ -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()); } diff --git a/packages/istex/src/istex.js b/packages/istex/src/istex.js index 08942c8f..420ee5ae 100644 --- a/packages/istex/src/istex.js +++ b/packages/istex/src/istex.js @@ -1,4 +1,3 @@ -import ezs from '@ezs/core'; import { PassThrough } from 'stream'; import os from 'os'; import queue from 'async.queue'; @@ -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.')); @@ -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.')); @@ -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(); } diff --git a/packages/transformers/src/operations/NUMBER.js b/packages/transformers/src/operations/NUMBER.js index 1982ad14..bfbd803c 100644 --- a/packages/transformers/src/operations/NUMBER.js +++ b/packages/transformers/src/operations/NUMBER.js @@ -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; }; diff --git a/packages/transformers/src/operations/NUMBER.spec.js b/packages/transformers/src/operations/NUMBER.spec.js index d79cbf85..de287c2f 100644 --- a/packages/transformers/src/operations/NUMBER.spec.js +++ b/packages/transformers/src/operations/NUMBER.spec.js @@ -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); });