datapipe-js/utils
datapipe-js/utils is a set of JavaScript utility and helper functions for parsing, converting many other data management tasks
parseCsv#
Parse 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
textFieldsproperty if you don't want some particular field to be converted. Also, usedateFieldsto specify date format e.g. US date:MM/dd/yyyy.
parseCsvToTable#
Parse 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
toCsv#
Converts array to the delimiter (comma) separated value
fromTable#
Converts 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
toTable#
Converts 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
toObject#
Converts array of items to the object map. Where key selector can be defined.
- array array to be converted
- keyField a key field selected
toSeries#
Convert array into an object of series.
parseDatetimeOrNull#
Parses 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
parseNumberOrNull#
Parses 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
parseBooleanOrNull#
Parses 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
dateToString#
Converts Date (or Date with time) to the ISO string with TimeZone trick. Usually it should be used before sending to the server
deepClone#
Returns a deep copy of your object or array.