datapipe-js/utils
datapipe-js/utils is a set of JavaScript utility and helper functions for parsing, converting many other data management tasks
#
parseCsvParse Csv text into array of items. It automatically recognizes Dates, numbers and booleans. Also, provides number of other options to skip values converts etc
Parsing options:
Name | Definition | Default Value |
---|---|---|
delimiter | Define delimiter | ',' |
skipRows | Rows to skip | 0 |
textFields | a list of text fields what requires NO conversion | [] |
dateFields | a list of date fields (string or string[]) e.g. ['Date1', ['Date2', 'MM/dd/yyyy'], ['Date3', 'yyyyMM']] | [] |
numberFields | A list of fields what should be parsed as numbers or stay blank | [] |
booleanFields | A list of boolean fields | [] |
skipUntil | A callback function to provide skip initial rows. (tokens: string[]) => boolean | |
takeWhile | A callback function to provide a take while rows (tokens: string[]) => boolean | |
elementSelector | element definition clallback (fieldDescriptions: FieldDescription[], tokens: string[]) => any |
Date and number fields will be converted automatically. In most cases you don't have to confugire fields. Please use
textFields
property if you don't want some particular field to be converted. Also, usedateFields
to specify date format e.g. US date:MM/dd/yyyy
.
#
parseCsvToTableParse Csv text into tables of string values. It does not resolves any types, but it provides suggestions. All other features like skipWhile, take while works well there
#
toCsvConverts array to the delimiter (comma) separated value
#
fromTableConverts rows and columns to a list of ScalarObjects.
- rowsOrTable Table data or Array of values .
- fieldNames Column names. If not provided then, it will be auto generated
- fieldDataTypes Column names
#
toTableConverts an array of ScalarObjects into the table. An efficient format to transfer over the wire
- values an array of ScalarObjects
Takes an array
Converts to
#
toObjectConverts array of items to the object map. Where key selector can be defined.
- array array to be converted
- keyField a key field selected
#
toSeriesConvert array into an object of series.
#
parseDatetimeOrNullParses string to the Date or returns null. It is more efficient parser than new Date() and works better with UK date format
- value value to parse
#
parseNumberOrNullParses string to the number or returns null. It is more efficient parser than standard (parseFloat) and parses numbers like 1,000.32
- value value to parse
#
parseBooleanOrNullParses string to the boolean or returns null. It is treating ['1', 'yes', 'true', 'on']
as true and ['0', 'no', 'false', 'off']
as false
- value value to parse
#
dateToStringConverts Date (or Date with time) to the ISO string with TimeZone trick. Usually it should be used before sending to the server
#
deepCloneReturns a deep copy of your object or array.