Merge tag 'csv2edn-0.1.5'
This commit is contained in:
commit
6523e41ec2
26
README.md
26
README.md
|
@ -1,36 +1,44 @@
|
||||||
# csv2edn
|
# csv2edn
|
||||||
|
|
||||||
Simple command line utility to convert CSV files to EDN. Assumes the first row of a CSV file contains column headers.
|
Simple command line utility and library to convert
|
||||||
|
[comma-separated value (CSV)](https://tools.ietf.org/html/rfc4180) files to
|
||||||
|
[extensible data notation (EDN)](https://github.com/edn-format/edn) or
|
||||||
|
[javascript object notation (JSON)](https://www.json.org/json-en.html). Assumes
|
||||||
|
the first row of a CSV file contains column headers.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
[](https://clojars.org/csv2edn)
|
[](https://clojars.org/csv2edn)
|
||||||
|
|
||||||
|
**NOTE**: if the version numbers given below differ from the number in the
|
||||||
|
image above, the image (which is automatically generated) is correct and
|
||||||
|
this file (which is manually maintained) is in error.
|
||||||
|
|
||||||
### Leiningen/Boot
|
### Leiningen/Boot
|
||||||
|
|
||||||
[csv2edn "0.1.4"]
|
[csv2edn "0.1.5"]
|
||||||
|
|
||||||
### Clojure CLI/deps.edn
|
### Clojure CLI/deps.edn
|
||||||
|
|
||||||
csv2edn {:mvn/version "0.1.4"}
|
csv2edn {:mvn/version "0.1.5"}
|
||||||
|
|
||||||
### Gradle
|
### Gradle
|
||||||
|
|
||||||
compile 'csv2edn:csv2edn:0.1.4'
|
compile 'csv2edn:csv2edn:0.1.5'
|
||||||
|
|
||||||
### Maven
|
### Maven
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>csv2edn</groupId>
|
<groupId>csv2edn</groupId>
|
||||||
<artifactId>csv2edn</artifactId>
|
<artifactId>csv2edn</artifactId>
|
||||||
<version>0.1.4</version>
|
<version>0.1.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
## Usage: as a standalone commandline tool
|
## Usage: as a standalone commandline tool
|
||||||
|
|
||||||
To run from the command line:
|
To run from the command line:
|
||||||
|
|
||||||
$ java -jar csv2edn-0.1.4-standalone.jar [options]
|
$ java -jar csv2edn-0.1.5-standalone.jar [options]
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
|
@ -51,17 +59,17 @@ Where options are:
|
||||||
The simplest possible use is to simply use this in a pipeline:
|
The simplest possible use is to simply use this in a pipeline:
|
||||||
|
|
||||||
$ cat path/to/file.csv |\
|
$ cat path/to/file.csv |\
|
||||||
java -jar csv2edn-0.1.4-standalone.jar > path/to/file.edn
|
java -jar csv2edn-0.1.5-standalone.jar > path/to/file.edn
|
||||||
|
|
||||||
Exactly the same behaviour can be achieved by specifying input and output
|
Exactly the same behaviour can be achieved by specifying input and output
|
||||||
paths:
|
paths:
|
||||||
|
|
||||||
$ java -jar csv2edn-0.1.4-standalone.jar \
|
$ java -jar csv2edn-0.1.5-standalone.jar \
|
||||||
-i path/to/file.csv -o path/to/file.edn
|
-i path/to/file.csv -o path/to/file.edn
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
$ java -jar csv2edn-0.1.4-standalone.jar \
|
$ java -jar csv2edn-0.1.5-standalone.jar \
|
||||||
--input path/to/file.csv --output path/to/file.edn
|
--input path/to/file.csv --output path/to/file.edn
|
||||||
|
|
||||||
## Usage: as a library
|
## Usage: as a library
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(defproject csv2edn "0.1.4"
|
(defproject csv2edn "0.1.5"
|
||||||
:description "Simple command line utility to convert CSV files to EDN."
|
:description "Simple command line utility to convert CSV files to EDN."
|
||||||
:url "https://github.com/simon-brooke/csv2edn"
|
:url "https://github.com/simon-brooke/csv2edn"
|
||||||
:license {:name "GPL-2.0-or-later WITH Classpath-exception-2.0"
|
:license {:name "GPL-2.0-or-later WITH Classpath-exception-2.0"
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
[clojure.data.json :as json]
|
[clojure.data.json :as json]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.pprint :refer [pprint]]
|
[clojure.pprint :refer [pprint]]
|
||||||
[clojure.string :refer [lower-case]]))
|
[clojure.string :as s]))
|
||||||
|
|
||||||
(def ^:dynamic *options*
|
(def ^:dynamic *options*
|
||||||
"Defaults for options used in conversion (essentially, `:separator` is `,`,
|
"Defaults for options used in conversion (essentially, `:separator` is `,`,
|
||||||
|
@ -33,7 +33,9 @@
|
||||||
(csv/read-csv
|
(csv/read-csv
|
||||||
reader
|
reader
|
||||||
:separator (first (str sep)))))
|
:separator (first (str sep)))))
|
||||||
headers (map #(keyword (lower-case %)) (first data))
|
headers (map #(keyword
|
||||||
|
(s/replace (s/lower-case %) #"[^a-z0-9]" "-"))
|
||||||
|
(first data))
|
||||||
result (map
|
result (map
|
||||||
#(zipmap headers (map maybe-read %))
|
#(zipmap headers (map maybe-read %))
|
||||||
(rest data))]
|
(rest data))]
|
||||||
|
|
Loading…
Reference in a new issue