+4
-4
@@ -160,3 +160,3 @@ var internals = {} | ||
| var value = String(inp[spec.name]) | ||
| value = preprocessCheck(spec, value) | ||
| value = preprocessCheck(spec, value, inp) | ||
@@ -197,3 +197,3 @@ var valueLength = value.length | ||
| value = String(value) | ||
| value = preprocessCheck(specs[spec], value) | ||
| value = preprocessCheck(specs[spec], value, input[row]) | ||
| var valueLength = value.length | ||
@@ -228,4 +228,4 @@ if (specs[spec].width - value.length >= 0) { | ||
| const preprocessCheck = (spec, value) => { | ||
| return (spec.preprocess) ? spec.preprocess(value) : value | ||
| const preprocessCheck = (spec, value, row) => { | ||
| return (spec.preprocess) ? spec.preprocess(value, row) : value | ||
| } | ||
@@ -232,0 +232,0 @@ |
+2
-2
| { | ||
| "name": "fixy", | ||
| "version": "1.3.0", | ||
| "version": "1.3.1", | ||
| "description": "A Fixed Width Input Parser", | ||
@@ -20,3 +20,3 @@ "main": "index.js", | ||
| "dependencies": { | ||
| "lodash": "4.17.15", | ||
| "lodash": "4.17.21", | ||
| "moment": "2.24.0", | ||
@@ -23,0 +23,0 @@ "papaparse": "5.2.0" |
+24
-1
@@ -93,3 +93,3 @@ [](https://badge.fury.io/js/fixy) | ||
| let noDecimal = (value) => { | ||
| let noDecimal = (value, row) => { | ||
| return `${value}`.replace(/\./, ''); | ||
@@ -114,2 +114,25 @@ } | ||
| ##### fixy.unparse | with preprocessing using other row data | ||
| const useOther = (value, row) => { | ||
| return `${value} ${row.Currency}`; | ||
| } | ||
| var fixy = fixy.unparse([{ | ||
| name: "Name", | ||
| width: 10, | ||
| padding_position: "start", | ||
| padding_symbol: " " | ||
| },{ | ||
| name: "Balance", | ||
| width: 10, | ||
| padding_position: "start", | ||
| padding_symbol: "0", | ||
| preprocess: useOther | ||
| }], [{ | ||
| Name: "Jenny", | ||
| Balance: 86753.09, | ||
| Currency: 'CAD' | ||
| }]); | ||
| ##### fixy.unparse | Multi Level | ||
@@ -116,0 +139,0 @@ |
+20
-0
@@ -442,2 +442,22 @@ var fixy = require('../index') | ||
| }) | ||
| it('should allow preprocessing using row data', function () { | ||
| const preprocessor = (value, row) => { | ||
| return row.Constant2.toString() | ||
| } | ||
| var test = fixy.unparse([{ | ||
| name: 'Constant', | ||
| width: 9, | ||
| preprocess: preprocessor, | ||
| padding_position: 'start', | ||
| padding_symbol: '0' | ||
| }], [{ | ||
| Constant: 1, | ||
| Constant2: 2 | ||
| }, { | ||
| Constant: 1, | ||
| Constant2: 3 | ||
| }]) | ||
| assert.deepStrictEqual(test, '000000002\n000000003') | ||
| }) | ||
| it('should return a fixed format when passed an array of data (with objects) padding front w/ spaces', function () { | ||
@@ -444,0 +464,0 @@ var test = fixy.unparse([{ |
33503
2.81%892
2.18%253
10%+ Added
- Removed
Updated