Permalink
Browse files

first commit

  • Loading branch information...
gradus committed Feb 23, 2012
0 parents commit 9c958fd7d7e426d950b24f74661bc5f3f6fa61b5
Showing with 338 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +49 −0 Cakefile
  3. +20 −0 LICENSE
  4. +48 −0 example/data.json
  5. +6 −0 example/default.coffee
  6. +38 −0 lib/index.js
  7. +19 −0 package.json
  8. +59 −0 readme.md
  9. +27 −0 src/index.coffee
  10. +66 −0 test/indexTest.coffee
  11. +4 −0 test/mainTest.coffee
@@ -0,0 +1,2 @@
+node_modules
+.DS_Store
@@ -0,0 +1,49 @@
+fs = require 'fs'
+{print} = require 'sys'
+{spawn, exec} = require 'child_process'
+
+# ANSI Terminal Colors
+bold = '\033[0;1m'
+green = '\033[0;32m'
+reset = '\033[0m'
+red = '\033[0;31m'
+
+log = (message, color, explanation) ->
+ console.log color + message + reset + ' ' + (explanation or '')
+
+build = (watch, callback) ->
+ if typeof watch is 'function'
+ callback = watch
+ watch = false
+ options = ['-c', '-o', 'lib', 'src']
+ options.unshift '-w' if watch
+
+ coffee = spawn 'coffee', options
+ coffee.stdout.on 'data', (data) -> print data.toString()
+ coffee.stderr.on 'data', (data) -> log data.toString(), red
+ coffee.on 'exit', (status) -> callback?() if status is 0
+
+
+task 'docs', 'Generate annotated source code with Docco', ->
+ fs.readdir 'src', (err, contents) ->
+ files = ("src/#{file}" for file in contents when /\.coffee$/.test file)
+ docco = spawn 'docco', files
+ docco.stdout.on 'data', (data) -> print data.toString()
+ docco.stderr.on 'data', (data) -> log data.toString(), red
+ docco.on 'exit', (status) -> callback?() if status is 0
+
+test = (callback) ->
+ spec = spawn './node_modules/mocha/bin/mocha'
+ spec.stdout.on 'data', (data) -> print data.toString()
+ spec.stderr.on 'data', (data) -> log data.toString(), red
+ spec.on 'exit', (status) -> callback?() if status is 0
+
+task 'test', ->
+ test -> console.log 'Done!'
+
+task 'build', ->
+ build -> log ":)", green
+
+# TODO
+# task 'auto', 'Watch and Run Spec', ->
+# build true, -> spec -> log ":)", green
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2012 Kris Windham
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
+[
+ {
+ "object": {
+ "FROM DATE": "01/24/12",
+ "THRU DATE": "01/31/12",
+ "CARRIER ID": "2838",
+ "ACCOUNT ID": "2838000",
+ "GROUP ID": "000",
+ "FACILITY ID": "",
+ "MEMBER ID": "16617725301",
+ "MEMBER First Name": "JOHNNIE",
+ "MEMBER Last Name": "TESTER",
+ "PRESC ID": "1843533671",
+ "PCP ID": "",
+ "PRESC NAME": "PRESCRIBER",
+ "PHARMACY": "1546424753",
+ "RX #": "6438741",
+ "DATE DISP": "01/11/12",
+ "REFILL": "01",
+ "DRUG NAME": "FUROSEMIDE TAB 40MG",
+ "NDC": "00378-0216-10",
+ "#DAYS SUP": "30",
+ "Decimal QTY": "60.000",
+ "SUBMITTED COST": "9.57",
+ "APPROVED COST": "3.49",
+ "OPAR": ".00",
+ "FEE": "1.50",
+ "INC FEE": ".00",
+ "TAX": ".00",
+ "PAT PAY": ".00",
+ "MGMT FEE": ".00",
+ "AMOUNT PAID": "4.99",
+ "batch_name": "test",
+ "billing_period": "201202",
+ "disp_ndc": "00378021610",
+ "cost": 0.08316666666666667,
+ "_events": {},
+ "prescriberId": 126,
+ "patientId": 345,
+ "awp": 0.1595,
+ "aac": 0,
+ "medication_type": "generic",
+ "prescription_type": "rx"
+ },
+ "verb": "validatingClaim",
+ "_events": {}
+ }
+]
@@ -0,0 +1,6 @@
+fs = require 'fs'
+jsoncsv = require '../lib/index'
+
+data = fs.readFileSync('data.json').toString()
+jsoncsv.parse data, (err, row) ->
+ console.log row

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,19 @@
+{
+ "name": "csvjs",
+ "description": "A JSON to csv converter for nodeJS",
+ "version": "0.0.1",
+ "homepage": "",
+ "author": "Kris Windham",
+ "private": false,
+ "main": "./lib",
+ "dependencies": {
+ },
+ "devDependencies": {
+ "coffee-script": ">= 1.1.x",
+ "mocha": "*",
+ "should": "*",
+ "assert": "*",
+ "docco": ">0"
+ },
+ "engines": { "node": "0.4 || 0.6 || 0.7" }
+}
@@ -0,0 +1,59 @@
+
+ __
+ |__| ______ ____ ____ ____ _________ __
+ | | / ___// _ \ / \ _/ ___\ / ___/\ \/ /
+ | | \___ \( <_> )| | \\ \___ \___ \ \ /
+ /\__| |/____ >\____/ |___| / \___ >/____ > \_/
+ \______| \/ \/ \/ \/
+
+
+---
+
+# jsoncsv
+- a json to csv library in javascript/coffeescript
+
+## Install
+
+``` bash
+npm install jsoncsv
+
+```
+
+## Usage Example in CoffeeScript
+
+``` coffeescript
+fs = require 'fs'
+csvjs = require 'jsoncsv'
+
+data = fs.readFileSync('data.json').toString()
+jsoncsv.parse data, (err, row) ->
+ console.log row
+
+```
+
+## Usage Example in JavaScript
+
+``` javascript
+var jsoncsv, data, fs;
+fs = require('fs');
+jsoncsv = require('jsoncsv');
+
+data = fs.readFileSync('data.json').toString();
+
+jsoncsv.parse(data, function(err, row) {
+ return console.log(row);
+});
+
+```
+
+## Examples
+
+* see example folder
+
+## License
+
+* see LICENSE
+
+## Contributions
+
+* Please submit any pull requests or issues.
@@ -0,0 +1,27 @@
+# jsoncsv
+# simple json to csv converter
+
+class JsonCsv extends require('events').EventEmitter
+ # parse JSON data and return csv output
+ # callback returns (err, row)
+
+ parse: (data, cb) ->
+ return cb('error no data') unless data?
+
+ json = JSON.parse(data)
+ csv = ''
+ i = 0
+
+ while i < json.length
+ line = ""
+ for index of json[i]
+ line += json[i][index] + ","
+ line.slice 0, line.Length - 1
+ csv += line + "\r\n"
+ i++
+
+ return csv
+
+
+
+module.exports = new JsonCsv()
@@ -0,0 +1,66 @@
+assert = require 'assert'
+should = require 'should'
+jsoncsv = require '../lib/index'
+
+data = """
+[
+ {
+ "object": {
+ "FROM DATE": "01/24/12",
+ "THRU DATE": "01/31/12",
+ "CARRIER ID": "2838",
+ "ACCOUNT ID": "2838000",
+ "GROUP ID": "000",
+ "FACILITY ID": "",
+ "MEMBER ID": "16617725301",
+ "MEMBER First Name": "JOHNNIE",
+ "MEMBER Last Name": "TESTER",
+ "PRESC ID": "1843533671",
+ "PCP ID": "",
+ "PRESC NAME": "PRESCRIBER",
+ "PHARMACY": "1546424753",
+ "RX #": "6438741",
+ "DATE DISP": "01/11/12",
+ "REFILL": "01",
+ "DRUG NAME": "FUROSEMIDE TAB 40MG",
+ "NDC": "00378-0216-10",
+ "#DAYS SUP": "30",
+ "Decimal QTY": "60.000",
+ "SUBMITTED COST": "9.57",
+ "APPROVED COST": "3.49",
+ "OPAR": ".00",
+ "FEE": "1.50",
+ "INC FEE": ".00",
+ "TAX": ".00",
+ "PAT PAY": ".00",
+ "MGMT FEE": ".00",
+ "AMOUNT PAID": "4.99",
+ "batch_name": "test",
+ "billing_period": "201202",
+ "disp_ndc": "00378021610",
+ "cost": 0.08316666666666667,
+ "_events": {},
+ "prescriberId": 126,
+ "patientId": 345,
+ "awp": 0.1595,
+ "aac": 0,
+ "medication_type": "generic",
+ "prescription_type": "rx"
+ },
+ "verb": "validatingClaim",
+ "_events": {}
+ }
+]
+ """
+
+describe 'jsoncsv', ->
+ describe '#parse', ->
+ it 'is successful', (done) ->
+ output = jsoncsv.parse data, (err, row) ->
+ console.log row
+ output.should == "some,csv,data"
+ done()
+ it 'let user know error occured via parsing', ->
+ jsoncsv.parse null, (err, row) ->
+ err.should == 'error no data'
+
@@ -0,0 +1,4 @@
+describe 'main', ->
+ it 'should be true', ->
+ x = true
+ x.should.equal(true)

0 comments on commit 9c958fd

Please sign in to comment.