2.2.0 • Published 5 years ago
devtechtools v2.2.0
DevTech Tools API
A set of tools for conversions and other functions.
NPM package here
Dependencies:
- underscore (http://underscorejs.org/)
- underscore.string (https://github.com/epeli/underscore.string)
Node:
const csv2json = require('./devtechtools.js');
csv2json(csv, options)
// import with namespace
import * as DTT from 'devtechtools';
DTT.csv2json(csv, options)
// import individually
import { csv2json } from 'devtechtools';
csv2json(csv, options)
Browser:
DTT.csv2json(csv, options)
csv2json
(csv, options)
Converts CSV to JSON. Returns an object. Use JSON.stringify
to convert to a string.
Available options:
separator
: Optional. Character which acts as separator. If omitted, will attempt to detect comma (,), semi-colon (;) or tab (\t).parseNumbers
: Optional. Will attempt to convert a value to a number, if possible.parseJSON
: Optional. Will attempt to convert a value to a valid JSON value if possible. Detects numbers, null, false, true, [] and {}.transpose
: Optional. Will pivot the table. Default is false.hash
: Optional. Will use the first column as a key and return a hash instead of an array of objects. Default is false.
json2csv
(data, options)
Converts JSON to CSV
Available options:
separator
: Character which acts as separator. For CSV use a comma (,). For TSV use a tab (\t).flatten
: Boolean indicating whether to flatten nested arrays or not. Optional. Default false.output_csvjson_variant
: Boolean indicating whether to output objects and arrays as is as per the CSVJSON format variant. Default is false.
SQLtoJSON
(sql)
Converts SQL to JSON. Returns an object. Detects CREATE TABLE and INSERT INTO
statements to extract table header and rows. Use JSON.stringify
to convert to a string.
Available options: None
json_beautifier
(object, options)
Parses, validates, beautifies and formats JSON. Returns a JSON string.
Available options:
space
: The number of spaces to indent. Default is 2.quoteType
: You can change double quotes to single quotes (') if you like to. Will make for invalid JSON but valid Javascript. Default is (").dropQuotesOnKeys
: JSON wraps keys with double quotes by default. Javascript doesn't need them though. Set to true to drop them. Will make for invalid JSON but valid Javascript. Default is false.dropQuotesOnNumbers
: Set to true to parse number values and drop quotes around them. Default is false.inlineShortArrays
: Set to true to collpase arrays inline if less than 80 characters. You can also set to an arbitrary number such as 160 to change the width. Default isfalse
.inlineShortArraysDepth
: If you turned on the above option, your can limit the nesting depth. Default is 1.minify
: Set totrue
to simply compact the JSON. Removes indentations and new lines. Default isfalse
.
csvjson2json
(csv, options)
Converts CSVJSON format variant to JSON. Returns an object.
Available options: None