Git Product home page Git Product logo

fixy's Introduction

npm version Dependency Status devDependency Status Build Status

Fixy

Fixy is an npm module for parsing fixed formatted strings/files and unparsing an Array of Objects.

Install

npm install fixy --save

Usage

fixy.parse | Single Level
var fixy = fixy.parse({
	map:[{
		name: "Age",
		width: 2,
		start: 1,
		type: "int"
	},{
		name: "Initial",
		width: 3,
		start: 3,
		type: "string"
	}],
	options:{
		fullwidth: 5,
		skiplines: null,
		format: "csv"
	}
}, "21ABC\n22DEF");
fixy.parse | Multi Level
var fixy = fixy.parse({
	map:[{
		name: "Name",
		width: 7,
		start: 1,
		type: "string",
		level: "A"
	},{
		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

fixy.parse({map, options}, fixed-format-string)
map

A map [array of objects] of the column names, width, starting point, type of value, extra type settings.

  • Integer
    • type : "int"
    • 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" (decimal use allowed but not required)
    • 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 (for single level)
  • 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
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

A map [array of objects] of the column names, width, starting point, type of value, extra type settings.

  • 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)
  • level (Required if Multi Level) | Level Map Name
example object with level mapping
{
	A: [{ Name: "Mike" }],
	B: [{
		Age: 30,
		Initial: "MSP"
	}]
}

fixy's People

Contributors

steveypugs avatar jakesjews avatar heyfrench avatar igmt avatar

Watchers

James Cloos avatar Jinsong Lu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.