Back to Top

Hype Data Parser master

Helper to parse strings into JavaScript multiple data formats and to easily extract specific facets from the data

countChar(str, c)

This function counts the times a char is found in a string

Parameters

Name Type Description
str String

This is the text to be searched in

c Char

This is the single text character to search

Returns

Number

Returns a number of found matches

getLineBreakChar(str)

This function determines the line endings used in a string

Parameters

Name Type Description
str String

This is the text to inspect

Returns

Number

Returns the used line ending type

getTables(text, convert, options)

This function splits a string containing multiple CSV/TSV tables and returns an object of string or if optionaly into a data format

Parameters

Name Type Description
text String

This is the text (either TSV or CSV) containing the tables

convert Boolean

If this boolean is set to true table is directly converted else it is kept as a string

options Object

This object can be used to override defaults and is only used if conversion is enabled

Returns

Object

Returns an object with tables referenced by index and if provided also by sheet and table name

includesTables(str)

This function determines if a string most likely contains multiple tables (very simple check)

Parameters

Name Type Description
str String

This is the text to inspect

Returns

Boolean

Returns if the provided text contains multiple tables

csvToArray(csv, options)

This function parses a CSV string into an array structur Given a second paramter options of type object, default options can be overriden

  • fSep defaults to ';' or ',' (depending on what character is found more often)
  • rSep defaults to '\n', '\r' or '\r\n' (depending on auto detection mechanism)
  • quot defaults to '"'
  • head defaults to false and allows ignoring the first row
  • trim defaults to false

Parameters

Name Type Description
csv String

This is the text to consider as CSV

options Object

This object can be used to override defaults

Returns

Array

Returns an array of rows with nested arrays of field data

rowsToColumns(csv, options)

This function transposes rows to columns as long as the length of the inital row is the same

Parameters

Name Type Description
csv String

This is the text to consider as CSV

options Object

This object can be used to override defaults

Returns

Array

Returns an array of rows transposed to columns

csvToObject(csv, options)

This function uses csvToArray (see function description), but converts the basic array into an object with keys based on the header. Because that is the case the removeHead option cannot be overriden and a header should be present in the CSV for text to work properly.

Parameters

Name Type Description
csv String

This is the text to consider as CSV

options Object

This object can be used to override defaults

Returns

Array

Returns an array of rows with nested objects containing named fields

csvToObjectByKey(csv, key, options)

Parse a CSV file into an object grouped by the specified key, containing each an array of rows of nested objects with named cells (key and value). If a specific object key only has a single member, the object is directly listed without being nested in an array. The behavior of this function can be modified by specifying the value of options.objectByKeyMode:

  • auto (default) - this setting parses each nested key into a direct object, but converts it into a list if multiple elements by the key are found
  • list - this setting always forces a nested array listing. Hence, even single entries by the specified key will result in a nested array
  • reduce - this function never creates a nested list and multiple entries by a specified key overwrite each other and the last occurrence prevails

Parameters

Name Type Description
csv String

This is the text to consider as CSV

key String Number

Either the key as a name or the index as a number (0 based)

options Object

This object can be used to override defaults

Returns

Object

Returns an object with named keys with nested objects containing named fields

csvToArrayByKey(csv, key, options)

This function parses a CSV string into an array structur while reducing the return to a shallow list with a single column of data

Parameters

Name Type Description
csv String

This is the text to consider as CSV

key String Number

Either the key as a name or the index as a number (0 based)

options Object

This object can be used to override defaults

Returns

Array

Returns an array data from the requested column

tsvToArray()

This is an alias to the TSV version of the csvToArray method. The only difference being that the field separator (fSep) is set to tab (\t). Please look at the documentation for csvToArray

Returns

Void

tsvToObject()

This is an alias to the TSV version of the csvToObject method. The only difference being that the field separator (fSep) is set to tab (\t). Please look at the documentation for csvToObject

Returns

Void

tsvToArrayByKey()

This is an alias to the TSV version of the csvToArrayByKey method. The only difference being that the field separator (fSep) is set to tab (\t). Please look at the documentation for csvToArrayByKey

Returns

Void

tsvToObjectByKey()

This is an alias to the TSV version of the csvToObjectByKey method. The only difference being that the field separator (fSep) is set to tab (\t). Please look at the documentation for csvToObjectByKey

Returns

Void

HypeDataParser()

Properties

Name Type Description
version String

Version of the extension

csvToArray Function

Convert a CSV string into an array rows with nested cells

csvToArrayByKey Function

Convert a CSV string into an array of cells

csvToObject Function

Convert a CSV string into an array of nested objects (cells as key, value)

csvToObjectByKey Function

Convert a CSV string into an object grouped by the specified key with array of nested objects (cells as key, value)

tsvToArray Function

Convert a TSV string into an array rows with nested cells

tsvToArrayByKey Function

Convert a TSV string into an array of cells

tsvToObject Function

Convert a TSV string into an array of nested objects (cells as key, value)

tsvToObjectByKey Function

Convert a TSV string into an object grouped by the specified key with array of nested objects (cells as key, value)

rowsToColumns Function

Returns a transposed array shifting row into columns (works on values from csvToArray)

getTables Function

Returns all found tables in an object lookup with index keys. If provided sheet and table names are additionaly used in the lookup.

includesTables Function

Returns a boolean indicating if a CSV/TSV string most likely contains multiple tables (simple check)

getLineBreakChar Function

Returns the line break character used in a multiline string

countChar Function

Returns the number of occurances of a given char in a string

Returns

Void