Skip to content

Commit

Permalink
Fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Pugliese committed May 25, 2016
1 parent 335ea3c commit efa1c79
Show file tree
Hide file tree
Showing 4 changed files with 389 additions and 104 deletions.
139 changes: 119 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,110 @@ Fixy is an npm module for parsing fixed formatted strings/files and unparsing an
npm install fixy --save

#### Usage
##### fixy.parse | Single Level

// fixy.parse | Parsing a Fixed Format Input
var fixy = fixy.parse({
map: [{
map:[{
name: "Age",
width: 2,
start: 1,
type: "int"
},{
name: "Initial",
width: 3,
start: 3,
type: "string"
}],
options: {
fullwidth: 2,
options:{
fullwidth: 5,
skiplines: null,
format: "json" //default
format: "csv"
}
},"30ABC20151201Y950");
}, "21ABC\n22DEF");

// fixy.unparse | Parsing to Fixed Format Output
var fixy = fixy.unparse([{
name: "Age",
##### fixy.parse | Multi Level

var fixy = fixy.parse({
map:[{
name: "Name",
width: 7,
padding_position: "end",
padding_symbol: "#"
start: 1,
type: "string",
level: "A"
},{
name: "Initial",
width: 4,
padding_position: "end",
padding_symbol: "@"
}], [{
name: "Age",
width: 2,
start: 1,
type: "int",
level: "B"
}],
options:{
skiplines: null,
levels: {
"A": {
nickname: "A",
start: 0,
end: 0,
fullwidth: 7
},
"B": {
nickname: "B",
start: 1,
end: 2,
fullwidth: 2
}
}
}
}, "Steve \n30");

##### fixy.unparse | Single Level

var fixy = fixy.unparse([{
name: "Age",
width: 7,
padding_position: "end",
padding_symbol: "#"
},{
name: "Initial",
width: 4,
padding_position: "end",
padding_symbol: "@"
}], [{
Age: 30,
Initial: "SJP"
},{
Age: 20,
Initial: "CCS"
}]);

##### fixy.unparse | Multi Level

var fixy = fixy.unparse([{
name: "Name",
width: 7,
padding_position: "end",
level: "A",
},{
name: "Age",
width: 3,
padding_position: "end",
level: "B"
},{
name: "Initial",
width: 4,
padding_position: "end",
level: "B"
}], {
A: [{ Name: "Mike" }],
B: [{
Age: 30,
Initial: "MAS"
},{
Age: 20,
Initial: "SAM"
}]
}, ["A", "B"]);


#### Configuration

Expand All @@ -62,40 +131,59 @@ A map [array of objects] of the column names, width, starting point, type of val
- name (Required) | Name of the Column
- width (Required) | Length of Column
- start (Required) | Start of Column in Row
- level (Required if Multi Level) | Level Map Name
- Float
- type : "float"
- name (Required) | Name of the Column
- width (Required) | Length of Column
- 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
- level (Required if Multi Level) | Level Map Name
- Date
- type : "date"
- name (Required) | Name of the Column
- width (Required) | Length of Column
- start (Required) | Start of Column in Row
- inputformat (Required) | Format Date Date is Currently In
- outputformat (Required) | Format Date Date is Returned As
- level (Required if Multi Level) | Level Map Name
- String
- type : "string"
- name (Required) | Name of the Column
- width (Required) | Length of Column
- start (Required) | Start of Column in Row
- level (Required if Multi Level) | Level Map Name
- Boolean
- type : "bool"
- name (Required) | Name of the Column
- width (Required) | Length of Column
- start (Required) | Start of Column in Row
- tVal (Required) | String Value of True
- fVal (Required) | String Value of False
- level (Required if Multi Level) | Level Map Name

###### options
###### options (for single level)

- fullwidth = full length / width of row from start to end
- fullwidth = full length of rows from start to end
- skiplines = optional array of rows to be skipped. May be left null
- format = defaults "json". Valid selections are: json, csv

##### fixy.unparse(map, input[array of objects])
###### options (for multi level)

- skiplines = optional array of rows to be skipped. May be left null
- levels = level map object (see example)


"LEVELNAME": {
nickname: "NameInMap",
start: 0, //row start, zero based
end: 0, //row end, zero based
fullwidth: 7 // row width per level
}


##### fixy.unparse(map, array of objects || object with levels [see example], [array level order (required for multi)])

###### map

Expand All @@ -104,4 +192,15 @@ A map [array of objects] of the column names, width, starting point, type of val
- name (Required) | Name of the Key
- width (Required) | Length of Fixed Section
- padding_position (Optional. Default: "start") | Where padding should start ("start" or "end")
- padding_symbol (Optional. Default: space " ") | What empty space should be padded with (any symbol, letter or number)
- padding_symbol (Optional. Default: space " ") | What empty space should be padded with (any symbol, letter or number)
- level (Required if Multi Level) | Level Map Name

###### example object with level mapping

{
A: [{ Name: "Mike" }],
B: [{
Age: 30,
Initial: "MSP"
}]
}
Loading

0 comments on commit efa1c79

Please sign in to comment.