FlexTable (flextablejs)
FlexTable (flextablejs) is a JavaScript library that provides a class with a simple API to work with tables (headers, rows, columns, sort, format) facilitating the analysis and data manipulation.
This library is commonly used with CSV Types to parse text files with fields delimited by a character (like CSV). FlexTable is compatible with the data structure produced by CSV Types. Every values-headers definition can be converted to a FlexTable. If the CSV file follow the types specs, multiple tables can be created from a single CSV file.
Gitlab repo Docs NPM package
Table of Contents
Description
FlexTable (flextablejs) is a JavaScript library that provides a class with a simple API to work with tables (headers, rows, columns, sort, format) facilitating the analysis and data manipulation.
Installation
npm i flextablejs -S
Or from the repo:
npm i "http://github.com/Group4Layers/flextable.git"
It has been tested with node >= 6
, but it is widely used in Firefox and Chrome with building tools like webpack
.
This library is commonly used with CSV Types to parse text files with fields delimited by a character (like CSV). FlexTable is compatible with the data structure produced by CSV Types. Every values-headers definition can be converted to a FlexTable. If the CSV file follow the types specs, multiple tables can be created from a single CSV file.
Examples
The best way to learn something is to see how it behaves.
Starting from an empty table
const FlexTable = FlexTable;let table = ; table;table; table; // get the indices and set values manuallylet idx = tableidx;// update the Xeon Phitablevalues3idx'speedup' = 3455; // change the header nametableheadersidx'speedup' = 'S(t)';delete tableidx; // remove the indices to force update // convert a column (rounding)table let results = table;
console.log(results)
:
| device type | S(t) ||-------------|------|| CPU | 1 || GPU | 8.4 || FPGA | 2.3 || Xeon Phi | 3.5 |
Importing the data from a CSV with headers
#device type,S(t)CPU,1GPU,8.43FPGA,2.3Xeon Phi,3.455
const CSV = CSV;const FlexTable = FlexTable; let parsed = ; let table = parsed; // convert a column (lower case, hyphen)table; let results = table;
console.log(results)
:
| device type | S(t) ||-------------|------|| CPU | 1 || GPU | 8.4 || FPGA | 2.3 || Xeon Phi | 3.5 |
Until the README is completed and improved with real examples, we encourage you to read the source code documentation. It has examples of use: Docs.
TODO
- Write multiple examples showing the library.
- Perform more tests and increase the code coverage.
- Improve the documentation of the source code.
- Show real use cases.
New features
You can request new features for this library by opening new issues. If we find it useful (or there are at least 2 users interested in a proposal) we can implement it. Also, we accept pull requests with bugfixes or new features.
Test & Coverage
npm testnpm run coverage
Test covered:
FlexTable
Rows
✓ append rows at the end
✓ insert rows at the middle
✓ insert rows at the beginning
✓ remove rows at the beginning
✓ remove rows at the middle
✓ remove rows at the end
✓ replace rows at the beginning
✓ replace rows at the middle
✓ replace rows at the end
✓ remove rows by a custom function (not true leaves unchanged)
✓ remove rows by a custom function (true removes)
✓ modify rows by a custom function (null leaves unchanged)
✓ modify rows by a custom function (not null modifies the row)
Columns
✓ setHeadersIndex
✓ setColumn triggers setHeadersIndex
✓ setColumn can remove a column that exists
✓ setColumn cannot remove a column that doesn't exist
✓ setColumns can remove columns
✓ setColumn can replace a column that exists
✓ setColumn can add a column that doesn't exist
✓ setColumns can replace and add columns
✓ setColumn can use a custom function to modify values (cast)
✓ setColumn can use a custom function to insert values (based on the row)
Create
✓ create an empty table, append a row and insert a row
✓ create an empty table and append rows
✓ create an empty table without headers and with rows throws
✓ create a table with rows
Sort
✓ can sort rows using mapchains and sorters (<num, skip)
✓ can sort rows using mapchains and sorters (>num, skip, <num)
✓ can sort rows using mapchains and sorters (custom funcs)
Format
✓ as markdown (default fmt)
✓ as markdown (custom fmt)
✓ as markdown (by column fmt)
✓ as markdown (escaping)
✓ as csv (default fmt)
✓ as csv (custom fmt)
✓ as csv (by column fmt)
✓ as csv (escaping)
clone
✓ supports cloning (not shared references)
39 passing (72ms)
Author
nozalr nozalr@group4layers.com (Group4Layers®).
ChangeLog
GitHub/Gitlab readers (repo, no docs): CHANGELOG.md.
License
ExImageInfo source code is released under the MIT License.
GitHub/Gitlab readers (repo, no docs): LICENSE.md.