| { | ||
| "env": { | ||
| "browser": true, | ||
| "commonjs": true, | ||
| "es6": true, | ||
| "mocha": true | ||
| }, | ||
| "extends": [ | ||
| "standard" | ||
| ], | ||
| "globals": { | ||
| "Atomics": "readonly", | ||
| "SharedArrayBuffer": "readonly" | ||
| }, | ||
| "parserOptions": { | ||
| "ecmaVersion": 2018 | ||
| }, | ||
| "rules": { | ||
| "indent": ["error", "tab", { | ||
| "SwitchCase": 1 | ||
| }], | ||
| "no-tabs": 0 | ||
| } | ||
| } |
+4
-5
| language: node_js | ||
| node_js: | ||
| - "6.0" | ||
| - "5.0" | ||
| - "4.0" | ||
| - "0.12" | ||
| - "0.10" | ||
| - "12" | ||
| - "10" | ||
| - "8" | ||
| - "6" |
+186
-188
@@ -1,231 +0,229 @@ | ||
| var internals = {}; | ||
| var moment = require("moment"); | ||
| var Papa = require("papaparse"); | ||
| var lodash = require("lodash"); | ||
| var internals = {} | ||
| var moment = require('moment') | ||
| var Papa = require('papaparse') | ||
| var lodash = require('lodash') | ||
| String.prototype.splice = function(idx, rem, str) { | ||
| return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem)); | ||
| }; | ||
| // eslint-disable-next-line no-extend-native | ||
| String.prototype.splice = function (idx, rem, str) { | ||
| return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem)) | ||
| } | ||
| var parseCol = function(row, map, format){ | ||
| var r = {}; | ||
| lodash.forEach(map, function(i){ | ||
| var v = row.substring(i.start-1, (i.start + i.width - 1)).trim(); | ||
| if(v){ | ||
| switch(i.type){ | ||
| case "date": | ||
| if(i.inputformat){ | ||
| if(moment(v, i.inputformat).isValid()){ | ||
| r[i.name] = moment(v, i.inputformat).format(i.outputformat); | ||
| var parseCol = function (row, map, format) { | ||
| var r = {} | ||
| lodash.forEach(map, function (i) { | ||
| var v = row.substring(i.start - 1, (i.start + i.width - 1)).trim() | ||
| if (v) { | ||
| switch (i.type) { | ||
| case 'date': | ||
| if (i.inputformat) { | ||
| if (moment(v, i.inputformat).isValid()) { | ||
| r[i.name] = moment(v, i.inputformat).format(i.outputformat) | ||
| } else { | ||
| r[i.name] = null | ||
| } | ||
| else{ | ||
| r[i.name] = null; | ||
| } else { | ||
| if (moment(v).isValid()) { | ||
| r[i.name] = moment(v).format(i.outputformat) | ||
| } else { | ||
| r[i.name] = null | ||
| } | ||
| } | ||
| else{ | ||
| if(moment(v).isValid()){ | ||
| r[i.name] = moment(v).format(i.outputformat); | ||
| } | ||
| else{ | ||
| r[i.name] = null; | ||
| } | ||
| break | ||
| case 'float': | ||
| var precision = 2 | ||
| if (i.percision) { // Support incorrect spelling for backward compatibility | ||
| precision = i.percision | ||
| } | ||
| break; | ||
| case "float": | ||
| var percision = 2; | ||
| if(i.percision){ | ||
| percision = i.percision; | ||
| if (i.precision) { | ||
| precision = i.precision | ||
| } | ||
| var symbol = ""; | ||
| if(i.symbol && format === "csv"){ | ||
| symbol = i.symbol; | ||
| var symbol = '' | ||
| if (i.symbol && format === 'csv') { | ||
| symbol = i.symbol | ||
| } | ||
| if(lodash.includes(v, ".")){ | ||
| r[i.name] = symbol + parseFloat(v).toFixed(percision); | ||
| if (lodash.includes(v, '.')) { | ||
| r[i.name] = symbol + parseFloat(v).toFixed(precision) | ||
| } else { | ||
| r[i.name] = symbol + parseFloat(v.splice(i.width - precision, 0, '.')).toFixed(precision) | ||
| } | ||
| else{ | ||
| r[i.name] = symbol + parseFloat(v.splice(i.width - percision, 0, ".")).toFixed(percision); | ||
| break | ||
| case 'int': | ||
| r[i.name] = parseInt(v) | ||
| break | ||
| case 'bool': | ||
| r[i.name] = false | ||
| if (v === i.tVal) { | ||
| r[i.name] = true | ||
| } | ||
| break; | ||
| case "int": | ||
| r[i.name] = parseInt(v); | ||
| break; | ||
| case "bool": | ||
| r[i.name] = false; | ||
| if(v === i.tVal){ | ||
| r[i.name] = true; | ||
| } | ||
| break; | ||
| case "string": | ||
| r[i.name] = v; | ||
| break; | ||
| break | ||
| case 'string': | ||
| r[i.name] = v | ||
| break | ||
| default: | ||
| r[i.name] = v; | ||
| r[i.name] = v | ||
| } | ||
| } else { | ||
| r[i.name] = null | ||
| } | ||
| else{ | ||
| r[i.name] = null; | ||
| } | ||
| }); | ||
| return r; | ||
| }; | ||
| }) | ||
| return r | ||
| } | ||
| internals.parse = function(specs, input){ | ||
| if(typeof(specs) !== "object") throw "specs is not an array"; | ||
| if(lodash.isEmpty(specs)) throw "specs is empty"; | ||
| if(lodash.isEmpty(specs.map)) throw "specs maps is empty"; | ||
| if(lodash.isEmpty(specs.options)) throw "specs options is empty"; | ||
| if(input === "") throw "input is empty"; | ||
| var array_output = []; | ||
| var object_output = {}; | ||
| var split_input = input.replace(/\r\n/g,'\n').split("\n"); | ||
| if(split_input.indexOf("") !== -1){ | ||
| split_input.splice(split_input.indexOf(""), 1); | ||
| internals.parse = function (specs, input) { | ||
| if (typeof (specs) !== 'object') throw new Error('specs is not an array') | ||
| if (lodash.isEmpty(specs)) throw new Error('specs is empty') | ||
| if (lodash.isEmpty(specs.map)) throw new Error('specs maps is empty') | ||
| if (lodash.isEmpty(specs.options)) throw new Error('specs options is empty') | ||
| if (input === '') throw new Error('input is empty') | ||
| var arrayOutput = [] | ||
| var objectOutput = {} | ||
| var splitInput = input.replace(/\r\n/g, '\n').split('\n') | ||
| if (splitInput.indexOf('') !== -1) { | ||
| splitInput.splice(splitInput.indexOf(''), 1) | ||
| } | ||
| lodash.forEach(split_input, function(i, idx){ | ||
| if(i.length === specs.options.fullwidth && !specs.options.levels){ | ||
| if(!lodash.isEmpty(specs.options.skiplines)){ | ||
| if(specs.options.skiplines.indexOf(parseInt(idx) + 1) === -1){ | ||
| array_output.push(parseCol(i, specs.map, specs.options.format)); | ||
| lodash.forEach(splitInput, function (i, idx) { | ||
| if (i.length === specs.options.fullwidth && !specs.options.levels) { | ||
| if (!lodash.isEmpty(specs.options.skiplines)) { | ||
| if (specs.options.skiplines.indexOf(parseInt(idx) + 1) === -1) { | ||
| arrayOutput.push(parseCol(i, specs.map, specs.options.format)) | ||
| } | ||
| } else { | ||
| arrayOutput.push(parseCol(i, specs.map, specs.options.format)) | ||
| } | ||
| else{ | ||
| array_output.push(parseCol(i, specs.map, specs.options.format)); | ||
| } | ||
| } | ||
| else if(specs.options.levels){ | ||
| var level = lodash.find(specs.options.levels, function(v){ | ||
| if(idx >= v.start && idx <= v.end){ | ||
| return true; | ||
| } else if (specs.options.levels) { | ||
| var level = lodash.find(specs.options.levels, function (v) { | ||
| if (idx >= v.start && idx <= v.end) { | ||
| return true | ||
| } | ||
| }); | ||
| var level_map = lodash.filter(specs.map, { | ||
| level: lodash.findKey(specs.options.levels, function(v){ | ||
| if(idx >= v.start && idx <= v.end){ | ||
| return true; | ||
| }) | ||
| var levelMap = lodash.filter(specs.map, { | ||
| level: lodash.findKey(specs.options.levels, function (v) { | ||
| if (idx >= v.start && idx <= v.end) { | ||
| return true | ||
| } | ||
| }) | ||
| }); | ||
| if(i.length === level.fullwidth){ | ||
| if(!object_output.hasOwnProperty(level.nickname)){ | ||
| object_output[level.nickname] = []; | ||
| }) | ||
| if (i.length === level.fullwidth) { | ||
| // eslint-disable-next-line no-prototype-builtins | ||
| if (!objectOutput.hasOwnProperty(level.nickname)) { | ||
| objectOutput[level.nickname] = [] | ||
| } | ||
| if(specs.options.skiplines !== null){ | ||
| if(specs.options.skiplines.indexOf(parseInt(idx) + 1) === -1){ | ||
| object_output[level.nickname].push(parseCol(i, level_map, specs.options.format)); | ||
| if (specs.options.skiplines !== null) { | ||
| if (specs.options.skiplines.indexOf(parseInt(idx) + 1) === -1) { | ||
| objectOutput[level.nickname].push(parseCol(i, levelMap, specs.options.format)) | ||
| } | ||
| } else { | ||
| objectOutput[level.nickname].push(parseCol(i, levelMap, specs.options.format)) | ||
| } | ||
| else{ | ||
| object_output[level.nickname].push(parseCol(i, level_map, specs.options.format)); | ||
| } | ||
| } else { | ||
| throw new Error('Row #' + (parseInt(idx) + 1) + ' does not match fullwidth') | ||
| } | ||
| else{ | ||
| throw "Row #" + (parseInt(idx) + 1) + " does not match fullwidth"; | ||
| } | ||
| } else { | ||
| throw new Error('Row #' + (parseInt(idx) + 1) + ' does not match fullwidth') | ||
| } | ||
| else{ | ||
| throw "Row #" + (parseInt(idx) + 1) + " does not match fullwidth"; | ||
| } | ||
| }); | ||
| switch(specs.options.format){ | ||
| case "csv": | ||
| if(array_output.length === 0){ | ||
| throw "Multi-Level Maps Cannot Convert to CSV"; | ||
| }) | ||
| switch (specs.options.format) { | ||
| case 'csv': | ||
| if (arrayOutput.length === 0) { | ||
| throw new Error('Multi-Level Maps Cannot Convert to CSV') | ||
| } else { | ||
| return Papa.unparse(arrayOutput.length > 0 ? arrayOutput : objectOutput, { | ||
| newline: '\n' | ||
| }) | ||
| } | ||
| else{ | ||
| return Papa.unparse(array_output.length > 0 ? array_output : object_output, { | ||
| newline: "\n" | ||
| }); | ||
| } | ||
| default: | ||
| return array_output.length > 0 ? array_output : object_output; | ||
| } | ||
| }; | ||
| return arrayOutput.length > 0 ? arrayOutput : objectOutput | ||
| } | ||
| } | ||
| internals.unparse = function(specs, input, levels){ | ||
| var output = []; | ||
| if(typeof(specs) !== "object") throw "specs is not an array"; | ||
| if(lodash.isEmpty(specs)) throw "specs is empty"; | ||
| if(input === "") throw "input is empty"; | ||
| var counter = 0; | ||
| if(levels){ | ||
| var rowCount = 0; | ||
| lodash.forEach(levels, function(l){ | ||
| var input_by_level = input[l]; | ||
| rowCount = rowCount + input_by_level.length; | ||
| }); | ||
| lodash.forEach(levels, function(l){ | ||
| var input_by_level = input[l]; | ||
| var specs_by_level = lodash.filter(specs, { | ||
| internals.unparse = function (specs, input, levels) { | ||
| var output = [] | ||
| if (typeof (specs) !== 'object') throw new Error('specs is not an array') | ||
| if (lodash.isEmpty(specs)) throw new Error('specs is empty') | ||
| if (input === '') throw new Error('input is empty') | ||
| var counter = 0 | ||
| if (levels) { | ||
| var rowCount = 0 | ||
| lodash.forEach(levels, function (l) { | ||
| var inputByLevel = input[l] | ||
| rowCount = rowCount + inputByLevel.length | ||
| }) | ||
| lodash.forEach(levels, function (l) { | ||
| var inputByLevel = input[l] | ||
| var specsByLevel = lodash.filter(specs, { | ||
| level: l | ||
| }); | ||
| lodash.forEach(input_by_level, function(inp){ | ||
| lodash.forEach(specs_by_level, function(spec){ | ||
| var value = String(inp[spec.name]); | ||
| var valueLength = value.length; | ||
| if(spec.width - value.length >= 0){ | ||
| for(var i = 1; i <= spec.width - valueLength; i++){ | ||
| var symbol = spec.padding_symbol ? spec.padding_symbol : " "; | ||
| if(symbol.length > 1) throw "padding_symbol can not have length > 1"; | ||
| switch(spec.padding_position){ | ||
| case "start": | ||
| value = symbol + value; | ||
| break; | ||
| case "end": | ||
| value = value + symbol; | ||
| break; | ||
| }) | ||
| lodash.forEach(inputByLevel, function (inp) { | ||
| lodash.forEach(specsByLevel, function (spec) { | ||
| var value = String(inp[spec.name]) | ||
| value = preprocessCheck(spec, value) | ||
| var valueLength = value.length | ||
| if (spec.width - value.length >= 0) { | ||
| for (var i = 1; i <= spec.width - valueLength; i++) { | ||
| var symbol = spec.padding_symbol ? spec.padding_symbol : ' ' | ||
| if (symbol.length > 1) throw new Error('padding_symbol can not have length > 1') | ||
| switch (spec.padding_position) { | ||
| case 'start': | ||
| value = symbol + value | ||
| break | ||
| case 'end': | ||
| value = value + symbol | ||
| break | ||
| default: | ||
| value = symbol + value; | ||
| break; | ||
| value = symbol + value | ||
| break | ||
| } | ||
| } | ||
| output = output + value.substring(0, spec.width); | ||
| output = output + value.substring(0, spec.width) | ||
| } | ||
| }); | ||
| counter = counter + 1; | ||
| if(rowCount !== counter){ | ||
| output = output + "\n"; | ||
| }) | ||
| counter = counter + 1 | ||
| if (rowCount !== counter) { | ||
| output = output + '\n' | ||
| } | ||
| }); | ||
| }); | ||
| return output; | ||
| } | ||
| else{ | ||
| for(var row in input){ | ||
| for(var spec in specs){ | ||
| var value = input[row][specs[spec].name]; | ||
| var defaultValue = lodash.defaultTo(specs[spec].default, ""); | ||
| value = lodash.defaultTo(value, defaultValue); | ||
| value = String(value); | ||
| var valueLength = value.length; | ||
| if(specs[spec].width - value.length >= 0){ | ||
| for(var i = 1; i <= specs[spec].width - valueLength; i++){ | ||
| var symbol = specs[spec].padding_symbol ? specs[spec].padding_symbol : " "; | ||
| if(symbol.length > 1) throw "padding_symbol can not have length > 1"; | ||
| switch(specs[spec].padding_position){ | ||
| case "start": | ||
| value = symbol + value; | ||
| break; | ||
| case "end": | ||
| value = value + symbol; | ||
| break; | ||
| }) | ||
| }) | ||
| return output | ||
| } else { | ||
| for (var row in input) { | ||
| for (var spec in specs) { | ||
| var value = input[row][specs[spec].name] | ||
| var defaultValue = lodash.defaultTo(specs[spec].default, '') | ||
| value = lodash.defaultTo(value, defaultValue) | ||
| value = String(value) | ||
| value = preprocessCheck(specs[spec], value) | ||
| var valueLength = value.length | ||
| if (specs[spec].width - value.length >= 0) { | ||
| for (var i = 1; i <= specs[spec].width - valueLength; i++) { | ||
| var symbol = specs[spec].padding_symbol ? specs[spec].padding_symbol : ' ' | ||
| if (symbol.length > 1) throw new Error('padding_symbol can not have length > 1') | ||
| switch (specs[spec].padding_position) { | ||
| case 'start': | ||
| value = symbol + value | ||
| break | ||
| case 'end': | ||
| value = value + symbol | ||
| break | ||
| default: | ||
| value = symbol + value; | ||
| break; | ||
| value = symbol + value | ||
| break | ||
| } | ||
| } | ||
| } | ||
| output = output + value.substring(0, specs[spec].width); | ||
| output = output + value.substring(0, specs[spec].width) | ||
| } | ||
| counter = counter + 1; | ||
| if(input.length !== counter){ | ||
| output = output + "\n"; | ||
| counter = counter + 1 | ||
| if (input.length !== counter) { | ||
| output = output + '\n' | ||
| } | ||
| } | ||
| return output; | ||
| return output | ||
| } | ||
| }; | ||
| } | ||
| module.exports = internals; | ||
| const preprocessCheck = (spec, value) => { | ||
| return (spec.preprocess) ? spec.preprocess(value) : value | ||
| } | ||
| module.exports = internals |
+22
-7
| { | ||
| "name": "fixy", | ||
| "version": "1.2.0", | ||
| "version": "1.2.1", | ||
| "description": "A Fixed Width Input Parser", | ||
@@ -20,11 +20,20 @@ "main": "index.js", | ||
| "dependencies": { | ||
| "lodash": "^4.12.0", | ||
| "moment": "^2.15.0", | ||
| "papaparse": "^4.1.2" | ||
| "lodash": "4.17.15", | ||
| "moment": "2.24.0", | ||
| "papaparse": "4.6.3" | ||
| }, | ||
| "devDependencies": { | ||
| "mocha": "^3.0.2" | ||
| "eslint": "6.7.2", | ||
| "eslint-config-standard": "14.1.0", | ||
| "eslint-plugin-import": "2.18.2", | ||
| "eslint-plugin-mocha": "6.2.2", | ||
| "eslint-plugin-node": "10.0.0", | ||
| "eslint-plugin-promise": "4.2.1", | ||
| "eslint-plugin-standard": "4.0.1", | ||
| "husky": "3.1.0", | ||
| "mocha": "6.2.2" | ||
| }, | ||
| "scripts": { | ||
| "test": "make test" | ||
| "test": "make test", | ||
| "lint": "./node_modules/.bin/eslint '**/*.js'" | ||
| }, | ||
@@ -35,3 +44,9 @@ "keywords": [ | ||
| "Parser" | ||
| ] | ||
| ], | ||
| "husky": { | ||
| "hooks": { | ||
| "pre-commit": "npm run lint", | ||
| "pre-push": "npm test" | ||
| } | ||
| } | ||
| } |
+29
-6
@@ -7,3 +7,3 @@ [](https://badge.fury.io/js/fixy) | ||
| # Fixy | ||
| Fixy is an npm module for parsing fixed formatted strings/files and unparsing an Array of Objects. | ||
@@ -92,2 +92,24 @@ | ||
| ##### fixy.unparse | with preprocessing | ||
| let noDecimal = (value) => { | ||
| return `${value}`.replace(/\./, ''); | ||
| } | ||
| var fixy = fixy.unparse([{ | ||
| name: "Name", | ||
| width: 10, | ||
| padding_position: "start", | ||
| padding_symbol: " " | ||
| },{ | ||
| name: "Balance", | ||
| width: 10, | ||
| padding_position: "start", | ||
| padding_symbol: "0", | ||
| preprocess: noDecimal | ||
| }], [{ | ||
| Name: "Jenny", | ||
| Balance: 86753.09 | ||
| }]); | ||
| ##### fixy.unparse | Multi Level | ||
@@ -142,4 +164,4 @@ | ||
| - start (Required) | Start of Column in Row | ||
| - percision (Optional) | Float Percision Value (Ex: 9.20 is 2) | DEFAULT TO 2 DECIMAL PLACES | ||
| - sybmol (Optional) | Symbol Value (Ex: $9.20) | ONLY AVAILABLE FOR FORMAT = CSV | ||
| - precision (Optional) | Float Precision Value (Ex: 9.20 is 2) | DEFAULT TO 2 DECIMAL PLACES | ||
| - symbol (Optional) | Symbol Value (Ex: $9.20) | ONLY AVAILABLE FOR FORMAT = CSV | ||
| - level (Required if Multi Level) | Level Map Name | ||
@@ -170,3 +192,3 @@ - Date | ||
| ###### options (for single level) | ||
| - fullwidth = full length of rows from start to end | ||
@@ -177,3 +199,3 @@ - skiplines = optional array of rows to be skipped. May be left null | ||
| ###### options (for multi level) | ||
| - skiplines = optional array of rows to be skipped. May be left null | ||
@@ -201,2 +223,3 @@ - levels = level map object (see example) | ||
| - padding_symbol (Optional. Default: space " ") | What empty space should be padded with (any symbol, letter or number) | ||
| - preprocess (Optional. Default: null) | What preprocessing should be enacted on respective values prior to padding. | ||
| - level (Required if Multi Level) | Level Map Name | ||
@@ -212,2 +235,2 @@ | ||
| }] | ||
| } | ||
| } |
+441
-421
@@ -1,255 +0,255 @@ | ||
| var fixy = require("../index"); | ||
| var assert = require("assert"); | ||
| describe("Fixy Tests", function(){ | ||
| describe("#parse()", function(){ | ||
| it("should allow optional values to be omitted", function(){ | ||
| var fixy = require('../index') | ||
| var assert = require('assert') | ||
| describe('Fixy Tests', function () { | ||
| describe('#parse()', function () { | ||
| it('should allow optional values to be omitted', function () { | ||
| var test = fixy.parse({ | ||
| map:[{ | ||
| name: "Age", | ||
| map: [{ | ||
| name: 'Age', | ||
| width: 2, | ||
| start: 1, | ||
| type: "int" | ||
| type: 'int' | ||
| }], | ||
| options:{ | ||
| fullwidth: 2, | ||
| options: { | ||
| fullwidth: 2 | ||
| } | ||
| }, '30'); | ||
| assert.deepEqual(test, [{ | ||
| Age: 30, | ||
| }]); | ||
| }); | ||
| it("should return fixed-width-input as array(object)", function(){ | ||
| }, '30') | ||
| assert.deepStrictEqual(test, [{ | ||
| Age: 30 | ||
| }]) | ||
| }) | ||
| it('should return fixed-width-input as array(object)', function () { | ||
| var test = fixy.parse({ | ||
| map:[{ | ||
| name: "Age", | ||
| width: 2, | ||
| start: 1, | ||
| type: "int" | ||
| },{ | ||
| name: "Initial", | ||
| width: 3, | ||
| start: 3, | ||
| type: "string" | ||
| },{ | ||
| name: "DateEntered", | ||
| width: 8, | ||
| start: 6, | ||
| type: "date", | ||
| inputformat: "YYYYMMDD", | ||
| outputformat: "YYYY-MM-DD" | ||
| },{ | ||
| name: "IsBad", | ||
| width: 1, | ||
| start: 14, | ||
| type: "bool", | ||
| tVal: "Y", | ||
| fVal: "N" | ||
| },{ | ||
| name: "Rating", | ||
| width: 3, | ||
| start: 15, | ||
| type: "float", | ||
| percision: 2 | ||
| }], | ||
| options:{ | ||
| map: [{ | ||
| name: 'Age', | ||
| width: 2, | ||
| start: 1, | ||
| type: 'int' | ||
| }, { | ||
| name: 'Initial', | ||
| width: 3, | ||
| start: 3, | ||
| type: 'string' | ||
| }, { | ||
| name: 'DateEntered', | ||
| width: 8, | ||
| start: 6, | ||
| type: 'date', | ||
| inputformat: 'YYYYMMDD', | ||
| outputformat: 'YYYY-MM-DD' | ||
| }, { | ||
| name: 'IsBad', | ||
| width: 1, | ||
| start: 14, | ||
| type: 'bool', | ||
| tVal: 'Y', | ||
| fVal: 'N' | ||
| }, { | ||
| name: 'Rating', | ||
| width: 3, | ||
| start: 15, | ||
| type: 'float', | ||
| percision: 2 | ||
| }], | ||
| options: { | ||
| fullwidth: 17, | ||
| skiplines: null | ||
| } | ||
| }, "30SJP20121231N920"); | ||
| assert.deepEqual(test, [{ | ||
| }, '30SJP20121231N920') | ||
| assert.deepStrictEqual(test, [{ | ||
| Age: 30, | ||
| Initial: "SJP", | ||
| DateEntered: "2012-12-31", | ||
| Initial: 'SJP', | ||
| DateEntered: '2012-12-31', | ||
| IsBad: false, | ||
| Rating: 9.20 | ||
| }]); | ||
| }); | ||
| it("should return fixed-width-input as array(object)", function(){ | ||
| Rating: '9.20' | ||
| }]) | ||
| }) | ||
| it('should return fixed-width-input as array(object)', function () { | ||
| var test = fixy.parse({ | ||
| map:[{ | ||
| name: "Age", | ||
| width: 2, | ||
| start: 1, | ||
| type: "int" | ||
| },{ | ||
| name: "Initial", | ||
| width: 3, | ||
| start: 3, | ||
| type: "string" | ||
| },{ | ||
| name: "DateEntered", | ||
| width: 8, | ||
| start: 6, | ||
| type: "date", | ||
| inputformat: "YYYYMMDD", | ||
| outputformat: "YYYY-MM-DD" | ||
| },{ | ||
| name: "IsBad", | ||
| width: 1, | ||
| start: 14, | ||
| type: "bool", | ||
| tVal: "Y", | ||
| fVal: "N" | ||
| },{ | ||
| name: "Rating", | ||
| width: 3, | ||
| start: 15, | ||
| type: "float", | ||
| percision: 2 | ||
| }], | ||
| options:{ | ||
| map: [{ | ||
| name: 'Age', | ||
| width: 2, | ||
| start: 1, | ||
| type: 'int' | ||
| }, { | ||
| name: 'Initial', | ||
| width: 3, | ||
| start: 3, | ||
| type: 'string' | ||
| }, { | ||
| name: 'DateEntered', | ||
| width: 8, | ||
| start: 6, | ||
| type: 'date', | ||
| inputformat: 'YYYYMMDD', | ||
| outputformat: 'YYYY-MM-DD' | ||
| }, { | ||
| name: 'IsBad', | ||
| width: 1, | ||
| start: 14, | ||
| type: 'bool', | ||
| tVal: 'Y', | ||
| fVal: 'N' | ||
| }, { | ||
| name: 'Rating', | ||
| width: 3, | ||
| start: 15, | ||
| type: 'float', | ||
| percision: 2 | ||
| }], | ||
| options: { | ||
| fullwidth: 17, | ||
| skiplines: null | ||
| } | ||
| }, "30SJP20121231N900"); | ||
| assert.deepEqual(test, [{ | ||
| }, '30SJP20121231N900') | ||
| assert.deepStrictEqual(test, [{ | ||
| Age: 30, | ||
| Initial: "SJP", | ||
| DateEntered: "2012-12-31", | ||
| Initial: 'SJP', | ||
| DateEntered: '2012-12-31', | ||
| IsBad: false, | ||
| Rating: 9.00 | ||
| }]); | ||
| }); | ||
| it("should return fixed-width-input as csv-string (no inner commas)", function(){ | ||
| Rating: '9.00' | ||
| }]) | ||
| }) | ||
| it('should return fixed-width-input as csv-string (no inner commas)', function () { | ||
| var test = fixy.parse({ | ||
| map:[{ | ||
| name: "Age", | ||
| map: [{ | ||
| name: 'Age', | ||
| width: 2, | ||
| start: 1, | ||
| type: "int" | ||
| },{ | ||
| name: "Initial", | ||
| type: 'int' | ||
| }, { | ||
| name: 'Initial', | ||
| width: 3, | ||
| start: 3, | ||
| type: "string" | ||
| type: 'string' | ||
| }], | ||
| options:{ | ||
| options: { | ||
| fullwidth: 5, | ||
| skiplines: null, | ||
| format: "csv" | ||
| format: 'csv' | ||
| } | ||
| }, "30SJP\n30SJP"); | ||
| assert.deepEqual(test, "Age,Initial\n30,SJP\n30,SJP"); | ||
| }); | ||
| it("should return fixed-width-input as csv-string (inner commas)", function(){ | ||
| }, '30SJP\n30SJP') | ||
| assert.deepStrictEqual(test, 'Age,Initial\n30,SJP\n30,SJP') | ||
| }) | ||
| it('should return fixed-width-input as csv-string (inner commas)', function () { | ||
| var test = fixy.parse({ | ||
| map:[{ | ||
| name: "Age", | ||
| map: [{ | ||
| name: 'Age', | ||
| width: 2, | ||
| start: 1, | ||
| type: "int" | ||
| },{ | ||
| name: "Initial", | ||
| type: 'int' | ||
| }, { | ||
| name: 'Initial', | ||
| width: 4, | ||
| start: 3, | ||
| type: "string" | ||
| type: 'string' | ||
| }], | ||
| options:{ | ||
| options: { | ||
| fullwidth: 6, | ||
| skiplines: null, | ||
| format: "csv" | ||
| format: 'csv' | ||
| } | ||
| }, "30S,JP\n30S,JP"); | ||
| assert.deepEqual(test, "Age,Initial\n30,\"S,JP\"\n30,\"S,JP\""); | ||
| }); | ||
| it("should return fixed-width-input as csv-string (no inner commas) and adds a sybmol for float", function(){ | ||
| }, '30S,JP\n30S,JP') | ||
| assert.deepStrictEqual(test, 'Age,Initial\n30,"S,JP"\n30,"S,JP"') | ||
| }) | ||
| it('should return fixed-width-input as csv-string (no inner commas) and adds a sybmol for float', function () { | ||
| var test = fixy.parse({ | ||
| map:[{ | ||
| name: "Product", | ||
| map: [{ | ||
| name: 'Product', | ||
| width: 10, | ||
| start: 1, | ||
| type: "string" | ||
| },{ | ||
| name: "Price", | ||
| type: 'string' | ||
| }, { | ||
| name: 'Price', | ||
| width: 5, | ||
| start: 11, | ||
| type: "float", | ||
| symbol: "$" | ||
| type: 'float', | ||
| symbol: '$' | ||
| }], | ||
| options:{ | ||
| options: { | ||
| fullwidth: 15, | ||
| skiplines: null, | ||
| format: "csv" | ||
| format: 'csv' | ||
| } | ||
| }, "Apple 00099\nOrange 00079"); | ||
| assert.deepEqual(test, "Product,Price\nApple,$0.99\nOrange,$0.79"); | ||
| }); | ||
| it("should return fixed-width-input as array(object) and does not include the sybmol", function(){ | ||
| }, 'Apple 00099\nOrange 00079') | ||
| assert.deepStrictEqual(test, 'Product,Price\nApple,$0.99\nOrange,$0.79') | ||
| }) | ||
| it('should return fixed-width-input as array(object) and does not include the sybmol', function () { | ||
| var test = fixy.parse({ | ||
| map:[{ | ||
| name: "Product", | ||
| map: [{ | ||
| name: 'Product', | ||
| width: 10, | ||
| start: 1, | ||
| type: "string" | ||
| },{ | ||
| name: "Price", | ||
| type: 'string' | ||
| }, { | ||
| name: 'Price', | ||
| width: 5, | ||
| start: 11, | ||
| type: "float", | ||
| symbol: "$" | ||
| type: 'float', | ||
| symbol: '$' | ||
| }], | ||
| options:{ | ||
| options: { | ||
| fullwidth: 15, | ||
| skiplines: null | ||
| } | ||
| }, "Apple 00099\nOrange 00079"); | ||
| assert.deepEqual(test, [{ | ||
| Product: "Apple", | ||
| Price: 0.99 | ||
| },{ | ||
| Product: "Orange", | ||
| Price: 0.79 | ||
| }]); | ||
| }); | ||
| it("should return fixed-width-input (multi-leveled) as array(object)", function(){ | ||
| }, 'Apple 00099\nOrange 00079') | ||
| assert.deepStrictEqual(test, [{ | ||
| Product: 'Apple', | ||
| Price: '0.99' | ||
| }, { | ||
| Product: 'Orange', | ||
| Price: '0.79' | ||
| }]) | ||
| }) | ||
| it('should return fixed-width-input (multi-leveled) as array(object)', function () { | ||
| var test = fixy.parse({ | ||
| map:[{ | ||
| name: "Name", | ||
| map: [{ | ||
| name: 'Name', | ||
| width: 7, | ||
| start: 1, | ||
| type: "string", | ||
| level: "A" | ||
| },{ | ||
| name: "Age", | ||
| type: 'string', | ||
| level: 'A' | ||
| }, { | ||
| name: 'Age', | ||
| width: 2, | ||
| start: 1, | ||
| type: "int", | ||
| level: "B" | ||
| },{ | ||
| name: "Initial", | ||
| type: 'int', | ||
| level: 'B' | ||
| }, { | ||
| name: 'Initial', | ||
| width: 3, | ||
| start: 3, | ||
| type: "string", | ||
| level: "B" | ||
| },{ | ||
| name: "DateEntered", | ||
| type: 'string', | ||
| level: 'B' | ||
| }, { | ||
| name: 'DateEntered', | ||
| width: 8, | ||
| start: 6, | ||
| type: "date", | ||
| inputformat: "YYYYMMDD", | ||
| outputformat: "YYYY-MM-DD", | ||
| level: "B" | ||
| },{ | ||
| name: "IsBad", | ||
| type: 'date', | ||
| inputformat: 'YYYYMMDD', | ||
| outputformat: 'YYYY-MM-DD', | ||
| level: 'B' | ||
| }, { | ||
| name: 'IsBad', | ||
| width: 1, | ||
| start: 14, | ||
| type: "bool", | ||
| tVal: "Y", | ||
| fVal: "N", | ||
| level: "B" | ||
| },{ | ||
| name: "Rating", | ||
| type: 'bool', | ||
| tVal: 'Y', | ||
| fVal: 'N', | ||
| level: 'B' | ||
| }, { | ||
| name: 'Rating', | ||
| width: 3, | ||
| start: 15, | ||
| type: "float", | ||
| type: 'float', | ||
| percision: 2, | ||
| level: "B" | ||
| level: 'B' | ||
| }], | ||
| options:{ | ||
| options: { | ||
| skiplines: null, | ||
| levels: { | ||
| "A": { | ||
| nickname: "A", | ||
| A: { | ||
| nickname: 'A', | ||
| start: 0, | ||
@@ -259,4 +259,4 @@ end: 0, | ||
| }, | ||
| "B": { | ||
| nickname: "B", | ||
| B: { | ||
| nickname: 'B', | ||
| start: 1, | ||
@@ -268,109 +268,109 @@ end: 2, | ||
| } | ||
| }, "Steve \n30SJP20121231N920"); | ||
| assert.deepEqual(test, { | ||
| A: [{ Name: "Steve" }], | ||
| }, 'Steve \n30SJP20121231N920') | ||
| assert.deepStrictEqual(test, { | ||
| A: [{ Name: 'Steve' }], | ||
| B: [{ | ||
| Age: 30, | ||
| Initial: "SJP", | ||
| DateEntered: "2012-12-31", | ||
| Initial: 'SJP', | ||
| DateEntered: '2012-12-31', | ||
| IsBad: false, | ||
| Rating: 9.20 | ||
| Rating: '9.20' | ||
| }] | ||
| }); | ||
| }); | ||
| it("should return fixed-width-input as array(object) if decimal within float", function(){ | ||
| }) | ||
| }) | ||
| it('should return fixed-width-input as array(object) if decimal within float', function () { | ||
| var test = fixy.parse({ | ||
| map:[{ | ||
| name: "Age", | ||
| width: 2, | ||
| start: 1, | ||
| type: "int" | ||
| },{ | ||
| name: "Initial", | ||
| width: 3, | ||
| start: 3, | ||
| type: "string" | ||
| },{ | ||
| name: "DateEntered", | ||
| width: 8, | ||
| start: 6, | ||
| type: "date", | ||
| inputformat: "YYYYMMDD", | ||
| outputformat: "YYYY-MM-DD" | ||
| },{ | ||
| name: "IsBad", | ||
| width: 1, | ||
| start: 14, | ||
| type: "bool", | ||
| tVal: "Y", | ||
| fVal: "N" | ||
| },{ | ||
| name: "Rating", | ||
| width: 4, | ||
| start: 15, | ||
| type: "float", | ||
| percision: 2 | ||
| }], | ||
| options:{ | ||
| map: [{ | ||
| name: 'Age', | ||
| width: 2, | ||
| start: 1, | ||
| type: 'int' | ||
| }, { | ||
| name: 'Initial', | ||
| width: 3, | ||
| start: 3, | ||
| type: 'string' | ||
| }, { | ||
| name: 'DateEntered', | ||
| width: 8, | ||
| start: 6, | ||
| type: 'date', | ||
| inputformat: 'YYYYMMDD', | ||
| outputformat: 'YYYY-MM-DD' | ||
| }, { | ||
| name: 'IsBad', | ||
| width: 1, | ||
| start: 14, | ||
| type: 'bool', | ||
| tVal: 'Y', | ||
| fVal: 'N' | ||
| }, { | ||
| name: 'Rating', | ||
| width: 4, | ||
| start: 15, | ||
| type: 'float', | ||
| percision: 2 | ||
| }], | ||
| options: { | ||
| fullwidth: 18, | ||
| skiplines: null | ||
| } | ||
| }, "30SJP20121231N9.20"); | ||
| assert.deepEqual(test, [{ | ||
| }, '30SJP20121231N9.20') | ||
| assert.deepStrictEqual(test, [{ | ||
| Age: 30, | ||
| Initial: "SJP", | ||
| DateEntered: "2012-12-31", | ||
| Initial: 'SJP', | ||
| DateEntered: '2012-12-31', | ||
| IsBad: false, | ||
| Rating: 9.20 | ||
| }]); | ||
| }); | ||
| it("should return fixed-width-input (multi-leveled) as array(object) if decimal within float", function(){ | ||
| Rating: '9.20' | ||
| }]) | ||
| }) | ||
| it('should return fixed-width-input (multi-leveled) as array(object) if decimal within float', function () { | ||
| var test = fixy.parse({ | ||
| map:[{ | ||
| name: "Name", | ||
| map: [{ | ||
| name: 'Name', | ||
| width: 7, | ||
| start: 1, | ||
| type: "string", | ||
| level: "A" | ||
| },{ | ||
| name: "Age", | ||
| type: 'string', | ||
| level: 'A' | ||
| }, { | ||
| name: 'Age', | ||
| width: 2, | ||
| start: 1, | ||
| type: "int", | ||
| level: "B" | ||
| },{ | ||
| name: "Initial", | ||
| type: 'int', | ||
| level: 'B' | ||
| }, { | ||
| name: 'Initial', | ||
| width: 3, | ||
| start: 3, | ||
| type: "string", | ||
| level: "B" | ||
| },{ | ||
| name: "DateEntered", | ||
| type: 'string', | ||
| level: 'B' | ||
| }, { | ||
| name: 'DateEntered', | ||
| width: 8, | ||
| start: 6, | ||
| type: "date", | ||
| inputformat: "YYYYMMDD", | ||
| outputformat: "YYYY-MM-DD", | ||
| level: "B" | ||
| },{ | ||
| name: "IsBad", | ||
| type: 'date', | ||
| inputformat: 'YYYYMMDD', | ||
| outputformat: 'YYYY-MM-DD', | ||
| level: 'B' | ||
| }, { | ||
| name: 'IsBad', | ||
| width: 1, | ||
| start: 14, | ||
| type: "bool", | ||
| tVal: "Y", | ||
| fVal: "N", | ||
| level: "B" | ||
| },{ | ||
| name: "Rating", | ||
| type: 'bool', | ||
| tVal: 'Y', | ||
| fVal: 'N', | ||
| level: 'B' | ||
| }, { | ||
| name: 'Rating', | ||
| width: 4, | ||
| start: 15, | ||
| type: "float", | ||
| type: 'float', | ||
| percision: 2, | ||
| level: "B" | ||
| level: 'B' | ||
| }], | ||
| options:{ | ||
| options: { | ||
| skiplines: null, | ||
| levels: { | ||
| "A": { | ||
| nickname: "A", | ||
| A: { | ||
| nickname: 'A', | ||
| start: 0, | ||
@@ -380,4 +380,4 @@ end: 0, | ||
| }, | ||
| "B": { | ||
| nickname: "B", | ||
| B: { | ||
| nickname: 'B', | ||
| start: 1, | ||
@@ -389,197 +389,217 @@ end: 2, | ||
| } | ||
| }, "Steve \n30SJP20121231N9.20"); | ||
| assert.deepEqual(test, { | ||
| A: [{ Name: "Steve" }], | ||
| }, 'Steve \n30SJP20121231N9.20') | ||
| assert.deepStrictEqual(test, { | ||
| A: [{ Name: 'Steve' }], | ||
| B: [{ | ||
| Age: 30, | ||
| Initial: "SJP", | ||
| DateEntered: "2012-12-31", | ||
| Initial: 'SJP', | ||
| DateEntered: '2012-12-31', | ||
| IsBad: false, | ||
| Rating: 9.20 | ||
| Rating: '9.20' | ||
| }] | ||
| }); | ||
| }); | ||
| }); | ||
| describe("#unparse()", function(){ | ||
| it("should return a fixed format when passed an array of data (with objects) padding front w/ spaces", function(){ | ||
| }) | ||
| }) | ||
| }) | ||
| describe('#unparse()', function () { | ||
| it('should allow preprocessing', function () { | ||
| const preprocessor = (value) => { | ||
| value = Number.parseFloat(value) * 10000 | ||
| value = Math.floor(value) / 10000 | ||
| return `${value}`.replace(/\./, '') | ||
| } | ||
| var test = fixy.unparse([{ | ||
| name: "Age", | ||
| width: 7, | ||
| padding_position: "start", | ||
| padding_symbol: " " | ||
| },{ | ||
| name: "Initial", | ||
| width: 4, | ||
| padding_position: "start", | ||
| padding_symbol: " " | ||
| }], [{ | ||
| name: 'Constant', | ||
| width: 9, | ||
| preprocess: preprocessor, | ||
| padding_position: 'start', | ||
| padding_symbol: '0' | ||
| }], [{ | ||
| Constant: 3.14159 | ||
| }, { | ||
| Constant: 2.71828 | ||
| }]) | ||
| assert.deepStrictEqual(test, '000031415\n000027182') | ||
| }) | ||
| it('should return a fixed format when passed an array of data (with objects) padding front w/ spaces', function () { | ||
| var test = fixy.unparse([{ | ||
| name: 'Age', | ||
| width: 7, | ||
| padding_position: 'start', | ||
| padding_symbol: ' ' | ||
| }, { | ||
| name: 'Initial', | ||
| width: 4, | ||
| padding_position: 'start', | ||
| padding_symbol: ' ' | ||
| }], [{ | ||
| Age: 30, | ||
| Initial: "SJP" | ||
| },{ | ||
| Initial: 'SJP' | ||
| }, { | ||
| Age: 20, | ||
| Initial: "CCS" | ||
| }]); | ||
| assert.deepEqual(test, " 30 SJP\n 20 CCS"); | ||
| }); | ||
| it("should return a fixed format when passed an array of data (with objects) padding behind w/ spaces", function(){ | ||
| Initial: 'CCS' | ||
| }]) | ||
| assert.deepStrictEqual(test, ' 30 SJP\n 20 CCS') | ||
| }) | ||
| it('should return a fixed format when passed an array of data (with objects) padding behind w/ spaces', function () { | ||
| var test = fixy.unparse([{ | ||
| name: "Age", | ||
| width: 7, | ||
| padding_position: "end", | ||
| padding_symbol: " " | ||
| },{ | ||
| name: "Initial", | ||
| width: 4, | ||
| padding_position: "end", | ||
| padding_symbol: " " | ||
| }], [{ | ||
| name: 'Age', | ||
| width: 7, | ||
| padding_position: 'end', | ||
| padding_symbol: ' ' | ||
| }, { | ||
| name: 'Initial', | ||
| width: 4, | ||
| padding_position: 'end', | ||
| padding_symbol: ' ' | ||
| }], [{ | ||
| Age: 30, | ||
| Initial: "SJP" | ||
| },{ | ||
| Initial: 'SJP' | ||
| }, { | ||
| Age: 20, | ||
| Initial: "CCS" | ||
| }]); | ||
| assert.deepEqual(test, "30 SJP \n20 CCS "); | ||
| }); | ||
| it("should return a fixed format when passed an array of data (with objects) padding front w/ # symbol", function(){ | ||
| Initial: 'CCS' | ||
| }]) | ||
| assert.deepStrictEqual(test, '30 SJP \n20 CCS ') | ||
| }) | ||
| it('should return a fixed format when passed an array of data (with objects) padding front w/ # symbol', function () { | ||
| var test = fixy.unparse([{ | ||
| name: "Age", | ||
| width: 7, | ||
| padding_position: "start", | ||
| padding_symbol: "#" | ||
| },{ | ||
| name: "Initial", | ||
| width: 4, | ||
| padding_position: "start", | ||
| padding_symbol: "#" | ||
| }], [{ | ||
| name: 'Age', | ||
| width: 7, | ||
| padding_position: 'start', | ||
| padding_symbol: '#' | ||
| }, { | ||
| name: 'Initial', | ||
| width: 4, | ||
| padding_position: 'start', | ||
| padding_symbol: '#' | ||
| }], [{ | ||
| Age: 30, | ||
| Initial: "SJP" | ||
| },{ | ||
| Initial: 'SJP' | ||
| }, { | ||
| Age: 20, | ||
| Initial: "CCS" | ||
| }]); | ||
| assert.deepEqual(test, "#####30#SJP\n#####20#CCS"); | ||
| }); | ||
| it("should return a fixed format when passed an array of data (with objects) padding behind w/ # symbol", function(){ | ||
| Initial: 'CCS' | ||
| }]) | ||
| assert.deepStrictEqual(test, '#####30#SJP\n#####20#CCS') | ||
| }) | ||
| it('should return a fixed format when passed an array of data (with objects) padding behind w/ # symbol', function () { | ||
| var test = fixy.unparse([{ | ||
| name: "Age", | ||
| width: 7, | ||
| padding_position: "end", | ||
| padding_symbol: "#" | ||
| },{ | ||
| name: "Initial", | ||
| width: 4, | ||
| padding_position: "end", | ||
| padding_symbol: "#" | ||
| }], [{ | ||
| name: 'Age', | ||
| width: 7, | ||
| padding_position: 'end', | ||
| padding_symbol: '#' | ||
| }, { | ||
| name: 'Initial', | ||
| width: 4, | ||
| padding_position: 'end', | ||
| padding_symbol: '#' | ||
| }], [{ | ||
| Age: 30, | ||
| Initial: "SJP" | ||
| },{ | ||
| Initial: 'SJP' | ||
| }, { | ||
| Age: 20, | ||
| Initial: "CCS" | ||
| }]); | ||
| assert.deepEqual(test, "30#####SJP#\n20#####CCS#"); | ||
| }); | ||
| it("should return a fixed format when passed an array of data (with objects) padding behind w/ different symbols", function(){ | ||
| Initial: 'CCS' | ||
| }]) | ||
| assert.deepStrictEqual(test, '30#####SJP#\n20#####CCS#') | ||
| }) | ||
| it('should return a fixed format when passed an array of data (with objects) padding behind w/ different symbols', function () { | ||
| var test = fixy.unparse([{ | ||
| name: "Age", | ||
| width: 7, | ||
| padding_position: "end", | ||
| padding_symbol: "#" | ||
| },{ | ||
| name: "Initial", | ||
| width: 4, | ||
| padding_position: "end", | ||
| padding_symbol: "@" | ||
| }], [{ | ||
| name: 'Age', | ||
| width: 7, | ||
| padding_position: 'end', | ||
| padding_symbol: '#' | ||
| }, { | ||
| name: 'Initial', | ||
| width: 4, | ||
| padding_position: 'end', | ||
| padding_symbol: '@' | ||
| }], [{ | ||
| Age: 30, | ||
| Initial: "SJP" | ||
| },{ | ||
| Initial: 'SJP' | ||
| }, { | ||
| Age: 20, | ||
| Initial: "CCS" | ||
| }]); | ||
| assert.deepEqual(test, "30#####SJP@\n20#####CCS@"); | ||
| }); | ||
| it("should return a fixed format when passed an array of data (with objects) no padding setting or symbol setting", function(){ | ||
| Initial: 'CCS' | ||
| }]) | ||
| assert.deepStrictEqual(test, '30#####SJP@\n20#####CCS@') | ||
| }) | ||
| it('should return a fixed format when passed an array of data (with objects) no padding setting or symbol setting', function () { | ||
| var test = fixy.unparse([{ | ||
| name: "Age", | ||
| width: 7 | ||
| },{ | ||
| name: "Initial", | ||
| width: 4 | ||
| }], [{ | ||
| name: 'Age', | ||
| width: 7 | ||
| }, { | ||
| name: 'Initial', | ||
| width: 4 | ||
| }], [{ | ||
| Age: 30, | ||
| Initial: "SJP" | ||
| },{ | ||
| Initial: 'SJP' | ||
| }, { | ||
| Age: 20, | ||
| Initial: "CCS" | ||
| }]); | ||
| assert.deepEqual(test, " 30 SJP\n 20 CCS"); | ||
| }); | ||
| it("should return a fixed format when passed an object", function(){ | ||
| Initial: 'CCS' | ||
| }]) | ||
| assert.deepStrictEqual(test, ' 30 SJP\n 20 CCS') | ||
| }) | ||
| it('should return a fixed format when passed an object', function () { | ||
| var test = fixy.unparse([{ | ||
| name: "Name", | ||
| name: 'Name', | ||
| width: 7, | ||
| padding_position: "end", | ||
| level: "A", | ||
| },{ | ||
| name: "Age", | ||
| padding_position: 'end', | ||
| level: 'A' | ||
| }, { | ||
| name: 'Age', | ||
| width: 3, | ||
| padding_position: "end", | ||
| level: "B" | ||
| },{ | ||
| name: "Initial", | ||
| padding_position: 'end', | ||
| level: 'B' | ||
| }, { | ||
| name: 'Initial', | ||
| width: 4, | ||
| padding_position: "end", | ||
| level: "B" | ||
| padding_position: 'end', | ||
| level: 'B' | ||
| }], { | ||
| A: [{ Name: "Steve" }], | ||
| A: [{ Name: 'Steve' }], | ||
| B: [{ | ||
| Age: 30, | ||
| Initial: "SJP" | ||
| },{ | ||
| Initial: 'SJP' | ||
| }, { | ||
| Age: 20, | ||
| Initial: "CCS" | ||
| Initial: 'CCS' | ||
| }] | ||
| }, ["A", "B"]); | ||
| assert.deepEqual(test, "Steve \n30 SJP \n20 CCS "); | ||
| }); | ||
| it("should allow default values", function(){ | ||
| }, ['A', 'B']) | ||
| assert.deepStrictEqual(test, 'Steve \n30 SJP \n20 CCS ') | ||
| }) | ||
| it('should allow default values', function () { | ||
| var test = fixy.unparse([{ | ||
| name: "Age", | ||
| width: 7, | ||
| default: 20 | ||
| },{ | ||
| name: "Initial", | ||
| name: 'Age', | ||
| width: 7, | ||
| default: 20 | ||
| }, { | ||
| name: 'Initial', | ||
| width: 4 | ||
| }], [{ | ||
| Initial: "SJP" | ||
| }]); | ||
| assert.deepEqual(test, " 20 SJP"); | ||
| }); | ||
| it("should handle null values", function(){ | ||
| Initial: 'SJP' | ||
| }]) | ||
| assert.deepStrictEqual(test, ' 20 SJP') | ||
| }) | ||
| it('should handle null values', function () { | ||
| var test = fixy.unparse([{ | ||
| name: "Age", | ||
| name: 'Age', | ||
| width: 7 | ||
| },{ | ||
| name: "Initial", | ||
| }, { | ||
| name: 'Initial', | ||
| width: 4, | ||
| padding_symbol: "#" | ||
| padding_symbol: '#' | ||
| }], [{ | ||
| Age: undefined, | ||
| Initial: null | ||
| }]); | ||
| assert.deepEqual(test, " ####"); | ||
| }); | ||
| it("should truncate values that are too long", function(){ | ||
| }]) | ||
| assert.deepStrictEqual(test, ' ####') | ||
| }) | ||
| it('should truncate values that are too long', function () { | ||
| var test = fixy.unparse([{ | ||
| name: "Name", | ||
| name: 'Name', | ||
| width: 7 | ||
| }], [{ | ||
| Name: "Alexander" | ||
| }]); | ||
| assert.deepEqual(test, "Alexand"); | ||
| }); | ||
| }); | ||
| }); | ||
| Name: 'Alexander' | ||
| }]) | ||
| assert.deepStrictEqual(test, 'Alexand') | ||
| }) | ||
| }) | ||
| }) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27216
9.35%8
14.29%843
4.98%230
11.65%9
800%1
Infinity%+ Added
+ Added
- Removed
- Removed
Updated
Updated
Updated