2.2.0 • Published 5 years ago

devtechtools v2.2.0

Weekly downloads
-
License
GPLv3
Repository
github
Last release
5 years ago

DevTech Tools API

A set of tools for conversions and other functions.

NPM package here

Dependencies:

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 is false.
  • inlineShortArraysDepth: If you turned on the above option, your can limit the nesting depth. Default is 1.
  • minify: Set to true to simply compact the JSON. Removes indentations and new lines. Default is false.

csvjson2json(csv, options)

Converts CSVJSON format variant to JSON. Returns an object.

Available options: None

2.2.0

5 years ago

2.0.0

5 years ago

1.10.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.6

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago