From ec04cbdc97be7bc0d5a3dd1e930fd6340b20bad6 Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Wed, 19 Jun 2024 23:51:07 +0000 Subject: [PATCH 01/34] feat: add `@stdlib/plot/table/unicode` Signed-off-by: Snehil Shah --- .../@stdlib/plot/table/unicode/README.md | 407 ++++++++++++++ .../plot/table/unicode/benchmark/benchmark.js | 495 ++++++++++++++++ .../unicode/benchmark/benchmark.render.js | 142 +++++ .../@stdlib/plot/table/unicode/docs/repl.txt | 112 ++++ .../plot/table/unicode/examples/index.js | 53 ++ .../@stdlib/plot/table/unicode/lib/addrow.js | 63 +++ .../plot/table/unicode/lib/defaults.js | 77 +++ .../@stdlib/plot/table/unicode/lib/getdata.js | 38 ++ .../@stdlib/plot/table/unicode/lib/index.js | 34 ++ .../@stdlib/plot/table/unicode/lib/main.js | 527 ++++++++++++++++++ .../unicode/lib/parser/parse_2d_array.js | 74 +++ .../table/unicode/lib/parser/parse_object.js | 105 ++++ .../unicode/lib/parser/parse_objects_list.js | 78 +++ .../table/unicode/lib/props/alignment/get.js | 35 ++ .../table/unicode/lib/props/alignment/set.js | 56 ++ .../table/unicode/lib/props/borders/get.js | 38 ++ .../table/unicode/lib/props/borders/set.js | 66 +++ .../unicode/lib/props/cell-padding/get.js | 35 ++ .../unicode/lib/props/cell-padding/set.js | 47 ++ .../unicode/lib/props/column-separator/get.js | 35 ++ .../unicode/lib/props/column-separator/set.js | 59 ++ .../table/unicode/lib/props/corners/get.js | 39 ++ .../table/unicode/lib/props/corners/set.js | 67 +++ .../unicode/lib/props/header-separator/get.js | 35 ++ .../unicode/lib/props/header-separator/set.js | 59 ++ .../table/unicode/lib/props/joints/get.js | 39 ++ .../table/unicode/lib/props/joints/set.js | 67 +++ .../table/unicode/lib/props/margin-x/get.js | 35 ++ .../table/unicode/lib/props/margin-x/set.js | 47 ++ .../table/unicode/lib/props/margin-y/get.js | 35 ++ .../table/unicode/lib/props/margin-y/set.js | 47 ++ .../unicode/lib/props/max-cell-width/get.js | 35 ++ .../unicode/lib/props/max-cell-width/set.js | 47 ++ .../unicode/lib/props/max-output-width/get.js | 35 ++ .../unicode/lib/props/max-output-width/set.js | 47 ++ .../unicode/lib/props/row-separator/get.js | 35 ++ .../unicode/lib/props/row-separator/set.js | 59 ++ .../@stdlib/plot/table/unicode/lib/render.js | 289 ++++++++++ .../@stdlib/plot/table/unicode/lib/setdata.js | 88 +++ .../@stdlib/plot/table/unicode/package.json | 65 +++ .../plot/table/unicode/test/test.add_row.js | 79 +++ .../plot/table/unicode/test/test.alignment.js | 81 +++ .../plot/table/unicode/test/test.borders.js | 81 +++ .../table/unicode/test/test.cell_padding.js | 80 +++ .../unicode/test/test.column_separator.js | 80 +++ .../plot/table/unicode/test/test.corners.js | 81 +++ .../unicode/test/test.header_separator.js | 80 +++ .../plot/table/unicode/test/test.joints.js | 81 +++ .../@stdlib/plot/table/unicode/test/test.js | 39 ++ .../plot/table/unicode/test/test.main.js | 229 ++++++++ .../plot/table/unicode/test/test.margin_x.js | 80 +++ .../plot/table/unicode/test/test.margin_y.js | 80 +++ .../table/unicode/test/test.max_cell_width.js | 80 +++ .../unicode/test/test.max_output_width.js | 80 +++ .../plot/table/unicode/test/test.parser.js | 240 ++++++++ .../plot/table/unicode/test/test.render.js | 417 ++++++++++++++ .../table/unicode/test/test.row_separator.js | 80 +++ 57 files changed, 5714 insertions(+) create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/README.md create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.render.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/examples/index.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/addrow.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/defaults.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/getdata.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/index.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/main.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_2d_array.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_object.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_objects_list.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-x/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-x/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-y/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-y/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-output-width/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-output-width/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/render.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/setdata.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/package.json create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.add_row.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.alignment.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.borders.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.column_separator.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.corners.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.header_separator.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.joints.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.main.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_x.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_y.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.max_cell_width.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.max_output_width.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.parser.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.render.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.row_separator.js diff --git a/lib/node_modules/@stdlib/plot/table/unicode/README.md b/lib/node_modules/@stdlib/plot/table/unicode/README.md new file mode 100644 index 000000000000..ccbb89363aa4 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/README.md @@ -0,0 +1,407 @@ + + +# Unicode Table + +> Create a Unicode table. + +
+ +## Usage + +```javascript +var UnicodeTable = require( '@stdlib/plot/table/unicode' ); +``` + +#### UnicodeTable( \[data,] \[headers,] \[options] ) + +Returns a table instance. + +```javascript +var table = new UnicodeTable(); +``` + +The constructor accepts the following `options`: + +- **alignment**: datum's cell alignment. Default: `'right'`. +- **borders**: border characters. Default: `'─ │ ─ │'`. +- **cellPadding**: cell padding. Default: `1`. +- **columnSeparator**: column separator character. Default: `'│'`. +- **corners**: corner characters. Default: `'┌ ┐ ┘ └'`. +- **headerSeparator**: header separator character. Default: `'─'`. +- **joints**: joint characters. Default: `'┼ ┬ ┤ ┴ ├'`. +- **marginX**: horizontal output margin. Default: `0`. +- **marginY**: vertical output margin. Default: `0`. +- **maxCellWidth**: maximum cell width (excluding padding). Default: `FLOAT64_MAX`. +- **maxOutputWidth**: maximum output width (including margin). Default: `FLOAT64_MAX`. +- **rowSeparator**: row separator character. Default: `'None'`. + +* * * + +### Writable Properties + + + +#### UnicodeTable.prototype.alignment + +Alignment of datum in cell. The value must be either `'right'`, `'left'` or `'center'`. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.alignment = 'center'; + +// Get: +var alignment = table.alignment; +// returns 'center' +``` + + + +#### UnicodeTable.prototype.borders + +Border characters. String must be four space separated characters in the order 'top right bottom left'. A value of `'None'` indicates no border would be rendered. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.borders = '= ! = !'; + +// Get: +var borders = table.borders; +// returns '= ! = !' +``` + + + +#### UnicodeTable.prototype.cellPadding + +Cell padding. Pads each side of the cell with whitespace characters. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.cellPadding = 3; + +// Get: +var padding = table.cellPadding; +// returns 3 +``` + + + +#### UnicodeTable.prototype.corners + +Corner characters. String must be four space separated characters in the order 'top-left top-right bottom-right bottom-left'. A value of `'None'` indicates no corners would be rendered. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.corners = '* * * *'; + +// Get: +var corners = table.corners; +// returns '* * * *' +``` + + + +#### UnicodeTable.prototype.columnSeparator + +Column Separator character. Must be a character string or `'None'`. A value of `'None'` indicates that columns won't be separated. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.columnSeparator = '|'; + +// Get: +var separator = table.columnSeparator; +// returns '|' +``` + + + +#### UnicodeTable.prototype.headerSeparator + +Header Separator character. Must be a character string or `'None'`. A value of `'None'` indicates that headers won't be separated from the data. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.headerSeparator = '-'; + +// Get: +var separator = table.headerSeparator; +// returns '-' +``` + + + +#### UnicodeTable.prototype.joints + +Joint characters. String must be five space separated characters in the order 'middle top right bottom left'. A value of `'None'` indicates no joints would be rendered. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.joints = '* * * * *'; + +// Get: +var joints = table.joints; +// returns '* * * * *' +``` + + + +#### UnicodeTable.prototype.marginX + +Horizontal output margin. This will add margin to both left and right of the output. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.marginX = 2; + +// Get: +var margin = table.marginX; +// returns 2 +``` + + + +#### UnicodeTable.prototype.marginY + +Vertical output margin. This will add margin to both top and bottom of the output. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.marginY = 2; + +// Get: +var margin = table.marginY; +// returns 2 +``` + + + +#### UnicodeTable.prototype.maxCellWidth + +Maximum cell width. If a datum is longer than the maximum cell width, it is truncated. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.maxCellWidth = 10; + +// Get: +var width = table.maxCellWidth; +// returns 10 +``` + + + +#### UnicodeTable.prototype.maxOutputWidth + +Maximum output width. If the output is longer than the maximum output width, it is wrapped into multiple tables. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.maxOutputWidth = 200; + +// Get: +var width = table.maxOutputWidth; +// returns 200 +``` + + + +#### UnicodeTable.prototype.rowSeparator + +Row Separator character. Must be a character string or `'None'`. A value of `'None'` indicates that rows won't be separated. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.rowSeparator = '-'; + +// Get: +var separator = table.rowSeparator; +// returns '-' +``` + +* * * + +### Methods + + + +#### UnicodeTable.prototype.addRow( row ) + +Adds a row to table data. The row must have the same number of columns as existing data. + +```javascript +var table = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); + +var data = table.getData().data; +// returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] + +table.addRow( [ 7, 8, 9 ] ); + +data = table.getData().data; +// returns [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] +``` + + + +#### UnicodeTable.prototype.getData() + +Gets table data and headers. + +```javascript +var table = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ 'col1', 'col2', 'col3' ] ); + +var data = table.getData(); +// returns { 'data': [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], 'headers': [ 'col1', 'col2', 'col3' ] } +``` + + + +#### UnicodeTable.prototype.render() + +Renders a Unicode table. + +```javascript +var table = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ 'col1', 'col2', 'col3' ] ); + +var str = table.render(); +// returns '...' +``` + + + +#### UnicodeTable.prototype.setData() + +Sets table data and headers. + +```javascript +var table = new UnicodeTable(); + +table.setData( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ 'col1', 'col2', 'col3' ] ); + +var data = table.getData(); +// returns { 'data': [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], 'headers': [ 'col1', 'col2', 'col3' ] } +``` + +* * * + +
+ + + +
+ +
+ + + +
+ +* * * + +## Examples + + + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var Float64Array = require( '@stdlib/array/float64' ); +var array = require( '@stdlib/ndarray/array' ); +var ctor = require( '@stdlib/plot/table/unicode' ); + +var headers; +var table; +var data; +var str; +var i; + +// Generate some random data... +data = new Float64Array( 50 ); +for ( i = 0; i < data.length; i++ ) { + data[ i ] = randu() * 100.0; +} +data = array( data, { + 'shape': [ 10, 5 ] +}); + +// Generate headers... +headers = new Float64Array( 5 ); +for ( i = 0; i < headers.length; i++ ) { + headers[ i ] = randu() * 100.0; +} + +// Create a table: +table = ctor( data, headers ); + +// Render the table: +str = table.render(); +console.log( str ); +// => '...' +``` + +
+ + + +* * * + +## See Also + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.js b/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.js new file mode 100644 index 000000000000..0e81b8561fac --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.js @@ -0,0 +1,495 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pkg = require( './../package.json' ).name; +var UnicodeTable = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::instantiation', function benchmark( b ) { + var v; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new UnicodeTable(); + if ( !( v instanceof UnicodeTable ) ) { + b.fail( 'should return an instance' ); + } + } + b.toc(); + if ( !( v instanceof UnicodeTable ) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,no_new', function benchmark( b ) { + var ctor; + var v; + var i; + + ctor = UnicodeTable; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = ctor(); + if ( !( v instanceof UnicodeTable ) ) { + b.fail( 'should return an instance' ); + } + } + b.toc(); + if ( !( v instanceof UnicodeTable ) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,data', function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); + if ( !( v instanceof UnicodeTable ) ) { + b.fail( 'should return an instance' ); + } + } + b.toc(); + if ( !( v instanceof UnicodeTable ) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,data,headers', function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ 'col1', 'col2', 'col3' ] ); + if ( !( v instanceof UnicodeTable ) ) { + b.fail( 'should return an instance' ); + } + } + b.toc(); + if ( !( v instanceof UnicodeTable ) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,data,options', function benchmark( b ) { + var opts; + var v; + var i; + + opts = { + 'alignment': 'left', + 'borders': '1 2 3 4', + 'cellPadding': 2, + 'columnSeparator': 'None', + 'corners': '* * * *', + 'headerSeparator': '-', + 'joints': '* * * * *', + 'marginX': 2, + 'marginY': 4, + 'maxCellWidth': 10, + 'maxOutputWidth': 60, + 'rowSeparator': '_' + }; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], opts ); + if ( !( v instanceof UnicodeTable ) ) { + b.fail( 'should return an instance' ); + } + } + b.toc(); + if ( !( v instanceof UnicodeTable ) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::instantiation,data,headers,options', function benchmark( b ) { + var opts; + var v; + var i; + + opts = { + 'alignment': 'left', + 'borders': '1 2 3 4', + 'cellPadding': 2, + 'columnSeparator': 'None', + 'corners': '* * * *', + 'headerSeparator': '-', + 'joints': '* * * * *', + 'marginX': 2, + 'marginY': 4, + 'maxCellWidth': 10, + 'maxOutputWidth': 60, + 'rowSeparator': '_' + }; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ 'col1', 'col2', 'col3' ], opts ); + if ( !( v instanceof UnicodeTable ) ) { + b.fail( 'should return an instance' ); + } + } + b.toc(); + if ( !( v instanceof UnicodeTable ) ) { + b.fail( 'should return an instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:alignment', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 'left', + 'center', + 'right' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.alignment = values[ i % values.length ]; + if ( typeof v.alignment !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof v.borders !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:borders', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '1 2 3 4', + '- | - |', + 'None' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.borders = values[ i % values.length ]; + if ( typeof v.borders !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof v.borders !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:cellPadding', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 1, + 2, + 3 + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.cellPadding = values[ i % values.length ]; + if ( typeof v.cellPadding !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( typeof v.cellPadding !== 'number' ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:columnSeparator', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '|', + 'None' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.columnSeparator = values[ i % values.length ]; + if ( typeof v.columnSeparator !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof v.columnSeparator !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:corners', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '1 2 3 4', + '* * * *', + 'None' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.corners = values[ i % values.length ]; + if ( typeof v.corners !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof v.corners !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:headerSeparator', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '-', + 'None' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.headerSeparator = values[ i % values.length ]; + if ( typeof v.headerSeparator !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof v.headerSeparator !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:joints', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '1 2 3 4 5', + '* * * * *', + 'None' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.joints = values[ i % values.length ]; + if ( typeof v.joints !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof v.joints !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:marginX', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 0, + 1, + 2 + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.marginX = values[ i % values.length ]; + if ( typeof v.marginX !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( typeof v.marginX !== 'number' ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:marginY', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 0, + 1, + 2 + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.marginY = values[ i % values.length ]; + if ( typeof v.marginY !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( typeof v.marginY !== 'number' ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:maxCellWidth', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 10, + 20, + 30 + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.maxCellWidth = values[ i % values.length ]; + if ( typeof v.maxCellWidth !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( typeof v.maxCellWidth !== 'number' ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:maxOutputWidth', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 100, + 200, + 300 + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.maxOutputWidth = values[ i % values.length ]; + if ( typeof v.maxOutputWidth !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( typeof v.maxOutputWidth !== 'number' ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:rowSeparator', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '-', + 'None' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.rowSeparator = values[ i % values.length ]; + if ( typeof v.rowSeparator !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof v.rowSeparator !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.render.js b/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.render.js new file mode 100644 index 000000000000..79f812e10670 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.render.js @@ -0,0 +1,142 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Float64Array = require( '@stdlib/array/float64' ); +var array = require( '@stdlib/ndarray/array' ); +var pkg = require( './../package.json' ).name; +var UnicodeTable = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} rows - number of rows +* @param {PositiveInteger} columns - number of columns +* @param {UnicodeSparkline} table - table instance +* @returns {Function} benchmark function +*/ +function createBenchmark( rows, columns, table ) { + return benchmark; + + /** + * Generates table data. + * + * @private + * @returns {ndarray} table data + */ + function data() { + var data; + var i; + + data = new Float64Array( rows * columns ); + for ( i = 0; i < data.length; i++ ) { + data[ i ] = randu(); + } + data = array( data, { + 'shape': [ rows, columns ] + }); + return data; + } + + /** + * Generates table headers. + * + * @private + * @returns {Float64Array} table data + */ + function headers() { + var data; + var i; + + data = new Float64Array( columns ); + for ( i = 0; i < data.length; i++ ) { + data[ i ] = randu(); + } + return data; + } + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var str; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + str = table.setData( data(), headers() ).render(); + if ( typeof str !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof str !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var columns; + var table; + var rows; + var min; + var max; + var f; + var i; + var j; + + min = 1; // 5^min + max = 3; // 5^max + + for ( i = min; i <= max; i++ ) { + for ( j = min; j <= max; j++ ) { + rows = pow( 5, i ); + columns = pow( 5, j ); + + table = new UnicodeTable(); + f = createBenchmark( rows, columns, table ); + bench( pkg+':render:rows='+rows+',columns='+columns, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/docs/repl.txt b/lib/node_modules/@stdlib/plot/table/unicode/docs/repl.txt new file mode 100644 index 000000000000..7200f71b2983 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/docs/repl.txt @@ -0,0 +1,112 @@ + +{{alias}}( [data,] [headers,] [options] ) + Returns a Unicode table instance. + + Parameters + ---------- + data: Object|Array|Array|MatrixLike (optional) + Table data. + + headers: Collection (optional) + Table headers. + + options: Object (optional) + Table options. + + options.alignment: string (optional) + Datum's cell alignment. Default: 'right'. + + options.borders: string (optional) + Border characters. Default: '─ │ ─ │'. + + options.cellPadding: NonNegativeInteger (optional) + Cell padding. Default: 1. + + options.columnSeparator: string (optional) + Column separator character. Default: '│'. + + options.corners: string (optional) + Corner characters. Default: '┌ ┐ ┘ └'. + + options.headerSeparator: string (optional) + Header separator character. Default: '─'. + + options.joints: string (optional) + Joint characters. Default: '┼ ┬ ┤ ┴ ├'. + + options.marginX: NonNegativeInteger (optional) + Horizontal output margin. Default: 0. + + options.marginY: NonNegativeInteger (optional) + Vertical output margin. Default: 0. + + options.maxCellWidth: NonNegativeInteger (optional) + Maximum cell width (excluding padding). Default: FLOAT64_MAX. + + options.maxOutputWidth: NonNegativeInteger (optional) + Maximum output width (including margin). Default: FLOAT64_MAX. + + options.rowSeparator: string (optional) + Row separator character. Default: 'None'. + + Returns + ------- + table.addRow( row ) + Adds a row to table data. + + table.alignment + Datum's cell alignment. + + table.borders + Border characters. + + table.cellPadding + Cell Padding. + + table.columnSeparator + Column separator character. + + table.corners + Corner characters. + + table.getData() + Gets table data and headers. + + table.headerSeparator + Header separator character. + + table.joints + Joint characters. + + table.marginX + Horizontal output margin. + + table.marginY + Vertical output margin. + + table.maxCellWidth + Maximum cell width. + + table.maxOutputWidth + Maximum output width. + + table.render() + Renders a table. + + table.rowSeparator + Row separator character. + + table.setData( data, [headers] ) + Sets table data and headers + + Examples + -------- + > var data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + > var headers = [ 'col1', 'col2', 'col3' ]; + > var table = new {{alias}}( data, headers ); + > table.render() + '...' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/plot/table/unicode/examples/index.js b/lib/node_modules/@stdlib/plot/table/unicode/examples/index.js new file mode 100644 index 000000000000..6903a124be79 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/examples/index.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/base/randu' ); +var Float64Array = require( '@stdlib/array/float64' ); +var array = require( '@stdlib/ndarray/array' ); +var ctor = require( './../lib' ); + +var headers; +var table; +var data; +var str; +var i; + +// Generate some random data... +data = new Float64Array( 50 ); +for ( i = 0; i < data.length; i++ ) { + data[ i ] = randu() * 100.0; +} +data = array( data, { + 'shape': [ 10, 5 ] +}); + +// Generate headers... +headers = new Float64Array( 5 ); +for ( i = 0; i < headers.length; i++ ) { + headers[ i ] = randu() * 100.0; +} + +// Create a table: +table = ctor( data, headers ); + +// Render the table: +str = table.render(); +console.log( str ); +// => '...' diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/addrow.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/addrow.js new file mode 100644 index 000000000000..caeeb454ca15 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/addrow.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var format = require( '@stdlib/string/format' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var parse2dArray = require( './parser/parse_2d_array.js' ); + + +// MAIN // + +/** +* Adds a row to table data. +* +* @private +* @param {Collection} row - row to add +* @throws {TypeError} must provide a collection with equal number of columns to existing data +* @returns {UnicodeTable} class instance +*/ +function addRow( row ) { + /* eslint-disable no-invalid-this */ + var parsed; + + if ( !isCollection ) { + throw new TypeError( format( 'invalid argument. Must provide a collection. Value: `%s`.', row ) ); + } + // If data doesn't already exist, parse row as new data... + if ( !this._data || !this._data.length ) { + parsed = parse2dArray( [ row ], this._headers ); + this._data = parsed.data; + this._headers = parsed.headers; + this._columnWidths = parsed.columnWidths; + return this; + } + if ( this._data[ 0 ].length !== row.length ) { + throw new TypeError( format( 'invalid argument. Must provide a collection with equal number of columns to existing data. Value: `%s`.', row ) ); + } + this._data.push( row ); + return this; +} + + +// EXPORTS // + +module.exports = addRow; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/defaults.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/defaults.js new file mode 100644 index 000000000000..d7a7883a39f1 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/defaults.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var FLOAT64_MAX = require( '@stdlib/constants/float64/max' ); + + +// MAIN // + +/** +* Returns default options. +* +* @private +* @returns {Object} default options +*/ +function defaults() { + var out = {}; + + // Cell alignment: + out.alignment = 'right'; + + // Border characters: + out.borders = '─ │ ─ │'; + + // Cell padding: + out.cellPadding = 1; + + // Corner characters: + out.corners = '┌ ┐ ┘ └'; + + // Column separator character: + out.columnSeparator = '│'; + + // Header separator character: + out.headerSeparator = '─'; + + // Row separator character: + out.rowSeparator = 'None'; + + // Joint characters: + out.joints = '┼ ┬ ┤ ┴ ├'; + + // Output margins: + out.marginX = 0; + out.marginY = 0; + + // Maximum cell width: + out.maxCellWidth = FLOAT64_MAX; + + // Maximum output width: + out.maxOutputWidth = FLOAT64_MAX; + + return out; +} + + +// EXPORTS // + +module.exports = defaults; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/getdata.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/getdata.js new file mode 100644 index 000000000000..5b8ab1bda4b0 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/getdata.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns table data and headers. +* +* @private +* @returns {Object} table data and headers +*/ +function getData() { + /* eslint-disable no-invalid-this */ + return { + 'headers': this._headers, + 'data': this._data + }; +} + + +// EXPORTS // + +module.exports = getData; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/index.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/index.js new file mode 100644 index 000000000000..f0b575b93d5f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/index.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Create a Unicode table. +* +* @module @stdlib/plot/table/unicode +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/main.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/main.js new file mode 100644 index 000000000000..830cec9f5796 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/main.js @@ -0,0 +1,527 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var logger = require( 'debug' ); +var format = require( '@stdlib/string/format' ); +var defineProperty = require( '@stdlib/utils/define-property' ); +var objectKeys = require( '@stdlib/utils/keys' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var mergeFcn = require( '@stdlib/utils/merge' ).factory; +var pick = require( '@stdlib/utils/pick' ); +var setAlignment = require( './props/alignment/set.js' ); +var getAlignment = require( './props/alignment/get.js' ); +var setBorders = require( './props/borders/set.js' ); +var getBorders = require( './props/borders/get.js' ); +var setCellPadding = require( './props/cell-padding/set.js' ); +var getCellPadding = require( './props/cell-padding/get.js' ); +var setCorners = require( './props/corners/set.js' ); +var getCorners = require( './props/corners/get.js' ); +var setColumnSeparator = require( './props/column-separator/set.js' ); +var getColumnSeparator = require( './props/column-separator/get.js' ); +var setHeaderSeparator = require( './props/header-separator/set.js' ); +var getHeaderSeparator = require( './props/header-separator/get.js' ); +var setJoints = require( './props/joints/set.js' ); +var getJoints = require( './props/joints/get.js' ); +var setMarginX = require( './props/margin-x/set.js' ); +var getMarginX = require( './props/margin-x/get.js' ); +var setMarginY = require( './props/margin-y/set.js' ); +var getMarginY = require( './props/margin-y/get.js' ); +var setMaxCellWidth = require( './props/max-cell-width/set.js' ); +var getMaxCellWidth = require( './props/max-cell-width/get.js' ); +var setMaxOutputWidth = require( './props/max-output-width/set.js' ); +var getMaxOutputWidth = require( './props/max-output-width/get.js' ); +var setRowSeparator = require( './props/row-separator/set.js' ); +var getRowSeparator = require( './props/row-separator/get.js' ); +var defaults = require( './defaults.js' ); +var render = require( './render.js' ); +var setData = require('./setdata.js'); +var getData = require( './getdata.js' ); +var addRow = require( './addrow.js' ); + + +// VARIABLES // + +var debug = logger( 'table:unicode:main' ); + +var merge = mergeFcn({ + 'extend': false +}); + +// List of private properties (note: keep in alphabetical order): +var PRIVATE_PROPS = [ + '_alignment', + '_borders', + '_cellPadding', + '_corners', + '_columnSeparator', + '_columnWidths', + '_data', + '_headers', + '_headerSeparator', + '_joints', + '_marginX', + '_marginY', + '_maxCellWidth', + '_maxOutputWidth', + '_rowSeparator' +]; + +// List of options properties (note: keep in alphabetical order): +var OPTIONS_PROPS = [ + 'alignment', + 'borders', + 'cellPadding', + 'columnSeparator', + 'corners', + 'headerSeparator', + 'joints', + 'marginX', + 'marginY', + 'maxCellWidth', + 'maxOutputWidth', + 'rowSeparator' +]; + + +// MAIN // + +/** +* Unicode table constructor. +* +* @constructor +* @param {(Object|Array|Array|MatrixLike)} [data] - table data +* @param {Collection} [headers] - table headers +* @param {Options} [options] - table options +* @param {string} [options.alignment='right'] - datum's cell alignment +* @param {(string)} [options.borders='─ │ ─ │'] - border characters +* @param {NonNegativeInteger} [options.cellPadding=1] - cell padding +* @param {string} [options.columnSeparator='│'] - column separator character +* @param {string} [options.corners='┌ ┐ ┘ └'] - corner characters +* @param {string} [options.headerSeparator='─'] - header separator character +* @param {string} [options.joints='┼ ┬ ┤ ┴ ├'] - joint characters +* @param {NonNegativeInteger} [options.marginX=0] - horizontal output margin +* @param {NonNegativeInteger} [options.marginY=0] - vertical output margin +* @param {NonNegativeInteger} [options.maxCellWidth=FLOAT64_MAX] - maximum cell width (excluding padding) +* @param {NonNegativeInteger} [options.maxOutputWidth=FLOAT64_MAX] - maximum output width (including margin) +* @param {string} [options.rowSeparator='None'] - row separator character +* @throws {TypeError} must provide valid options +* @returns {UnicodeTable} table instance +*/ +function UnicodeTable() { + var headers; + var options; + var nargs; + var data; + var opts; + var keys; + var key; + var i; + + nargs = arguments.length; + if ( !( this instanceof UnicodeTable ) ) { + if ( nargs === 0 ) { + return new UnicodeTable(); + } + if ( nargs === 1 ) { + return new UnicodeTable( arguments[ 0 ] ); + } + if ( nargs === 2 ) { + return new UnicodeTable( arguments[ 0 ], arguments[ 1 ] ); + } + return new UnicodeTable( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] ); // eslint-disable-line max-len + } + + // Extract table-specific options... + opts = defaults(); + if ( nargs === 0 ) { + data = null; + headers = null; + options = {}; + } else if ( nargs === 1 ) { + data = arguments[ 0 ]; + headers = null; + options = {}; + } else if ( nargs === 2 ) { + if ( isCollection( arguments[ 1 ] ) ) { + data = arguments[ 0 ]; + headers = arguments[ 1 ]; + options = {}; + } else { + data = arguments[ 0 ]; + headers = null; + options = arguments[ 1 ]; + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + } + } else { + data = arguments[ 0 ]; + headers = arguments[ 1 ]; + options = arguments[ 2 ]; + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + } + opts = merge( opts, pick( options, OPTIONS_PROPS ) ); + + debug( 'Creating an instance with the following configuration: %s.', JSON.stringify( opts ) ); + + // Initialize private table-specific properties... + for ( i = 0; i < PRIVATE_PROPS.length; i++ ) { + defineProperty( this, PRIVATE_PROPS[i], { + 'configurable': false, + 'enumerable': false, + 'writable': true, + 'value': null + }); + } + // Set table data and headers... + if ( headers ) { + this.setData( data, headers ); + } else if ( data ) { + this.setData( data ); + } + // Set table-specific properties... + keys = objectKeys( opts ); + for ( i = 0; i < keys.length; i++ ) { + key = keys[ i ]; + this[ key ] = opts[ key ]; + } + return this; +} + +/** +* Alignment of datum in cell. +* +* @name alignment +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a supported alignment string +* @default 'right' +* +* @example +* var table = new UnicodeTable(); +* table.alignment = 'left'; +* var alignment = table.alignment; +* // returns 'left' +*/ +defineProperty( UnicodeTable.prototype, 'alignment', { + 'configurable': false, + 'enumerable': true, + 'set': setAlignment, + 'get': getAlignment +}); + +/** +* Border characters. +* +* @name borders +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a four space separated characters or 'None' +* @default '─ │ ─ │' +* +* @example +* var table = new UnicodeTable(); +* table.borders = '= ! = !'; +* var borders = table.borders; +* // returns '= ! = !' +*/ +defineProperty( UnicodeTable.prototype, 'borders', { + 'configurable': false, + 'enumerable': true, + 'set': setBorders, + 'get': getBorders +}); + +/** +* Cell padding. +* +* @name cellPadding +* @memberof UnicodeTable.prototype +* @type {NonNegativeInteger} +* @throws {TypeError} must be a non-negative integer +* @default '1' +* +* @example +* var table = new UnicodeTable(); +* table.cellPadding = 3; +* var padding = table.cellPadding; +* // returns 3 +*/ +defineProperty( UnicodeTable.prototype, 'cellPadding', { + 'configurable': false, + 'enumerable': true, + 'set': setCellPadding, + 'get': getCellPadding +}); + +/** +* Corner characters. +* +* @name corners +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string with four space separated characters or 'None' +* @default '┌ ┐ ┘ └' +* +* @example +* var table = new UnicodeTable(); +* table.corners = '* * * *'; +* var corners = table.corners; +* // returns '* * * *' +*/ +defineProperty( UnicodeTable.prototype, 'corners', { + 'configurable': false, + 'enumerable': true, + 'set': setCorners, + 'get': getCorners +}); + +/** +* Column separator character. +* +* @name columnSeparator +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a character string or 'None' +* @default '│' +* +* @example +* var table = new UnicodeTable(); +* table.columnSeparator = '$'; +* var separator = table.columnSeparator; +* // returns '$' +*/ +defineProperty( UnicodeTable.prototype, 'columnSeparator', { + 'configurable': false, + 'enumerable': true, + 'set': setColumnSeparator, + 'get': getColumnSeparator +}); + +/** +* Header separator character. +* +* @name headerSeparator +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a character string or 'None' +* @default '─' +* +* @example +* var table = new UnicodeTable(); +* table.headerSeparator = '$'; +* var separator = table.headerSeparator; +* // returns '$' +*/ +defineProperty( UnicodeTable.prototype, 'headerSeparator', { + 'configurable': false, + 'enumerable': true, + 'set': setHeaderSeparator, + 'get': getHeaderSeparator +}); + +/** +* Joint characters. +* +* @name joints +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string with five space separated characters or 'None' +* @default '┼ ┬ ┤ ┴ ├' +* +* @example +* var table = new UnicodeTable(); +* table.joints = '* * * * *'; +* var joints = table.joints; +* // returns '* * * * *' +*/ +defineProperty( UnicodeTable.prototype, 'joints', { + 'configurable': false, + 'enumerable': true, + 'set': setJoints, + 'get': getJoints +}); + +/** +* Horizontal output margin. +* +* @name marginX +* @memberof UnicodeTable.prototype +* @type {NonNegativeInteger} +* @throws {TypeError} must be a non-negative integer +* @default '0' +* +* @example +* var table = new UnicodeTable(); +* table.marginX = 2; +* var margin = table.marginX; +* // returns 2 +*/ +defineProperty( UnicodeTable.prototype, 'marginX', { + 'configurable': false, + 'enumerable': true, + 'set': setMarginX, + 'get': getMarginX +}); + +/** +* Vertical output margin. +* +* @name marginY +* @memberof UnicodeTable.prototype +* @type {NonNegativeInteger} +* @throws {TypeError} must be a non-negative integer +* @default '0' +* +* @example +* var table = new UnicodeTable(); +* table.marginY = 2; +* var margin = table.marginY; +* // returns 2 +*/ +defineProperty( UnicodeTable.prototype, 'marginY', { + 'configurable': false, + 'enumerable': true, + 'set': setMarginY, + 'get': getMarginY +}); + +/** +* Maximum cell width (excluding padding). +* +* @name maxCellWidth +* @memberof UnicodeTable.prototype +* @type {NonNegativeInteger} +* @throws {TypeError} must be a non-negative integer +* @default 'FLOAT64_MAX' +* +* @example +* var table = new UnicodeTable(); +* table.maxCellWidth = 10; +* var width = table.maxCellWidth; +* // returns 10 +*/ +defineProperty( UnicodeTable.prototype, 'maxCellWidth', { + 'configurable': false, + 'enumerable': true, + 'set': setMaxCellWidth, + 'get': getMaxCellWidth +}); + +/** +* Maximum output width (including margin). +* +* @name maxOutputWidth +* @memberof UnicodeTable.prototype +* @type {NonNegativeInteger} +* @throws {TypeError} must be a non-negative integer +* @default 'FLOAT64_MAX' +* +* @example +* var table = new UnicodeTable(); +* table.maxOutputWidth = 50; +* var width = table.maxOutputWidth; +* // returns 50 +*/ +defineProperty( UnicodeTable.prototype, 'maxOutputWidth', { + 'configurable': false, + 'enumerable': true, + 'set': setMaxOutputWidth, + 'get': getMaxOutputWidth +}); + +/** +* Row separator character. +* +* @name rowSeparator +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a character string or 'None' +* @default 'None' +* +* @example +* var table = new UnicodeTable(); +* table.rowSeparator = '$'; +* var separator = table.rowSeparator; +* // returns '$' +*/ +defineProperty( UnicodeTable.prototype, 'rowSeparator', { + 'configurable': false, + 'enumerable': true, + 'set': setRowSeparator, + 'get': getRowSeparator +}); + +/** +* Adds a row to table data. +* +* @name addRow +* @memberof UnicodeTable.prototype +* @type {Function} +* @param {Collection} row - row to add +* @throws {TypeError} must provide a collection with equal number of columns to existing data +* @returns {UnicodeTable} class instance +*/ +UnicodeTable.prototype.addRow = addRow; + +/** +* Gets table data and headers. +* +* @name getData +* @memberof UnicodeTable.prototype +* @type {Function} +* @returns {Object} table data and headers +*/ +UnicodeTable.prototype.getData = getData; + +/** +* Renders a table. +* +* @name render +* @memberof UnicodeTable.prototype +* @type {Function} +* @throws {Error} output must be able to accommodate every column individually +* @returns {string} rendered table +*/ +UnicodeTable.prototype.render = render; + +/** +* Sets table data and headers. +* +* @name setData +* @memberof UnicodeTable.prototype +* @type {Function} +* @param {(Object|Array|Array|MatrixLike)} data - table data +* @param {Collection} [headers] - table headers +* @throws {TypeError} first argument must be an object, array of objects, or a 2 dimensional array/ndarray +* @throws {TypeError} second argument must be a collection +* @returns {UnicodeTable} class instance +*/ +UnicodeTable.prototype.setData = setData; + + +// EXPORTS // + +module.exports = UnicodeTable; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_2d_array.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_2d_array.js new file mode 100644 index 000000000000..411157f88db3 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_2d_array.js @@ -0,0 +1,74 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Parses 2D array into tabular data. +* +* @private +* @param {Array} data - tabular data +* @param {Collection} [headers] - column names +* @throws {Error} must provide correct number of columns +* @returns {Object} table metadata +*/ +function parse2dArray( data, headers ) { + var widths = []; + var cols; + var len; + var i; + var j; + + // If headers exist, initialize the widths array... + if ( headers ) { + cols = headers.length; + for ( i = 0; i < cols; i++ ) { + widths.push( String( headers[ i ] ).length ); + } + } else { + headers = null; + cols = data[ 0 ].length; + for ( i = 0; i < cols; i++ ) { + widths.push( 0 ); + } + } + // Calculating max widths of all columns: + for ( i = 0; i < data.length; i++ ) { + if ( cols !== data[ i ].length ) { + throw new Error( 'invalid data. All rows must have equal number of columns' ); + } + for ( j = 0; j < cols; j++ ) { + len = String( data[ i ][ j ] ).length; + if ( len > widths[ j ] ) { + widths[ j ] = len; + } + } + } + return { + 'headers': headers, + 'data': data, + 'columnWidths': widths + }; +} + + +// EXPORTS // + +module.exports = parse2dArray; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_object.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_object.js new file mode 100644 index 000000000000..69b5edf2a71d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_object.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var objectKeys = require( '@stdlib/utils/keys' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var format = require( '@stdlib/string/format' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); + + +// MAIN // + +/** +* Parses an object into tabular data. +* +* @private +* @param {Object} data - tabular data +* @param {Collection} [headers] - column names +* @throws {Error} must provide correct number of rows +* @throws {Error} headers must exist in the object +* @throws {Error} each key must correspond to a collection +* @returns {Object} table metadata +*/ +function parseObject( data, headers ) { + var columns; + var header; + var widths; + var cols; + var rows; + var len; + var i; + var j; + + // If headers don't exist, extract headers from data: + if ( !headers ) { + headers = objectKeys( data ); + } + + // Parsing data into a 2D array: + rows = []; // final data after parsing + columns = []; // final headers list after parsing + widths = []; // max widths of each column + for ( i = 0; i < headers.length; i++ ) { + header = String( headers[ i ] ); + + // Skip header if it doesn't exist in the data... + if ( hasOwnProp( data, header ) ) { + if ( !isCollection( data[ header ] ) ) { + throw new Error( format( 'invalid data. Each key must correspond to an array. Value: `%s`.', data ) ); + } + columns.push( header ); + widths.push( header.length ); + for ( j = 0; j < data[ header ].length; j++ ) { + len = String( data[ header ][ j ] ).length; + + // Updating max width of column: + if ( len > widths[ i ] ) { + widths[ i ] = len; + } + if ( !rows[ j ] ) { + rows[ j ] = []; + } + rows[ j ][ i ] = data[ header ][ j ]; + } + } + } + if ( columns.length === 0 ) { + throw new Error( format( 'invalid data. No headers found in data. Value: `%s`.', data ) ); + } + // Checking if all columns have the same number of rows... + cols = data[ columns[ 0 ] ].length; + for ( i = 1; i < columns.length; i++ ) { + if ( cols !== data[ columns[ i ] ].length ) { + throw new Error( 'invalid data. All columns must have the same number of rows' ); + } + } + return { + 'headers': columns, + 'data': rows, + 'columnWidths': widths + }; +} + + +// EXPORTS // + +module.exports = parseObject; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_objects_list.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_objects_list.js new file mode 100644 index 000000000000..671854f9d2e6 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_objects_list.js @@ -0,0 +1,78 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var objectKeys = require( '@stdlib/utils/keys' ); + + +// MAIN // + +/** +* Parses array of objects into tabular data. +* +* @private +* @param {Array} data - tabular data +* @param {Collection} [headers] - column names +* @returns {Object} table metadata +*/ +function parseObjectsList( data, headers ) { + var header; + var widths; + var rows; + var len; + var i; + var j; + + // If headers don't exist, extract headers from data: + if ( !headers ) { + headers = objectKeys( data[ 0 ] ); + } + + // Parsing data into a 2D array... + rows = []; // final data after parsing + widths = []; // max widths of each column + for ( i = 0; i < headers.length; i++ ) { // initialize widths + widths.push( String( headers[ i ] ).length ); + } + for ( i = 0; i < data.length; i++ ) { + rows[ i ] = []; + for ( j = 0; j < headers.length; j++ ) { + header = headers[ j ]; + len = String( data[ i ][ header ] ).length; + + // Updating max width of column: + if ( len > widths[ j ] ) { + widths[ j ] = len; + } + rows[ i ][ j ] = data[ i ][ header ]; + } + } + return { + 'headers': headers, + 'data': rows, + 'columnWidths': widths + }; +} + + +// EXPORTS // + +module.exports = parseObjectsList; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/get.js new file mode 100644 index 000000000000..7ab5a7b8d181 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/get.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the table cell alignment. +* +* @private +* @returns {string} cell alignment +*/ +function get() { + /* eslint-disable no-invalid-this */ + return this._alignment; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/set.js new file mode 100644 index 000000000000..e9b5f100e5db --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/set.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var contains = require( '@stdlib/assert/contains' ); +var isString = require( '@stdlib/assert/is-string' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var ALIGNMENTS = [ 'right', 'center', 'left' ]; + + +// MAIN // + +/** +* Sets the table cell alignment. +* +* @private +* @param {string} alignment - cell alignment +* @throws {TypeError} must be a supported alignment string +*/ +function set( alignment ) { + /* eslint-disable no-invalid-this */ + if ( !isString( alignment ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'alignment', alignment ) ); + } + if ( !contains( ALIGNMENTS, alignment ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', 'alignment', ALIGNMENTS.join( '", "' ), alignment ) ); + } + this._alignment = alignment; +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/get.js new file mode 100644 index 000000000000..f19ba3763f86 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the table's border characters. +* +* @private +* @returns {string} borders string +*/ +function get() { + /* eslint-disable no-invalid-this */ + if ( this._borders === 'None' ) { + return 'None'; + } + return this._borders.join( ' ' ); +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/set.js new file mode 100644 index 000000000000..b500f70ce062 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/set.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var BORDER_STRING_LEN = 7; +var BORDER_CHARACTERS = 4; + + +// MAIN // + +/** +* Sets the table's border characters. +* +* @private +* @param {string} borders - borders string +* @throws {TypeError} must be a four space separated characters or 'None' +*/ +function set( borders ) { + var arr; + + /* eslint-disable no-invalid-this */ + if ( !isString( borders ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'borders', borders ) ); + } + if ( borders === 'None' ) { + this._borders = borders; + return; + } + arr = borders.split( ' ' ); + if ( borders.length !== BORDER_STRING_LEN ) { + throw new TypeError( format( 'invalid assignment. `%s` must be four space separated characters or \'None\'. Value: `%s`.', 'borders', borders ) ); + } + if ( arr.length !== BORDER_CHARACTERS ) { + throw new TypeError( format( 'invalid assignment. `%s` must be four space separated characters or \'None\'. Value: `%s`.', 'borders', borders ) ); + } + this._borders = arr; +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/get.js new file mode 100644 index 000000000000..c33cfcc67aa4 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/get.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the table's cell padding. +* +* @private +* @returns {NonNegativeInteger} cell padding +*/ +function get() { + /* eslint-disable no-invalid-this */ + return this._cellPadding; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/set.js new file mode 100644 index 000000000000..ff5365675c3b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/set.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the table's cell padding. +* +* @private +* @param {NonNegativeInteger} padding - cell padding +* @throws {TypeError} must provide a non-negative integer +*/ +function set( padding ) { + /* eslint-disable no-invalid-this */ + if ( !isNonNegativeInteger( padding ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer. Value: `%s`.', 'cellPadding', padding ) ); + } + this._cellPadding = padding; +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/get.js new file mode 100644 index 000000000000..60fd29996d58 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/get.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the column separator character. +* +* @private +* @returns {string} column separator +*/ +function get() { + /* eslint-disable no-invalid-this */ + return this._columnSeparator; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/set.js new file mode 100644 index 000000000000..e43341a4c047 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var CHARACTER_LENGTH = 1; + + +// MAIN // + +/** +* Sets the column separator character. +* +* @private +* @param {string} separator - column separator +* @throws {TypeError} must be a character string or 'None' +*/ +function set( separator ) { + /* eslint-disable no-invalid-this */ + if ( !isString( separator ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'columnSeparator', separator ) ); + } + if ( separator === 'None' ) { + this._columnSeparator = separator; + return; + } + if ( separator.length !== CHARACTER_LENGTH ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a single character or \'None\'. Value: `%s`.', 'columnSeparator', separator ) ); + } + this._columnSeparator = separator; +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/get.js new file mode 100644 index 000000000000..13500c3b0160 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/get.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the table's corner characters. +* +* @private +* @returns {string} corners string +*/ +function get() { + /* eslint-disable no-invalid-this */ + if ( this._corners[ 0 ] === ' ' ) { + // Empty corner: + return 'None'; + } + return this._corners.join( ' ' ); +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/set.js new file mode 100644 index 000000000000..6f3c5e03759f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/set.js @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var CORNER_STRING_LEN = 7; +var CORNER_CHARACTERS = 4; +var EMPTY_CORNERS = [ ' ', ' ', ' ', ' ' ]; + + +// MAIN // + +/** +* Sets the table's corner characters. +* +* @private +* @param {string} corners - corners string +* @throws {TypeError} must be a string with four space separated characters or 'None' +*/ +function set( corners ) { + /* eslint-disable no-invalid-this */ + var arr; + + if ( !isString( corners ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'corners', corners ) ); + } + if ( corners === 'None' ) { + this._corners = EMPTY_CORNERS; + return; + } + arr = corners.split( ' ' ); + if ( corners.length !== CORNER_STRING_LEN ) { + throw new TypeError( format( 'invalid assignment. `%s` must be four space separated characters or \'None\'. Value: `%s`.', 'corners', corners ) ); + } + if ( arr.length !== CORNER_CHARACTERS ) { + throw new TypeError( format( 'invalid assignment. `%s` must be four space separated characters or \'None\'. Value: `%s`.', 'corners', corners ) ); + } + this._corners = arr; +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/get.js new file mode 100644 index 000000000000..8f87e32abca4 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/get.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the header separator character. +* +* @private +* @returns {string} header separator +*/ +function get() { + /* eslint-disable no-invalid-this */ + return this._headerSeparator; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/set.js new file mode 100644 index 000000000000..584db81ebea1 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var CHARACTER_LENGTH = 1; + + +// MAIN // + +/** +* Sets the header separator character. +* +* @private +* @param {string} separator - header separator +* @throws {TypeError} must be a character string or 'None' +*/ +function set( separator ) { + /* eslint-disable no-invalid-this */ + if ( !isString( separator ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'headerSeparator', separator ) ); + } + if ( separator === 'None' ) { + this._headerSeparator = separator; + return; + } + if ( separator.length !== CHARACTER_LENGTH ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a character or \'None\'. Value: `%s`.', 'headerSeparator', separator ) ); + } + this._headerSeparator = separator; +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/get.js new file mode 100644 index 000000000000..1a8a6811697c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/get.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the joint characters. +* +* @private +* @returns {string} joint character +*/ +function get() { + /* eslint-disable no-invalid-this */ + if ( this._joints[ 0 ] === ' ' ) { + // Empty joint: + return 'None'; + } + return this._joints.join( ' ' ); +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/set.js new file mode 100644 index 000000000000..1ba1a89ce48b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/set.js @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var JOINT_STRING_LEN = 9; +var JOINT_CHARACTERS = 5; +var EMPTY_JOINTS = [ ' ', ' ', ' ', ' ', ' ' ]; + + +// MAIN // + +/** +* Sets the joint characters. +* +* @private +* @param {string} joints - joint character +* @throws {TypeError} must be a string with five space separated characters or 'None' +*/ +function set( joints ) { + /* eslint-disable no-invalid-this */ + var arr; + + if ( !isString( joints ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'joints', joints ) ); + } + if ( joints === 'None' ) { + this._joints = EMPTY_JOINTS; + return; + } + arr = joints.split( ' ' ); + if ( joints.length !== JOINT_STRING_LEN ) { + throw new TypeError( format( 'invalid assignment. `%s` must be five space separated characters or \'None\'. Value: `%s`.', 'joints', joints ) ); + } + if ( arr.length !== JOINT_CHARACTERS ) { + throw new TypeError( format( 'invalid assignment. `%s` must be five space separated characters or \'None\'. Value: `%s`.', 'joints', joints ) ); + } + this._joints = arr; +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-x/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-x/get.js new file mode 100644 index 000000000000..395cb89f03d9 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-x/get.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the table's horizontal margin. +* +* @private +* @returns {NonNegativeInteger} X margin +*/ +function get() { + /* eslint-disable no-invalid-this */ + return this._marginX; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-x/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-x/set.js new file mode 100644 index 000000000000..66407ad7200d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-x/set.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the table's horizontal margin. +* +* @private +* @param {NonNegativeInteger} x - X margin +* @throws {TypeError} must provide a non-negative integer +*/ +function set( x ) { + /* eslint-disable no-invalid-this */ + if ( !isNonNegativeInteger( x ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer. Value: `%s`.', 'marginX', x ) ); + } + this._marginX = x; +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-y/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-y/get.js new file mode 100644 index 000000000000..b8672fbdf6f2 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-y/get.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the table's vertical margin. +* +* @private +* @returns {NonNegativeInteger} Y margin +*/ +function get() { + /* eslint-disable no-invalid-this */ + return this._marginY; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-y/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-y/set.js new file mode 100644 index 000000000000..f1c5652c7c53 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-y/set.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the table's vertical margin. +* +* @private +* @param {NonNegativeInteger} y - Y margin +* @throws {TypeError} must provide a non-negative integer +*/ +function set( y ) { + /* eslint-disable no-invalid-this */ + if ( !isNonNegativeInteger( y ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer. Value: `%s`.', 'marginY', y ) ); + } + this._marginY = y; +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/get.js new file mode 100644 index 000000000000..10513c017df6 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/get.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the table's max cell width. +* +* @private +* @returns {NonNegativeInteger} max cell width +*/ +function get() { + /* eslint-disable no-invalid-this */ + return this._maxCellWidth; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/set.js new file mode 100644 index 000000000000..a5762c2e6f63 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/set.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the table's max cell width. +* +* @private +* @param {NonNegativeInteger} width - max cell width +* @throws {TypeError} must provide a non-negative integer +*/ +function set( width ) { + /* eslint-disable no-invalid-this */ + if ( !isNonNegativeInteger( width ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer. Value: `%s`.', 'maxCellWidth', width ) ); + } + this._maxCellWidth = width; +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-output-width/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-output-width/get.js new file mode 100644 index 000000000000..606e4d09337a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-output-width/get.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the table's max output width. +* +* @private +* @returns {NonNegativeInteger} max output width +*/ +function get() { + /* eslint-disable no-invalid-this */ + return this._maxOutputWidth; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-output-width/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-output-width/set.js new file mode 100644 index 000000000000..59d2ab40e686 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-output-width/set.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the table's max output width. +* +* @private +* @param {NonNegativeInteger} width - max output width +* @throws {TypeError} must provide a non-negative integer +*/ +function set( width ) { + /* eslint-disable no-invalid-this */ + if ( !isNonNegativeInteger( width ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer. Value: `%s`.', 'maxOutputWidth', width ) ); + } + this._maxOutputWidth = width; +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/get.js new file mode 100644 index 000000000000..d404104acc21 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/get.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the row separator character. +* +* @private +* @returns {string} row separator +*/ +function get() { + /* eslint-disable no-invalid-this */ + return this._rowSeparator; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/set.js new file mode 100644 index 000000000000..0c824793df1d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var CHARACTER_LENGTH = 1; + + +// MAIN // + +/** +* Sets the row separator character. +* +* @private +* @param {string} separator - row separator +* @throws {TypeError} must be a character string or 'None' +*/ +function set( separator ) { + /* eslint-disable no-invalid-this */ + if ( !isString( separator ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'rowSeparator', separator ) ); + } + if ( separator === 'None' ) { + this._rowSeparator = separator; + return; + } + if ( separator.length !== CHARACTER_LENGTH ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a character or \'None\'. Value: `%s`.', 'rowSeparator', separator ) ); + } + this._rowSeparator = separator; +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/render.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/render.js new file mode 100644 index 000000000000..b6829c758a98 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/render.js @@ -0,0 +1,289 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var format = require( '@stdlib/string/format' ); +var repeat = require( '@stdlib/string/repeat' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var ceil = require( '@stdlib/math/base/special/ceil' ); +var min = require( '@stdlib/math/base/special/min' ); +var slice = require( '@stdlib/array/slice' ); +var truncate = require( '@stdlib/string/truncate' ); + + +// MAIN // + +/** +* Renders a table. +* +* @private +* @throws {Error} output must be able to accommodate every column individually +* @returns {string} rendered table +*/ +function render() { + /* eslint-disable no-invalid-this, no-underscore-dangle */ + var wrapIndices; + var widths; + var start; + var table; + var wraps; + var self; + var row; + var end; + var out; + var i; + var j; + + self = this; + out = ''; + + if ( !this._columnWidths ) { + // Empty table: + return out; + } + + // Resolve indices to wrap the table at: + wrapIndices = resolveWrapping(); + + // Render top margin: + out += repeat( '\n', this._marginY ); + + // Render table: + wraps = []; + for ( j = 0; j < wrapIndices.length - 1; j++ ) { + table = ''; + start = wrapIndices[ j ]; + end = wrapIndices[ j + 1 ]; + + // Render top border: + if ( this._borders !== 'None' ) { + widths = slice( this._columnWidths, start, end ); + table += renderLine( this._borders[ 0 ], widths, this._corners[ 0 ], this._joints[ 1 ], this._corners[ 1 ] ); // eslint-disable-line max-len + table += '\n'; + } + + // Render headers: + if ( this._headers ) { + row = slice( this._headers, start, end ); + widths = slice( this._columnWidths, start, end ); + table += renderRow( row, widths ); + table += '\n'; + } + + // Render header separator: + if ( this._headers && this._headerSeparator !== 'None' ) { + widths = slice( this._columnWidths, start, end ); + table += renderLine( this._headerSeparator, widths, this._joints[ 4 ], this._joints[ 0 ], this._joints[ 2 ] ); // eslint-disable-line max-len + table += '\n'; + } + + // Render data: + if ( this._data ) { + for ( i = 0; i < this._data.length; i++ ) { + // Render row: + row = slice( this._data[ i ], start, end ); + widths = slice( this._columnWidths, start, end ); + table += renderRow( row, widths ); + if ( i !== this._data.length - 1 || this._borders !== 'None' ) { + table += '\n'; + } + // Render row separator: + if ( this._rowSeparator !== 'None' && i !== this._data.length - 1 ) { + widths = slice( this._columnWidths, start, end ); + table += renderLine( this._rowSeparator, widths, this._joints[ 4 ], this._joints[ 0 ], this._joints[ 2 ] ); // eslint-disable-line max-len + table += '\n'; + } + } + } + + // Render bottom border: + if ( this._borders !== 'None' ) { + widths = slice( this._columnWidths, start, end ); + table += renderLine( this._borders[ 2 ], widths, this._corners[ 3 ], this._joints[ 3 ], this._corners[ 2 ] ); // eslint-disable-line max-len + } + wraps.push( table ); + } + out += wraps.join( '\n' ); + + // Render bottom margin: + out += repeat( '\n', this._marginY ); + return out; + + /** + * Resolves columns to wrap the table at (includes bounding indices). + * + * @private + * @throws {Error} output must be able to accommodate every column individually + * @returns {Array} list of column indices + */ + function resolveWrapping() { + var outputWidth; + var fixedLength; + var colWidth; + var indices; + + // Initialize with zeroth index: + indices = [ 0 ]; + + // Calculate fixed horizontal length: + fixedLength = 2 * self._marginX; + if ( self._borders !== 'None' ) { + fixedLength += 2; + } + outputWidth = 0; + for ( i = 0; i < self._columnWidths.length; i++ ) { + colWidth = min( self._columnWidths[ i ], self._maxCellWidth ); // width of current column + outputWidth += colWidth + ( 2 * self._cellPadding ); + + // If output crosses the maximum, time to wrap: + if ( outputWidth + fixedLength > self._maxOutputWidth ) { + if ( i === indices[ indices.length - 1 ] ) { + // The output width cannot accommodate current column: + throw new Error( format( 'invalid operation. `maxOutputWidth` must be able to accommodate every column individually. Value: `%s`', self._maxOutputWidth ) ); + } + indices.push( i ); + outputWidth = 0; + continue; + } + // Include column separator. Exclude for last column as we included them as borders: + if ( i !== self._columnWidths.length - 1 && self._columnSeparator !== 'None' ) { + outputWidth += 1; + } + } + // Include last bounding index: + indices.push( self._columnWidths.length ); + return indices; + } + + /** + * Renders a line. + * + * @private + * @param {string} lineChar - line character + * @param {Array} columnWidths - column widths + * @param {string} jointL - left joint + * @param {string} jointM - middle joint + * @param {jointR} jointR - right joint + * @returns {string} rendered line + */ + function renderLine( lineChar, columnWidths, jointL, jointM, jointR ) { + var colWidth; + var out; + var i; + + out = ''; + + // Render left margin: + out += repeat( ' ', self._marginX ); + + // Render left joint: + if ( self._borders !== 'None' ) { + out += jointL; + } + // Render line: + for ( i = 0; i < columnWidths.length; i++ ) { + // If columns are separated, render the middle joint... + if ( self._columnSeparator !== 'None' && i !== 0 ) { + out += jointM; + } + colWidth = min( columnWidths[ i ], self._maxCellWidth ); + out += repeat( lineChar, colWidth + ( 2 * self._cellPadding ) ); + } + // Render right joint: + if ( self._borders !== 'None' ) { + out += jointR; + } + // Render right margin: + out += repeat( ' ', self._marginX ); + return out; + } + + /** + * Renders a data row. + * + * @private + * @param {Array} data - row data + * @param {Array} columnWidths - column widths + * @returns {string} rendered line + */ + function renderRow( data, columnWidths ) { + var width; + var datum; + var out; + var i; + + out = ''; + + // Render left margin: + out += repeat( ' ', self._marginX ); + + // Render left border: + if ( self._borders !== 'None' ) { + out += self._borders[ 3 ]; + } + for ( i = 0; i < columnWidths.length; i++ ) { + // Render column separator... + if ( self._columnSeparator !== 'None' && i !== 0 ) { + out += self._columnSeparator; + } + // Render left cell padding: + out += repeat( ' ', self._cellPadding ); + datum = String( data[ i ] ); + width = min( columnWidths[ i ], self._maxCellWidth ); + if ( datum.length > self._maxCellWidth ) { + // Truncate long datum: + datum = truncate( datum, self._maxCellWidth ); + } + // Render datum: + switch ( self._alignment ) { + case 'left': + out += datum; + out += repeat( ' ', width - datum.length ); + break; + case 'center': + out += repeat( ' ', ceil( ( width - datum.length ) / 2 ) ); + out += datum; + out += repeat( ' ', floor( ( width - datum.length ) / 2 ) ); + break; + case 'right': + out += repeat( ' ', width - datum.length ); + out += datum; + break; + default: + break; + } + // Render right cell padding: + out += repeat( ' ', self._cellPadding ); + } + // Render right border: + if ( self._borders !== 'None' ) { + out += self._borders[ 1 ]; + } + // Render right margin: + out += repeat( ' ', self._marginX ); + return out; + } +} + + +// EXPORTS // + +module.exports = render; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/setdata.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/setdata.js new file mode 100644 index 000000000000..1e2b2f882497 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/setdata.js @@ -0,0 +1,88 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var format = require( '@stdlib/string/format' ); +var isMatrixLike = require( '@stdlib/assert/is-matrix-like' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isObjectArray = require( '@stdlib/assert/is-object-array' ); +var isArrayArray = require( '@stdlib/assert/is-array-array' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var parseObject = require( './parser/parse_object.js' ); +var parseObjectsList = require( './parser/parse_objects_list.js' ); +var parse2dArray = require( './parser/parse_2d_array.js' ); + + +// MAIN // + +/** +* Sets the table data. +* +* @private +* @param {(Object|Array|Array|MatrixLike)} data - table data +* @param {Collection} [headers] - table headers +* @throws {TypeError} first argument must be an object, array of objects, or a 2 dimensional array/ndarray +* @throws {TypeError} second argument must be a collection +* @returns {UnicodeTable} class instance +*/ +function setData() { + /* eslint-disable no-invalid-this */ + var headers; + var parsed; + var nargs; + var data; + + nargs = arguments.length; + if ( nargs === 0 ) { + throw new TypeError( format( 'invalid argument. First argument must be an object, array of objects, or a 2 dimensional array/ndarray. Value: `%s`.', data ) ); + } else if ( nargs === 1 ) { + data = arguments[ 0 ]; + headers = this._headers; + } else { + data = arguments[ 0 ]; + headers = arguments[ 1 ]; + if ( !isCollection( headers ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a collection. Value: `%s`.', headers ) ); + } + } + // Parse according to data-type... + if ( isMatrixLike( data ) ) { + parsed = parse2dArray( ndarray2array( data ), headers ); + } else if ( isArrayArray( data ) ) { + parsed = parse2dArray( data, headers ); + } else if ( isObjectArray( data ) ) { + parsed = parseObjectsList( data, headers ); + } else if ( isPlainObject( data ) ) { + parsed = parseObject( data, headers ); + } else { + throw new TypeError( format( 'invalid argument. First argument must be an object, array of objects, or a 2 dimensional array/ndarray. Value: `%s`.', data ) ); + } + this._data = parsed.data; + this._headers = parsed.headers; + this._columnWidths = parsed.columnWidths; + return this; +} + + +// EXPORTS // + +module.exports = setData; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/package.json b/lib/node_modules/@stdlib/plot/table/unicode/package.json new file mode 100644 index 000000000000..aac9d0f1a47a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/plot/table/unicode", + "version": "0.0.0", + "description": "Create a Unicode table.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "bin": {}, + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "plot", + "table", + "tabular", + "chart", + "graph", + "graphic", + "data", + "visualize", + "viz", + "vis", + "unicode" + ] +} diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.add_row.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.add_row.js new file mode 100644 index 000000000000..12d2ba6cf4f5 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.add_row.js @@ -0,0 +1,79 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function adds a row to existing data', function test( t ) { + var expected; + var headers; + var table; + var data; + var row; + var v; + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table = ctor( data, headers ); + + row = [ 1, true, 'hello' ]; + table.addRow( row ); + v = table.getData(); + + expected = {}; + expected.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ], [ 1, true, 'hello' ] ]; + expected.headers = [ 'col1', 'col2', 'col3' ]; + + t.deepEqual( v, expected, 'sets table data' ); + + t.end(); +}); + +tape( 'the function creates table data if no existing data found', function test( t ) { + var expected; + var table; + var row; + var v; + + table = ctor(); + + row = [ 1, true, 'hello' ]; + table.addRow( row ); + v = table.getData(); + + expected = {}; + expected.data = [ [ 1, true, 'hello' ] ]; + expected.headers = null; + + t.deepEqual( v, expected, 'sets table data' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.alignment.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.alignment.js new file mode 100644 index 000000000000..5bd1dff4e153 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.alignment.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `alignment` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + '1234', + 'middle' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.alignment = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var data = null; + + table = ctor( data, { + 'alignment': 'right' + }); + t.strictEqual( table.alignment, 'right', 'returns expected value' ); + + table.alignment = 'left'; + t.strictEqual( table.alignment, 'left', 'returns expected value' ); + + table.alignment = 'center'; + t.strictEqual( table.alignment, 'center', 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.borders.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.borders.js new file mode 100644 index 000000000000..f1bc1538cf28 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.borders.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `borders` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + 'hello', + '1234567' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.borders = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var data = null; + + table = ctor( data, { + 'borders': '1 2 3 4' + }); + t.strictEqual( table.borders, '1 2 3 4', 'returns expected value' ); + + table.borders = '- | _ |'; + t.strictEqual( table.borders, '- | _ |', 'returns expected value' ); + + table.borders = 'None'; + t.strictEqual( table.borders, 'None', 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding.js new file mode 100644 index 000000000000..230d613f0e7b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `cellPadding` value', function test( t ) { + var values; + var i; + + values = [ + '5', + 2.4, + -3, + true, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.cellPadding = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var data = null; + + table = ctor( data, { + 'cellPadding': 2 + }); + t.strictEqual( table.cellPadding, 2, 'returns expected value' ); + + table.cellPadding = 3; + t.strictEqual( table.cellPadding, 3, 'returns expected value' ); + + table.cellPadding = 0; + t.strictEqual( table.cellPadding, 0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.column_separator.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.column_separator.js new file mode 100644 index 000000000000..9517244e5f3d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.column_separator.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `columnSeparator` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + '5437' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.columnSeparator = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var data = null; + + table = ctor( data, { + 'columnSeparator': '1' + }); + t.strictEqual( table.columnSeparator, '1', 'returns expected value' ); + + table.columnSeparator = '!'; + t.strictEqual( table.columnSeparator, '!', 'returns expected value' ); + + table.columnSeparator = 'None'; + t.strictEqual( table.columnSeparator, 'None', 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.corners.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.corners.js new file mode 100644 index 000000000000..690514acf20b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.corners.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `corners` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + 'hello', + '1234567' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.corners = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var data = null; + + table = ctor( data, { + 'corners': '1 2 3 4' + }); + t.strictEqual( table.corners, '1 2 3 4', 'returns expected value' ); + + table.corners = '* * * *'; + t.strictEqual( table.corners, '* * * *', 'returns expected value' ); + + table.corners = 'None'; + t.strictEqual( table.corners, 'None', 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.header_separator.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.header_separator.js new file mode 100644 index 000000000000..d5d3c68c555a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.header_separator.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `headerSeparator` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + '5437' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.headerSeparator = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var data = null; + + table = ctor( data, { + 'headerSeparator': '1' + }); + t.strictEqual( table.headerSeparator, '1', 'returns expected value' ); + + table.headerSeparator = '!'; + t.strictEqual( table.headerSeparator, '!', 'returns expected value' ); + + table.headerSeparator = 'None'; + t.strictEqual( table.headerSeparator, 'None', 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.joints.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.joints.js new file mode 100644 index 000000000000..efc987353387 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.joints.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `joints` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + 'hello', + '1234567' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.joints = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var data = null; + + table = ctor( data, { + 'joints': '1 2 3 4 5' + }); + t.strictEqual( table.joints, '1 2 3 4 5', 'returns expected value' ); + + table.joints = '& # * ^ @'; + t.strictEqual( table.joints, '& # * ^ @', 'returns expected value' ); + + table.joints = 'None'; + t.strictEqual( table.joints, 'None', 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.js new file mode 100644 index 000000000000..9858a4d627f6 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Table = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Table, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the export is a class constructor', function test( t ) { + var table = new Table(); + t.strictEqual( table instanceof Table, true, 'returns class instance' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.main.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.main.js new file mode 100644 index 000000000000..f0ec1f362309 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.main.js @@ -0,0 +1,229 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var UnicodeTable = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof UnicodeTable, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the export is a class constructor', function test( t ) { + var table = new UnicodeTable(); + t.strictEqual( table instanceof UnicodeTable, true, 'returns class instance' ); + t.end(); +}); + +tape( 'the constructor does not require the `new` keyword (no data, no options)', function test( t ) { + var table; + var ctor; + + ctor = UnicodeTable; + table = ctor(); + + t.strictEqual( table instanceof UnicodeTable, true, 'returns class instance' ); + t.end(); +}); + +tape( 'the constructor does not require the `new` keyword (data)', function test( t ) { + var table; + var ctor; + + ctor = UnicodeTable; + table = ctor( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); + + t.strictEqual( table instanceof UnicodeTable, true, 'returns class instance' ); + t.end(); +}); + +tape( 'the constructor does not require the `new` keyword (data and headers)', function test( t ) { + var table; + var ctor; + + ctor = UnicodeTable; + table = ctor( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ 'col1', 'col2', 'col3' ] ); + + t.strictEqual( table instanceof UnicodeTable, true, 'returns class instance' ); + t.end(); +}); + +tape( 'the constructor does not require the `new` keyword (data and options)', function test( t ) { + var table; + var ctor; + var data; + + ctor = UnicodeTable; + data = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; + table = ctor( data, { + 'alignment': 'left', + 'borders': '1 2 3 4', + 'cellPadding': 2, + 'columnSeparator': 'None', + 'corners': '* * * *', + 'headerSeparator': '-', + 'joints': '* * * * *', + 'marginX': 2, + 'marginY': 4, + 'maxCellWidth': 10, + 'maxOutputWidth': 60, + 'rowSeparator': '_' + }); + + t.strictEqual( table instanceof UnicodeTable, true, 'returns class instance' ); + t.end(); +}); + +tape( 'the constructor does not require the `new` keyword (data, headers and options)', function test( t ) { + var headers; + var table; + var ctor; + var data; + + ctor = UnicodeTable; + data = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table = ctor( data, headers, { + 'alignment': 'left', + 'borders': '1 2 3 4', + 'cellPadding': 2, + 'columnSeparator': 'None', + 'corners': '* * * *', + 'headerSeparator': '-', + 'joints': '* * * * *', + 'marginX': 2, + 'marginY': 4, + 'maxCellWidth': 10, + 'maxOutputWidth': 60, + 'rowSeparator': '_' + }); + + t.strictEqual( table instanceof UnicodeTable, true, 'returns class instance' ); + t.end(); +}); + +tape( 'the constructor will throw an error if provided an invalid options argument (no headers argument)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], value ); // eslint-disable-line no-unused-vars + }; + } +}); + +tape( 'the constructor will throw an error if provided an invalid options argument (headers argument)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = new UnicodeTable( [ [ 1, 3 ], [ 4, 6 ] ], [ 'col1', 'col2' ], value ); // eslint-disable-line no-unused-vars + }; + } +}); + +tape( 'the constructor throws an error if provided an invalid option (no headers argument)', function test( t ) { + t.throws( foo, TypeError, 'throws an error' ); + t.end(); + + function foo() { + // eslint-disable-next-line no-unused-vars + var table = new UnicodeTable( [ [ 1, 3 ], [ 4, 6 ] ], { + 'alignment': [] + }); + } +}); + +tape( 'the constructor throws an error if provided an invalid option (headers argument)', function test( t ) { + t.throws( foo, TypeError, 'throws an error' ); + t.end(); + + function foo() { + // eslint-disable-next-line no-unused-vars + var table = new UnicodeTable( [ [ 1, 3 ], [ 4, 6 ] ], [ 'col1', 'col2' ], { + 'alignment': [] + }); + } +}); + +tape( 'an instance has a `addRow` method for adding a row', function test( t ) { + var table = new UnicodeTable(); + t.strictEqual( typeof table.addRow, 'function', 'has addRow method' ); + t.end(); +}); + +tape( 'an instance has a `setData` method for setting data', function test( t ) { + var table = new UnicodeTable(); + t.strictEqual( typeof table.setData, 'function', 'has setData method' ); + t.end(); +}); + +tape( 'an instance has a `getData` method for getting data', function test( t ) { + var table = new UnicodeTable(); + t.strictEqual( typeof table.getData, 'function', 'has getData method' ); + t.end(); +}); + +tape( 'an instance has a `render` method for rendering the table', function test( t ) { + var table = new UnicodeTable(); + t.strictEqual( typeof table.render, 'function', 'has render method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_x.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_x.js new file mode 100644 index 000000000000..09a773b014e4 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_x.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `marginX` value', function test( t ) { + var values; + var i; + + values = [ + '5', + 2.4, + -3, + true, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.marginX = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var data = null; + + table = ctor( data, { + 'marginX': 2 + }); + t.strictEqual( table.marginX, 2, 'returns expected value' ); + + table.marginX = 3; + t.strictEqual( table.marginX, 3, 'returns expected value' ); + + table.marginX = 0; + t.strictEqual( table.marginX, 0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_y.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_y.js new file mode 100644 index 000000000000..da4835b2aecd --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_y.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `marginY` value', function test( t ) { + var values; + var i; + + values = [ + '5', + 2.4, + -3, + true, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.marginY = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var data = null; + + table = ctor( data, { + 'marginY': 2 + }); + t.strictEqual( table.marginY, 2, 'returns expected value' ); + + table.marginY = 3; + t.strictEqual( table.marginY, 3, 'returns expected value' ); + + table.marginY = 0; + t.strictEqual( table.marginY, 0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_cell_width.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_cell_width.js new file mode 100644 index 000000000000..068a06340878 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_cell_width.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `maxCellWidth` value', function test( t ) { + var values; + var i; + + values = [ + '5', + 2.4, + -3, + true, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.maxCellWidth = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var data = null; + + table = ctor( data, { + 'maxCellWidth': 2 + }); + t.strictEqual( table.maxCellWidth, 2, 'returns expected value' ); + + table.maxCellWidth = 3; + t.strictEqual( table.maxCellWidth, 3, 'returns expected value' ); + + table.maxCellWidth = 0; + t.strictEqual( table.maxCellWidth, 0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_output_width.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_output_width.js new file mode 100644 index 000000000000..b14fd3c80873 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_output_width.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `maxOutputWidth` value', function test( t ) { + var values; + var i; + + values = [ + '5', + 2.4, + -3, + true, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.maxOutputWidth = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var data = null; + + table = ctor( data, { + 'maxOutputWidth': 20 + }); + t.strictEqual( table.maxOutputWidth, 20, 'returns expected value' ); + + table.maxOutputWidth = 30; + t.strictEqual( table.maxOutputWidth, 30, 'returns expected value' ); + + table.maxOutputWidth = 10; + t.strictEqual( table.maxOutputWidth, 10, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.parser.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.parser.js new file mode 100644 index 000000000000..d12666c551ba --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.parser.js @@ -0,0 +1,240 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function sets the table data for an array of objects (with headers)', function test( t ) { + var expected; + var headers; + var table; + var data; + var v; + + data = [ + { + 'col1': 'hello', + 'col2': 45, + 'col3': true + }, + { + 'col1': null, + 'col3': 45.3 + } + ]; + headers = [ 'col1', 'col2', 'col3' ]; + table = ctor(); + + table.setData( data, headers ); + v = table.getData(); + + expected = {}; + expected.data = [ [ 'hello', 45, true ], [ null, undefined, 45.3 ] ]; + expected.headers = [ 'col1', 'col2', 'col3' ]; + + t.deepEqual( v, expected, 'sets table data' ); + + t.end(); +}); + +tape( 'the function sets the table data for an array of objects (without headers)', function test( t ) { + var expected; + var table; + var data; + var v; + + data = [ + { + 'col1': 'hello', + 'col2': 45, + 'col3': true + }, + { + 'col1': null, + 'col3': 45.3 + } + ]; + table = ctor(); + + table.setData( data ); + v = table.getData(); + + expected = {}; + expected.data = [ [ 'hello', 45, true ], [ null, undefined, 45.3 ] ]; + expected.headers = [ 'col1', 'col2', 'col3' ]; + + t.deepEqual( v, expected, 'sets table data' ); + + t.end(); +}); + +tape( 'the function sets the table data for an object of columns (with headers)', function test( t ) { + var expected; + var headers; + var table; + var data; + var v; + + data = { + 'col1': [ 'hello', true ], + 'col2': [ null, 45 ] + }; + headers = [ 'col1', 'col2', 'col3' ]; + table = ctor(); + + table.setData( data, headers ); + v = table.getData(); + + expected = {}; + expected.data = [ [ 'hello', null ], [ true, 45 ] ]; + expected.headers = [ 'col1', 'col2' ]; + + t.deepEqual( v, expected, 'sets table data' ); + + t.end(); +}); + +tape( 'the function sets the table data for an object of columns (without headers)', function test( t ) { + var expected; + var table; + var data; + var v; + + data = { + 'col1': [ 'hello', true ], + 'col2': [ null, 45 ] + }; + table = ctor(); + + table.setData( data ); + v = table.getData(); + + expected = {}; + expected.data = [ [ 'hello', null ], [ true, 45 ] ]; + expected.headers = [ 'col1', 'col2' ]; + + t.deepEqual( v, expected, 'sets table data' ); + + t.end(); +}); + +tape( 'the function sets the table data for an array of arrays (with headers)', function test( t ) { + var expected; + var headers; + var table; + var data; + var v; + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table = ctor(); + + table.setData( data, headers ); + v = table.getData(); + + expected = {}; + expected.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + expected.headers = [ 'col1', 'col2', 'col3' ]; + + t.deepEqual( v, expected, 'sets table data' ); + + t.end(); +}); + +tape( 'the function sets the table data for an array of arrays (without headers)', function test( t ) { + var expected; + var table; + var data; + var v; + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table = ctor(); + + table.setData( data ); + v = table.getData(); + + expected = {}; + expected.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + expected.headers = null; + + t.deepEqual( v, expected, 'sets table data' ); + + t.end(); +}); + +tape( 'the function sets the table data for a matrix-like ndarray (with headers)', function test( t ) { + var expected; + var headers; + var buffer; + var table; + var data; + var v; + + buffer = [ 14, 2, 'hello', false, 32.54, true, null, 'bye', 9, 10, 11, 12 ]; + data = ndarray( 'generic', buffer, [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); + headers = [ 'col1', 'col2', 'col3', 'col4' ]; + table = ctor(); + + table.setData( data, headers ); + v = table.getData(); + + expected = {}; + expected.data = [ [ 14, 2, 'hello', false ], [ 32.54, true, null, 'bye' ], [ 9, 10, 11, 12 ] ]; + expected.headers = [ 'col1', 'col2', 'col3', 'col4' ]; + + t.deepEqual( v, expected, 'sets table data' ); + + t.end(); +}); + +tape( 'the function sets the table data for a matrix-like ndarray (without headers)', function test( t ) { + var expected; + var buffer; + var table; + var data; + var v; + + buffer = [ 14, 2, 'hello', false, 32.54, true, null, 'bye', 9, 10, 11, 12 ]; + data = ndarray( 'generic', buffer, [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); + table = ctor(); + + table.setData( data ); + v = table.getData(); + + expected = {}; + expected.data = [ [ 14, 2, 'hello', false ], [ 32.54, true, null, 'bye' ], [ 9, 10, 11, 12 ] ]; + expected.headers = null; + + t.deepEqual( v, expected, 'sets table data' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.render.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.render.js new file mode 100644 index 000000000000..c3870e155e4c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.render.js @@ -0,0 +1,417 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an empty string if no table data provided ', function test( t ) { + var table; + var str; + + table = ctor(); + + str = table.render(); + t.strictEqual( str, '', 'returns empty string' ); + + t.end(); +}); + +tape( 'the function supports rendering a table', function test( t ) { + var expected; + var headers; + var table; + var data; + var str; + + table = ctor(); + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table.setData( data, headers ); + + expected = [ + '┌───────┬──────┬───────┐', + '│ col1 │ col2 │ col3 │', + '├───────┼──────┼───────┤', + '│ 45 │ 33 │ hello │', + '│ 32.54 │ true │ null │', + '└───────┴──────┴───────┘' + ].join( '\n' ); + + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + t.end(); +}); + +tape( 'the function supports rendering a table (without headers)', function test( t ) { + var expected; + var table; + var data; + var str; + + table = ctor(); + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.setData( data ); + + expected = [ + '┌───────┬──────┬───────┐', + '│ 45 │ 33 │ hello │', + '│ 32.54 │ true │ null │', + '└───────┴──────┴───────┘' + ].join( '\n' ); + + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + t.end(); +}); + +tape( 'the function supports rendering a table (with row separators)', function test( t ) { + var expected; + var headers; + var table; + var data; + var str; + + table = ctor(); + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table.setData( data, headers ); + table.rowSeparator = '─'; + + expected = [ + '┌───────┬──────┬───────┐', + '│ col1 │ col2 │ col3 │', + '├───────┼──────┼───────┤', + '│ 45 │ 33 │ hello │', + '├───────┼──────┼───────┤', + '│ 32.54 │ true │ null │', + '└───────┴──────┴───────┘' + ].join( '\n' ); + + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + t.end(); +}); + +tape( 'the function supports rendering a table (without borders)', function test( t ) { + var expected; + var headers; + var table; + var data; + var str; + + table = ctor(); + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table.setData( data, headers ); + table.borders = 'None'; + + expected = [ + ' col1 │ col2 │ col3 ', + '───────┼──────┼───────', + ' 45 │ 33 │ hello ', + ' 32.54 │ true │ null ' + ].join( '\n' ); + + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + t.end(); +}); + +tape( 'the function supports rendering a table (without column separators)', function test( t ) { + var expected; + var headers; + var table; + var data; + var str; + + table = ctor(); + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table.setData( data, headers ); + table.columnSeparator = 'None'; + + expected = [ + '┌────────────────────┐', + '│ col1 col2 col3 │', + '├────────────────────┤', + '│ 45 33 hello │', + '│ 32.54 true null │', + '└────────────────────┘' + ].join( '\n' ); + + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + t.end(); +}); + +tape( 'the function supports rendering a table (without header separator)', function test( t ) { + var expected; + var headers; + var table; + var data; + var str; + + table = ctor(); + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table.setData( data, headers ); + table.headerSeparator = 'None'; + + expected = [ + '┌───────┬──────┬───────┐', + '│ col1 │ col2 │ col3 │', + '│ 45 │ 33 │ hello │', + '│ 32.54 │ true │ null │', + '└───────┴──────┴───────┘' + ].join( '\n' ); + + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + t.end(); +}); + +tape( 'the function supports rendering a table (without corners)', function test( t ) { + var expected; + var headers; + var table; + var data; + var str; + + table = ctor(); + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table.setData( data, headers ); + table.corners = 'None'; + + expected = [ + ' ───────┬──────┬─────── ', + '│ col1 │ col2 │ col3 │', + '├───────┼──────┼───────┤', + '│ 45 │ 33 │ hello │', + '│ 32.54 │ true │ null │', + ' ───────┴──────┴─────── ' + ].join( '\n' ); + + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + t.end(); +}); + +tape( 'the function supports rendering a table (without joints)', function test( t ) { + var expected; + var headers; + var table; + var data; + var str; + + table = ctor(); + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table.setData( data, headers ); + table.joints = 'None'; + + expected = [ + '┌─────── ────── ───────┐', + '│ col1 │ col2 │ col3 │', + ' ─────── ────── ─────── ', + '│ 45 │ 33 │ hello │', + '│ 32.54 │ true │ null │', + '└─────── ────── ───────┘' + ].join( '\n' ); + + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + t.end(); +}); + +tape( 'the function supports rendering a table with a margin', function test( t ) { + var expected; + var headers; + var table; + var data; + var str; + + table = ctor(); + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table.setData( data, headers ); + table.marginX = 1; + table.marginY = 1; + + expected = [ + '', + ' ┌───────┬──────┬───────┐ ', + ' │ col1 │ col2 │ col3 │ ', + ' ├───────┼──────┼───────┤ ', + ' │ 45 │ 33 │ hello │ ', + ' │ 32.54 │ true │ null │ ', + ' └───────┴──────┴───────┘ ', + '' + ].join( '\n' ); + + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + t.end(); +}); + +tape( 'the function supports rendering a table with truncated data', function test( t ) { + var expected; + var headers; + var table; + var data; + var str; + + table = ctor(); + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table.setData( data, headers ); + table.maxCellWidth = 4; + + expected = [ + '┌──────┬──────┬──────┐', + '│ col1 │ col2 │ col3 │', + '├──────┼──────┼──────┤', + '│ 45 │ 33 │ h... │', + '│ 3... │ true │ null │', + '└──────┴──────┴──────┘' + ].join( '\n' ); + + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + t.end(); +}); + +tape( 'the function supports rendering a table with different alignments', function test( t ) { + var expected; + var headers; + var table; + var data; + var str; + + table = ctor(); + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table.setData( data, headers ); + + table.alignment = 'right'; + expected = [ + '┌───────┬──────┬───────┐', + '│ col1 │ col2 │ col3 │', + '├───────┼──────┼───────┤', + '│ 45 │ 33 │ hello │', + '│ 32.54 │ true │ null │', + '└───────┴──────┴───────┘' + ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns right-aligned rendered table' ); + + table.alignment = 'left'; + expected = [ + '┌───────┬──────┬───────┐', + '│ col1 │ col2 │ col3 │', + '├───────┼──────┼───────┤', + '│ 45 │ 33 │ hello │', + '│ 32.54 │ true │ null │', + '└───────┴──────┴───────┘' + ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns left-aligned rendered table' ); + + table.alignment = 'center'; + expected = [ + '┌───────┬──────┬───────┐', + '│ col1 │ col2 │ col3 │', + '├───────┼──────┼───────┤', + '│ 45 │ 33 │ hello │', + '│ 32.54 │ true │ null │', + '└───────┴──────┴───────┘' + ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns center-aligned rendered table' ); + + t.end(); +}); + +tape( 'the function supports rendering a wrapped table for long outputs', function test( t ) { + var expected; + var headers; + var table; + var data; + var str; + + table = ctor(); + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table.setData( data, headers ); + table.maxOutputWidth = 16; + + expected = [ + '┌───────┬──────┐', + '│ col1 │ col2 │', + '├───────┼──────┤', + '│ 45 │ 33 │', + '│ 32.54 │ true │', + '└───────┴──────┘', + '┌───────┐', + '│ col3 │', + '├───────┤', + '│ hello │', + '│ null │', + '└───────┘' + ].join( '\n' ); + + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.row_separator.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.row_separator.js new file mode 100644 index 000000000000..2e34d82bed3e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.row_separator.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `rowSeparator` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + '5437' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.rowSeparator = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var data = null; + + table = ctor( data, { + 'rowSeparator': '1' + }); + t.strictEqual( table.rowSeparator, '1', 'returns expected value' ); + + table.rowSeparator = '!'; + t.strictEqual( table.rowSeparator, '!', 'returns expected value' ); + + table.rowSeparator = 'None'; + t.strictEqual( table.rowSeparator, 'None', 'returns expected value' ); + + t.end(); +}); From 8ab53e7c5f130cc3c2e41932765fce9a8c89a7af Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Sat, 20 Jul 2024 19:52:27 +0000 Subject: [PATCH 02/34] refactor: update table from code review Signed-off-by: Snehil Shah --- .../@stdlib/plot/table/unicode/README.md | 326 ++++++++++--- .../plot/table/unicode/benchmark/benchmark.js | 408 ++++++++++++++-- .../unicode/benchmark/benchmark.render.js | 52 +- .../@stdlib/plot/table/unicode/docs/repl.txt | 108 +++-- .../plot/table/unicode/examples/index.js | 14 +- .../plot/table/unicode/lib/defaults.js | 25 +- .../@stdlib/plot/table/unicode/lib/index.js | 10 + .../@stdlib/plot/table/unicode/lib/main.js | 450 ++++++++++++++---- .../unicode/lib/{setdata.js => parse.js} | 41 +- .../unicode/lib/parser/parse_2d_array.js | 4 +- .../table/unicode/lib/parser/parse_headers.js | 58 +++ .../table/unicode/lib/parser/parse_object.js | 46 +- .../unicode/lib/parser/parse_objects_list.js | 6 + .../table/unicode/lib/props/alignment/get.js | 14 +- .../table/unicode/lib/props/alignment/set.js | 41 +- .../{cell-padding => auto-render}/get.js | 6 +- .../{cell-padding => auto-render}/set.js | 19 +- .../table/unicode/lib/props/borders/get.js | 7 +- .../table/unicode/lib/props/borders/set.js | 26 +- .../{getdata.js => props/buffer-size/get.js} | 13 +- .../unicode/lib/props/buffer-size/set.js | 60 +++ .../lib/props/cell-padding-left/get.js | 45 ++ .../lib/props/cell-padding-left/set.js | 62 +++ .../lib/props/cell-padding-right/get.js | 45 ++ .../lib/props/cell-padding-right/set.js | 62 +++ .../unicode/lib/props/column-separator/get.js | 2 +- .../unicode/lib/props/column-separator/set.js | 17 +- .../table/unicode/lib/props/corners/get.js | 8 +- .../table/unicode/lib/props/corners/set.js | 35 +- .../plot/table/unicode/lib/props/data/get.js | 45 ++ .../plot/table/unicode/lib/props/data/set.js | 72 +++ .../unicode/lib/props/header-separator/get.js | 2 +- .../unicode/lib/props/header-separator/set.js | 17 +- .../table/unicode/lib/props/headers/get.js | 45 ++ .../table/unicode/lib/props/headers/set.js | 63 +++ .../props/horizontal-separator-mode/get.js | 35 ++ .../props/horizontal-separator-mode/set.js | 56 +++ .../table/unicode/lib/props/joints/get.js | 8 +- .../table/unicode/lib/props/joints/set.js | 35 +- .../table/unicode/lib/props/margin-x/set.js | 5 +- .../table/unicode/lib/props/margin-y/set.js | 5 +- .../unicode/lib/props/max-cell-width/get.js | 14 +- .../unicode/lib/props/max-cell-width/set.js | 49 +- .../unicode/lib/props/max-output-width/set.js | 19 +- .../unicode/lib/props/row-separator/get.js | 2 +- .../unicode/lib/props/row-separator/set.js | 17 +- .../lib/props/vertical-separator-mode/get.js | 35 ++ .../lib/props/vertical-separator-mode/set.js | 56 +++ .../table/unicode/lib/{addrow.js => push.js} | 27 +- .../@stdlib/plot/table/unicode/lib/render.js | 170 +++++-- .../plot/table/unicode/test/test.add_row.js | 79 --- .../plot/table/unicode/test/test.alignment.js | 74 ++- .../table/unicode/test/test.auto_render.js | 152 ++++++ .../plot/table/unicode/test/test.borders.js | 64 ++- .../table/unicode/test/test.buffer_size.js | 146 ++++++ .../table/unicode/test/test.cell_padding.js | 80 ---- .../unicode/test/test.cell_padding_left.js | 143 ++++++ .../unicode/test/test.cell_padding_right.js | 143 ++++++ .../unicode/test/test.column_separator.js | 48 +- .../plot/table/unicode/test/test.corners.js | 64 ++- .../plot/table/unicode/test/test.data.js | 177 +++++++ .../unicode/test/test.header_separator.js | 48 +- .../plot/table/unicode/test/test.headers.js | 138 ++++++ .../test/test.horizontal_separator_mode.js | 119 +++++ .../plot/table/unicode/test/test.joints.js | 64 ++- .../plot/table/unicode/test/test.main.js | 50 +- .../plot/table/unicode/test/test.margin_x.js | 42 +- .../plot/table/unicode/test/test.margin_y.js | 42 +- .../table/unicode/test/test.max_cell_width.js | 84 +++- .../unicode/test/test.max_output_width.js | 38 +- .../plot/table/unicode/test/test.parse.js | 337 +++++++++++++ .../plot/table/unicode/test/test.parser.js | 240 ---------- .../plot/table/unicode/test/test.push.js | 133 ++++++ .../plot/table/unicode/test/test.render.js | 275 +++++++---- .../table/unicode/test/test.row_separator.js | 48 +- .../test/test.vertical_separator_mode.js | 119 +++++ 76 files changed, 4587 insertions(+), 1147 deletions(-) rename lib/node_modules/@stdlib/plot/table/unicode/lib/{setdata.js => parse.js} (67%) create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_headers.js rename lib/node_modules/@stdlib/plot/table/unicode/lib/props/{cell-padding => auto-render}/get.js (87%) rename lib/node_modules/@stdlib/plot/table/unicode/lib/props/{cell-padding => auto-render}/set.js (67%) rename lib/node_modules/@stdlib/plot/table/unicode/lib/{getdata.js => props/buffer-size/get.js} (79%) create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/buffer-size/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-left/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-left/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-right/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-right/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/data/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/data/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/horizontal-separator-mode/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/horizontal-separator-mode/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/vertical-separator-mode/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/vertical-separator-mode/set.js rename lib/node_modules/@stdlib/plot/table/unicode/lib/{addrow.js => push.js} (61%) delete mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.add_row.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.auto_render.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.buffer_size.js delete mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding_left.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding_right.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.data.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.headers.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.horizontal_separator_mode.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.parse.js delete mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.parser.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.push.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/test/test.vertical_separator_mode.js diff --git a/lib/node_modules/@stdlib/plot/table/unicode/README.md b/lib/node_modules/@stdlib/plot/table/unicode/README.md index ccbb89363aa4..98d9eeb72097 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/README.md +++ b/lib/node_modules/@stdlib/plot/table/unicode/README.md @@ -41,17 +41,50 @@ var table = new UnicodeTable(); The constructor accepts the following `options`: - **alignment**: datum's cell alignment. Default: `'right'`. -- **borders**: border characters. Default: `'─ │ ─ │'`. -- **cellPadding**: cell padding. Default: `1`. -- **columnSeparator**: column separator character. Default: `'│'`. -- **corners**: corner characters. Default: `'┌ ┐ ┘ └'`. -- **headerSeparator**: header separator character. Default: `'─'`. -- **joints**: joint characters. Default: `'┼ ┬ ┤ ┴ ├'`. + +- **autoRender**: `boolean` indicating whether to re-render on a `change` event. Default: `false`. + +- **borders**: border characters. Default: `[ '─', '│', '─', '│' ]`. + +- **bufferSize**: data buffer size. If provided, data is kept in a first-in first-out (FIFO) buffer which cannot exceed the buffer size. Default: `+infinity`. + +- **cellPaddingLeft**: cell's left padding. Default: `1`. + +- **cellPaddingRight**: cell's right padding. Default: `1`. + +- **columnSeparator**: column separator character(s). Default: `'│'`. + +- **corners**: corner characters. Default: `[ '┌', '┐', '┘', '└' ]`. + +- **headerSeparator**: header separator character(s). Default: `'─'`. + +- **horizontalSeparatorMode**: Horizontal line separator mode. The following modes are supported: + + - `resume`: resume line sequence after a joint. + - `interpolate`: skip line character at a joint. + - `repeat`: repeat line sequence after a joint. + + Default: `resume`. + +- **joints**: joint characters. Default: `[ '┼', '┬', '┤', '┴', '├' ]`. + - **marginX**: horizontal output margin. Default: `0`. + - **marginY**: vertical output margin. Default: `0`. -- **maxCellWidth**: maximum cell width (excluding padding). Default: `FLOAT64_MAX`. -- **maxOutputWidth**: maximum output width (including margin). Default: `FLOAT64_MAX`. -- **rowSeparator**: row separator character. Default: `'None'`. + +- **maxCellWidth**: maximum cell width(s). Default: `+infinity`. + +- **maxOutputWidth**: maximum output width. Default: `+infinity`. + +- **rowSeparator**: row separator character(s). Default: `''`. + +- **verticalSeparatorMode**: Vertical line separator mode. The following modes are supported: + + - `resume`: resume line sequence after a joint. + - `interpolate`: skip line character at a joint. + - `repeat`: repeat line sequence after a joint. + + Default: `resume`. * * * @@ -61,7 +94,7 @@ The constructor accepts the following `options`: #### UnicodeTable.prototype.alignment -Alignment of datum in cell. The value must be either `'right'`, `'left'` or `'center'`. +Alignment(s) of datum in cell. The value must be either `'right'`, `'left'`, or `'center'` or an array of them. ```javascript var table = new UnicodeTable(); @@ -72,64 +105,131 @@ table.alignment = 'center'; // Get: var alignment = table.alignment; // returns 'center' + +// Set: +table.alignment = [ 'left', 'right', 'center' ]; + +// Get: +alignment = table.alignment; +// returns [ 'left', 'right', 'center' ] +``` + + + +#### UnicodeTable.prototype.autoRender + +Rendering mode. If `true`, an instance renders on each `'change'` event; otherwise, rendering must be triggered manually. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.autoRender = false; + +// Get: +var mode = table.autoRender; +// returns false ``` #### UnicodeTable.prototype.borders -Border characters. String must be four space separated characters in the order 'top right bottom left'. A value of `'None'` indicates no border would be rendered. +Border characters. Must be an array of `four` strings in the order `[ 'top', 'right', 'bottom', 'left' ]`. ```javascript var table = new UnicodeTable(); // Set: -table.borders = '= ! = !'; +table.borders = [ '=', '!', '=', '!' ]; // Get: var borders = table.borders; -// returns '= ! = !' +// returns [ '=', '!', '=', '!' ] +``` + + + +#### UnicodeTable.prototype.bufferSize + +Data buffer size. If set, this specifies the maximum number of rows which can be rendered. Once the data buffer is full, each new row results in the oldest row being removed. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.bufferSize = 3; + +// Get: +var size = table.bufferSize; +// returns 3 + +table.data = [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]; + +var data = table.data; +// returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] + +table.push( [ 7, 8 ] ); + +data = table.data; +// returns [ [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ] ``` - +Setting a data buffer size is useful when rendering data streams. + + -#### UnicodeTable.prototype.cellPadding +#### UnicodeTable.prototype.cellPaddingLeft -Cell padding. Pads each side of the cell with whitespace characters. +Cell's left padding(s). Pads the left side of the cell with whitespace characters. Pad each cell individually by providing an array of paddings. ```javascript var table = new UnicodeTable(); // Set: -table.cellPadding = 3; +table.cellPaddingLeft = 3; // Get: -var padding = table.cellPadding; +var padding = table.cellPaddingLeft; // returns 3 + +// Set: +table.cellPaddingLeft = [ 3, 4 ]; + +// Get: +padding = table.cellPaddingLeft; +// returns [ 3, 4 ] ``` - + -#### UnicodeTable.prototype.corners +#### UnicodeTable.prototype.cellPaddingRight -Corner characters. String must be four space separated characters in the order 'top-left top-right bottom-right bottom-left'. A value of `'None'` indicates no corners would be rendered. +Cell's right padding(s). Pads the right side of the cell with whitespace characters. Pad each cell individually by providing an array of paddings. ```javascript var table = new UnicodeTable(); // Set: -table.corners = '* * * *'; +table.cellPaddingRight = 3; // Get: -var corners = table.corners; -// returns '* * * *' +var padding = table.cellPaddingRight; +// returns 3 + +// Set: +table.cellPaddingRight = [ 3, 4 ]; + +// Get: +padding = table.cellPaddingRight; +// returns [ 3, 4 ] ``` #### UnicodeTable.prototype.columnSeparator -Column Separator character. Must be a character string or `'None'`. A value of `'None'` indicates that columns won't be separated. +Column separator character(s). If provided a string with multiple graphmeme clusters, each grapheme cluster is rendered sequentially. No separator is rendered if provided an empty string. ```javascript var table = new UnicodeTable(); @@ -142,11 +242,62 @@ var separator = table.columnSeparator; // returns '|' ``` + + +#### UnicodeTable.prototype.corners + +Corner characters. Must be an array of `four` grapheme clusters in the order `[ 'top-left', 'top-right', 'bottom-right', 'bottom-left' ]`. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.corners = [ '*', '*', '*', '*' ]; + +// Get: +var corners = table.corners; +// returns [ '*', '*', '*', '*' ] +``` + + + +#### UnicodeTable.prototype.data + +Table data. Must be an array of arrays or a MatrixLike ndarray and should not exceed the `bufferSize`. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.data = [ [ 1, 2 ], [ 3, 4 ] ]; + +// Get: +var data = table.data; +// returns [ [ 1, 2 ], [ 3, 4 ] ] +``` + + + +#### UnicodeTable.prototype.headers + +Table headers. Must be an array. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.headers = [ 'A', 'B' ]; + +// Get: +var headers = table.headers; +// returns [ 'A', 'B' ] +``` + #### UnicodeTable.prototype.headerSeparator -Header Separator character. Must be a character string or `'None'`. A value of `'None'` indicates that headers won't be separated from the data. +Header separator character(s). If provided a string with multiple graphmeme clusters, each grapheme cluster is rendered sequentially. No separator is rendered if provided an empty string. ```javascript var table = new UnicodeTable(); @@ -159,21 +310,42 @@ var separator = table.headerSeparator; // returns '-' ``` + + +#### UnicodeTable.prototype.horizontalSeparatorMode + +Horizontal line separator mode. The following modes are supported: + +- `resume`: resume line sequence after a joint. +- `interpolate`: skip line character at a joint. +- `repeat`: repeat line sequence after a joint. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.horizontalSeparatorMode = 'interpolate'; + +// Get: +var mode = table.horizontalSeparatorMode; +// returns 'interpolate' +``` + #### UnicodeTable.prototype.joints -Joint characters. String must be five space separated characters in the order 'middle top right bottom left'. A value of `'None'` indicates no joints would be rendered. +Joint characters. Must be an array of `five` grapheme clusters in the order `[ 'middle', 'top', 'right', 'bottom', 'left' ]`. ```javascript var table = new UnicodeTable(); // Set: -table.joints = '* * * * *'; +table.joints = [ '*', '*', '*', '*', '*' ]; // Get: var joints = table.joints; -// returns '* * * * *' +// returns [ '*', '*', '*', '*', '*' ] ``` @@ -214,7 +386,7 @@ var margin = table.marginY; #### UnicodeTable.prototype.maxCellWidth -Maximum cell width. If a datum is longer than the maximum cell width, it is truncated. +Maximum cell width. If a datum is longer than the maximum cell width, it is truncated. Truncate each cell individually by providing an array of widhts. ```javascript var table = new UnicodeTable(); @@ -225,6 +397,12 @@ table.maxCellWidth = 10; // Get: var width = table.maxCellWidth; // returns 10 + +// Set: +table.maxCellWidth = [ 10, 15 ]; + +// Get: +width = table.maxCellWidth; ``` @@ -248,7 +426,7 @@ var width = table.maxOutputWidth; #### UnicodeTable.prototype.rowSeparator -Row Separator character. Must be a character string or `'None'`. A value of `'None'` indicates that rows won't be separated. +Row separator character(s). If provided a string with multiple graphmeme clusters, each grapheme cluster is rendered sequentially. No separator is rendered if provided an empty string. ```javascript var table = new UnicodeTable(); @@ -261,39 +439,50 @@ var separator = table.rowSeparator; // returns '-' ``` -* * * - -### Methods + - +#### UnicodeTable.prototype.verticalSeparatorMode -#### UnicodeTable.prototype.addRow( row ) +Vertical line separator mode. The following modes are supported: -Adds a row to table data. The row must have the same number of columns as existing data. +- `resume`: resume line sequence after a joint. +- `interpolate`: skip line character at a joint. +- `repeat`: repeat line sequence after a joint. ```javascript -var table = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); - -var data = table.getData().data; -// returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] +var table = new UnicodeTable(); -table.addRow( [ 7, 8, 9 ] ); +// Set: +table.verticalSeparatorMode = 'interpolate'; -data = table.getData().data; -// returns [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] +// Get: +var mode = table.verticalSeparatorMode; +// returns 'interpolate' ``` - +* * * -#### UnicodeTable.prototype.getData() +### Methods -Gets table data and headers. + + +#### UnicodeTable.prototype.push( row ) + +Appends a row to table data. The row must have the same number of columns as existing data. ```javascript -var table = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ 'col1', 'col2', 'col3' ] ); +var table = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); -var data = table.getData(); -// returns { 'data': [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], 'headers': [ 'col1', 'col2', 'col3' ] } +// Get: +var data = table.data; +// returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] + +// Push: +table.push( [ 7, 8, 9 ] ); + +// Get: +data = table.data; +// returns [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ``` @@ -303,27 +492,18 @@ var data = table.getData(); Renders a Unicode table. ```javascript -var table = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ 'col1', 'col2', 'col3' ] ); +var headers; +var table; +var data; + +headers = [ 'col1', 'col2', 'col3' ]; +data = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; +table = new UnicodeTable( data, headers ); var str = table.render(); // returns '...' ``` - - -#### UnicodeTable.prototype.setData() - -Sets table data and headers. - -```javascript -var table = new UnicodeTable(); - -table.setData( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ 'col1', 'col2', 'col3' ] ); - -var data = table.getData(); -// returns { 'data': [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], 'headers': [ 'col1', 'col2', 'col3' ] } -``` - * * * @@ -347,8 +527,7 @@ var data = table.getData(); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/array/uniform' ); var array = require( '@stdlib/ndarray/array' ); var ctor = require( '@stdlib/plot/table/unicode' ); @@ -356,22 +535,15 @@ var headers; var table; var data; var str; -var i; // Generate some random data... -data = new Float64Array( 50 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = randu() * 100.0; -} +data = uniform( 50, 1, 100 ); data = array( data, { 'shape': [ 10, 5 ] }); // Generate headers... -headers = new Float64Array( 5 ); -for ( i = 0; i < headers.length; i++ ) { - headers[ i ] = randu() * 100.0; -} +headers = [ 'A', 'B', 'C', 'D', 'E' ]; // Create a table: table = ctor( data, headers ); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.js b/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.js index 0e81b8561fac..14b46d529cc6 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.js @@ -21,6 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); var pkg = require( './../package.json' ).name; var UnicodeTable = require( './../lib' ); @@ -112,17 +113,22 @@ bench( pkg+'::instantiation,data,options', function benchmark( b ) { opts = { 'alignment': 'left', - 'borders': '1 2 3 4', - 'cellPadding': 2, + 'autoRender': false, + 'borders': [ '1', '23', '456', '7890' ], + 'bufferSize': 10, + 'cellPaddingLeft': 2, + 'cellPaddingRight': [ 2, 3, 4 ], 'columnSeparator': 'None', - 'corners': '* * * *', - 'headerSeparator': '-', - 'joints': '* * * * *', + 'corners': [ '*', '*', '*', '*' ], + 'headerSeparator': '-=', + 'horizontalSeparatorMode': 'repeat', + 'joints': [ '*', '*', '*', '*', '*' ], 'marginX': 2, 'marginY': 4, 'maxCellWidth': 10, 'maxOutputWidth': 60, - 'rowSeparator': '_' + 'rowSeparator': '_-', + 'verticalSeparatorMode': 'resume' }; b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -146,17 +152,22 @@ bench( pkg+'::instantiation,data,headers,options', function benchmark( b ) { opts = { 'alignment': 'left', - 'borders': '1 2 3 4', - 'cellPadding': 2, + 'autoRender': false, + 'borders': [ '1', '23', '456', '7890' ], + 'bufferSize': 10, + 'cellPaddingLeft': 2, + 'cellPaddingRight': [ 2, 3, 4 ], 'columnSeparator': 'None', - 'corners': '* * * *', - 'headerSeparator': '-', - 'joints': '* * * * *', + 'corners': [ '*', '*', '*', '*' ], + 'headerSeparator': '-=', + 'horizontalSeparatorMode': 'repeat', + 'joints': [ '*', '*', '*', '*', '*' ], 'marginX': 2, 'marginY': 4, 'maxCellWidth': 10, 'maxOutputWidth': 60, - 'rowSeparator': '_' + 'rowSeparator': '_-', + 'verticalSeparatorMode': 'resume' }; b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -173,7 +184,7 @@ bench( pkg+'::instantiation,data,headers,options', function benchmark( b ) { b.end(); }); -bench( pkg+'::set,get:alignment', function benchmark( b ) { +bench( pkg+'::set,get:alignment:string', function benchmark( b ) { var values; var v; var i; @@ -193,41 +204,123 @@ bench( pkg+'::set,get:alignment', function benchmark( b ) { } } b.toc(); - if ( typeof v.borders !== 'string' ) { + if ( typeof v.alignment !== 'string' ) { b.fail( 'should return a string' ); } b.pass( 'benchmark finished' ); b.end(); }); +bench( pkg+'::set,get:alignment:array', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + [ 'left', 'right' ], + [ 'center', 'right' ], + [ 'left', 'center' ] + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.alignment = values[ i % values.length ]; + if ( typeof v.alignment !== 'object' || !v.alignment.length ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( typeof v.alignment !== 'object' || !v.alignment.length ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:autoRender', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + false, + true + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.autoRender = values[ i % values.length ]; + if ( typeof v.autoRender !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( typeof v.autoRender !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + bench( pkg+'::set,get:borders', function benchmark( b ) { var values; var v; var i; values = [ - '1 2 3 4', - '- | - |', - 'None' + [ '-', '|', '-', '|' ], + [ '1', '23', '456', '7890' ], + [ '', '', '', '' ], + [ '🌹', '🥀', '🔥', '👍' ] ]; v = new UnicodeTable(); b.tic(); for ( i = 0; i < b.iterations; i++ ) { v.borders = values[ i % values.length ]; - if ( typeof v.borders !== 'string' ) { - b.fail( 'should return a string' ); + if ( typeof v.borders !== 'object' || !v.borders.length ) { + b.fail( 'should return an array' ); } } b.toc(); - if ( typeof v.borders !== 'string' ) { - b.fail( 'should return a string' ); + if ( typeof v.borders !== 'object' || !v.borders.length ) { + b.fail( 'should return an array' ); } b.pass( 'benchmark finished' ); b.end(); }); -bench( pkg+'::set,get:cellPadding', function benchmark( b ) { +bench( pkg+'::set,get:bufferSize', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 1, + 2, + 3, + null + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.bufferSize = values[ i % values.length ]; + if ( typeof v.bufferSize !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( typeof v.bufferSize !== 'number' ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:cellPaddingLeft:number', function benchmark( b ) { var values; var v; var i; @@ -241,19 +334,100 @@ bench( pkg+'::set,get:cellPadding', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v.cellPadding = values[ i % values.length ]; - if ( typeof v.cellPadding !== 'number' ) { + v.cellPaddingLeft = values[ i % values.length ]; + if ( typeof v.cellPaddingLeft !== 'number' ) { b.fail( 'should return a number' ); } } b.toc(); - if ( typeof v.cellPadding !== 'number' ) { + if ( typeof v.cellPaddingLeft !== 'number' ) { b.fail( 'should return a number' ); } b.pass( 'benchmark finished' ); b.end(); }); +bench( pkg+'::set,get:cellPaddingLeft:array', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + [ 1, 2 ], + [ 3, 4 ], + [ 5, 6 ] + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.cellPaddingLeft = values[ i % values.length ]; + if ( typeof v.cellPaddingLeft !== 'object' || !v.cellPaddingLeft.length ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( typeof v.cellPaddingLeft !== 'object' || !v.cellPaddingLeft.length ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:cellPaddingRight:number', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 1, + 2, + 3 + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.cellPaddingRight = values[ i % values.length ]; + if ( typeof v.cellPaddingRight !== 'number' ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( typeof v.cellPaddingRight !== 'number' ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:cellPaddingRight:array', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + [ 1, 2 ], + [ 3, 4 ], + [ 5, 6 ] + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.cellPaddingRight = values[ i % values.length ]; + if ( typeof v.cellPaddingRight !== 'object' || !v.cellPaddingRight.length ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( typeof v.cellPaddingRight !== 'object' || !v.cellPaddingRight.length ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + bench( pkg+'::set,get:columnSeparator', function benchmark( b ) { var values; var v; @@ -261,7 +435,9 @@ bench( pkg+'::set,get:columnSeparator', function benchmark( b ) { values = [ '|', - 'None' + '123', + '🥀', + '' ]; v = new UnicodeTable(); @@ -286,22 +462,73 @@ bench( pkg+'::set,get:corners', function benchmark( b ) { var i; values = [ - '1 2 3 4', - '* * * *', - 'None' + [ '-', '|', '-', '|' ], + [ '🌹', '🥀', '🔥', '👍' ] ]; v = new UnicodeTable(); b.tic(); for ( i = 0; i < b.iterations; i++ ) { v.corners = values[ i % values.length ]; - if ( typeof v.corners !== 'string' ) { - b.fail( 'should return a string' ); + if ( typeof v.corners !== 'object' || !v.corners.length ) { + b.fail( 'should return an array' ); } } b.toc(); - if ( typeof v.corners !== 'string' ) { - b.fail( 'should return a string' ); + if ( typeof v.corners !== 'object' || !v.corners.length ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:data', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], + ndarray( 'generic', [ 1, 2, 3, 4, 5, 6 ], [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ) + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.data = values[ i % values.length ]; + if ( typeof v.data !== 'object' || !v.data.length ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( typeof v.data !== 'object' || !v.data.length ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:headers', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + [ 'col1', 'col2', 'col3' ], + [ 1, 2, 3] + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.headers = values[ i % values.length ]; + if ( typeof v.headers !== 'object' || !v.headers.length ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( typeof v.headers !== 'object' || !v.headers.length ) { + b.fail( 'should return an array' ); } b.pass( 'benchmark finished' ); b.end(); @@ -313,8 +540,10 @@ bench( pkg+'::set,get:headerSeparator', function benchmark( b ) { var i; values = [ - '-', - 'None' + '|', + '123', + '🥀', + '' ]; v = new UnicodeTable(); @@ -333,33 +562,59 @@ bench( pkg+'::set,get:headerSeparator', function benchmark( b ) { b.end(); }); -bench( pkg+'::set,get:joints', function benchmark( b ) { +bench( pkg+'::set,get:horizontalSeparatorMode', function benchmark( b ) { var values; var v; var i; values = [ - '1 2 3 4 5', - '* * * * *', - 'None' + 'repeat', + 'resume', + 'interpolate' ]; v = new UnicodeTable(); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v.joints = values[ i % values.length ]; - if ( typeof v.joints !== 'string' ) { + v.horizontalSeparatorMode = values[ i % values.length ]; + if ( typeof v.horizontalSeparatorMode !== 'string' ) { b.fail( 'should return a string' ); } } b.toc(); - if ( typeof v.joints !== 'string' ) { + if ( typeof v.horizontalSeparatorMode !== 'string' ) { b.fail( 'should return a string' ); } b.pass( 'benchmark finished' ); b.end(); }); +bench( pkg+'::set,get:joints', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + [ '-', '|', '-', '|', '=' ], + [ '🌹', '🥀', '🔥', '👍', '📸' ] + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.joints = values[ i % values.length ]; + if ( typeof v.joints !== 'object' || !v.joints.length ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( typeof v.joints !== 'object' || !v.joints.length ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + bench( pkg+'::set,get:marginX', function benchmark( b ) { var values; var v; @@ -414,7 +669,7 @@ bench( pkg+'::set,get:marginY', function benchmark( b ) { b.end(); }); -bench( pkg+'::set,get:maxCellWidth', function benchmark( b ) { +bench( pkg+'::set,get:maxCellWidth:number', function benchmark( b ) { var values; var v; var i; @@ -422,7 +677,8 @@ bench( pkg+'::set,get:maxCellWidth', function benchmark( b ) { values = [ 10, 20, - 30 + 30, + null ]; v = new UnicodeTable(); @@ -441,6 +697,34 @@ bench( pkg+'::set,get:maxCellWidth', function benchmark( b ) { b.end(); }); +bench( pkg+'::set,get:maxCellWidth:array', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + [ 1, 2, 3 ], + [ 4, 5, 6 ], + [ 7, null, 9 ], + [ null, null, null ] + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.maxCellWidth = values[ i % values.length ]; + if ( typeof v.maxCellWidth !== 'object' || !v.maxCellWidth.length ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( typeof v.maxCellWidth !== 'object' || !v.maxCellWidth.length ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + bench( pkg+'::set,get:maxOutputWidth', function benchmark( b ) { var values; var v; @@ -449,7 +733,8 @@ bench( pkg+'::set,get:maxOutputWidth', function benchmark( b ) { values = [ 100, 200, - 300 + 300, + null ]; v = new UnicodeTable(); @@ -474,8 +759,10 @@ bench( pkg+'::set,get:rowSeparator', function benchmark( b ) { var i; values = [ - '-', - 'None' + '|', + '123', + '🥀', + '' ]; v = new UnicodeTable(); @@ -493,3 +780,30 @@ bench( pkg+'::set,get:rowSeparator', function benchmark( b ) { b.pass( 'benchmark finished' ); b.end(); }); + +bench( pkg+'::set,get:verticalSeparatorMode', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 'repeat', + 'resume', + 'interpolate' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.verticalSeparatorMode = values[ i % values.length ]; + if ( typeof v.verticalSeparatorMode !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof v.verticalSeparatorMode !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.render.js b/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.render.js index 79f812e10670..11c989b4bbd1 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.render.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.render.js @@ -37,45 +37,42 @@ var UnicodeTable = require( './../lib' ); * @private * @param {PositiveInteger} rows - number of rows * @param {PositiveInteger} columns - number of columns -* @param {UnicodeSparkline} table - table instance +* @param {UnicodeTable} table - table instance * @returns {Function} benchmark function */ function createBenchmark( rows, columns, table ) { - return benchmark; - - /** - * Generates table data. - * - * @private - * @returns {ndarray} table data - */ - function data() { - var data; - var i; + var headers; + var data; + var i; - data = new Float64Array( rows * columns ); - for ( i = 0; i < data.length; i++ ) { - data[ i ] = randu(); - } - data = array( data, { - 'shape': [ rows, columns ] - }); - return data; + data = new Float64Array( rows * columns ); + for ( i = 0; i < data.length; i++ ) { + data[ i ] = randu(); + } + data = array( data, { + 'shape': [ rows, columns ] + }); + headers = []; + for ( i = 0; i < columns; i++ ) { + headers.push( randu() ); } + table.data = data; + table.headers = headers; + return benchmark; /** - * Generates table headers. + * Generates a row of table data. * * @private - * @returns {Float64Array} table data + * @returns {Array} table data */ - function headers() { + function row() { var data; var i; - data = new Float64Array( columns ); - for ( i = 0; i < data.length; i++ ) { - data[ i ] = randu(); + data = []; + for ( i = 0; i < columns; i++ ) { + data.push( randu() ); } return data; } @@ -92,7 +89,7 @@ function createBenchmark( rows, columns, table ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - str = table.setData( data(), headers() ).render(); + str = table.push( row() ).render(); if ( typeof str !== 'string' ) { b.fail( 'should return a string' ); } @@ -133,6 +130,7 @@ function main() { columns = pow( 5, j ); table = new UnicodeTable(); + table.bufferSize = rows; f = createBenchmark( rows, columns, table ); bench( pkg+':render:rows='+rows+',columns='+columns, f ); } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/docs/repl.txt b/lib/node_modules/@stdlib/plot/table/unicode/docs/repl.txt index 7200f71b2983..0947404ced32 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/docs/repl.txt +++ b/lib/node_modules/@stdlib/plot/table/unicode/docs/repl.txt @@ -13,26 +13,48 @@ options: Object (optional) Table options. - options.alignment: string (optional) - Datum's cell alignment. Default: 'right'. + options.alignment: Array|string (optional) + Datum's cell alignment(s). Default: 'right'. - options.borders: string (optional) - Border characters. Default: '─ │ ─ │'. + options.autoRender: boolean (optional) + Boolean indicating whether to re-render on a 'change' event. Default: + false. - options.cellPadding: NonNegativeInteger (optional) - Cell padding. Default: 1. + options.borders: Array (optional) + Border characters. Default: [ '─', '│', '─', '│' ]. + + options.bufferSize: integer|null (optional) + Data buffer size. If provided, data is kept in a first-in first-out + (FIFO) buffer which cannot exceed the buffer size. Default: +infinity. + + options.cellPaddingLeft: Array|NonNegativeInteger + (optional) + Cell's left padding(s). Default: 1. + + options.cellPaddingRight: Array|NonNegativeInteger + (optional) + Cell's right padding(s). Default: 1. options.columnSeparator: string (optional) - Column separator character. Default: '│'. + Column separator character(s). Default: '│'. - options.corners: string (optional) - Corner characters. Default: '┌ ┐ ┘ └'. + options.corners: Array (optional) + Corner characters. Default: [ '┌', '┐', '┘', '└' ]. options.headerSeparator: string (optional) - Header separator character. Default: '─'. + Header separator character(s). Default: '─'. + + options.horizontalSeparatorMode: string (optional) + Horizontal line separator mode. The following modes are supported: + + - resume: resume line sequence after a joint. + - interpolate: skip line character at a joint. + - repeat: repeat line sequence after a joint. - options.joints: string (optional) - Joint characters. Default: '┼ ┬ ┤ ┴ ├'. + Default: `resume`. + + options.joints: Array (optional) + Joint characters. Default: [ '┼', '┬', '┤', '┴', '├' ]. options.marginX: NonNegativeInteger (optional) Horizontal output margin. Default: 0. @@ -40,40 +62,63 @@ options.marginY: NonNegativeInteger (optional) Vertical output margin. Default: 0. - options.maxCellWidth: NonNegativeInteger (optional) - Maximum cell width (excluding padding). Default: FLOAT64_MAX. + options.maxCellWidth: Array|NonNegativeInteger|null + (optional) + Maximum cell width(s). Default: +infinity. - options.maxOutputWidth: NonNegativeInteger (optional) - Maximum output width (including margin). Default: FLOAT64_MAX. + options.maxOutputWidth: NonNegativeInteger|null (optional) + Maximum output width. Default: +infinity. options.rowSeparator: string (optional) - Row separator character. Default: 'None'. + Row separator character(s). Default: ''. + + options.verticalSeparatorMode: string (optional) + Vertical line separator mode. The following modes are supported: + + - resume: resume line sequence after a joint. + - interpolate: skip line character at a joint. + - repeat: repeat line sequence after a joint. + + Default: `resume`. Returns ------- - table.addRow( row ) - Adds a row to table data. - table.alignment - Datum's cell alignment. + Datum's cell alignment(s). + + table.autoRender + Rendering mode. If `true`, an instance renders on each 'change' event; + otherwise, rendering must be triggered manually. table.borders Border characters. - table.cellPadding - Cell Padding. + table.bufferSize + Data buffer size. + + table.cellPaddingLeft + Cell's left Padding. + + table.cellPaddingRight + Cell's right Padding. table.columnSeparator - Column separator character. + Column separator character(s). table.corners Corner characters. - table.getData() - Gets table data and headers. + table.data + Table data. + + table.headers + Table headers. table.headerSeparator - Header separator character. + Header separator character(s). + + table.horizontalSeparatorMode + Horizontal line separator mode. table.joints Joint characters. @@ -90,14 +135,17 @@ table.maxOutputWidth Maximum output width. + table.push( row ) + Appends a row to table data. + table.render() Renders a table. table.rowSeparator - Row separator character. + Row separator character(s). - table.setData( data, [headers] ) - Sets table data and headers + table.verticalSeparatorMode + Vertical line separator mode. Examples -------- diff --git a/lib/node_modules/@stdlib/plot/table/unicode/examples/index.js b/lib/node_modules/@stdlib/plot/table/unicode/examples/index.js index 6903a124be79..722cd52735c1 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/examples/index.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/examples/index.js @@ -18,8 +18,7 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/array/uniform' ); var array = require( '@stdlib/ndarray/array' ); var ctor = require( './../lib' ); @@ -27,22 +26,15 @@ var headers; var table; var data; var str; -var i; // Generate some random data... -data = new Float64Array( 50 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = randu() * 100.0; -} +data = uniform( 50, 1, 100 ); data = array( data, { 'shape': [ 10, 5 ] }); // Generate headers... -headers = new Float64Array( 5 ); -for ( i = 0; i < headers.length; i++ ) { - headers[ i ] = randu() * 100.0; -} +headers = [ 'A', 'B', 'C', 'D', 'E' ]; // Create a table: table = ctor( data, headers ); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/defaults.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/defaults.js index d7a7883a39f1..ad2e9a670cab 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/defaults.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/defaults.js @@ -37,14 +37,21 @@ function defaults() { // Cell alignment: out.alignment = 'right'; + // Boolean indicating whether to re-render on a `change` event: + out.autoRender = false; + // Border characters: - out.borders = '─ │ ─ │'; + out.borders = [ '─', '│', '─', '│' ]; + + // Buffer size: + out.bufferSize = FLOAT64_MAX; // Cell padding: - out.cellPadding = 1; + out.cellPaddingLeft = 1; + out.cellPaddingRight = 1; // Corner characters: - out.corners = '┌ ┐ ┘ └'; + out.corners = [ '┌', '┐', '┘', '└' ]; // Column separator character: out.columnSeparator = '│'; @@ -52,11 +59,12 @@ function defaults() { // Header separator character: out.headerSeparator = '─'; - // Row separator character: - out.rowSeparator = 'None'; - // Joint characters: - out.joints = '┼ ┬ ┤ ┴ ├'; + out.joints = [ '┼', '┬', '┤', '┴', '├' ]; + + // Line separator mode: + out.horizontalSeparatorMode = 'resume'; + out.verticalSeparatorMode = 'resume'; // Output margins: out.marginX = 0; @@ -68,6 +76,9 @@ function defaults() { // Maximum output width: out.maxOutputWidth = FLOAT64_MAX; + // Row separator character: + out.rowSeparator = ''; + return out; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/index.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/index.js index f0b575b93d5f..ec280ed94dab 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/index.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/index.js @@ -22,6 +22,16 @@ * Create a Unicode table. * * @module @stdlib/plot/table/unicode +* +* @example +* var UnicodeTable = require( '@stdlib/plot/table/unicode' ); +* +* var data = [ [ 1, 2 ], [ 3, 4 ] ]; +* var headers = [ 'A', 'B' ] +* var table = UnicodeTable( data, headers ); +* +* var str = table.render(); +* // returns '...' */ // MODULES // diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/main.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/main.js index 830cec9f5796..e10232b7f300 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/main.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/main.js @@ -16,30 +16,46 @@ * limitations under the License. */ +/* eslint-disable max-lines */ + 'use strict'; // MODULES // +var EventEmitter = require( 'events' ).EventEmitter; var logger = require( 'debug' ); var format = require( '@stdlib/string/format' ); var defineProperty = require( '@stdlib/utils/define-property' ); var objectKeys = require( '@stdlib/utils/keys' ); -var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var inherit = require( '@stdlib/utils/inherit' ); +var isObject = require( '@stdlib/assert/is-plain-object' ); var isCollection = require( '@stdlib/assert/is-collection' ); var mergeFcn = require( '@stdlib/utils/merge' ).factory; var pick = require( '@stdlib/utils/pick' ); var setAlignment = require( './props/alignment/set.js' ); var getAlignment = require( './props/alignment/get.js' ); +var setAutoRender = require( './props/auto-render/set.js' ); +var getAutoRender = require( './props/auto-render/get.js' ); var setBorders = require( './props/borders/set.js' ); var getBorders = require( './props/borders/get.js' ); -var setCellPadding = require( './props/cell-padding/set.js' ); -var getCellPadding = require( './props/cell-padding/get.js' ); +var setBufferSize = require( './props/buffer-size/set.js' ); +var getBufferSize = require( './props/buffer-size/get.js' ); +var setCellPaddingLeft = require( './props/cell-padding-left/set.js' ); +var getCellPaddingLeft = require( './props/cell-padding-left/get.js' ); +var setCellPaddingRight = require( './props/cell-padding-right/set.js' ); +var getCellPaddingRight = require( './props/cell-padding-right/get.js' ); var setCorners = require( './props/corners/set.js' ); var getCorners = require( './props/corners/get.js' ); var setColumnSeparator = require( './props/column-separator/set.js' ); var getColumnSeparator = require( './props/column-separator/get.js' ); +var setData = require( './props/data/set.js' ); +var getData = require( './props/data/get.js' ); +var setHeaders = require( './props/headers/set.js' ); +var getHeaders = require( './props/headers/get.js' ); var setHeaderSeparator = require( './props/header-separator/set.js' ); var getHeaderSeparator = require( './props/header-separator/get.js' ); +var setHorizontalSeparatorMode = require( './props/horizontal-separator-mode/set.js' ); // eslint-disable-line id-length +var getHorizontalSeparatorMode = require( './props/horizontal-separator-mode/get.js' ); // eslint-disable-line id-length var setJoints = require( './props/joints/set.js' ); var getJoints = require( './props/joints/get.js' ); var setMarginX = require( './props/margin-x/set.js' ); @@ -52,11 +68,12 @@ var setMaxOutputWidth = require( './props/max-output-width/set.js' ); var getMaxOutputWidth = require( './props/max-output-width/get.js' ); var setRowSeparator = require( './props/row-separator/set.js' ); var getRowSeparator = require( './props/row-separator/get.js' ); +var setVerticalSeparatorMode = require( './props/vertical-separator-mode/set.js' ); +var getVerticalSeparatorMode = require( './props/vertical-separator-mode/get.js' ); var defaults = require( './defaults.js' ); var render = require( './render.js' ); -var setData = require('./setdata.js'); -var getData = require( './getdata.js' ); -var addRow = require( './addrow.js' ); +var push = require( './push.js' ); +var parse = require( './parse.js' ); // VARIABLES // @@ -70,36 +87,47 @@ var merge = mergeFcn({ // List of private properties (note: keep in alphabetical order): var PRIVATE_PROPS = [ '_alignment', + '_autoRender', '_borders', - '_cellPadding', + '_bufferSize', + '_cellPaddingLeft', + '_cellPaddingRight', '_corners', '_columnSeparator', '_columnWidths', '_data', '_headers', '_headerSeparator', + '_horizontalSeparatorMode', '_joints', '_marginX', '_marginY', '_maxCellWidth', '_maxOutputWidth', - '_rowSeparator' + '_numColumns', + '_rowSeparator', + '_verticalSeparatorMode' ]; // List of options properties (note: keep in alphabetical order): var OPTIONS_PROPS = [ 'alignment', + 'autoRender', 'borders', - 'cellPadding', + 'bufferSize', + 'cellPaddingLeft', + 'cellPaddingRight', 'columnSeparator', 'corners', 'headerSeparator', + 'horizontalSeparatorMode', 'joints', 'marginX', 'marginY', 'maxCellWidth', 'maxOutputWidth', - 'rowSeparator' + 'rowSeparator', + 'verticalSeparatorMode' ]; @@ -112,28 +140,45 @@ var OPTIONS_PROPS = [ * @param {(Object|Array|Array|MatrixLike)} [data] - table data * @param {Collection} [headers] - table headers * @param {Options} [options] - table options -* @param {string} [options.alignment='right'] - datum's cell alignment -* @param {(string)} [options.borders='─ │ ─ │'] - border characters -* @param {NonNegativeInteger} [options.cellPadding=1] - cell padding -* @param {string} [options.columnSeparator='│'] - column separator character -* @param {string} [options.corners='┌ ┐ ┘ └'] - corner characters -* @param {string} [options.headerSeparator='─'] - header separator character -* @param {string} [options.joints='┼ ┬ ┤ ┴ ├'] - joint characters +* @param {(Array|string)} [options.alignment='right'] - datum's cell alignment(s) +* @param {boolean} [options.autoRender=false] - boolean indicating whether to re-render on each `change` event +* @param {Array} [options.borders=[ '─', '│', '─', '│' ]] - border characters +* @param {(PositiveInteger|null)} [options.bufferSize] - size of data buffer +* @param {(Array|NonNegativeInteger)} [options.cellPaddingLeft=1] - cell's left padding +* @param {(Array|NonNegativeInteger)} [options.cellPaddingRight=1] - cell's right padding +* @param {string} [options.columnSeparator='│'] - column separator character(s) +* @param {Array} [options.corners=[ '┌', '┐', '┘', '└' ]] - corner characters +* @param {string} [options.headerSeparator='─'] - header separator character(s) +* @param {string} [options.horizontalSeparatorMode='resume'] - horizontal line separator mode +* @param {Array} [options.joints=[ '┼', '┬', '┤', '┴', '├' ]] - joint characters * @param {NonNegativeInteger} [options.marginX=0] - horizontal output margin * @param {NonNegativeInteger} [options.marginY=0] - vertical output margin -* @param {NonNegativeInteger} [options.maxCellWidth=FLOAT64_MAX] - maximum cell width (excluding padding) -* @param {NonNegativeInteger} [options.maxOutputWidth=FLOAT64_MAX] - maximum output width (including margin) -* @param {string} [options.rowSeparator='None'] - row separator character +* @param {(Array|NonNegativeInteger)} [options.maxCellWidth] - maximum cell width(s) +* @param {NonNegativeInteger} [options.maxOutputWidth] - maximum output width +* @param {string} [options.rowSeparator=''] - row separator character(s) +* @param {string} [options.verticalSeparatorMode='resume'] - vertical line separator mode * @throws {TypeError} must provide valid options * @returns {UnicodeTable} table instance +* +* @example +* var UnicodeTable = require( '@stdlib/plot/table/unicode' ); +* +* var data = [ [ 1, 2 ], [ 3, 4 ] ]; +* var headers = [ 'A', 'B' ] +* var table = UnicodeTable( data, headers ); +* +* var str = table.render(); +* // returns '...' */ function UnicodeTable() { var headers; var options; + var parsed; var nargs; var data; var opts; var keys; + var self; var key; var i; @@ -150,6 +195,7 @@ function UnicodeTable() { } return new UnicodeTable( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] ); // eslint-disable-line max-len } + self = this; // Extract table-specific options... opts = defaults(); @@ -170,7 +216,7 @@ function UnicodeTable() { data = arguments[ 0 ]; headers = null; options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { + if ( !isObject( options ) ) { throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); } } @@ -178,7 +224,7 @@ function UnicodeTable() { data = arguments[ 0 ]; headers = arguments[ 1 ]; options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { + if ( !isObject( options ) ) { throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); } } @@ -196,27 +242,62 @@ function UnicodeTable() { }); } // Set table data and headers... - if ( headers ) { - this.setData( data, headers ); - } else if ( data ) { - this.setData( data ); + if ( data || headers ) { + parsed = parse( data, headers ); + this._data = parsed.data; + this._headers = parsed.headers; + this._columnWidths = parsed.columnWidths; + this._numColumns = parsed.columnWidths.length; } + // Set table-specific properties... keys = objectKeys( opts ); for ( i = 0; i < keys.length; i++ ) { key = keys[ i ]; this[ key ] = opts[ key ]; } + // Add event listeners: + this.on( 'change', onChange ); + this.on( 'render', onRender ); + return this; + + /** + * Callback invoked upon receiving a `change` event. + * + * @private + */ + function onChange() { + /* eslint-disable no-underscore-dangle */ + debug( 'Received a change event.' ); + if ( self._autoRender ) { + self.render(); + } + } + + /** + * Callback invoked upon receiving a `render` event. + * + * @private + * @param {string} table - rendered table + */ + function onRender() { + debug( 'Received a render event.' ); + } } +/* +* Inherit from the `EventEmitter` prototype. +*/ +inherit( UnicodeTable, EventEmitter ); + /** -* Alignment of datum in cell. +* Alignment(s) of datum in cell. * * @name alignment * @memberof UnicodeTable.prototype -* @type {string} -* @throws {TypeError} must be a supported alignment string +* @type {(Array|string)} +* @throws {TypeError} must be a supported alignment string or an array of alignment strings * @default 'right' * * @example @@ -224,6 +305,12 @@ function UnicodeTable() { * table.alignment = 'left'; * var alignment = table.alignment; * // returns 'left' +* +* @example +* var table = new UnicodeTable(); +* table.alignment = [ 'left', 'right', 'center' ]; +* var alignment = table.alignment; +* // returns [ 'left', 'right', 'center' ] */ defineProperty( UnicodeTable.prototype, 'alignment', { 'configurable': false, @@ -232,20 +319,46 @@ defineProperty( UnicodeTable.prototype, 'alignment', { 'get': getAlignment }); +/** +* Rendering mode. +* +* ## Notes +* +* - If `true`, an instance re-renders on each `change` event. +* +* @name autoRender +* @memberof UnicodeTable.prototype +* @type {boolean} +* @throws {TypeError} must be a boolean +* @default false +* +* @example +* var table = new UnicodeTable(); +* table.autoRender = true; +* var mode = table.autoRender; +* // returns true +*/ +defineProperty( UnicodeTable.prototype, 'autoRender', { + 'configurable': false, + 'enumerable': true, + 'set': setAutoRender, + 'get': getAutoRender +}); + /** * Border characters. * * @name borders * @memberof UnicodeTable.prototype -* @type {string} -* @throws {TypeError} must be a four space separated characters or 'None' -* @default '─ │ ─ │' +* @type {Array} +* @throws {TypeError} must be an array of four strings +* @default '[ "─", "│", "─", "│" ]' * * @example * var table = new UnicodeTable(); -* table.borders = '= ! = !'; +* table.borders = [ '=', '!', '=', '!' ]; * var borders = table.borders; -* // returns '= ! = !' +* // returns [ '=', '!', '=', '!' ] */ defineProperty( UnicodeTable.prototype, 'borders', { 'configurable': false, @@ -255,25 +368,79 @@ defineProperty( UnicodeTable.prototype, 'borders', { }); /** -* Cell padding. +* Size of data buffer. * -* @name cellPadding +* @name bufferSize * @memberof UnicodeTable.prototype -* @type {NonNegativeInteger} -* @throws {TypeError} must be a non-negative integer +* @type {(PositiveInteger|null)} +* @throws {TypeError} must be a positive integer or null +* @throws {RangeError} must be greater than or equal to the number of rows +* +* @example +* var table = new UnicodeTable(); +* table.bufferSize = 20; +*/ +defineProperty( UnicodeTable.prototype, 'bufferSize', { + 'configurable': false, + 'enumerable': true, + 'set': setBufferSize, + 'get': getBufferSize +}); + +/** +* Cell's left padding. +* +* @name cellPaddingLeft +* @memberof UnicodeTable.prototype +* @type {(Array|NonNegativeInteger)} +* @throws {TypeError} must be a non-negative integer or an array of non-negative integers +* @default '1' +* +* @example +* var table = new UnicodeTable(); +* table.cellPaddingLeft = 3; +* var padding = table.cellPaddingLeft; +* // returns 3 +* +* @example +* var table = new UnicodeTable(); +* table.cellPaddingLeft = [ 3, 2 ]; +* var paddings = table.cellPaddingLeft; +* // returns [ 3, 2 ] +*/ +defineProperty( UnicodeTable.prototype, 'cellPaddingLeft', { + 'configurable': false, + 'enumerable': true, + 'set': setCellPaddingLeft, + 'get': getCellPaddingLeft +}); + +/** +* Cell's right padding. +* +* @name cellPaddingRight +* @memberof UnicodeTable.prototype +* @type {(Array|NonNegativeInteger)} +* @throws {TypeError} must be a non-negative integer or an array of non-negative integers * @default '1' * * @example * var table = new UnicodeTable(); -* table.cellPadding = 3; -* var padding = table.cellPadding; +* table.cellPaddingRight = 3; +* var padding = table.cellPaddingRight; * // returns 3 +* +* @example +* var table = new UnicodeTable(); +* table.cellPaddingRight = [ 3, 2 ]; +* var paddings = table.cellPaddingRight; +* // returns [ 3, 2 ] */ -defineProperty( UnicodeTable.prototype, 'cellPadding', { +defineProperty( UnicodeTable.prototype, 'cellPaddingRight', { 'configurable': false, 'enumerable': true, - 'set': setCellPadding, - 'get': getCellPadding + 'set': setCellPaddingRight, + 'get': getCellPaddingRight }); /** @@ -281,15 +448,15 @@ defineProperty( UnicodeTable.prototype, 'cellPadding', { * * @name corners * @memberof UnicodeTable.prototype -* @type {string} -* @throws {TypeError} must be a string with four space separated characters or 'None' -* @default '┌ ┐ ┘ └' +* @type {Array} +* @throws {TypeError} must be an array of four grapheme clusters +* @default '[ "┌", "┐", "┘", "└" ]' * * @example * var table = new UnicodeTable(); -* table.corners = '* * * *'; +* table.corners = [ '*', '*', '*', '*' ]; * var corners = table.corners; -* // returns '* * * *' +* // returns [ '*', '*', '*', '*' ] */ defineProperty( UnicodeTable.prototype, 'corners', { 'configurable': false, @@ -299,19 +466,19 @@ defineProperty( UnicodeTable.prototype, 'corners', { }); /** -* Column separator character. +* Column separator character(s). * * @name columnSeparator * @memberof UnicodeTable.prototype * @type {string} -* @throws {TypeError} must be a character string or 'None' +* @throws {TypeError} must be a string * @default '│' * * @example * var table = new UnicodeTable(); -* table.columnSeparator = '$'; +* table.columnSeparator = '$='; * var separator = table.columnSeparator; -* // returns '$' +* // returns '$=' */ defineProperty( UnicodeTable.prototype, 'columnSeparator', { 'configurable': false, @@ -321,19 +488,64 @@ defineProperty( UnicodeTable.prototype, 'columnSeparator', { }); /** -* Header separator character. +* Table data. +* +* @name data +* @memberof UnicodeTable.prototype +* @type {Array|MatrixLike} +* @throws {TypeError} must be a 2 dimensional array/ndarray +* @throws {RangeError} must provide correct number of columns +* @throws {RangeError} rows must not exceed maximum data buffer size +* +* @example +* var table = new UnicodeTable(); +* table.data = [ [ 'a', 'b' ], [ 1, 2 ] ]; +* var data = table.data; +* // returns [ [ 'a', 'b' ], [ 1, 2 ] ] +*/ +defineProperty( UnicodeTable.prototype, 'data', { + 'configurable': false, + 'enumerable': true, + 'set': setData, + 'get': getData +}); + +/** +* Table headers. +* +* @name headers +* @memberof UnicodeTable.prototype +* @type {Collection} +* @throws {TypeError} must be a collection +* @throws {RangeError} must provide correct number of columns +* +* @example +* var table = new UnicodeTable(); +* table.headers = [ 'name', 'age' ]; +* var headers = table.headers; +* // returns [ 'name', 'age' ] +*/ +defineProperty( UnicodeTable.prototype, 'headers', { + 'configurable': false, + 'enumerable': true, + 'set': setHeaders, + 'get': getHeaders +}); + +/** +* Header separator character(s). * * @name headerSeparator * @memberof UnicodeTable.prototype * @type {string} -* @throws {TypeError} must be a character string or 'None' +* @throws {TypeError} must be a string * @default '─' * * @example * var table = new UnicodeTable(); -* table.headerSeparator = '$'; +* table.headerSeparator = '$='; * var separator = table.headerSeparator; -* // returns '$' +* // returns '$=' */ defineProperty( UnicodeTable.prototype, 'headerSeparator', { 'configurable': false, @@ -342,20 +554,42 @@ defineProperty( UnicodeTable.prototype, 'headerSeparator', { 'get': getHeaderSeparator }); +/** +* Horizontal line separator mode. +* +* @name horizontalSeparatorMode +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a supported line separator mode string +* @default 'resume' +* +* @example +* var table = new UnicodeTable(); +* table.horizontalSeparatorMode = 'repeat'; +* var mode = table.horizontalSeparatorMode; +* // returns 'repeat' +*/ +defineProperty( UnicodeTable.prototype, 'horizontalSeparatorMode', { + 'configurable': false, + 'enumerable': true, + 'set': setHorizontalSeparatorMode, + 'get': getHorizontalSeparatorMode +}); + /** * Joint characters. * * @name joints * @memberof UnicodeTable.prototype -* @type {string} -* @throws {TypeError} must be a string with five space separated characters or 'None' -* @default '┼ ┬ ┤ ┴ ├' +* @type {Array} +* @throws {TypeError} must be an array of five grapheme clusters +* @default '[ "┼", "┬", "┤", "┴", "├" ]' * * @example * var table = new UnicodeTable(); -* table.joints = '* * * * *'; +* table.joints = [ '*', '*', '*', '*', '*' ]; * var joints = table.joints; -* // returns '* * * * *' +* // returns [ '*', '*', '*', '*', '*' ] */ defineProperty( UnicodeTable.prototype, 'joints', { 'configurable': false, @@ -409,19 +643,25 @@ defineProperty( UnicodeTable.prototype, 'marginY', { }); /** -* Maximum cell width (excluding padding). +* Maximum cell width. * * @name maxCellWidth * @memberof UnicodeTable.prototype -* @type {NonNegativeInteger} -* @throws {TypeError} must be a non-negative integer -* @default 'FLOAT64_MAX' +* @type {(Array|NonNegativeInteger|null)} +* @throws {TypeError} must be a non-negative integer, an array of non-negative integers or null +* @default '+infinity' * * @example * var table = new UnicodeTable(); * table.maxCellWidth = 10; * var width = table.maxCellWidth; * // returns 10 +* +* @example +* var table = new UnicodeTable(); +* table.maxCellWidth = [ 10, 8 ]; +* var widhts = table.maxCellWidth; +* // returns [ 10, 8 ] */ defineProperty( UnicodeTable.prototype, 'maxCellWidth', { 'configurable': false, @@ -431,13 +671,13 @@ defineProperty( UnicodeTable.prototype, 'maxCellWidth', { }); /** -* Maximum output width (including margin). +* Maximum output width. * * @name maxOutputWidth * @memberof UnicodeTable.prototype -* @type {NonNegativeInteger} -* @throws {TypeError} must be a non-negative integer -* @default 'FLOAT64_MAX' +* @type {(NonNegativeInteger|null)} +* @throws {TypeError} must be a non-negative integer or null +* @default '+infinity' * * @example * var table = new UnicodeTable(); @@ -453,19 +693,19 @@ defineProperty( UnicodeTable.prototype, 'maxOutputWidth', { }); /** -* Row separator character. +* Row separator character(s). * * @name rowSeparator * @memberof UnicodeTable.prototype * @type {string} -* @throws {TypeError} must be a character string or 'None' -* @default 'None' +* @throws {TypeError} must be a string +* @default '' * * @example * var table = new UnicodeTable(); -* table.rowSeparator = '$'; +* table.rowSeparator = '$='; * var separator = table.rowSeparator; -* // returns '$' +* // returns '$=' */ defineProperty( UnicodeTable.prototype, 'rowSeparator', { 'configurable': false, @@ -475,26 +715,47 @@ defineProperty( UnicodeTable.prototype, 'rowSeparator', { }); /** -* Adds a row to table data. +* Vertical line separator mode. * -* @name addRow +* @name verticalSeparatorMode * @memberof UnicodeTable.prototype -* @type {Function} -* @param {Collection} row - row to add -* @throws {TypeError} must provide a collection with equal number of columns to existing data -* @returns {UnicodeTable} class instance +* @type {string} +* @throws {TypeError} must be a supported line separator mode string +* @default 'resume' +* +* @example +* var table = new UnicodeTable(); +* table.verticalSeparatorMode = 'repeat'; +* var mode = table.verticalSeparatorMode; +* // returns 'repeat' */ -UnicodeTable.prototype.addRow = addRow; +defineProperty( UnicodeTable.prototype, 'verticalSeparatorMode', { + 'configurable': false, + 'enumerable': true, + 'set': setVerticalSeparatorMode, + 'get': getVerticalSeparatorMode +}); /** -* Gets table data and headers. +* Appends row to table data. * -* @name getData +* @name push * @memberof UnicodeTable.prototype * @type {Function} -* @returns {Object} table data and headers +* @param {Collection} row - row to add +* @throws {TypeError} must provide a collection with equal number of columns to existing data +* @returns {UnicodeTable} class instance +* +* @example +* var table = new UnicodeTable( [ [ 1, 2 ], [ 3, 4 ] ] ); +* var data = table.data; +* // returns [ [ 1, 2 ], [ 3, 4 ] ] +* +* table.push( [ 5, 6 ] ); +* data = table.data; +* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] */ -UnicodeTable.prototype.getData = getData; +UnicodeTable.prototype.push = push; /** * Renders a table. @@ -504,22 +765,13 @@ UnicodeTable.prototype.getData = getData; * @type {Function} * @throws {Error} output must be able to accommodate every column individually * @returns {string} rendered table -*/ -UnicodeTable.prototype.render = render; - -/** -* Sets table data and headers. * -* @name setData -* @memberof UnicodeTable.prototype -* @type {Function} -* @param {(Object|Array|Array|MatrixLike)} data - table data -* @param {Collection} [headers] - table headers -* @throws {TypeError} first argument must be an object, array of objects, or a 2 dimensional array/ndarray -* @throws {TypeError} second argument must be a collection -* @returns {UnicodeTable} class instance +* @example +* var table = new UnicodeTable( [ [ 1, 2 ], [ 3, 4 ] ], [ 'A', 'B' ] ); +* var str = table.render(); +* // returns '...' */ -UnicodeTable.prototype.setData = setData; +UnicodeTable.prototype.render = render; // EXPORTS // diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/setdata.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/parse.js similarity index 67% rename from lib/node_modules/@stdlib/plot/table/unicode/lib/setdata.js rename to lib/node_modules/@stdlib/plot/table/unicode/lib/parse.js index 1e2b2f882497..42c00ebc3e32 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/setdata.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/parse.js @@ -30,6 +30,7 @@ var ndarray2array = require( '@stdlib/ndarray/to-array' ); var parseObject = require( './parser/parse_object.js' ); var parseObjectsList = require( './parser/parse_objects_list.js' ); var parse2dArray = require( './parser/parse_2d_array.js' ); +var parseHeaders = require( './parser/parse_headers.js' ); // MAIN // @@ -39,30 +40,27 @@ var parse2dArray = require( './parser/parse_2d_array.js' ); * * @private * @param {(Object|Array|Array|MatrixLike)} data - table data -* @param {Collection} [headers] - table headers +* @param {Collection} headers - table headers * @throws {TypeError} first argument must be an object, array of objects, or a 2 dimensional array/ndarray * @throws {TypeError} second argument must be a collection -* @returns {UnicodeTable} class instance +* @returns {Object} table metadata */ -function setData() { - /* eslint-disable no-invalid-this */ - var headers; +function setData( data, headers ) { var parsed; - var nargs; - var data; - nargs = arguments.length; - if ( nargs === 0 ) { - throw new TypeError( format( 'invalid argument. First argument must be an object, array of objects, or a 2 dimensional array/ndarray. Value: `%s`.', data ) ); - } else if ( nargs === 1 ) { - data = arguments[ 0 ]; - headers = this._headers; - } else { - data = arguments[ 0 ]; - headers = arguments[ 1 ]; - if ( !isCollection( headers ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a collection. Value: `%s`.', headers ) ); + if ( headers && !isCollection( headers ) ) { + throw new TypeError( format( 'invalid argument. `%s` argument must be a collection. Value: `%s`.', 'headers', headers ) ); + } + if ( !data ) { + if ( !headers ) { + return { + 'data': null, + 'headers': null, + 'columnWidths': null + }; } + parsed = parseHeaders( headers ); + return parsed; } // Parse according to data-type... if ( isMatrixLike( data ) ) { @@ -74,12 +72,9 @@ function setData() { } else if ( isPlainObject( data ) ) { parsed = parseObject( data, headers ); } else { - throw new TypeError( format( 'invalid argument. First argument must be an object, array of objects, or a 2 dimensional array/ndarray. Value: `%s`.', data ) ); + throw new TypeError( format( 'invalid argument. `%s` argument must be an object, array of objects, or a 2 dimensional array/ndarray. Value: `%s`.', 'data', data ) ); } - this._data = parsed.data; - this._headers = parsed.headers; - this._columnWidths = parsed.columnWidths; - return this; + return parsed; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_2d_array.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_2d_array.js index 411157f88db3..999afcf7b2a5 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_2d_array.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_2d_array.js @@ -26,7 +26,7 @@ * @private * @param {Array} data - tabular data * @param {Collection} [headers] - column names -* @throws {Error} must provide correct number of columns +* @throws {RangeError} must provide correct number of columns * @returns {Object} table metadata */ function parse2dArray( data, headers ) { @@ -52,7 +52,7 @@ function parse2dArray( data, headers ) { // Calculating max widths of all columns: for ( i = 0; i < data.length; i++ ) { if ( cols !== data[ i ].length ) { - throw new Error( 'invalid data. All rows must have equal number of columns' ); + throw new RangeError( 'invalid data. All rows must have equal number of columns' ); } for ( j = 0; j < cols; j++ ) { len = String( data[ i ][ j ] ).length; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_headers.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_headers.js new file mode 100644 index 000000000000..53fa83ce1a7a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_headers.js @@ -0,0 +1,58 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Parses an array into table headers. +* +* @private +* @param {Collection} headers - column names +* @param {Array} [columnWidths] - column widths +* @returns {Object} table metadata +*/ +function parseHeaders( headers, columnWidths ) { + var header; + var i; + + if ( columnWidths ) { + for ( i = 0; i < headers.length; i++ ) { + header = String( headers[ i ] ); + if ( header.length > columnWidths[ i ] ) { + columnWidths[ i ] = header.length; + } + } + } else { + columnWidths = []; + for ( i = 0; i < headers.length; i++ ) { + columnWidths.push( String( headers[ i ] ).length ); + } + } + return { + 'headers': headers, + 'columnWidths': columnWidths, + 'data': null + }; +} + + +// EXPORTS // + +module.exports = parseHeaders; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_object.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_object.js index 69b5edf2a71d..1f6582f550fc 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_object.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_object.js @@ -40,7 +40,6 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' ); * @returns {Object} table metadata */ function parseObject( data, headers ) { - var columns; var header; var widths; var cols; @@ -56,44 +55,39 @@ function parseObject( data, headers ) { // Parsing data into a 2D array: rows = []; // final data after parsing - columns = []; // final headers list after parsing widths = []; // max widths of each column for ( i = 0; i < headers.length; i++ ) { header = String( headers[ i ] ); - // Skip header if it doesn't exist in the data... - if ( hasOwnProp( data, header ) ) { - if ( !isCollection( data[ header ] ) ) { - throw new Error( format( 'invalid data. Each key must correspond to an array. Value: `%s`.', data ) ); - } - columns.push( header ); - widths.push( header.length ); - for ( j = 0; j < data[ header ].length; j++ ) { - len = String( data[ header ][ j ] ).length; + if ( !hasOwnProp( data, header ) ) { + throw new Error( format( 'invalid data. Column `%s` not found in data. Value: `%s`.', header, data ) ); + } + if ( !isCollection( data[ header ] ) ) { + throw new Error( format( 'invalid data. Each key must correspond to an array. Value: `%s`.', data ) ); + } + widths.push( header.length ); + for ( j = 0; j < data[ header ].length; j++ ) { + len = String( data[ header ][ j ] ).length; - // Updating max width of column: - if ( len > widths[ i ] ) { - widths[ i ] = len; - } - if ( !rows[ j ] ) { - rows[ j ] = []; - } - rows[ j ][ i ] = data[ header ][ j ]; + // Updating max width of column: + if ( len > widths[ i ] ) { + widths[ i ] = len; } + if ( !rows[ j ] ) { + rows[ j ] = []; + } + rows[ j ][ i ] = data[ header ][ j ]; } } - if ( columns.length === 0 ) { - throw new Error( format( 'invalid data. No headers found in data. Value: `%s`.', data ) ); - } // Checking if all columns have the same number of rows... - cols = data[ columns[ 0 ] ].length; - for ( i = 1; i < columns.length; i++ ) { - if ( cols !== data[ columns[ i ] ].length ) { + cols = data[ headers[ 0 ] ].length; + for ( i = 1; i < headers.length; i++ ) { + if ( cols !== data[ headers[ i ] ].length ) { throw new Error( 'invalid data. All columns must have the same number of rows' ); } } return { - 'headers': columns, + 'headers': headers, 'data': rows, 'columnWidths': widths }; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_objects_list.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_objects_list.js index 671854f9d2e6..79894ea57a8d 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_objects_list.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_objects_list.js @@ -20,7 +20,9 @@ // MODULES // +var format = require( '@stdlib/string/format' ); var objectKeys = require( '@stdlib/utils/keys' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); // MAIN // @@ -31,6 +33,7 @@ var objectKeys = require( '@stdlib/utils/keys' ); * @private * @param {Array} data - tabular data * @param {Collection} [headers] - column names +* @throws {Error} must provide valid data * @returns {Object} table metadata */ function parseObjectsList( data, headers ) { @@ -56,6 +59,9 @@ function parseObjectsList( data, headers ) { rows[ i ] = []; for ( j = 0; j < headers.length; j++ ) { header = headers[ j ]; + if ( !hasOwnProp( data[ i ], header ) ) { + throw new Error( format( 'invalid data. Column `%s` not found in data. Value: `%s`.', header, data ) ); + } len = String( data[ i ][ header ] ).length; // Updating max width of column: diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/get.js index 7ab5a7b8d181..09175302ff9e 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/get.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/get.js @@ -18,14 +18,24 @@ 'use strict'; +// MODULES // + +var isArray = require( '@stdlib/assert/is-array' ); + + +// MAIN // + /** -* Returns the table cell alignment. +* Returns the table's cell alignment(s). * * @private -* @returns {string} cell alignment +* @returns {(Array|string)} cell alignment(s) */ function get() { /* eslint-disable no-invalid-this */ + if ( isArray( this._alignment ) ) { + return this._alignment.slice(); + } return this._alignment; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/set.js index e9b5f100e5db..f17065fdb39b 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/set.js @@ -20,34 +20,55 @@ // MODULES // -var contains = require( '@stdlib/assert/contains' ); +var contains = require( '@stdlib/array/base/assert/contains' ).factory; var isString = require( '@stdlib/assert/is-string' ); +var isStringArray = require( '@stdlib/assert/is-string-array' ); +var isEqual = require( '@stdlib/assert/deep-equal' ); var format = require( '@stdlib/string/format' ); // VARIABLES // -var ALIGNMENTS = [ 'right', 'center', 'left' ]; +var isValidAlignment = contains( [ 'right', 'center', 'left' ] ); // MAIN // /** -* Sets the table cell alignment. +* Sets the table's cell alignment(s). * * @private -* @param {string} alignment - cell alignment -* @throws {TypeError} must be a supported alignment string +* @param {(Array|string)} alignment - cell alignment(s) +* @throws {TypeError} must be a supported alignment string or an array of alignment strings +* @throws {RangeError} must provide correct number of columns if providing an array */ function set( alignment ) { /* eslint-disable no-invalid-this */ - if ( !isString( alignment ) ) { - throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'alignment', alignment ) ); + var i; + if ( isString( alignment ) ) { + if ( !isValidAlignment( alignment ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a supported alignment string. Value: `%s`.', 'alignment', alignment ) ); + } + } else if ( isStringArray( alignment ) ) { + for ( i = 0; i < alignment.length; i++ ) { + if ( !isValidAlignment( alignment[ i ] ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of supported alignment strings. Value: `%s`.', 'alignment', alignment ) ); + } + } + if ( this._numColumns ) { + if ( alignment.length !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have `%d` number of columns. Value: `%d`.', 'alignment', this._numColumns, alignment.length ) ); + } + } else { + this._numColumns = alignment.length; + } + } else { + throw new TypeError( format( 'invalid assignment. `%s` must be a string or an array of strings. Value: `%s`.', 'alignment', alignment ) ); } - if ( !contains( ALIGNMENTS, alignment ) ) { - throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', 'alignment', ALIGNMENTS.join( '", "' ), alignment ) ); + if ( !isEqual( alignment, this._alignment ) ) { + this._alignment = alignment; + this.emit( 'change' ); } - this._alignment = alignment; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/auto-render/get.js similarity index 87% rename from lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/get.js rename to lib/node_modules/@stdlib/plot/table/unicode/lib/props/auto-render/get.js index c33cfcc67aa4..19f5a8e9b3df 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/get.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/auto-render/get.js @@ -19,14 +19,14 @@ 'use strict'; /** -* Returns the table's cell padding. +* Returns the rendering mode. * * @private -* @returns {NonNegativeInteger} cell padding +* @returns {boolean} rendering mode */ function get() { /* eslint-disable no-invalid-this */ - return this._cellPadding; + return this._autoRender; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/auto-render/set.js similarity index 67% rename from lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/set.js rename to lib/node_modules/@stdlib/plot/table/unicode/lib/props/auto-render/set.js index ff5365675c3b..343a2305a3ae 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/auto-render/set.js @@ -20,25 +20,28 @@ // MODULES // -var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var format = require( '@stdlib/string/format' ); // MAIN // /** -* Sets the table's cell padding. +* Sets the rendering mode. * * @private -* @param {NonNegativeInteger} padding - cell padding -* @throws {TypeError} must provide a non-negative integer +* @param {boolean} bool - boolean indicating whether to re-render on a change event +* @throws {TypeError} must be a boolean */ -function set( padding ) { +function set( bool ) { /* eslint-disable no-invalid-this */ - if ( !isNonNegativeInteger( padding ) ) { - throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer. Value: `%s`.', 'cellPadding', padding ) ); + if ( !isBoolean( bool ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a boolean. Value: `%s`.', 'autoRender', bool ) ); + } + if ( bool !== this._autoRender ) { + this._autoRender = bool; + this.emit( 'change' ); } - this._cellPadding = padding; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/get.js index f19ba3763f86..ab66d4f30ab2 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/get.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/get.js @@ -22,14 +22,11 @@ * Returns the table's border characters. * * @private -* @returns {string} borders string +* @returns {Array} borders */ function get() { /* eslint-disable no-invalid-this */ - if ( this._borders === 'None' ) { - return 'None'; - } - return this._borders.join( ' ' ); + return this._borders.slice(); } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/set.js index b500f70ce062..f66106e202be 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/set.js @@ -20,14 +20,14 @@ // MODULES // -var isString = require( '@stdlib/assert/is-string' ); +var isStringArray = require( '@stdlib/assert/is-string-array' ); +var isEqual = require( '@stdlib/assert/deep-equal' ); var format = require( '@stdlib/string/format' ); // VARIABLES // -var BORDER_STRING_LEN = 7; -var BORDER_CHARACTERS = 4; +var NUM_BORDERS = 4; // MAIN // @@ -37,27 +37,17 @@ var BORDER_CHARACTERS = 4; * * @private * @param {string} borders - borders string -* @throws {TypeError} must be a four space separated characters or 'None' +* @throws {TypeError} must be an array of four strings */ function set( borders ) { - var arr; - /* eslint-disable no-invalid-this */ - if ( !isString( borders ) ) { - throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'borders', borders ) ); + if ( !isStringArray( borders ) || borders.length !== NUM_BORDERS ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of four strings. Value: `%s`.', 'borders', borders ) ); } - if ( borders === 'None' ) { + if ( !isEqual( borders, this._borders ) ) { this._borders = borders; - return; - } - arr = borders.split( ' ' ); - if ( borders.length !== BORDER_STRING_LEN ) { - throw new TypeError( format( 'invalid assignment. `%s` must be four space separated characters or \'None\'. Value: `%s`.', 'borders', borders ) ); - } - if ( arr.length !== BORDER_CHARACTERS ) { - throw new TypeError( format( 'invalid assignment. `%s` must be four space separated characters or \'None\'. Value: `%s`.', 'borders', borders ) ); + this.emit( 'change' ); } - this._borders = arr; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/getdata.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/buffer-size/get.js similarity index 79% rename from lib/node_modules/@stdlib/plot/table/unicode/lib/getdata.js rename to lib/node_modules/@stdlib/plot/table/unicode/lib/props/buffer-size/get.js index 5b8ab1bda4b0..0e647aff2dee 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/getdata.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/buffer-size/get.js @@ -19,20 +19,17 @@ 'use strict'; /** -* Returns table data and headers. +* Returns the data buffer size. * * @private -* @returns {Object} table data and headers +* @returns {PositiveInteger} data buffer size */ -function getData() { +function get() { /* eslint-disable no-invalid-this */ - return { - 'headers': this._headers, - 'data': this._data - }; + return this._bufferSize; } // EXPORTS // -module.exports = getData; +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/buffer-size/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/buffer-size/set.js new file mode 100644 index 000000000000..d34fddaa3360 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/buffer-size/set.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var isNull = require( '@stdlib/assert/is-null' ); +var format = require( '@stdlib/string/format' ); +var FLOAT64_MAX = require( '@stdlib/constants/float64/max' ); + + +// MAIN // + +/** +* Sets the data buffer size. +* +* @private +* @param {(PositiveInteger|null)} size - data buffer size +* @throws {TypeError} must be a positive integer or null +* @throws {RangeError} must be greater than or equal to the number of rows +*/ +function set( size ) { + /* eslint-disable no-invalid-this */ + var FLG = isNull( size ); + if ( !isPositiveInteger( size ) && !FLG ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a positive integer or null. Value: `%s`.', 'bufferSize', size ) ); + } + if ( FLG ) { + size = FLOAT64_MAX; + } + if ( this._data && size < this._data.length ) { + throw new RangeError( format( 'invalid assignment. `%s` size is less than the number of data elements. Number of elements: `%u`. Value: `%u`.', 'bufferSize', this._data.length, size ) ); + } + if ( size !== this._bufferSize ) { + this._bufferSize = size; + this.emit( 'change' ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-left/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-left/get.js new file mode 100644 index 000000000000..ba983074f66c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-left/get.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isArray = require( '@stdlib/assert/is-array' ); + + +// MAIN // + +/** +* Returns the cell's left padding(s). +* +* @private +* @returns {(Array|NonNegativeInteger)} cell's left padding(s) +*/ +function get() { + /* eslint-disable no-invalid-this */ + if ( isArray( this._cellPaddingLeft ) ) { + return this._cellPaddingLeft.slice(); + } + return this._cellPaddingLeft; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-left/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-left/set.js new file mode 100644 index 000000000000..5d5094ceebdb --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-left/set.js @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); +var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ); +var isEqual = require( '@stdlib/assert/deep-equal' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the cell's left padding(s). +* +* @private +* @param {(Array|NonNegativeInteger)} padding - cell's left padding(s) +* @throws {TypeError} must provide a non-negative integer +* @throws {RangeError} must provide correct number of columns if providing an array +*/ +function set( padding ) { + /* eslint-disable no-invalid-this */ + if ( !isNonNegativeInteger( padding ) && !isNonNegativeIntegerArray( padding ) ) { // eslint-disable-line max-len + throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer or an array of non-negative integers. Value: `%s`.', 'cellPadding', padding ) ); + } + if ( isNonNegativeIntegerArray( padding ) ) { + if ( this._numColumns ) { + if ( padding.length !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have `%d` number of columns. Value: `%d`.', 'padding', this._numColumns, padding.length ) ); + } + } else { + this._numColumns = padding.length; + } + } + if ( !isEqual( padding, this._cellPaddingLeft ) ) { + this._cellPaddingLeft = padding; + this.emit( 'change' ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-right/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-right/get.js new file mode 100644 index 000000000000..a16f7fafb3e1 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-right/get.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isArray = require( '@stdlib/assert/is-array' ); + + +// MAIN // + +/** +* Returns the cell's right padding(s). +* +* @private +* @returns {(Array|NonNegativeInteger)} cell's right padding(s) +*/ +function get() { + /* eslint-disable no-invalid-this */ + if ( isArray( this._cellPaddingRight ) ) { + return this._cellPaddingRight.slice(); + } + return this._cellPaddingRight; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-right/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-right/set.js new file mode 100644 index 000000000000..45329e67db29 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-right/set.js @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); +var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ); +var isEqual = require( '@stdlib/assert/deep-equal' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the cell's right padding(s). +* +* @private +* @param {(Array|NonNegativeInteger)} padding - cell's right padding(s) +* @throws {TypeError} must provide a non-negative integer +* @throws {RangeError} must provide correct number of columns if providing an array +*/ +function set( padding ) { + /* eslint-disable no-invalid-this */ + if ( !isNonNegativeInteger( padding ) && !isNonNegativeIntegerArray( padding ) ) { // eslint-disable-line max-len + throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer or an array of non-negative integers. Value: `%s`.', 'cellPadding', padding ) ); + } + if ( isNonNegativeIntegerArray( padding ) ) { + if ( this._numColumns ) { + if ( padding.length !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have `%d` number of columns. Value: `%d`.', 'padding', this._numColumns, padding.length ) ); + } + } else { + this._numColumns = padding.length; + } + } + if ( !isEqual( padding, this._cellPaddingRight ) ) { + this._cellPaddingRight = padding; + this.emit( 'change' ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/get.js index 60fd29996d58..69395f1df009 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/get.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/get.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Returns the column separator character. +* Returns the column separator character(s). * * @private * @returns {string} column separator diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/set.js index e43341a4c047..2e97c7cc4b91 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/set.js @@ -24,33 +24,24 @@ var isString = require( '@stdlib/assert/is-string' ); var format = require( '@stdlib/string/format' ); -// VARIABLES // - -var CHARACTER_LENGTH = 1; - - // MAIN // /** -* Sets the column separator character. +* Sets the column separator character(s). * * @private * @param {string} separator - column separator -* @throws {TypeError} must be a character string or 'None' +* @throws {TypeError} must be a string */ function set( separator ) { /* eslint-disable no-invalid-this */ if ( !isString( separator ) ) { throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'columnSeparator', separator ) ); } - if ( separator === 'None' ) { + if ( separator !== this._columnSeparator ) { this._columnSeparator = separator; - return; - } - if ( separator.length !== CHARACTER_LENGTH ) { - throw new TypeError( format( 'invalid assignment. `%s` must be a single character or \'None\'. Value: `%s`.', 'columnSeparator', separator ) ); + this.emit( 'change' ); } - this._columnSeparator = separator; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/get.js index 13500c3b0160..bb498efeb240 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/get.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/get.js @@ -22,15 +22,11 @@ * Returns the table's corner characters. * * @private -* @returns {string} corners string +* @returns {Array} corners */ function get() { /* eslint-disable no-invalid-this */ - if ( this._corners[ 0 ] === ' ' ) { - // Empty corner: - return 'None'; - } - return this._corners.join( ' ' ); + return this._corners.slice(); } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/set.js index 6f3c5e03759f..74633d863669 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/set.js @@ -20,15 +20,15 @@ // MODULES // -var isString = require( '@stdlib/assert/is-string' ); +var isStringArray = require( '@stdlib/assert/is-string-array' ); +var numGraphemeClusters = require( '@stdlib/string/num-grapheme-clusters' ); +var isEqual = require( '@stdlib/assert/deep-equal' ); var format = require( '@stdlib/string/format' ); // VARIABLES // -var CORNER_STRING_LEN = 7; -var CORNER_CHARACTERS = 4; -var EMPTY_CORNERS = [ ' ', ' ', ' ', ' ' ]; +var NUM_CORNERS = 4; // MAIN // @@ -37,28 +37,25 @@ var EMPTY_CORNERS = [ ' ', ' ', ' ', ' ' ]; * Sets the table's corner characters. * * @private -* @param {string} corners - corners string -* @throws {TypeError} must be a string with four space separated characters or 'None' +* @param {Array} corners - corners +* @throws {TypeError} must be an array of four grapheme clusters */ function set( corners ) { /* eslint-disable no-invalid-this */ - var arr; + var i; - if ( !isString( corners ) ) { - throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'corners', corners ) ); + if ( !isStringArray( corners ) || corners.length !== NUM_CORNERS ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of four grapheme clusters. Value: `%s`.', 'corners', corners ) ); } - if ( corners === 'None' ) { - this._corners = EMPTY_CORNERS; - return; + for ( i = 0; i < NUM_CORNERS; i++ ) { + if ( numGraphemeClusters( corners[ i ] ) !== 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of four grapheme clusters. Value: `%s`.', 'corners', corners ) ); + } } - arr = corners.split( ' ' ); - if ( corners.length !== CORNER_STRING_LEN ) { - throw new TypeError( format( 'invalid assignment. `%s` must be four space separated characters or \'None\'. Value: `%s`.', 'corners', corners ) ); + if ( !isEqual( corners, this._corners ) ) { + this._corners = corners; + this.emit( 'change' ); } - if ( arr.length !== CORNER_CHARACTERS ) { - throw new TypeError( format( 'invalid assignment. `%s` must be four space separated characters or \'None\'. Value: `%s`.', 'corners', corners ) ); - } - this._corners = arr; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/data/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/data/get.js new file mode 100644 index 000000000000..26e6b99c9d67 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/data/get.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isArray = require( '@stdlib/assert/is-array' ); + + +// MAIN // + +/** +* Returns table data. +* +* @private +* @returns {Array|null} table data +*/ +function get() { + /* eslint-disable no-invalid-this */ + if ( isArray( this._data ) ) { + return this._data.slice(); + } + return this._data; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/data/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/data/set.js new file mode 100644 index 000000000000..3d6583c3da87 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/data/set.js @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var format = require( '@stdlib/string/format' ); +var isMatrixLike = require( '@stdlib/assert/is-matrix-like' ); +var isArrayArray = require( '@stdlib/assert/is-array-array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var isEqual = require( '@stdlib/assert/deep-equal' ); +var parse2dArray = require( './../../parser/parse_2d_array.js' ); + + +// MAIN // + +/** +* Sets the table data. +* +* @private +* @param {Array|MatrixLike} data - table data +* @throws {TypeError} must be a 2 dimensional array/ndarray +* @throws {RangeError} must provide correct number of columns +* @throws {RangeError} rows must not exceed maximum data buffer size +*/ +function set( data ) { + /* eslint-disable no-invalid-this */ + var parsed; + if ( isMatrixLike( data ) ) { + data = ndarray2array( data ); + } + if ( !isArrayArray( data ) ) { + throw new TypeError( format( 'invalid argument. `%s` must be an object, array of objects, or a 2 dimensional array/ndarray. Value: `%s`.', 'data', data ) ); + } + parsed = parse2dArray( data, this._headers ); + if ( parsed.data.length > this._bufferSize ) { + throw new RangeError( format( 'invalid assignment. `%s` length exceeds maximum data buffer size. Buffer size: `%u`. Length: `%u`.', 'data', this._bufferSize, parsed.data.length ) ); + } + if ( this._numColumns ) { + if ( parsed.columnWidths.length !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have `%d` number of columns. Value: `%d`.', 'data', this._numColumns, parsed.columnWidths.length ) ); + } + } else { + this._numColumns = parsed.columnWidths.length; + } + if ( !isEqual( parsed.data, this._data ) ) { + this._data = parsed.data; + this._columnWidths = parsed.columnWidths; + this.emit( 'change' ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/get.js index 8f87e32abca4..251f39912e81 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/get.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/get.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Returns the header separator character. +* Returns the header separator character(s). * * @private * @returns {string} header separator diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/set.js index 584db81ebea1..592bb4bc9090 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/set.js @@ -24,33 +24,24 @@ var isString = require( '@stdlib/assert/is-string' ); var format = require( '@stdlib/string/format' ); -// VARIABLES // - -var CHARACTER_LENGTH = 1; - - // MAIN // /** -* Sets the header separator character. +* Sets the header separator character(s). * * @private * @param {string} separator - header separator -* @throws {TypeError} must be a character string or 'None' +* @throws {TypeError} must be a string */ function set( separator ) { /* eslint-disable no-invalid-this */ if ( !isString( separator ) ) { throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'headerSeparator', separator ) ); } - if ( separator === 'None' ) { + if ( separator !== this._headerSeparator ) { this._headerSeparator = separator; - return; - } - if ( separator.length !== CHARACTER_LENGTH ) { - throw new TypeError( format( 'invalid assignment. `%s` must be a character or \'None\'. Value: `%s`.', 'headerSeparator', separator ) ); + this.emit( 'change' ); } - this._headerSeparator = separator; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/get.js new file mode 100644 index 000000000000..f92278d36f41 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/get.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isArray = require( '@stdlib/assert/is-array' ); + + +// MAIN // + +/** +* Returns table headers. +* +* @private +* @returns {Array|null} table headers +*/ +function get() { + /* eslint-disable no-invalid-this */ + if ( isArray( this._headers ) ) { + return this._headers.slice(); + } + return this._headers; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/set.js new file mode 100644 index 000000000000..a3d90bcc23ec --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/set.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var format = require( '@stdlib/string/format' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var isEqual = require( '@stdlib/assert/deep-equal' ); +var parseHeaders = require( './../../parser/parse_headers.js' ); + + +// MAIN // + +/** +* Sets the table data. +* +* @private +* @param {Collection} headers - table headers +* @throws {TypeError} must be a collection +* @throws {RangeError} must provide correct number of columns +*/ +function set( headers ) { + /* eslint-disable no-invalid-this */ + var parsed; + if ( !isCollection( headers ) ) { + throw new TypeError( format( 'invalid argument. `%s` must be a collection. Value: `%s`.', 'headers', headers ) ); + } + parsed = parseHeaders( headers, this._columnWidths ); + if ( this._numColumns ) { + if ( parsed.headers.length !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have `%d` number of columns. Value: `%d`.', 'headers', this._numColumns, parsed.columnWidths.length ) ); + } + } else { + this._numColumns = parsed.columnWidths.length; + } + if ( !isEqual( parsed.headers, this._headers ) ) { + this._headers = parsed.headers; + this._columnWidths = parsed.columnWidths; + this.emit( 'change' ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/horizontal-separator-mode/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/horizontal-separator-mode/get.js new file mode 100644 index 000000000000..f23865de9cdf --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/horizontal-separator-mode/get.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the table's horizontal line separator mode. +* +* @private +* @returns {string} line separator mode +*/ +function get() { + /* eslint-disable no-invalid-this */ + return this._horizontalSeparatorMode; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/horizontal-separator-mode/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/horizontal-separator-mode/set.js new file mode 100644 index 000000000000..aa31f0ef2cfb --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/horizontal-separator-mode/set.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var isString = require( '@stdlib/assert/is-string' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var isValidMode = contains( [ 'resume', 'interpolate', 'repeat' ] ); + + +// MAIN // + +/** +* Sets the table's horizontal line separator mode. +* +* @private +* @param {string} mode - line separator mode +* @throws {TypeError} must be a supported line separator mode string +*/ +function set( mode ) { + /* eslint-disable no-invalid-this */ + if ( !isString( mode ) || !isValidMode( mode ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a valid line separator mode string. Value: `%s`.', 'lineSeparatorMode', mode ) ); + } + if ( mode !== this._horizontalSeparatorMode ) { + this._horizontalSeparatorMode = mode; + this.emit( 'change' ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/get.js index 1a8a6811697c..1d2ba1b9cb38 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/get.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/get.js @@ -22,15 +22,11 @@ * Returns the joint characters. * * @private -* @returns {string} joint character +* @returns {Array} joint characters */ function get() { /* eslint-disable no-invalid-this */ - if ( this._joints[ 0 ] === ' ' ) { - // Empty joint: - return 'None'; - } - return this._joints.join( ' ' ); + return this._joints.slice(); } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/set.js index 1ba1a89ce48b..3307a16f32d4 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/set.js @@ -20,15 +20,15 @@ // MODULES // -var isString = require( '@stdlib/assert/is-string' ); +var isStringArray = require( '@stdlib/assert/is-string-array' ); +var numGraphemeClusters = require( '@stdlib/string/num-grapheme-clusters' ); +var isEqual = require( '@stdlib/assert/deep-equal' ); var format = require( '@stdlib/string/format' ); // VARIABLES // -var JOINT_STRING_LEN = 9; -var JOINT_CHARACTERS = 5; -var EMPTY_JOINTS = [ ' ', ' ', ' ', ' ', ' ' ]; +var NUM_JOINTS = 5; // MAIN // @@ -37,28 +37,25 @@ var EMPTY_JOINTS = [ ' ', ' ', ' ', ' ', ' ' ]; * Sets the joint characters. * * @private -* @param {string} joints - joint character -* @throws {TypeError} must be a string with five space separated characters or 'None' +* @param {Array} joints - joint characters +* @throws {TypeError} must be an array of five grapheme clusters */ function set( joints ) { /* eslint-disable no-invalid-this */ - var arr; + var i; - if ( !isString( joints ) ) { - throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'joints', joints ) ); + if ( !isStringArray( joints ) || joints.length !== NUM_JOINTS ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of five grapheme clusters. Value: `%s`.', 'joints', joints ) ); } - if ( joints === 'None' ) { - this._joints = EMPTY_JOINTS; - return; + for ( i = 0; i < NUM_JOINTS; i++ ) { + if ( numGraphemeClusters( joints[ i ] ) !== 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of five grapheme clusters. Value: `%s`.', 'joints', joints ) ); + } } - arr = joints.split( ' ' ); - if ( joints.length !== JOINT_STRING_LEN ) { - throw new TypeError( format( 'invalid assignment. `%s` must be five space separated characters or \'None\'. Value: `%s`.', 'joints', joints ) ); + if ( !isEqual( joints, this._joints ) ) { + this._joints = joints; + this.emit( 'change' ); } - if ( arr.length !== JOINT_CHARACTERS ) { - throw new TypeError( format( 'invalid assignment. `%s` must be five space separated characters or \'None\'. Value: `%s`.', 'joints', joints ) ); - } - this._joints = arr; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-x/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-x/set.js index 66407ad7200d..c424112179be 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-x/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-x/set.js @@ -38,7 +38,10 @@ function set( x ) { if ( !isNonNegativeInteger( x ) ) { throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer. Value: `%s`.', 'marginX', x ) ); } - this._marginX = x; + if ( x !== this._marginX ) { + this._marginX = x; + this.emit( 'change' ); + } } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-y/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-y/set.js index f1c5652c7c53..2ba10b80f880 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-y/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-y/set.js @@ -38,7 +38,10 @@ function set( y ) { if ( !isNonNegativeInteger( y ) ) { throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer. Value: `%s`.', 'marginY', y ) ); } - this._marginY = y; + if ( y !== this._marginY ) { + this._marginY = y; + this.emit( 'change' ); + } } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/get.js index 10513c017df6..2936f0d15728 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/get.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/get.js @@ -18,14 +18,24 @@ 'use strict'; +// MODULES // + +var isArray = require( '@stdlib/assert/is-array' ); + + +// MAIN // + /** -* Returns the table's max cell width. +* Returns the table's max cell width(s). * * @private -* @returns {NonNegativeInteger} max cell width +* @returns {(Array|NonNegativeInteger)} max cell width(s) */ function get() { /* eslint-disable no-invalid-this */ + if ( isArray( this._maxCellWidth ) ) { + return this._maxCellWidth.slice(); + } return this._maxCellWidth; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/set.js index a5762c2e6f63..8f9f31341fd5 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-cell-width/set.js @@ -21,24 +21,61 @@ // MODULES // var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isNull = require( '@stdlib/assert/is-null' ); +var isEqual = require( '@stdlib/assert/deep-equal' ); var format = require( '@stdlib/string/format' ); +var FLOAT64_MAX = require( '@stdlib/constants/float64/max' ); // MAIN // /** -* Sets the table's max cell width. +* Sets the table's max cell width(s). * * @private -* @param {NonNegativeInteger} width - max cell width -* @throws {TypeError} must provide a non-negative integer +* @param {(Array|NonNegativeInteger|null)} width - max cell width(s) +* @throws {TypeError} must provide a non-negative integer, an array of non-negative integers or null +* @throws {RangeError} must provide correct number of columns if providing an array */ function set( width ) { /* eslint-disable no-invalid-this */ - if ( !isNonNegativeInteger( width ) ) { - throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer. Value: `%s`.', 'maxCellWidth', width ) ); + var out; + var FLG; + var i; + + FLG = isNull( width ); + if ( !isNonNegativeInteger( width ) && !isArray( width ) && !FLG ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer or an array of non-negative integers. Value: `%s`.', 'width', width ) ); + } + if ( isArray( width ) ) { + out = []; + for ( i = 0; i < width.length; i++ ) { + if ( isNull( width[ i ] ) ) { + out.push( FLOAT64_MAX ); + continue; + } + if ( !isNonNegativeInteger( width[ i ] ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer or an array of non-negative integers. Value: `%s`.', 'width', width ) ); + } + out.push( width[ i ] ); + } + if ( this._numColumns ) { + if ( out.length !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have `%d` number of columns. Value: `%d`.', 'width', this._numColumns, width.length ) ); + } + } else { + this._numColumns = out.length; + } + } else if ( FLG ) { + out = FLOAT64_MAX; + } else { + out = width; + } + if ( !isEqual( out, this._maxCellWidth ) ) { + this._maxCellWidth = out; + this.emit( 'change' ); } - this._maxCellWidth = width; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-output-width/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-output-width/set.js index 59d2ab40e686..b87da48ef6cc 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-output-width/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-output-width/set.js @@ -21,7 +21,9 @@ // MODULES // var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); +var isNull = require( '@stdlib/assert/is-null' ); var format = require( '@stdlib/string/format' ); +var FLOAT64_MAX = require( '@stdlib/constants/float64/max' ); // MAIN // @@ -30,15 +32,22 @@ var format = require( '@stdlib/string/format' ); * Sets the table's max output width. * * @private -* @param {NonNegativeInteger} width - max output width -* @throws {TypeError} must provide a non-negative integer +* @param {(NonNegativeInteger|null)} width - max output width +* @throws {TypeError} must provide a non-negative integer or null */ function set( width ) { /* eslint-disable no-invalid-this */ - if ( !isNonNegativeInteger( width ) ) { - throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer. Value: `%s`.', 'maxOutputWidth', width ) ); + var FLG = isNull( width ); + if ( !isNonNegativeInteger( width ) && !FLG ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a non-negative integer or null. Value: `%s`.', 'maxOutputWidth', width ) ); + } + if ( FLG ) { + width = FLOAT64_MAX; + } + if ( width !== this._maxOutputWidth ) { + this._maxOutputWidth = width; + this.emit( 'change' ); } - this._maxOutputWidth = width; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/get.js index d404104acc21..ba503a4e2ddb 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/get.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/get.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Returns the row separator character. +* Returns the row separator character(s). * * @private * @returns {string} row separator diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/set.js index 0c824793df1d..3b2c96821a39 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/set.js @@ -24,33 +24,24 @@ var isString = require( '@stdlib/assert/is-string' ); var format = require( '@stdlib/string/format' ); -// VARIABLES // - -var CHARACTER_LENGTH = 1; - - // MAIN // /** -* Sets the row separator character. +* Sets the row separator character(s). * * @private * @param {string} separator - row separator -* @throws {TypeError} must be a character string or 'None' +* @throws {TypeError} must be a string */ function set( separator ) { /* eslint-disable no-invalid-this */ if ( !isString( separator ) ) { throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'rowSeparator', separator ) ); } - if ( separator === 'None' ) { + if ( separator !== this._rowSeparator ) { this._rowSeparator = separator; - return; - } - if ( separator.length !== CHARACTER_LENGTH ) { - throw new TypeError( format( 'invalid assignment. `%s` must be a character or \'None\'. Value: `%s`.', 'rowSeparator', separator ) ); + this.emit( 'change' ); } - this._rowSeparator = separator; } diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/vertical-separator-mode/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/vertical-separator-mode/get.js new file mode 100644 index 000000000000..b8760b12e1c2 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/vertical-separator-mode/get.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Returns the table's vertical line separator mode. +* +* @private +* @returns {string} line separator mode +*/ +function get() { + /* eslint-disable no-invalid-this */ + return this._verticalSeparatorMode; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/vertical-separator-mode/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/vertical-separator-mode/set.js new file mode 100644 index 000000000000..9c40fb45a651 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/vertical-separator-mode/set.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var isString = require( '@stdlib/assert/is-string' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var isValidMode = contains( [ 'resume', 'interpolate', 'repeat' ] ); + + +// MAIN // + +/** +* Sets the table's vertical line separator mode. +* +* @private +* @param {string} mode - line separator mode +* @throws {TypeError} must be a supported line separator mode string +*/ +function set( mode ) { + /* eslint-disable no-invalid-this */ + if ( !isString( mode ) || !isValidMode( mode ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a valid line separator mode string. Value: `%s`.', 'lineSeparatorMode', mode ) ); + } + if ( mode !== this._verticalSeparatorMode ) { + this._verticalSeparatorMode = mode; + this.emit( 'change' ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/addrow.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/push.js similarity index 61% rename from lib/node_modules/@stdlib/plot/table/unicode/lib/addrow.js rename to lib/node_modules/@stdlib/plot/table/unicode/lib/push.js index caeeb454ca15..85b3393a3344 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/addrow.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/push.js @@ -28,14 +28,15 @@ var parse2dArray = require( './parser/parse_2d_array.js' ); // MAIN // /** -* Adds a row to table data. +* Appends row. * * @private * @param {Collection} row - row to add -* @throws {TypeError} must provide a collection with equal number of columns to existing data +* @throws {TypeError} must provide a collection +* @throws {RangeError} must provide correct number of columns * @returns {UnicodeTable} class instance */ -function addRow( row ) { +function push( row ) { /* eslint-disable no-invalid-this */ var parsed; @@ -45,19 +46,33 @@ function addRow( row ) { // If data doesn't already exist, parse row as new data... if ( !this._data || !this._data.length ) { parsed = parse2dArray( [ row ], this._headers ); + if ( this._numColumns ) { + if ( parsed.columnWidths.length !== this._numColumns ) { + throw new RangeError( format( 'invalid argument. `%s` must have `%d` number of columns. Value: `%d`.', 'data', this._numColumns, parsed.columnWidths.length ) ); + } + } else { + this._numColumns = parsed.columnWidths.length; + } this._data = parsed.data; this._headers = parsed.headers; this._columnWidths = parsed.columnWidths; + this.emit( 'change' ); return this; } - if ( this._data[ 0 ].length !== row.length ) { - throw new TypeError( format( 'invalid argument. Must provide a collection with equal number of columns to existing data. Value: `%s`.', row ) ); + if ( this._numColumns !== row.length ) { + throw new RangeError( format( 'invalid argument. `%s` must have `%d` number of columns. Value: `%d`.', 'data', this._numColumns, row.length ) ); + } + if ( this._data.length >= this._bufferSize ) { + this._data.shift(); } this._data.push( row ); + parsed = parse2dArray( this._data, this._headers ); + this._columnWidths = parsed.columnWidths; + this.emit( 'change' ); return this; } // EXPORTS // -module.exports = addRow; +module.exports = push; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/render.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/render.js index b6829c758a98..601f3d6ad632 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/render.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/render.js @@ -16,12 +16,18 @@ * limitations under the License. */ +/* eslint-disable no-invalid-this, no-underscore-dangle, max-lines-per-function */ + 'use strict'; // MODULES // var format = require( '@stdlib/string/format' ); var repeat = require( '@stdlib/string/repeat' ); +var splitGraphemeClusters = require( '@stdlib/string/split-grapheme-clusters' ); +var isString = require( '@stdlib/assert/is-string' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); +var filled = require( '@stdlib/array/base/filled' ); var floor = require( '@stdlib/math/base/special/floor' ); var ceil = require( '@stdlib/math/base/special/ceil' ); var min = require( '@stdlib/math/base/special/min' ); @@ -39,8 +45,16 @@ var truncate = require( '@stdlib/string/truncate' ); * @returns {string} rendered table */ function render() { - /* eslint-disable no-invalid-this, no-underscore-dangle */ + var verticalLineIdx; + var columnSeparator; + var headerSeparator; + var maxCellWidths; + var paddingsRight; + var rowSeparator; + var paddingsLeft; var wrapIndices; + var alignments; + var borders; var widths; var start; var table; @@ -55,10 +69,8 @@ function render() { self = this; out = ''; - if ( !this._columnWidths ) { - // Empty table: - return out; - } + // Resolve table properties: + resolveProps(); // Resolve indices to wrap the table at: wrapIndices = resolveWrapping(); @@ -70,14 +82,18 @@ function render() { wraps = []; for ( j = 0; j < wrapIndices.length - 1; j++ ) { table = ''; + verticalLineIdx = 0; start = wrapIndices[ j ]; end = wrapIndices[ j + 1 ]; // Render top border: - if ( this._borders !== 'None' ) { + if ( borders[ 0 ].length !== 0 ) { widths = slice( this._columnWidths, start, end ); - table += renderLine( this._borders[ 0 ], widths, this._corners[ 0 ], this._joints[ 1 ], this._corners[ 1 ] ); // eslint-disable-line max-len + table += renderLine( borders[ 0 ], widths, this._corners[ 0 ], this._joints[ 1 ], this._corners[ 1 ] ); // eslint-disable-line max-len table += '\n'; + if ( this._verticalSeparatorMode === 'interpolate' ) { + verticalLineIdx += 1; + } } // Render headers: @@ -86,13 +102,19 @@ function render() { widths = slice( this._columnWidths, start, end ); table += renderRow( row, widths ); table += '\n'; + verticalLineIdx += 1; } // Render header separator: - if ( this._headers && this._headerSeparator !== 'None' ) { + if ( this._headers && headerSeparator.length !== 0 ) { widths = slice( this._columnWidths, start, end ); - table += renderLine( this._headerSeparator, widths, this._joints[ 4 ], this._joints[ 0 ], this._joints[ 2 ] ); // eslint-disable-line max-len + table += renderLine( headerSeparator, widths, this._joints[ 4 ], this._joints[ 0 ], this._joints[ 2 ] ); // eslint-disable-line max-len table += '\n'; + if ( this._verticalSeparatorMode === 'interpolate' ) { + verticalLineIdx += 1; + } else if ( this._verticalSeparatorMode === 'repeat' ) { + verticalLineIdx = 0; + } } // Render data: @@ -102,22 +124,30 @@ function render() { row = slice( this._data[ i ], start, end ); widths = slice( this._columnWidths, start, end ); table += renderRow( row, widths ); - if ( i !== this._data.length - 1 || this._borders !== 'None' ) { + if ( i !== this._data.length - 1 ) { table += '\n'; } + verticalLineIdx += 1; + // Render row separator: - if ( this._rowSeparator !== 'None' && i !== this._data.length - 1 ) { + if ( rowSeparator.length !== 0 && i !== this._data.length - 1 ) { // eslint-disable-line max-len widths = slice( this._columnWidths, start, end ); - table += renderLine( this._rowSeparator, widths, this._joints[ 4 ], this._joints[ 0 ], this._joints[ 2 ] ); // eslint-disable-line max-len + table += renderLine( rowSeparator, widths, this._joints[ 4 ], this._joints[ 0 ], this._joints[ 2 ] ); // eslint-disable-line max-len table += '\n'; + if ( this._verticalSeparatorMode === 'interpolate' ) { + verticalLineIdx += 1; + } else if ( this._verticalSeparatorMode === 'repeat' ) { + verticalLineIdx = 0; + } } } } // Render bottom border: - if ( this._borders !== 'None' ) { + if ( borders[ 2 ].length !== 0 ) { + table += '\n'; widths = slice( this._columnWidths, start, end ); - table += renderLine( this._borders[ 2 ], widths, this._corners[ 3 ], this._joints[ 3 ], this._corners[ 2 ] ); // eslint-disable-line max-len + table += renderLine( borders[ 2 ], widths, this._corners[ 3 ], this._joints[ 3 ], this._corners[ 2 ] ); // eslint-disable-line max-len } wraps.push( table ); } @@ -125,8 +155,46 @@ function render() { // Render bottom margin: out += repeat( '\n', this._marginY ); + + this.emit( 'render', out ); return out; + /** + * Resolves table properties for rendering. + * + * @private + */ + function resolveProps() { + var i; + if ( isString( self._alignment ) ) { + alignments = filled( self._alignment, self._numColumns ); + } else { + alignments = self._alignment; + } + if ( isNonNegativeInteger( self._cellPaddingLeft ) ) { + paddingsLeft = filled( self._cellPaddingLeft, self._numColumns ); + } else { + paddingsLeft = self._cellPaddingLeft; + } + if ( isNonNegativeInteger( self._cellPaddingRight ) ) { + paddingsRight = filled( self._cellPaddingRight, self._numColumns ); + } else { + paddingsRight = self._cellPaddingRight; + } + if ( isNonNegativeInteger( self._maxCellWidth ) ) { + maxCellWidths = filled( self._maxCellWidth, self._numColumns ); + } else { + maxCellWidths = self._maxCellWidth; + } + borders = []; + for ( i = 0; i < self._borders.length; i++ ) { + borders.push( splitGraphemeClusters( self._borders[ i ] ) ); + } + columnSeparator = splitGraphemeClusters( self._columnSeparator ); + headerSeparator = splitGraphemeClusters( self._headerSeparator ); + rowSeparator = splitGraphemeClusters( self._rowSeparator ); + } + /** * Resolves columns to wrap the table at (includes bounding indices). * @@ -137,7 +205,6 @@ function render() { function resolveWrapping() { var outputWidth; var fixedLength; - var colWidth; var indices; // Initialize with zeroth index: @@ -145,13 +212,18 @@ function render() { // Calculate fixed horizontal length: fixedLength = 2 * self._marginX; - if ( self._borders !== 'None' ) { - fixedLength += 2; + if ( borders[ 1 ] !== 0 ) { + fixedLength += 1; + } + if ( borders[ 3 ] !== 0 ) { + fixedLength += 1; + } + if ( !self._columnWidths ) { + return indices; } outputWidth = 0; for ( i = 0; i < self._columnWidths.length; i++ ) { - colWidth = min( self._columnWidths[ i ], self._maxCellWidth ); // width of current column - outputWidth += colWidth + ( 2 * self._cellPadding ); + outputWidth += min( self._columnWidths[ i ] + ( paddingsLeft[ i ] + paddingsRight[ i ] ), maxCellWidths[ i ] ); // eslint-disable-line max-len // If output crosses the maximum, time to wrap: if ( outputWidth + fixedLength > self._maxOutputWidth ) { @@ -164,7 +236,7 @@ function render() { continue; } // Include column separator. Exclude for last column as we included them as borders: - if ( i !== self._columnWidths.length - 1 && self._columnSeparator !== 'None' ) { + if ( i !== self._columnWidths.length - 1 && columnSeparator.length !== 0 ) { // eslint-disable-line max-len outputWidth += 1; } } @@ -177,38 +249,52 @@ function render() { * Renders a line. * * @private - * @param {string} lineChar - line character + * @param {string} lineChars - line character * @param {Array} columnWidths - column widths * @param {string} jointL - left joint * @param {string} jointM - middle joint * @param {jointR} jointR - right joint * @returns {string} rendered line */ - function renderLine( lineChar, columnWidths, jointL, jointM, jointR ) { + function renderLine( lineChars, columnWidths, jointL, jointM, jointR ) { + var horizontalLineIdx; var colWidth; var out; var i; + var j; out = ''; + horizontalLineIdx = 0; // Render left margin: out += repeat( ' ', self._marginX ); // Render left joint: - if ( self._borders !== 'None' ) { + if ( borders[ 3 ].length !== 0 ) { out += jointL; + if ( self._horizontalSeparatorMode === 'interpolate' ) { + horizontalLineIdx += 1; + } } // Render line: for ( i = 0; i < columnWidths.length; i++ ) { // If columns are separated, render the middle joint... - if ( self._columnSeparator !== 'None' && i !== 0 ) { + if ( columnSeparator.length !== 0 && i !== 0 ) { out += jointM; + if ( self._horizontalSeparatorMode === 'interpolate' ) { + horizontalLineIdx += 1; + } else if ( self._horizontalSeparatorMode === 'repeat' ) { + horizontalLineIdx = 0; + } + } + colWidth = min( columnWidths[ i ] + ( paddingsLeft[ i ] + paddingsRight[ i ] ), maxCellWidths[ i ] ); // eslint-disable-line max-len + for ( j = 0; j < colWidth; j++ ) { + out += lineChars[ horizontalLineIdx % lineChars.length ]; + horizontalLineIdx += 1; } - colWidth = min( columnWidths[ i ], self._maxCellWidth ); - out += repeat( lineChar, colWidth + ( 2 * self._cellPadding ) ); } // Render right joint: - if ( self._borders !== 'None' ) { + if ( borders[ 1 ].length !== 0 ) { out += jointR; } // Render right margin: @@ -225,6 +311,7 @@ function render() { * @returns {string} rendered line */ function renderRow( data, columnWidths ) { + var maxDatumWidth; var width; var datum; var out; @@ -236,24 +323,27 @@ function render() { out += repeat( ' ', self._marginX ); // Render left border: - if ( self._borders !== 'None' ) { - out += self._borders[ 3 ]; + if ( borders[ 3 ].length !== 0 ) { + out += borders[ 3 ][ verticalLineIdx % borders[ 3 ].length ]; } for ( i = 0; i < columnWidths.length; i++ ) { // Render column separator... - if ( self._columnSeparator !== 'None' && i !== 0 ) { - out += self._columnSeparator; + if ( columnSeparator.length !== 0 && i !== 0 ) { + out += columnSeparator[ verticalLineIdx % columnSeparator.length ]; // eslint-disable-line max-len } // Render left cell padding: - out += repeat( ' ', self._cellPadding ); + out += repeat( ' ', paddingsLeft[ i ] ); + + // If datum is longer than what is allowed by `maxCellWidth`, truncate it... datum = String( data[ i ] ); - width = min( columnWidths[ i ], self._maxCellWidth ); - if ( datum.length > self._maxCellWidth ) { - // Truncate long datum: - datum = truncate( datum, self._maxCellWidth ); + maxDatumWidth = maxCellWidths[ i ] - ( paddingsLeft[ i ] + paddingsRight[ i ] ); // eslint-disable-line max-len + width = columnWidths[ i ]; + if ( width > maxDatumWidth ) { + datum = truncate( datum, maxDatumWidth ); + width = maxDatumWidth; } // Render datum: - switch ( self._alignment ) { + switch ( alignments[ i ] ) { case 'left': out += datum; out += repeat( ' ', width - datum.length ); @@ -271,11 +361,11 @@ function render() { break; } // Render right cell padding: - out += repeat( ' ', self._cellPadding ); + out += repeat( ' ', paddingsRight[ i ] ); } // Render right border: - if ( self._borders !== 'None' ) { - out += self._borders[ 1 ]; + if ( borders[ 1 ].length !== 0 ) { + out += borders[ 1 ][ verticalLineIdx % borders[ 1 ].length ]; } // Render right margin: out += repeat( ' ', self._marginX ); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.add_row.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.add_row.js deleted file mode 100644 index 12d2ba6cf4f5..000000000000 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.add_row.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ctor = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctor, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function adds a row to existing data', function test( t ) { - var expected; - var headers; - var table; - var data; - var row; - var v; - - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - headers = [ 'col1', 'col2', 'col3' ]; - table = ctor( data, headers ); - - row = [ 1, true, 'hello' ]; - table.addRow( row ); - v = table.getData(); - - expected = {}; - expected.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ], [ 1, true, 'hello' ] ]; - expected.headers = [ 'col1', 'col2', 'col3' ]; - - t.deepEqual( v, expected, 'sets table data' ); - - t.end(); -}); - -tape( 'the function creates table data if no existing data found', function test( t ) { - var expected; - var table; - var row; - var v; - - table = ctor(); - - row = [ 1, true, 'hello' ]; - table.addRow( row ); - v = table.getData(); - - expected = {}; - expected.data = [ [ 1, true, 'hello' ] ]; - expected.headers = null; - - t.deepEqual( v, expected, 'sets table data' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.alignment.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.alignment.js index 5bd1dff4e153..0fa4b33bbf2b 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.alignment.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.alignment.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); var ctor = require( './../lib' ); @@ -46,7 +47,9 @@ tape( 'an instance throws an error if provided an invalid `alignment` value', fu {}, [], '1234', - 'middle' + 'middle', + [ 4, 'hello', null ], + [ 'beep', 'boop' ] ]; for ( i = 0; i < values.length; i++ ) { @@ -64,11 +67,13 @@ tape( 'an instance throws an error if provided an invalid `alignment` value', fu tape( 'an instance supports setting and getting the property value', function test( t ) { var table; - var data = null; + var arr; - table = ctor( data, { + table = ctor( null, { 'alignment': 'right' }); + table.render = noop; + t.strictEqual( table.alignment, 'right', 'returns expected value' ); table.alignment = 'left'; @@ -77,5 +82,68 @@ tape( 'an instance supports setting and getting the property value', function te table.alignment = 'center'; t.strictEqual( table.alignment, 'center', 'returns expected value' ); + arr = [ 'left', 'right', 'center' ]; + table.alignment = arr; + t.notEqual( table.alignment, arr, 'returns a new reference' ); + t.deepEqual( table.alignment, arr, 'returns expected value' ); + + t.end(); +}); + +tape( 'an instance throws an error if provided an `alignment` array with incorrect number of columns', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + var table = ctor( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); // 3 columns + table.alignment = [ 'left', 'right' ]; // 2 columns + } +}); + +tape( 'settings the `alignment` property to an array sets number of columns', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); t.end(); + + function badValue() { + var table = ctor( null, { + 'alignment': [ 'left', 'center', 'right' ] // 3 columns + }); + table.data = [ [ 1, 2 ], [ 4, 5 ] ]; // 2 columns + } +}); + +tape( 'setting the `alignment` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'alignment': 'right' + }); + table.render = noop; + + table.on( 'change', onChange ); + table.alignment = [ 'left', 'right' ]; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `alignment` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'alignment': [ 'left', 'right' ] + }); + table.render = noop; + + table.on( 'change', onChange ); + table.alignment = [ 'left', 'right' ]; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } }); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.auto_render.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.auto_render.js new file mode 100644 index 000000000000..05bbdbe6c379 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.auto_render.js @@ -0,0 +1,152 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `autoRender` value', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.autoRender = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + + table = ctor( null, { + 'autoRender': false + }); + table.render = noop; + t.strictEqual( table.autoRender, false, 'returns expected value' ); + + table.autoRender = true; + t.strictEqual( table.autoRender, true, 'returns expected value' ); + + table.autoRender = false; + t.strictEqual( table.autoRender, false, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `autoRender` is `true`, when a returned instance receives a `change` event, it re-renders and emits a `render` event', function test( t ) { + var table; + + table = ctor( null, { + 'autoRender': true + }); + + table.on( 'render', onRender ); + table.emit( 'change' ); + + function onRender( str ) { + t.ok( true, 'emits a render event' ); + t.strictEqual( str, '', 'provides expected value' ); + t.end(); + } +}); + +tape( 'if `autoRender` is `false`, when a returned instance receives a `change` event, it does not re-render or emit a `render` event', function test( t ) { + var table; + + table = ctor( null, { + 'autoRender': false + }); + table.render = noop; + + table.on( 'render', onRender ); + table.emit( 'change' ); + + t.pass( 'is ok' ); + t.end(); + + function onRender() { + t.fail( 'should never be invoked' ); + } +}); + +tape( 'setting the `autoRender` property triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'autoRender': false + }); + table.render = noop; + + table.on( 'change', onChange ); + table.autoRender = true; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `autoRender` property to an existing value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'autoRender': true + }); + table.render = noop; + + table.on( 'change', onChange ); + table.autoRender = true; + + t.pass( 'is ok' ); + t.end(); + + function onChange() { + t.fail( 'should never be called' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.borders.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.borders.js index f1bc1538cf28..086c9d6d8885 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.borders.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.borders.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); var ctor = require( './../lib' ); @@ -45,8 +46,9 @@ tape( 'an instance throws an error if provided an invalid `borders` value', func void 0, {}, [], - 'hello', - '1234567' + 'beep', + [ 4, 'hello', null, 'world' ], + [ 'beep', 'boop', 'foo' ] ]; for ( i = 0; i < values.length; i++ ) { @@ -64,18 +66,60 @@ tape( 'an instance throws an error if provided an invalid `borders` value', func tape( 'an instance supports setting and getting the property value', function test( t ) { var table; - var data = null; + var arr; - table = ctor( data, { - 'borders': '1 2 3 4' + arr = [ '-', '|', '=', '!' ]; + table = ctor( null, { + 'borders': arr }); - t.strictEqual( table.borders, '1 2 3 4', 'returns expected value' ); + t.notEqual( table.borders, arr, 'returns a new reference' ); + t.deepEqual( table.borders, arr, 'returns expected value' ); - table.borders = '- | _ |'; - t.strictEqual( table.borders, '- | _ |', 'returns expected value' ); + arr = [ '1', '23', '456', '7890' ]; + table.borders = arr; + t.notEqual( table.borders, arr, 'returns a new reference' ); + t.deepEqual( table.borders, arr, 'returns expected value' ); - table.borders = 'None'; - t.strictEqual( table.borders, 'None', 'returns expected value' ); + arr = [ '', '🌹', '', '@🥀' ]; + table.borders = arr; + t.notEqual( table.borders, arr, 'returns a new reference' ); + t.deepEqual( table.borders, arr, 'returns expected value' ); t.end(); }); + +tape( 'setting the `borders` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'borders': [ '-', '|', '=', '!' ] + }); + table.render = noop; + + table.on( 'change', onChange ); + table.borders = [ '1', '23', '456', '7890' ]; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `borders` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'borders': [ '-', '|', '=', '!' ] + }); + table.render = noop; + + table.on( 'change', onChange ); + table.borders = [ '-', '|', '=', '!' ]; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.buffer_size.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.buffer_size.js new file mode 100644 index 000000000000..b44594ac2e68 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.buffer_size.js @@ -0,0 +1,146 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var FLOAT64_MAX = require( '@stdlib/constants/float64/max' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `bufferSize` value', function test( t ) { + var values; + var i; + + values = [ + '5', + -5, + 0, + 3.14, + NaN, + void 0, + true, + false, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.bufferSize = value; + }; + } +}); + +tape( 'an instance throws an error if provided a `bufferSize` which is less than the number of data elements', function test( t ) { + var values; + var i; + + values = [ + 1, + 2, + 3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ] ); + table.bufferSize = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + + table = ctor( null, { + 'bufferSize': 10 + }); + table.render = noop; + t.strictEqual( table.bufferSize, 10, 'returns expected value' ); + + table.bufferSize = 20; + t.strictEqual( table.bufferSize, 20, 'returns expected value' ); + + table.bufferSize = 30; + t.strictEqual( table.bufferSize, 30, 'returns expected value' ); + + table.bufferSize = null; + t.strictEqual( table.bufferSize, FLOAT64_MAX, 'returns expected value' ); + + t.end(); +}); + +tape( 'setting the `bufferSize` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'bufferSize': 10 + }); + table.render = noop; + + table.on( 'change', onChange ); + table.bufferSize = 30; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `bufferSize` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'bufferSize': 10 + }); + table.render = noop; + + table.on( 'change', onChange ); + table.bufferSize = 10; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding.js deleted file mode 100644 index 230d613f0e7b..000000000000 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ctor = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctor, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'an instance throws an error if provided an invalid `cellPadding` value', function test( t ) { - var values; - var i; - - values = [ - '5', - 2.4, - -3, - true, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var table = ctor(); - table.cellPadding = value; - }; - } -}); - -tape( 'an instance supports setting and getting the property value', function test( t ) { - var table; - var data = null; - - table = ctor( data, { - 'cellPadding': 2 - }); - t.strictEqual( table.cellPadding, 2, 'returns expected value' ); - - table.cellPadding = 3; - t.strictEqual( table.cellPadding, 3, 'returns expected value' ); - - table.cellPadding = 0; - t.strictEqual( table.cellPadding, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding_left.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding_left.js new file mode 100644 index 000000000000..51486f34c220 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding_left.js @@ -0,0 +1,143 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `cellPaddingLeft` value', function test( t ) { + var values; + var i; + + values = [ + '5', + 2.4, + -3, + true, + null, + void 0, + {}, + [], + function noop() {}, + [ 4, 'hello', null ], + [ 2, -5, 3.4 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.cellPaddingLeft = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var arr; + + table = ctor( null, { + 'cellPaddingLeft': 2 + }); + t.strictEqual( table.cellPaddingLeft, 2, 'returns expected value' ); + + table.cellPaddingLeft = 3; + t.strictEqual( table.cellPaddingLeft, 3, 'returns expected value' ); + + arr = [ 0, 5 ]; + table.cellPaddingLeft = arr; + t.notEqual( table.cellPaddingLeft, arr, 'returns a new reference' ); + t.deepEqual( table.cellPaddingLeft, arr, 'returns expected value' ); + + t.end(); +}); + +tape( 'an instance throws an error if provided a `cellPaddingLeft` array with incorrect number of columns', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + var table = ctor( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); // 3 columns + table.cellPaddingLeft = [ 1, 2 ]; // 2 columns + } +}); + +tape( 'settings the `cellPaddingLeft` property to an array sets number of columns', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + var table = ctor( null, { + 'cellPaddingLeft': [ 1, 2, 3 ] // 3 columns + }); + table.data = [ [ 1, 2 ], [ 4, 5 ] ]; // 2 columns + } +}); + +tape( 'setting the `cellPaddingLeft` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'cellPaddingLeft': 2 + }); + table.render = noop; + + table.on( 'change', onChange ); + table.cellPaddingLeft = [ 1, 2 ]; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `cellPaddingLeft` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'cellPaddingLeft': [ 2, 3 ] + }); + table.render = noop; + + table.on( 'change', onChange ); + table.cellPaddingLeft = [ 2, 3 ]; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding_right.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding_right.js new file mode 100644 index 000000000000..15655cb96d46 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding_right.js @@ -0,0 +1,143 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `cellPaddingRight` value', function test( t ) { + var values; + var i; + + values = [ + '5', + 2.4, + -3, + true, + null, + void 0, + {}, + [], + function noop() {}, + [ 4, 'hello', null ], + [ 2, -5, 3.4 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.cellPaddingRight = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var arr; + + table = ctor( null, { + 'cellPaddingRight': 2 + }); + t.strictEqual( table.cellPaddingRight, 2, 'returns expected value' ); + + table.cellPaddingRight = 3; + t.strictEqual( table.cellPaddingRight, 3, 'returns expected value' ); + + arr = [ 0, 5 ]; + table.cellPaddingRight = arr; + t.notEqual( table.cellPaddingRight, arr, 'returns a new reference' ); + t.deepEqual( table.cellPaddingRight, arr, 'returns expected value' ); + + t.end(); +}); + +tape( 'an instance throws an error if provided a `cellPaddingRight` array with incorrect number of columns', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + var table = ctor( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); // 3 columns + table.cellPaddingRight = [ 1, 2 ]; // 2 columns + } +}); + +tape( 'settings the `cellPaddingRight` property to an array sets number of columns', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + var table = ctor( null, { + 'cellPaddingRight': [ 1, 2, 3 ] // 3 columns + }); + table.data = [ [ 1, 2 ], [ 4, 5 ] ]; // 2 columns + } +}); + +tape( 'setting the `cellPaddingRight` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'cellPaddingRight': 2 + }); + table.render = noop; + + table.on( 'change', onChange ); + table.cellPaddingRight = [ 1, 2 ]; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `cellPaddingRight` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'cellPaddingRight': [ 2, 3 ] + }); + table.render = noop; + + table.on( 'change', onChange ); + table.cellPaddingRight = [ 2, 3 ]; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.column_separator.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.column_separator.js index 9517244e5f3d..9cc52ba6ca42 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.column_separator.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.column_separator.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); var ctor = require( './../lib' ); @@ -44,8 +45,7 @@ tape( 'an instance throws an error if provided an invalid `columnSeparator` valu null, void 0, {}, - [], - '5437' + [] ]; for ( i = 0; i < values.length; i++ ) { @@ -70,11 +70,47 @@ tape( 'an instance supports setting and getting the property value', function te }); t.strictEqual( table.columnSeparator, '1', 'returns expected value' ); - table.columnSeparator = '!'; - t.strictEqual( table.columnSeparator, '!', 'returns expected value' ); + table.columnSeparator = '!/1'; + t.strictEqual( table.columnSeparator, '!/1', 'returns expected value' ); - table.columnSeparator = 'None'; - t.strictEqual( table.columnSeparator, 'None', 'returns expected value' ); + table.columnSeparator = ''; + t.strictEqual( table.columnSeparator, '', 'returns expected value' ); t.end(); }); + +tape( 'setting the `columnSeparator` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'columnSeparator': '1' + }); + table.render = noop; + + table.on( 'change', onChange ); + table.columnSeparator = '23'; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `columnSeparator` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'columnSeparator': '1' + }); + table.render = noop; + + table.on( 'change', onChange ); + table.columnSeparator = '1'; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.corners.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.corners.js index 690514acf20b..18d774c1abc1 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.corners.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.corners.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); var ctor = require( './../lib' ); @@ -45,8 +46,9 @@ tape( 'an instance throws an error if provided an invalid `corners` value', func void 0, {}, [], - 'hello', - '1234567' + 'beep', + [ 4, 'hello', null, 'world' ], + [ 'beep', 'boop', 'foo', '' ] ]; for ( i = 0; i < values.length; i++ ) { @@ -64,18 +66,60 @@ tape( 'an instance throws an error if provided an invalid `corners` value', func tape( 'an instance supports setting and getting the property value', function test( t ) { var table; - var data = null; + var arr; - table = ctor( data, { - 'corners': '1 2 3 4' + arr = [ '1', '2', '3', '4' ]; + table = ctor( null, { + 'corners': [ '1', '2', '3', '4' ] }); - t.strictEqual( table.corners, '1 2 3 4', 'returns expected value' ); + t.notEqual( table.corners, arr, 'returns a new reference' ); + t.deepEqual( table.corners, arr, 'returns expected value' ); - table.corners = '* * * *'; - t.strictEqual( table.corners, '* * * *', 'returns expected value' ); + arr = [ '*', '&', '-', '=' ]; + table.corners = arr; + t.notEqual( table.corners, arr, 'returns a new reference' ); + t.deepEqual( table.corners, arr, 'returns expected value' ); - table.corners = 'None'; - t.strictEqual( table.corners, 'None', 'returns expected value' ); + arr = [ '🥀', '🌹', ' ', '🔥' ]; + table.corners = arr; + t.notEqual( table.corners, arr, 'returns a new reference' ); + t.deepEqual( table.corners, arr, 'returns expected value' ); t.end(); }); + +tape( 'setting the `corners` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'corners': [ '-', '|', '=', '!' ] + }); + table.render = noop; + + table.on( 'change', onChange ); + table.corners = [ '1', '2', '3', '4' ]; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `corners` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'corners': [ '-', '|', '=', '!' ] + }); + table.render = noop; + + table.on( 'change', onChange ); + table.corners = [ '-', '|', '=', '!' ]; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.data.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.data.js new file mode 100644 index 000000000000..fee3f5527cc3 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.data.js @@ -0,0 +1,177 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `data` value', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + [], + {}, + function noop() {}, + [ 1, 'hello', null ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.data = value; + }; + } +}); + +tape( 'an instance throws an error if provided a `data` value which more rows than the data buffer size', function test( t ) { + var values; + var i; + + values = [ + [ [ 1, 2 ], [ 3, 4 ] ], + [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ], + [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor( null, { + 'bufferSize': 1 + }); + table.data = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var arr; + + arr = [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]; + table = ctor( arr ); + table.render = noop; + t.notEqual( table.data, arr, 'returns a new reference' ); + t.deepEqual( table.data, arr, 'returns expected value' ); + + arr = [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ]; + table.data = arr; + t.notEqual( table.data, arr, 'returns a new reference' ); + t.deepEqual( table.data, arr, 'returns expected value' ); + + arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + table.data = arr; + t.notEqual( table.data, arr, 'returns a new reference' ); + t.deepEqual( table.data, [ [ 1, 2 ], [ 3, 4 ] ], 'returns expected value' ); + + t.end(); +}); + +tape( 'an instance throws an error if provided `data` with incorrect number of columns', function test( t ) { + var values; + var i; + + values = [ + [ [ 1, 2 ], [ 3, 4 ] ], + [ [ 1, 2, 3 ], [ 4, 5 ] ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error' ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor( null, [ 'col1', 'col2', 'col3' ] ); // 3 columns + table.data = value; + }; + } +}); + +tape( 'settings the `data` property sets number of columns', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + var table = ctor( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); // 3 columns + table.headers = [ 'col1', 'col2' ]; // 2 columns + } +}); + +tape( 'setting the `data` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( [ [ 1, 2 ], [ 3, 4 ] ] ); + table.render = noop; + + table.on( 'change', onChange ); + table.data = [ [ 5, 6 ], [ 7, 8 ] ]; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `data` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( [ [ 1, 2 ], [ 3, 4 ] ] ); + table.render = noop; + + table.on( 'change', onChange ); + table.data = [ [ 1, 2 ], [ 3, 4 ] ]; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.header_separator.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.header_separator.js index d5d3c68c555a..fc5ecaac3057 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.header_separator.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.header_separator.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); var ctor = require( './../lib' ); @@ -44,8 +45,7 @@ tape( 'an instance throws an error if provided an invalid `headerSeparator` valu null, void 0, {}, - [], - '5437' + [] ]; for ( i = 0; i < values.length; i++ ) { @@ -70,11 +70,47 @@ tape( 'an instance supports setting and getting the property value', function te }); t.strictEqual( table.headerSeparator, '1', 'returns expected value' ); - table.headerSeparator = '!'; - t.strictEqual( table.headerSeparator, '!', 'returns expected value' ); + table.headerSeparator = '!/1'; + t.strictEqual( table.headerSeparator, '!/1', 'returns expected value' ); - table.headerSeparator = 'None'; - t.strictEqual( table.headerSeparator, 'None', 'returns expected value' ); + table.headerSeparator = ''; + t.strictEqual( table.headerSeparator, '', 'returns expected value' ); t.end(); }); + +tape( 'setting the `headerSeparator` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'headerSeparator': '1' + }); + table.render = noop; + + table.on( 'change', onChange ); + table.headerSeparator = '23'; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `headerSeparator` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'headerSeparator': '1' + }); + table.render = noop; + + table.on( 'change', onChange ); + table.headerSeparator = '1'; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.headers.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.headers.js new file mode 100644 index 000000000000..fdffdba4976d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.headers.js @@ -0,0 +1,138 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `headers` value', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.data = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var arr; + + arr = [ 'col1', 'col2' ]; + table = ctor( null, arr ); + table.render = noop; + t.notEqual( table.headers, arr, 'returns a new reference' ); + t.deepEqual( table.headers, arr, 'returns expected value' ); + + arr = [ 1, 2 ]; + table.headers = arr; + t.notEqual( table.headers, arr, 'returns a new reference' ); + t.deepEqual( table.headers, arr, 'returns expected value' ); + + arr = [ null, undefined ]; + table.headers = arr; + t.notEqual( table.headers, arr, 'returns a new reference' ); + t.deepEqual( table.headers, arr, 'returns expected value' ); + + t.end(); +}); + +tape( 'an instance throws an error if provided `headers` with incorrect number of columns', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + var table = ctor( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); // 3 columns + table.headers = [ 'col1', 'col2' ]; // 2 columns + } +}); + +tape( 'settings the `headers` property sets number of columns', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + var table = ctor( null, [ 'col1', 'col2', 'col3' ] ); // 3 columns + table.data = [ [ 1, 2 ], [ 3, 4 ] ]; // 2 columns + } +}); + +tape( 'setting the `headers` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, [ 'col1', 'col2' ] ); + table.render = noop; + + table.on( 'change', onChange ); + table.headers = [ 1, 2 ]; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `headers` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, [ 'col1', 'col2' ] ); + table.render = noop; + + table.on( 'change', onChange ); + table.headers = [ 'col1', 'col2' ]; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.horizontal_separator_mode.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.horizontal_separator_mode.js new file mode 100644 index 000000000000..eee3b275a76e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.horizontal_separator_mode.js @@ -0,0 +1,119 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `horizontalSeparatorMode` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + '1234', + 'beep' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.horizontalSeparatorMode = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + + table = ctor( null, { + 'horizontalSeparatorMode': 'interpolate' + }); + table.render = noop; + + t.strictEqual( table.horizontalSeparatorMode, 'interpolate', 'returns expected value' ); + + table.horizontalSeparatorMode = 'repeat'; + t.strictEqual( table.horizontalSeparatorMode, 'repeat', 'returns expected value' ); + + table.horizontalSeparatorMode = 'resume'; + t.strictEqual( table.horizontalSeparatorMode, 'resume', 'returns expected value' ); + + t.end(); +}); + +tape( 'setting the `horizontalSeparatorMode` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'horizontalSeparatorMode': 'interpolate' + }); + table.render = noop; + + table.on( 'change', onChange ); + table.horizontalSeparatorMode = 'resume'; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `horizontalSeparatorMode` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'horizontalSeparatorMode': 'repeat' + }); + table.render = noop; + + table.on( 'change', onChange ); + table.horizontalSeparatorMode = 'repeat'; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.joints.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.joints.js index efc987353387..f414ae198739 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.joints.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.joints.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); var ctor = require( './../lib' ); @@ -45,8 +46,9 @@ tape( 'an instance throws an error if provided an invalid `joints` value', funct void 0, {}, [], - 'hello', - '1234567' + 'beep', + [ 4, 'hello', null, 'world' ], + [ 'beep', 'boop', 'foo', '', 'bar' ] ]; for ( i = 0; i < values.length; i++ ) { @@ -64,18 +66,60 @@ tape( 'an instance throws an error if provided an invalid `joints` value', funct tape( 'an instance supports setting and getting the property value', function test( t ) { var table; - var data = null; + var arr; - table = ctor( data, { - 'joints': '1 2 3 4 5' + arr = [ '1', '2', '3', '4', '5' ]; + table = ctor( null, { + 'joints': arr }); - t.strictEqual( table.joints, '1 2 3 4 5', 'returns expected value' ); + t.notEqual( table.joints, arr, 'returns a new reference' ); + t.deepEqual( table.joints, arr, 'returns expected value' ); - table.joints = '& # * ^ @'; - t.strictEqual( table.joints, '& # * ^ @', 'returns expected value' ); + arr = [ '&', '#', '*', '^', '@' ]; + table.joints = arr; + t.notEqual( table.corners, arr, 'returns a new reference' ); + t.deepEqual( table.joints, arr, 'returns expected value' ); - table.joints = 'None'; - t.strictEqual( table.joints, 'None', 'returns expected value' ); + arr = [ '🥀', '🌹', ' ', '🔥', '*' ]; + table.joints = arr; + t.notEqual( table.corners, arr, 'returns a new reference' ); + t.deepEqual( table.joints, arr, 'returns expected value' ); t.end(); }); + +tape( 'setting the `joints` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'joints': [ '-', '|', '=', '!', '1' ] + }); + table.render = noop; + + table.on( 'change', onChange ); + table.joints = [ '1', '2', '3', '4', '5' ]; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `joints` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'joints': [ '-', '|', '=', '!', '1' ] + }); + table.render = noop; + + table.on( 'change', onChange ); + table.joints = [ '-', '|', '=', '!', '1' ]; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.main.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.main.js index f0ec1f362309..9ed2bf13acc9 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.main.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.main.js @@ -80,17 +80,22 @@ tape( 'the constructor does not require the `new` keyword (data and options)', f data = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; table = ctor( data, { 'alignment': 'left', - 'borders': '1 2 3 4', - 'cellPadding': 2, + 'autoRender': false, + 'borders': [ '1', '23', '456', '7890' ], + 'bufferSize': 10, + 'cellPaddingLeft': 2, + 'cellPaddingRight': [ 2, 3, 4 ], 'columnSeparator': 'None', - 'corners': '* * * *', - 'headerSeparator': '-', - 'joints': '* * * * *', + 'corners': [ '*', '*', '*', '*' ], + 'headerSeparator': '-=', + 'horizontalSeparatorMode': 'repeat', + 'joints': [ '*', '*', '*', '*', '*' ], 'marginX': 2, 'marginY': 4, 'maxCellWidth': 10, 'maxOutputWidth': 60, - 'rowSeparator': '_' + 'rowSeparator': '_-', + 'verticalSeparatorMode': 'resume' }); t.strictEqual( table instanceof UnicodeTable, true, 'returns class instance' ); @@ -108,17 +113,22 @@ tape( 'the constructor does not require the `new` keyword (data, headers and opt headers = [ 'col1', 'col2', 'col3' ]; table = ctor( data, headers, { 'alignment': 'left', - 'borders': '1 2 3 4', - 'cellPadding': 2, + 'autoRender': false, + 'borders': [ '1', '23', '456', '7890' ], + 'bufferSize': 10, + 'cellPaddingLeft': 2, + 'cellPaddingRight': [ 2, 3, 4 ], 'columnSeparator': 'None', - 'corners': '* * * *', - 'headerSeparator': '-', - 'joints': '* * * * *', + 'corners': [ '*', '*', '*', '*' ], + 'headerSeparator': '-=', + 'horizontalSeparatorMode': 'repeat', + 'joints': [ '*', '*', '*', '*', '*' ], 'marginX': 2, 'marginY': 4, 'maxCellWidth': 10, 'maxOutputWidth': 60, - 'rowSeparator': '_' + 'rowSeparator': '_-', + 'verticalSeparatorMode': 'resume' }); t.strictEqual( table instanceof UnicodeTable, true, 'returns class instance' ); @@ -204,21 +214,9 @@ tape( 'the constructor throws an error if provided an invalid option (headers ar } }); -tape( 'an instance has a `addRow` method for adding a row', function test( t ) { +tape( 'an instance has a `push` method for adding a row', function test( t ) { var table = new UnicodeTable(); - t.strictEqual( typeof table.addRow, 'function', 'has addRow method' ); - t.end(); -}); - -tape( 'an instance has a `setData` method for setting data', function test( t ) { - var table = new UnicodeTable(); - t.strictEqual( typeof table.setData, 'function', 'has setData method' ); - t.end(); -}); - -tape( 'an instance has a `getData` method for getting data', function test( t ) { - var table = new UnicodeTable(); - t.strictEqual( typeof table.getData, 'function', 'has getData method' ); + t.strictEqual( typeof table.push, 'function', 'has addRow method' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_x.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_x.js index 09a773b014e4..e119935f5776 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_x.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_x.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); var ctor = require( './../lib' ); @@ -63,11 +64,12 @@ tape( 'an instance throws an error if provided an invalid `marginX` value', func tape( 'an instance supports setting and getting the property value', function test( t ) { var table; - var data = null; - table = ctor( data, { + table = ctor( null, { 'marginX': 2 }); + table.render = noop; + t.strictEqual( table.marginX, 2, 'returns expected value' ); table.marginX = 3; @@ -78,3 +80,39 @@ tape( 'an instance supports setting and getting the property value', function te t.end(); }); + +tape( 'setting the `marginX` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'marginX': 2 + }); + table.render = noop; + + table.on( 'change', onChange ); + table.marginX = 3; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `marginX` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'marginX': 2 + }); + table.render = noop; + + table.on( 'change', onChange ); + table.marginX = 2; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_y.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_y.js index da4835b2aecd..aceff08bed43 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_y.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_y.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); var ctor = require( './../lib' ); @@ -63,11 +64,12 @@ tape( 'an instance throws an error if provided an invalid `marginY` value', func tape( 'an instance supports setting and getting the property value', function test( t ) { var table; - var data = null; - table = ctor( data, { + table = ctor( null, { 'marginY': 2 }); + table.render = noop; + t.strictEqual( table.marginY, 2, 'returns expected value' ); table.marginY = 3; @@ -78,3 +80,39 @@ tape( 'an instance supports setting and getting the property value', function te t.end(); }); + +tape( 'setting the `marginY` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'marginY': 2 + }); + table.render = noop; + + table.on( 'change', onChange ); + table.marginY = 3; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `marginY` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'marginY': 2 + }); + table.render = noop; + + table.on( 'change', onChange ); + table.marginY = 2; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_cell_width.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_cell_width.js index 068a06340878..c44982a0f1c7 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_cell_width.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_cell_width.js @@ -21,6 +21,8 @@ // MODULES // var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var FLOAT64_MAX = require( '@stdlib/constants/float64/max' ); var ctor = require( './../lib' ); @@ -41,11 +43,11 @@ tape( 'an instance throws an error if provided an invalid `maxCellWidth` value', 2.4, -3, true, - null, void 0, {}, - [], - function noop() {} + function noop() {}, + [ 4, 'hello', null ], + [ 2, -5, 3.4 ] ]; for ( i = 0; i < values.length; i++ ) { @@ -63,9 +65,9 @@ tape( 'an instance throws an error if provided an invalid `maxCellWidth` value', tape( 'an instance supports setting and getting the property value', function test( t ) { var table; - var data = null; + var arr; - table = ctor( data, { + table = ctor( null, { 'maxCellWidth': 2 }); t.strictEqual( table.maxCellWidth, 2, 'returns expected value' ); @@ -73,8 +75,76 @@ tape( 'an instance supports setting and getting the property value', function te table.maxCellWidth = 3; t.strictEqual( table.maxCellWidth, 3, 'returns expected value' ); - table.maxCellWidth = 0; - t.strictEqual( table.maxCellWidth, 0, 'returns expected value' ); + table.maxCellWidth = null; + t.strictEqual( table.maxCellWidth, FLOAT64_MAX, 'returns expected value' ); + arr = [ 0, 5 ]; + table.maxCellWidth = arr; + t.notEqual( table.maxCellWidth, arr, 'returns a new reference' ); + t.deepEqual( table.maxCellWidth, arr, 'returns expected value' ); + + arr = [ null, 5 ]; + table.maxCellWidth = arr; + t.notEqual( table.maxCellWidth, arr, 'returns a new reference' ); + t.deepEqual( table.maxCellWidth, [ FLOAT64_MAX, 5 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'an instance throws an error if provided a `maxCellWidth` array with incorrect number of columns', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + var table = ctor( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); // 3 columns + table.maxCellWidth = [ 1, 2 ]; // 2 columns + } +}); + +tape( 'settings the `maxCellWidth` property to an array sets number of columns', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); t.end(); + + function badValue() { + var table = ctor( null, { + 'maxCellWidth': [ 1, 2, 3 ] // 3 columns + }); + table.data = [ [ 1, 2 ], [ 4, 5 ] ]; // 2 columns + } +}); + +tape( 'setting the `maxCellWidth` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'maxCellWidth': 2 + }); + table.render = noop; + + table.on( 'change', onChange ); + table.maxCellWidth = [ 1, 2 ]; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `maxCellWidth` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'maxCellWidth': [ 2, 3 ] + }); + table.render = noop; + + table.on( 'change', onChange ); + table.maxCellWidth = [ 2, 3 ]; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } }); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_output_width.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_output_width.js index b14fd3c80873..41560f3d54e2 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_output_width.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_output_width.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); var ctor = require( './../lib' ); @@ -41,7 +42,6 @@ tape( 'an instance throws an error if provided an invalid `maxOutputWidth` value 2.4, -3, true, - null, void 0, {}, [], @@ -78,3 +78,39 @@ tape( 'an instance supports setting and getting the property value', function te t.end(); }); + +tape( 'setting the `maxOutputWidth` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'maxOutputWidth': 10 + }); + table.render = noop; + + table.on( 'change', onChange ); + table.maxOutputWidth = 30; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `maxOutputWidth` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'maxOutputWidth': 10 + }); + table.render = noop; + + table.on( 'change', onChange ); + table.maxOutputWidth = 10; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.parse.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.parse.js new file mode 100644 index 000000000000..47180d39e893 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.parse.js @@ -0,0 +1,337 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid array of objects', function test( t ) { + t.throws( badValue, Error, 'throws an error' ); + t.end(); + + function badValue() { + var headers; + var table; + var data; + + data = [ + { + 'col1': 'hello', + 'col2': 45, + 'col3': true + }, + { + 'col1': null, + 'col3': 45.3 + } + ]; + headers = [ 'col1', 'col2', 'col3' ]; + table = ctor( data, headers ); // eslint-disable-line no-unused-vars + } +}); + +tape( 'the function sets the table data for an array of objects (with headers)', function test( t ) { + var expected; + var headers; + var table; + var data; + var v; + + data = [ + { + 'col1': 'hello', + 'col2': 45, + 'col3': true + }, + { + 'col1': null, + 'col3': 45.3 + } + ]; + headers = [ 'col1', 'col3' ]; + table = ctor( data, headers ); + + v = table.data; + expected = [ [ 'hello', true ], [ null, 45.3 ] ]; + t.deepEqual( v, expected, 'sets table data' ); + + v = table.headers; + expected = [ 'col1', 'col3' ]; + t.deepEqual( v, expected, 'sets table headers' ); + + t.end(); +}); + +tape( 'the function sets the table data for an array of objects (without headers)', function test( t ) { + var expected; + var table; + var data; + var v; + + data = [ + { + 'col1': 'hello', + 'col2': 45, + 'col3': true + }, + { + 'col1': null, + 'col2': undefined, + 'col3': 45.3 + } + ]; + table = ctor( data ); + + v = table.data; + expected = [ [ 'hello', 45, true ], [ null, undefined, 45.3 ] ]; + t.deepEqual( v, expected, 'sets table data' ); + + v = table.headers; + expected = [ 'col1', 'col2', 'col3' ]; + t.deepEqual( v, expected, 'sets table headers' ); + + t.end(); +}); + +tape( 'the function throws an error if provided an invalid object of columns', function test( t ) { + var values; + var i; + + values = [ + { + 'data': { + 'col1': [ 'hello', true ], + 'col2': [ 45.3, null ] + }, + 'headers': [ 'col1', 'col2', 'col3' ] + }, + { + 'data': { + 'col1': [ 'hello', true ], + 'col2': [ 45.3 ] + }, + 'headers': [ 'col1', 'col2' ] + } + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor( value.data, value.headers ); // eslint-disable-line no-unused-vars + }; + } +}); + +tape( 'the function sets the table data for an object of columns (with headers)', function test( t ) { + var expected; + var headers; + var table; + var data; + var v; + + data = { + 'col1': [ 'hello', true ], + 'col2': [ null, 45 ], + 'col3': [ undefined, 45.3 ] + }; + headers = [ 'col1', 'col2' ]; + table = ctor( data, headers ); + + v = table.data; + expected = [ [ 'hello', null ], [ true, 45 ] ]; + t.deepEqual( v, expected, 'sets table data' ); + + v = table.headers; + expected = [ 'col1', 'col2' ]; + t.deepEqual( v, expected, 'sets table headers' ); + + t.end(); +}); + +tape( 'the function sets the table data for an object of columns (without headers)', function test( t ) { + var expected; + var table; + var data; + var v; + + data = { + 'col1': [ 'hello', true ], + 'col2': [ null, 45 ], + 'col3': [ undefined, 45.3 ] + }; + table = ctor( data ); + + v = table.data; + expected = [ [ 'hello', null, undefined ], [ true, 45, 45.3 ] ]; + t.deepEqual( v, expected, 'sets table data' ); + + v = table.headers; + expected = [ 'col1', 'col2', 'col3' ]; + t.deepEqual( v, expected, 'sets table headers' ); + + t.end(); +}); + +tape( 'the function throws an error if provided an invalid array of arrays', function test( t ) { + var values; + var i; + + values = [ + { + 'data': [ [ 45, 33 ], [ 32.54, true, null ] ], + 'headers': [ 'col1', 'col2', 'col3' ] + }, + { + 'data': [ [ 45, 33, 'hello', undefined ], [ 32.54, true, null ] ], + 'headers': [ 'col1', 'col2', 'col3' ] + } + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor( value.data, value.headers ); // eslint-disable-line no-unused-vars + }; + } +}); + +tape( 'the function sets the table data for an array of arrays (with headers)', function test( t ) { + var expected; + var headers; + var table; + var data; + var v; + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + headers = [ 'col1', 'col2', 'col3' ]; + table = ctor( data, headers ); + + v = table.data; + expected = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + t.deepEqual( v, expected, 'sets table data' ); + + v = table.headers; + expected = [ 'col1', 'col2', 'col3' ]; + t.deepEqual( v, expected, 'sets table headers' ); + + t.end(); +}); + +tape( 'the function sets the table data for an array of arrays (without headers)', function test( t ) { + var expected; + var table; + var data; + var v; + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table = ctor( data ); + + v = table.data; + expected = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + t.deepEqual( v, expected, 'sets table data' ); + + v = table.headers; + expected = null; + t.deepEqual( v, expected, 'sets table headers' ); + + t.end(); +}); + +tape( 'the function throws an error if provided an invalid array of objects', function test( t ) { + t.throws( badValue, Error, 'throws an error' ); + t.end(); + + function badValue() { + var headers; + var buffer; + var table; + var data; + + buffer = [ 14, 2, 'hello', false, 32.54, true, null, 'bye', 9, 10, 11, 12 ]; + data = ndarray( 'generic', buffer, [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); + headers = [ 'col1', 'col2', 'col3' ]; + table = ctor( data, headers ); // eslint-disable-line no-unused-vars + } +}); + +tape( 'the function sets the table data for a matrix-like ndarray (with headers)', function test( t ) { + var expected; + var headers; + var buffer; + var table; + var data; + var v; + + buffer = [ 14, 2, 'hello', false, 32.54, true, null, 'bye', 9, 10, 11, 12 ]; + data = ndarray( 'generic', buffer, [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); + headers = [ 'col1', 'col2', 'col3', 'col4' ]; + table = ctor( data, headers ); + + v = table.data; + expected = [ [ 14, 2, 'hello', false ], [ 32.54, true, null, 'bye' ], [ 9, 10, 11, 12 ] ]; + t.deepEqual( v, expected, 'sets table data' ); + + v = table.headers; + expected = [ 'col1', 'col2', 'col3', 'col4' ]; + t.deepEqual( v, expected, 'sets table headers' ); + + t.end(); +}); + +tape( 'the function sets the table data for a matrix-like ndarray (without headers)', function test( t ) { + var expected; + var buffer; + var table; + var data; + var v; + + buffer = [ 14, 2, 'hello', false, 32.54, true, null, 'bye', 9, 10, 11, 12 ]; + data = ndarray( 'generic', buffer, [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); + table = ctor( data ); + + v = table.data; + expected = [ [ 14, 2, 'hello', false ], [ 32.54, true, null, 'bye' ], [ 9, 10, 11, 12 ] ]; + t.deepEqual( v, expected, 'sets table data' ); + + v = table.headers; + expected = null; + t.deepEqual( v, expected, 'sets table headers' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.parser.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.parser.js deleted file mode 100644 index d12666c551ba..000000000000 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.parser.js +++ /dev/null @@ -1,240 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( '@stdlib/ndarray/ctor' ); -var ctor = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctor, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the table data for an array of objects (with headers)', function test( t ) { - var expected; - var headers; - var table; - var data; - var v; - - data = [ - { - 'col1': 'hello', - 'col2': 45, - 'col3': true - }, - { - 'col1': null, - 'col3': 45.3 - } - ]; - headers = [ 'col1', 'col2', 'col3' ]; - table = ctor(); - - table.setData( data, headers ); - v = table.getData(); - - expected = {}; - expected.data = [ [ 'hello', 45, true ], [ null, undefined, 45.3 ] ]; - expected.headers = [ 'col1', 'col2', 'col3' ]; - - t.deepEqual( v, expected, 'sets table data' ); - - t.end(); -}); - -tape( 'the function sets the table data for an array of objects (without headers)', function test( t ) { - var expected; - var table; - var data; - var v; - - data = [ - { - 'col1': 'hello', - 'col2': 45, - 'col3': true - }, - { - 'col1': null, - 'col3': 45.3 - } - ]; - table = ctor(); - - table.setData( data ); - v = table.getData(); - - expected = {}; - expected.data = [ [ 'hello', 45, true ], [ null, undefined, 45.3 ] ]; - expected.headers = [ 'col1', 'col2', 'col3' ]; - - t.deepEqual( v, expected, 'sets table data' ); - - t.end(); -}); - -tape( 'the function sets the table data for an object of columns (with headers)', function test( t ) { - var expected; - var headers; - var table; - var data; - var v; - - data = { - 'col1': [ 'hello', true ], - 'col2': [ null, 45 ] - }; - headers = [ 'col1', 'col2', 'col3' ]; - table = ctor(); - - table.setData( data, headers ); - v = table.getData(); - - expected = {}; - expected.data = [ [ 'hello', null ], [ true, 45 ] ]; - expected.headers = [ 'col1', 'col2' ]; - - t.deepEqual( v, expected, 'sets table data' ); - - t.end(); -}); - -tape( 'the function sets the table data for an object of columns (without headers)', function test( t ) { - var expected; - var table; - var data; - var v; - - data = { - 'col1': [ 'hello', true ], - 'col2': [ null, 45 ] - }; - table = ctor(); - - table.setData( data ); - v = table.getData(); - - expected = {}; - expected.data = [ [ 'hello', null ], [ true, 45 ] ]; - expected.headers = [ 'col1', 'col2' ]; - - t.deepEqual( v, expected, 'sets table data' ); - - t.end(); -}); - -tape( 'the function sets the table data for an array of arrays (with headers)', function test( t ) { - var expected; - var headers; - var table; - var data; - var v; - - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - headers = [ 'col1', 'col2', 'col3' ]; - table = ctor(); - - table.setData( data, headers ); - v = table.getData(); - - expected = {}; - expected.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - expected.headers = [ 'col1', 'col2', 'col3' ]; - - t.deepEqual( v, expected, 'sets table data' ); - - t.end(); -}); - -tape( 'the function sets the table data for an array of arrays (without headers)', function test( t ) { - var expected; - var table; - var data; - var v; - - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - table = ctor(); - - table.setData( data ); - v = table.getData(); - - expected = {}; - expected.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - expected.headers = null; - - t.deepEqual( v, expected, 'sets table data' ); - - t.end(); -}); - -tape( 'the function sets the table data for a matrix-like ndarray (with headers)', function test( t ) { - var expected; - var headers; - var buffer; - var table; - var data; - var v; - - buffer = [ 14, 2, 'hello', false, 32.54, true, null, 'bye', 9, 10, 11, 12 ]; - data = ndarray( 'generic', buffer, [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); - headers = [ 'col1', 'col2', 'col3', 'col4' ]; - table = ctor(); - - table.setData( data, headers ); - v = table.getData(); - - expected = {}; - expected.data = [ [ 14, 2, 'hello', false ], [ 32.54, true, null, 'bye' ], [ 9, 10, 11, 12 ] ]; - expected.headers = [ 'col1', 'col2', 'col3', 'col4' ]; - - t.deepEqual( v, expected, 'sets table data' ); - - t.end(); -}); - -tape( 'the function sets the table data for a matrix-like ndarray (without headers)', function test( t ) { - var expected; - var buffer; - var table; - var data; - var v; - - buffer = [ 14, 2, 'hello', false, 32.54, true, null, 'bye', 9, 10, 11, 12 ]; - data = ndarray( 'generic', buffer, [ 3, 4 ], [ 4, 1 ], 0, 'row-major' ); - table = ctor(); - - table.setData( data ); - v = table.getData(); - - expected = {}; - expected.data = [ [ 14, 2, 'hello', false ], [ 32.54, true, null, 'bye' ], [ 9, 10, 11, 12 ] ]; - expected.headers = null; - - t.deepEqual( v, expected, 'sets table data' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.push.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.push.js new file mode 100644 index 000000000000..92467d17b9c2 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.push.js @@ -0,0 +1,133 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function appends a row to existing data', function test( t ) { + var expected; + var table; + var data; + var row; + var v; + + data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table = ctor( data ); + table.render = noop; + + row = [ 1, true, 'hello' ]; + table.push( row ); + v = table.data; + + expected = [ [ 45, 33, 'hello' ], [ 32.54, true, null ], [ 1, true, 'hello' ] ]; + t.deepEqual( v, expected, 'sets table data' ); + + t.end(); +}); + +tape( 'the function creates table data if no existing data found', function test( t ) { + var expected; + var table; + var row; + var v; + + table = ctor(); + table.render = noop; + + row = [ 1, true, 'hello' ]; + table.push( row ); + v = table.data; + + expected = [ row ]; + t.deepEqual( v, expected, 'sets table data' ); + + t.end(); +}); + +tape( 'the function throws an error if provided incorrect number of columns', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + var table = ctor( [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ] ); // 3 columns + table.push( [ 1, 2 ] ); // 2 columns + } +}); + +tape( 'the function sets the number of columns if no existing columns found', function test( t ) { + t.throws( badValue, RangeError, 'throws an error' ); + t.end(); + + function badValue() { + var table = ctor(); + table.push( [ 1, 2, 3 ] ); // 3 columns + table.headers = [ 'col1', 'col2' ]; // 2 columns + } +}); + +tape( 'if appending data to the internal data buffer will result in the table data exceeding the data buffer size, the function will remove the first row', function test( t ) { + var expected; + var table; + var data; + var v; + + data = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; + table = ctor( data, { + 'bufferSize': 2 + }); + table.render = noop; + + table.push( [ 7, 8, 9 ] ); + v = table.data; + + expected = [ [ 4, 5, 6 ], [ 7, 8, 9 ] ]; + t.deepEqual( v, expected, 'removes first row' ); + + t.end(); +}); + +tape( 'appending `data` triggers a `change` event', function test( t ) { + var table; + var data; + + data = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; + table = ctor( data ); + table.render = noop; + + table.on( 'change', onChange ); + table.push( [ 7, 8, 9 ] ); + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.render.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.render.js index c3870e155e4c..582217e2958a 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.render.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.render.js @@ -46,16 +46,12 @@ tape( 'the function returns an empty string if no table data provided ', functio tape( 'the function supports rendering a table', function test( t ) { var expected; - var headers; var table; - var data; var str; table = ctor(); - - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - headers = [ 'col1', 'col2', 'col3' ]; - table.setData( data, headers ); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; expected = [ '┌───────┬──────┬───────┐', @@ -75,13 +71,10 @@ tape( 'the function supports rendering a table', function test( t ) { tape( 'the function supports rendering a table (without headers)', function test( t ) { var expected; var table; - var data; var str; table = ctor(); - - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - table.setData( data ); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; expected = [ '┌───────┬──────┬───────┐', @@ -98,16 +91,12 @@ tape( 'the function supports rendering a table (without headers)', function test tape( 'the function supports rendering a table (with row separators)', function test( t ) { var expected; - var headers; var table; - var data; var str; table = ctor(); - - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - headers = [ 'col1', 'col2', 'col3' ]; - table.setData( data, headers ); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; table.rowSeparator = '─'; expected = [ @@ -128,17 +117,13 @@ tape( 'the function supports rendering a table (with row separators)', function tape( 'the function supports rendering a table (without borders)', function test( t ) { var expected; - var headers; var table; - var data; var str; table = ctor(); - - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - headers = [ 'col1', 'col2', 'col3' ]; - table.setData( data, headers ); - table.borders = 'None'; + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; + table.borders = [ '', '', '', '' ]; expected = [ ' col1 │ col2 │ col3 ', @@ -155,17 +140,14 @@ tape( 'the function supports rendering a table (without borders)', function test tape( 'the function supports rendering a table (without column separators)', function test( t ) { var expected; - var headers; var table; - var data; var str; table = ctor(); - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - headers = [ 'col1', 'col2', 'col3' ]; - table.setData( data, headers ); - table.columnSeparator = 'None'; + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; + table.columnSeparator = ''; expected = [ '┌────────────────────┐', @@ -184,17 +166,13 @@ tape( 'the function supports rendering a table (without column separators)', fun tape( 'the function supports rendering a table (without header separator)', function test( t ) { var expected; - var headers; var table; - var data; var str; table = ctor(); - - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - headers = [ 'col1', 'col2', 'col3' ]; - table.setData( data, headers ); - table.headerSeparator = 'None'; + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; + table.headerSeparator = ''; expected = [ '┌───────┬──────┬───────┐', @@ -210,58 +188,38 @@ tape( 'the function supports rendering a table (without header separator)', func t.end(); }); -tape( 'the function supports rendering a table (without corners)', function test( t ) { +tape( 'the function supports rendering a table with different cell paddings', function test( t ) { var expected; - var headers; var table; - var data; var str; table = ctor(); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - headers = [ 'col1', 'col2', 'col3' ]; - table.setData( data, headers ); - table.corners = 'None'; - + table.cellPaddingLeft = 2; + table.cellPaddingRight = 1; expected = [ - ' ───────┬──────┬─────── ', - '│ col1 │ col2 │ col3 │', - '├───────┼──────┼───────┤', - '│ 45 │ 33 │ hello │', - '│ 32.54 │ true │ null │', - ' ───────┴──────┴─────── ' + '┌────────┬───────┬────────┐', + '│ col1 │ col2 │ col3 │', + '├────────┼───────┼────────┤', + '│ 45 │ 33 │ hello │', + '│ 32.54 │ true │ null │', + '└────────┴───────┴────────┘' ].join( '\n' ); - str = table.render(); t.strictEqual( str, expected, 'returns rendered table' ); - t.end(); -}); - -tape( 'the function supports rendering a table (without joints)', function test( t ) { - var expected; - var headers; - var table; - var data; - var str; - - table = ctor(); - - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - headers = [ 'col1', 'col2', 'col3' ]; - table.setData( data, headers ); - table.joints = 'None'; - + table.cellPaddingLeft = [ 2, 0, 3 ]; + table.cellPaddingRight = [ 0, 1, 2 ]; expected = [ - '┌─────── ────── ───────┐', - '│ col1 │ col2 │ col3 │', - ' ─────── ────── ─────── ', - '│ 45 │ 33 │ hello │', - '│ 32.54 │ true │ null │', - '└─────── ────── ───────┘' + '┌───────┬─────┬──────────┐', + '│ col1│col2 │ col3 │', + '├───────┼─────┼──────────┤', + '│ 45│ 33 │ hello │', + '│ 32.54│true │ null │', + '└───────┴─────┴──────────┘' ].join( '\n' ); - str = table.render(); t.strictEqual( str, expected, 'returns rendered table' ); @@ -270,16 +228,12 @@ tape( 'the function supports rendering a table (without joints)', function test( tape( 'the function supports rendering a table with a margin', function test( t ) { var expected; - var headers; var table; - var data; var str; table = ctor(); - - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - headers = [ 'col1', 'col2', 'col3' ]; - table.setData( data, headers ); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; table.marginX = 1; table.marginY = 1; @@ -302,18 +256,14 @@ tape( 'the function supports rendering a table with a margin', function test( t tape( 'the function supports rendering a table with truncated data', function test( t ) { var expected; - var headers; var table; - var data; var str; table = ctor(); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - headers = [ 'col1', 'col2', 'col3' ]; - table.setData( data, headers ); - table.maxCellWidth = 4; - + table.maxCellWidth = 6; expected = [ '┌──────┬──────┬──────┐', '│ col1 │ col2 │ col3 │', @@ -322,7 +272,18 @@ tape( 'the function supports rendering a table with truncated data', function te '│ 3... │ true │ null │', '└──────┴──────┴──────┘' ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + table.maxCellWidth = [ 6, 3, 5 ]; + expected = [ + '┌──────┬───┬─────┐', + '│ col1 │ . │ ... │', + '├──────┼───┼─────┤', + '│ 45 │ . │ ... │', + '│ 3... │ . │ ... │', + '└──────┴───┴─────┘' + ].join( '\n' ); str = table.render(); t.strictEqual( str, expected, 'returns rendered table' ); @@ -331,16 +292,12 @@ tape( 'the function supports rendering a table with truncated data', function te tape( 'the function supports rendering a table with different alignments', function test( t ) { var expected; - var headers; var table; - var data; var str; table = ctor(); - - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - headers = [ 'col1', 'col2', 'col3' ]; - table.setData( data, headers ); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; table.alignment = 'right'; expected = [ @@ -352,7 +309,7 @@ tape( 'the function supports rendering a table with different alignments', funct '└───────┴──────┴───────┘' ].join( '\n' ); str = table.render(); - t.strictEqual( str, expected, 'returns right-aligned rendered table' ); + t.strictEqual( str, expected, 'returns rendered table' ); table.alignment = 'left'; expected = [ @@ -364,7 +321,7 @@ tape( 'the function supports rendering a table with different alignments', funct '└───────┴──────┴───────┘' ].join( '\n' ); str = table.render(); - t.strictEqual( str, expected, 'returns left-aligned rendered table' ); + t.strictEqual( str, expected, 'returns rendered table' ); table.alignment = 'center'; expected = [ @@ -376,23 +333,135 @@ tape( 'the function supports rendering a table with different alignments', funct '└───────┴──────┴───────┘' ].join( '\n' ); str = table.render(); - t.strictEqual( str, expected, 'returns center-aligned rendered table' ); + t.strictEqual( str, expected, 'returns rendered table' ); + + table.alignment = [ 'left', 'center', 'right' ]; + expected = [ + '┌───────┬──────┬───────┐', + '│ col1 │ col2 │ col3 │', + '├───────┼──────┼───────┤', + '│ 45 │ 33 │ hello │', + '│ 32.54 │ true │ null │', + '└───────┴──────┴───────┘' + ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); t.end(); }); -tape( 'the function supports rendering a wrapped table for long outputs', function test( t ) { +tape( 'the function supports rendering a table with different horizontal line separator modes', function test( t ) { var expected; - var headers; var table; - var data; var str; table = ctor(); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; + table.headerSeparator = '123'; + table.rowSeparator = '123'; + table.borders = [ '123', '│', '123', '│' ]; + + table.horizontalSeparatorMode = 'resume'; + expected = [ + '┌1231231┬231231┬2312312┐', + '│ col1 │ col2 │ col3 │', + '├1231231┼231231┼2312312┤', + '│ 45 │ 33 │ hello │', + '├1231231┼231231┼2312312┤', + '│ 32.54 │ true │ null │', + '└1231231┴231231┴2312312┘' + ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); - data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; - headers = [ 'col1', 'col2', 'col3' ]; - table.setData( data, headers ); + table.horizontalSeparatorMode = 'interpolate'; + expected = [ + '┌2312312┬123123┬2312312┐', + '│ col1 │ col2 │ col3 │', + '├2312312┼123123┼2312312┤', + '│ 45 │ 33 │ hello │', + '├2312312┼123123┼2312312┤', + '│ 32.54 │ true │ null │', + '└2312312┴123123┴2312312┘' + ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + table.horizontalSeparatorMode = 'repeat'; + expected = [ + '┌1231231┬123123┬1231231┐', + '│ col1 │ col2 │ col3 │', + '├1231231┼123123┼1231231┤', + '│ 45 │ 33 │ hello │', + '├1231231┼123123┼1231231┤', + '│ 32.54 │ true │ null │', + '└1231231┴123123┴1231231┘' + ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + t.end(); +}); + +tape( 'the function supports rendering a table with different vertical line separator modes', function test( t ) { + var expected; + var table; + var str; + + table = ctor(); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; + table.columnSeparator = '123'; + table.borders = [ '─', '123', '─', '123' ]; + + table.verticalSeparatorMode = 'resume'; + expected = [ + '┌───────┬──────┬───────┐', + '1 col1 1 col2 1 col3 1', + '├───────┼──────┼───────┤', + '2 45 2 33 2 hello 2', + '3 32.54 3 true 3 null 3', + '└───────┴──────┴───────┘' + ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + table.verticalSeparatorMode = 'interpolate'; + expected = [ + '┌───────┬──────┬───────┐', + '2 col1 2 col2 2 col3 2', + '├───────┼──────┼───────┤', + '1 45 1 33 1 hello 1', + '2 32.54 2 true 2 null 2', + '└───────┴──────┴───────┘' + ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + table.verticalSeparatorMode = 'repeat'; + expected = [ + '┌───────┬──────┬───────┐', + '1 col1 1 col2 1 col3 1', + '├───────┼──────┼───────┤', + '1 45 1 33 1 hello 1', + '2 32.54 2 true 2 null 2', + '└───────┴──────┴───────┘' + ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + t.end(); +}); + +tape( 'the function supports rendering a wrapped table for long outputs', function test( t ) { + var expected; + var table; + var str; + + table = ctor(); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; table.maxOutputWidth = 16; expected = [ diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.row_separator.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.row_separator.js index 2e34d82bed3e..9f8d6db4e535 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/test/test.row_separator.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.row_separator.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); var ctor = require( './../lib' ); @@ -44,8 +45,7 @@ tape( 'an instance throws an error if provided an invalid `rowSeparator` value', null, void 0, {}, - [], - '5437' + [] ]; for ( i = 0; i < values.length; i++ ) { @@ -70,11 +70,47 @@ tape( 'an instance supports setting and getting the property value', function te }); t.strictEqual( table.rowSeparator, '1', 'returns expected value' ); - table.rowSeparator = '!'; - t.strictEqual( table.rowSeparator, '!', 'returns expected value' ); + table.rowSeparator = '!/1'; + t.strictEqual( table.rowSeparator, '!/1', 'returns expected value' ); - table.rowSeparator = 'None'; - t.strictEqual( table.rowSeparator, 'None', 'returns expected value' ); + table.rowSeparator = ''; + t.strictEqual( table.rowSeparator, '', 'returns expected value' ); t.end(); }); + +tape( 'setting the `rowSeparator` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'rowSeparator': '1' + }); + table.render = noop; + + table.on( 'change', onChange ); + table.rowSeparator = '23'; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `rowSeparator` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'rowSeparator': '1' + }); + table.render = noop; + + table.on( 'change', onChange ); + table.rowSeparator = '1'; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); diff --git a/lib/node_modules/@stdlib/plot/table/unicode/test/test.vertical_separator_mode.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.vertical_separator_mode.js new file mode 100644 index 000000000000..d8a49ae57697 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.vertical_separator_mode.js @@ -0,0 +1,119 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var ctor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ctor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'an instance throws an error if provided an invalid `verticalSeparatorMode` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + '1234', + 'beep' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var table = ctor(); + table.verticalSeparatorMode = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + + table = ctor( null, { + 'verticalSeparatorMode': 'interpolate' + }); + table.render = noop; + + t.strictEqual( table.verticalSeparatorMode, 'interpolate', 'returns expected value' ); + + table.verticalSeparatorMode = 'repeat'; + t.strictEqual( table.verticalSeparatorMode, 'repeat', 'returns expected value' ); + + table.verticalSeparatorMode = 'resume'; + t.strictEqual( table.verticalSeparatorMode, 'resume', 'returns expected value' ); + + t.end(); +}); + +tape( 'setting the `verticalSeparatorMode` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'verticalSeparatorMode': 'interpolate' + }); + table.render = noop; + + table.on( 'change', onChange ); + table.verticalSeparatorMode = 'resume'; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `verticalSeparatorMode` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'verticalSeparatorMode': 'repeat' + }); + table.render = noop; + + table.on( 'change', onChange ); + table.verticalSeparatorMode = 'repeat'; + + t.ok( true, 'does not trigger event' ); + t.end(); + + function onChange() { + t.ok( false, 'should not trigger event' ); + } +}); From 2c7c6043bb6a46b75b286c099147d251960cb307 Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Sat, 20 Jul 2024 20:29:10 +0000 Subject: [PATCH 03/34] docs: update jsdoc Signed-off-by: Snehil Shah --- .../@stdlib/plot/table/unicode/lib/props/borders/set.js | 2 +- .../@stdlib/plot/table/unicode/lib/props/headers/set.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/set.js index f66106e202be..af94a32e1c88 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/set.js @@ -36,7 +36,7 @@ var NUM_BORDERS = 4; * Sets the table's border characters. * * @private -* @param {string} borders - borders string +* @param {Array} borders - border characters * @throws {TypeError} must be an array of four strings */ function set( borders ) { diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/set.js index a3d90bcc23ec..e283428aea26 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/set.js +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/set.js @@ -29,7 +29,7 @@ var parseHeaders = require( './../../parser/parse_headers.js' ); // MAIN // /** -* Sets the table data. +* Sets the table headers. * * @private * @param {Collection} headers - table headers From 8d36829871d03218a5581f7f0471a58acdf8660e Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Sat, 27 Jul 2024 06:46:09 +0000 Subject: [PATCH 04/34] docs: add events to README Signed-off-by: Snehil Shah --- .../@stdlib/plot/table/unicode/README.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/node_modules/@stdlib/plot/table/unicode/README.md b/lib/node_modules/@stdlib/plot/table/unicode/README.md index 98d9eeb72097..1faa698470e2 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/README.md +++ b/lib/node_modules/@stdlib/plot/table/unicode/README.md @@ -506,6 +506,36 @@ var str = table.render(); * * * +### Events + +#### 'change' + +Emitted whenever a property value changes. + +```javascript +var table = new UnicodeTable(); + +table.on( 'change', onChange ); + +function onChange() { + console.log( 'A property was updated.' ); +} +``` + +#### 'render' + +Emitted whenever a sparkline is rendered. + +```javascript +var table = new UnicodeTable(); + +table.on( 'render', onRender ); + +function onRender( str ) { + console.log( 'Rendered table: %s', str ); +} +``` + From 9ea8bad77f909bf5415f992d019e4f12874ce33a Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Tue, 11 Feb 2025 01:40:58 -0800 Subject: [PATCH 05/34] refactor: update implementation and clean-up --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/plot/table/unicode/README.md | 570 ++++++++--- .../plot/table/unicode/benchmark/benchmark.js | 654 ++++++++++--- .../unicode/benchmark/benchmark.render.js | 42 +- .../@stdlib/plot/table/unicode/docs/repl.txt | 236 +++-- .../plot/table/unicode/examples/index.js | 28 +- .../plot/table/unicode/lib/defaults.js | 155 ++- .../{parser/parse_headers.js => every_by2.js} | 40 +- .../@stdlib/plot/table/unicode/lib/index.js | 7 +- .../@stdlib/plot/table/unicode/lib/main.js | 889 ++++++++++++------ .../@stdlib/plot/table/unicode/lib/parse.js | 83 -- .../unicode/lib/parser/parse_2d_array.js | 74 -- .../table/unicode/lib/parser/parse_object.js | 99 -- .../unicode/lib/parser/parse_objects_list.js | 84 -- .../lib/props/{alignment => align}/get.js | 16 +- .../plot/table/unicode/lib/props/align/set.js | 93 ++ .../table/unicode/lib/props/alignment/set.js | 77 -- .../unicode/lib/props/auto-render/get.js | 5 +- .../unicode/lib/props/auto-render/set.js | 19 +- .../unicode/lib/props/border-bottom/get.js | 38 + .../unicode/lib/props/border-bottom/set.js | 60 ++ .../props/{margin-y => border-left}/get.js | 11 +- .../unicode/lib/props/border-left/set.js | 60 ++ .../unicode/lib/props/border-right/get.js | 38 + .../unicode/lib/props/border-right/set.js | 60 ++ .../{max-output-width => border-top}/get.js | 11 +- .../table/unicode/lib/props/border-top/set.js | 60 ++ .../table/unicode/lib/props/borders/get.js | 14 +- .../table/unicode/lib/props/borders/set.js | 60 +- .../unicode/lib/props/buffer-size/get.js | 7 +- .../unicode/lib/props/buffer-size/set.js | 36 +- .../lib/props/cell-padding-left/get.js | 45 - .../lib/props/cell-padding-left/set.js | 62 -- .../lib/props/cell-padding-right/get.js | 45 - .../lib/props/cell-padding-right/set.js | 62 -- .../unicode/lib/props/column-separator/get.js | 7 +- .../unicode/lib/props/column-separator/set.js | 28 +- .../lib/props/corner-bottom-left/get.js | 38 + .../lib/props/corner-bottom-left/set.js | 63 ++ .../lib/props/corner-bottom-right/get.js | 38 + .../lib/props/corner-bottom-right/set.js | 63 ++ .../unicode/lib/props/corner-top-left/get.js | 38 + .../unicode/lib/props/corner-top-left/set.js | 63 ++ .../unicode/lib/props/corner-top-right/get.js | 38 + .../unicode/lib/props/corner-top-right/set.js | 63 ++ .../table/unicode/lib/props/corners/get.js | 14 +- .../table/unicode/lib/props/corners/set.js | 69 +- .../plot/table/unicode/lib/props/data/get.js | 19 +- .../plot/table/unicode/lib/props/data/set.js | 243 ++++- .../unicode/lib/props/header-separator/get.js | 7 +- .../unicode/lib/props/header-separator/set.js | 26 +- .../table/unicode/lib/props/headers/get.js | 8 +- .../table/unicode/lib/props/headers/set.js | 68 +- .../props/horizontal-separator-mode/get.js | 7 +- .../props/horizontal-separator-mode/set.js | 19 +- .../unicode/lib/props/joint-bottom/get.js | 38 + .../unicode/lib/props/joint-bottom/set.js | 63 ++ .../table/unicode/lib/props/joint-left/get.js | 38 + .../table/unicode/lib/props/joint-left/set.js | 63 ++ .../unicode/lib/props/joint-middle/get.js | 38 + .../unicode/lib/props/joint-middle/set.js | 63 ++ .../unicode/lib/props/joint-right/get.js | 38 + .../unicode/lib/props/joint-right/set.js | 63 ++ .../table/unicode/lib/props/joint-top/get.js | 38 + .../table/unicode/lib/props/joint-top/set.js | 63 ++ .../table/unicode/lib/props/joints/get.js | 12 +- .../table/unicode/lib/props/joints/set.js | 69 +- .../unicode/lib/props/margin-bottom/get.js | 38 + .../unicode/lib/props/margin-bottom/set.js | 53 ++ .../unicode/lib/props/margin-left/get.js | 38 + .../props/{margin-y => margin-left}/set.js | 25 +- .../unicode/lib/props/margin-right/get.js | 38 + .../unicode/lib/props/margin-right/set.js | 53 ++ .../table/unicode/lib/props/margin-top/get.js | 38 + .../lib/props/{margin-x => margin-top}/set.js | 25 +- .../lib/props/{margin-x => margins}/get.js | 11 +- .../table/unicode/lib/props/margins/set.js | 66 ++ .../unicode/lib/props/max-cell-width/get.js | 16 +- .../unicode/lib/props/max-cell-width/set.js | 86 +- .../table/unicode/lib/props/max-width/get.js | 38 + .../{max-output-width => max-width}/set.js | 36 +- .../unicode/lib/props/padding-left/get.js | 41 + .../unicode/lib/props/padding-left/set.js | 75 ++ .../unicode/lib/props/padding-right/get.js | 41 + .../unicode/lib/props/padding-right/set.js | 75 ++ .../unicode/lib/props/row-separator/get.js | 7 +- .../unicode/lib/props/row-separator/set.js | 28 +- .../lib/props/vertical-separator-mode/get.js | 7 +- .../lib/props/vertical-separator-mode/set.js | 27 +- .../@stdlib/plot/table/unicode/lib/push.js | 18 +- .../@stdlib/plot/table/unicode/lib/render.js | 751 +++++++++------ 90 files changed, 5075 insertions(+), 1901 deletions(-) rename lib/node_modules/@stdlib/plot/table/unicode/lib/{parser/parse_headers.js => every_by2.js} (50%) delete mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/parse.js delete mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_2d_array.js delete mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_object.js delete mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/parser/parse_objects_list.js rename lib/node_modules/@stdlib/plot/table/unicode/lib/props/{alignment => align}/get.js (76%) create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/align/set.js delete mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/alignment/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-bottom/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-bottom/set.js rename lib/node_modules/@stdlib/plot/table/unicode/lib/props/{margin-y => border-left}/get.js (80%) create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-left/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-right/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-right/set.js rename lib/node_modules/@stdlib/plot/table/unicode/lib/props/{max-output-width => border-top}/get.js (80%) create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-top/set.js delete mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-left/get.js delete mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-left/set.js delete mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-right/get.js delete mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/cell-padding-right/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-left/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-left/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-right/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-right/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-left/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-left/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-right/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-right/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-bottom/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-bottom/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-left/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-left/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-middle/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-middle/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-right/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-right/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-top/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-top/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-bottom/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-bottom/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-left/get.js rename lib/node_modules/@stdlib/plot/table/unicode/lib/props/{margin-y => margin-left}/set.js (65%) create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-right/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-right/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-top/get.js rename lib/node_modules/@stdlib/plot/table/unicode/lib/props/{margin-x => margin-top}/set.js (67%) rename lib/node_modules/@stdlib/plot/table/unicode/lib/props/{margin-x => margins}/get.js (82%) create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/margins/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-width/get.js rename lib/node_modules/@stdlib/plot/table/unicode/lib/props/{max-output-width => max-width}/set.js (65%) create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-left/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-left/set.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-right/get.js create mode 100644 lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-right/set.js diff --git a/lib/node_modules/@stdlib/plot/table/unicode/README.md b/lib/node_modules/@stdlib/plot/table/unicode/README.md index 1faa698470e2..148ac9cde14b 100644 --- a/lib/node_modules/@stdlib/plot/table/unicode/README.md +++ b/lib/node_modules/@stdlib/plot/table/unicode/README.md @@ -30,7 +30,7 @@ limitations under the License. var UnicodeTable = require( '@stdlib/plot/table/unicode' ); ``` -#### UnicodeTable( \[data,] \[headers,] \[options] ) +#### UnicodeTable( \[data,] \[options] ) Returns a table instance. @@ -38,87 +38,140 @@ Returns a table instance. var table = new UnicodeTable(); ``` +The constructor accepts the following arguments: + +- **data**: table data provided as either an object, an array of objects, an array of arrays, or a two-dimensional [ndarray][@stdlib/ndarray/ctor] (_optional_). +- **options**: constructor options (_optional_). + The constructor accepts the following `options`: -- **alignment**: datum's cell alignment. Default: `'right'`. +- **align**: alignment of data within table cells. Must be one of the following: + + - `'right'`: right-aligned. + - `'left'`: left-aligned. + - `'center'`: center-aligned. + + To specify the alignment of data within each table column, provide an array of alignment specifiers. Default: `'right'`. -- **autoRender**: `boolean` indicating whether to re-render on a `change` event. Default: `false`. +- **autoRender**: boolean indicating whether to automatically re-render a table on a `change` event. Default: `false`. -- **borders**: border characters. Default: `[ '─', '│', '─', '│' ]`. +- **borderTop**: top table border character(s). Default: `'-'`. -- **bufferSize**: data buffer size. If provided, data is kept in a first-in first-out (FIFO) buffer which cannot exceed the buffer size. Default: `+infinity`. +- **borderRight**: right table border character(s). Default: `'|'`. -- **cellPaddingLeft**: cell's left padding. Default: `1`. +- **borderBottom**: bottom table border character(s). Default: `'-'`. -- **cellPaddingRight**: cell's right padding. Default: `1`. +- **borderLeft**: left table border character(s). Default: `'|'`. + +- **borders**: table border characters in the order `[top, right, bottom, left]`. This is a shorthand option instead of specifying borders individually. Default: `[ '─', '│', '─', '│' ]`. + +- **bufferSize**: data buffer size. If specified, data is kept in a first-in first-out (FIFO) buffer which cannot exceed the specified buffer size. Default: `+infinity`. - **columnSeparator**: column separator character(s). Default: `'│'`. -- **corners**: corner characters. Default: `[ '┌', '┐', '┘', '└' ]`. +- **cornerTopLeft**: top-left table corner grapheme cluster (i.e., visual character). Default: `'┌'`. + +- **cornerTopRight**: top-right table corner grapheme cluster (i.e., visual character). Default: `'┌'`. + +- **cornerBottomRight**: bottom-right table corner grapheme cluster (i.e., visual character). Default: `'┘'`. + +- **cornerBottomLeft**: bottom-left table corner grapheme cluster (i.e., visual character). Default: `'└'`. + +- **corners**: table corner grapheme clusters (i.e., visual characters) in the order `[top-left, top-right, bottom-right, bottom-left]`. This is a shorthand option instead of specifying corner character sequences individually. Default: `[ '┌', '┐', '┘', '└' ]`. + +- **headers**: table headers. - **headerSeparator**: header separator character(s). Default: `'─'`. -- **horizontalSeparatorMode**: Horizontal line separator mode. The following modes are supported: +- **horizontalSeparatorMode**: horizontal line separator mode. Must be one of the following: - `resume`: resume line sequence after a joint. - `interpolate`: skip line character at a joint. - `repeat`: repeat line sequence after a joint. - - Default: `resume`. -- **joints**: joint characters. Default: `[ '┼', '┬', '┤', '┴', '├' ]`. + Default: `'resume'`. + +- **jointMiddle**: joint grapheme cluster (i.e., visual character) connecting table cells within the middle of the table. Default: `'┼'`. + +- **jointTop**: joint grapheme cluster (i.e., visual character) connecting table cells along the top of the table. Default: `'┬'`. + +- **jointRight**: joint grapheme cluster (i.e., visual character) connecting table cells along the right of the table. Default: `'┤'`. + +- **jointBottom**: joint grapheme cluster (i.e., visual character) connecting table cells along the bottom of the table. Default: `'┴'`. + +- **jointLeft**: joint grapheme cluster (i.e., visual character) connecting table cells along the left of the table. Default: `'├'`. -- **marginX**: horizontal output margin. Default: `0`. +- **joints**: joint grapheme clusters (i.e., visual characters) connecting table cells in the order `[middle, top, right, bottom, left]`. This is a shorthand option instead of specifying join character sequences individually. Default: `[ '┼', '┬', '┤', '┴', '├' ]`. -- **marginY**: vertical output margin. Default: `0`. +- **marginTop**: margin at the top of the table in units of blank lines. Default: `0`. -- **maxCellWidth**: maximum cell width(s). Default: `+infinity`. +- **marginRight**: margin to the right of the table in units of whitespace. Default: `0`. -- **maxOutputWidth**: maximum output width. Default: `+infinity`. +- **marginBottom**: margin at the bottom of the table in units of blank lines. Default: `0`. + +- **marginLeft**: margin to the left of the table in units of whitespace. Default: `0`. + +- **margins**: table margins in the order `[top, right, bottom, left]`. This is a shorthand option instead of specifying margins individually. Default: `[ 0, 0, 0, 0 ]`. + +- **maxCellWidth**: maximum cell width(s) in units of grapheme clusters (i.e., visual characters). Default: `+infinity`. + +- **maxWidth**: maximum table width in units of grapheme clusters (i.e., visual characters). Default: `+infinity`. + +- **paddingLeft**: cell left padding in units of whitespace characters. Default: `1`. + +- **paddingRight**: cell right padding in units of whitespace characters. Default: `1`. - **rowSeparator**: row separator character(s). Default: `''`. -- **verticalSeparatorMode**: Vertical line separator mode. The following modes are supported: +- **verticalSeparatorMode**: vertical line separator mode. Must be one of the following: - - `resume`: resume line sequence after a joint. - - `interpolate`: skip line character at a joint. - - `repeat`: repeat line sequence after a joint. - - Default: `resume`. + - `'resume'`: resume line sequence after a joint. + - `'interpolate'`: skip line character at a joint. + - `'repeat'`: repeat line sequence after a joint. + + Default: `'resume'`. * * * ### Writable Properties - + -#### UnicodeTable.prototype.alignment +#### UnicodeTable.prototype.align -Alignment(s) of datum in cell. The value must be either `'right'`, `'left'`, or `'center'` or an array of them. +Alignment(s) of data within table cells. ```javascript var table = new UnicodeTable(); // Set: -table.alignment = 'center'; +table.align = 'center'; // Get: -var alignment = table.alignment; +var align = table.align; // returns 'center' // Set: -table.alignment = [ 'left', 'right', 'center' ]; +table.align = [ 'left', 'right', 'center' ]; // Get: -alignment = table.alignment; +align = table.align; // returns [ 'left', 'right', 'center' ] ``` +The following alignments are supported: + +- **right**: right-aligned. +- **left**: left-aligned. +- **center**: center-aligned. + +To specify the alignment for each column of table cells, set to an array of alignment values. + #### UnicodeTable.prototype.autoRender -Rendering mode. If `true`, an instance renders on each `'change'` event; otherwise, rendering must be triggered manually. +Rendering mode. If `true`, an instance automatically re-renders a table on each `'change'` event; otherwise, rendering must be triggered manually. ```javascript var table = new UnicodeTable(); @@ -131,11 +184,79 @@ var mode = table.autoRender; // returns false ``` + + +#### UnicodeTable.prototype.borderTop + +Top table border character(s). + +```javascript +var table = new UnicodeTable(); + +// Set: +table.borderTop = '='; + +// Get: +var border = table.borderTop; +// returns '=' +``` + + + +#### UnicodeTable.prototype.borderRight + +Right table border character(s). + +```javascript +var table = new UnicodeTable(); + +// Set: +table.borderRight = '!'; + +// Get: +var border = table.borderRight; +// returns '!' +``` + + + +#### UnicodeTable.prototype.borderBottom + +Bottom table border character(s). + +```javascript +var table = new UnicodeTable(); + +// Set: +table.borderBottom = '='; + +// Get: +var border = table.borderBottom; +// returns '=' +``` + + + +#### UnicodeTable.prototype.borderLeft + +Left table border character(s). + +```javascript +var table = new UnicodeTable(); + +// Set: +table.borderLeft = '!'; + +// Get: +var border = table.borderLeft; +// returns '!' +``` + #### UnicodeTable.prototype.borders -Border characters. Must be an array of `four` strings in the order `[ 'top', 'right', 'bottom', 'left' ]`. +Table border characters in the order `[ 'top', 'right', 'bottom', 'left' ]`. ```javascript var table = new UnicodeTable(); @@ -152,7 +273,7 @@ var borders = table.borders; #### UnicodeTable.prototype.bufferSize -Data buffer size. If set, this specifies the maximum number of rows which can be rendered. Once the data buffer is full, each new row results in the oldest row being removed. +Data buffer size. If set, this specifies the maximum number of rows which can be rendered. Once an internal data buffer is full, each new row results in the oldest row being removed. ```javascript var table = new UnicodeTable(); @@ -177,76 +298,96 @@ data = table.data; Setting a data buffer size is useful when rendering data streams. - + -#### UnicodeTable.prototype.cellPaddingLeft +#### UnicodeTable.prototype.columnSeparator -Cell's left padding(s). Pads the left side of the cell with whitespace characters. Pad each cell individually by providing an array of paddings. +Column separator character(s). If provided a string with multiple grapheme clusters, each grapheme cluster is rendered sequentially. No separator is rendered if provided an empty string. ```javascript var table = new UnicodeTable(); // Set: -table.cellPaddingLeft = 3; +table.columnSeparator = '|'; // Get: -var padding = table.cellPaddingLeft; -// returns 3 +var separator = table.columnSeparator; +// returns '|' +``` + + + +#### UnicodeTable.prototype.cornerTopLeft + +Top-left table corner grapheme cluster (i.e., visual character). + +```javascript +var table = new UnicodeTable(); // Set: -table.cellPaddingLeft = [ 3, 4 ]; +table.cornerTopLeft = '*'; // Get: -padding = table.cellPaddingLeft; -// returns [ 3, 4 ] +var corner = table.cornerTopLeft; +// returns '*' ``` - + -#### UnicodeTable.prototype.cellPaddingRight +#### UnicodeTable.prototype.cornerTopRight -Cell's right padding(s). Pads the right side of the cell with whitespace characters. Pad each cell individually by providing an array of paddings. +Top-right table corner grapheme cluster (i.e., visual character). ```javascript var table = new UnicodeTable(); // Set: -table.cellPaddingRight = 3; +table.cornerTopRight = '*'; // Get: -var padding = table.cellPaddingRight; -// returns 3 +var corner = table.cornerTopRight; +// returns '*' +``` + + + +#### UnicodeTable.prototype.cornerBottomRight + +Bottom-right table corner grapheme cluster (i.e., visual character). + +```javascript +var table = new UnicodeTable(); // Set: -table.cellPaddingRight = [ 3, 4 ]; +table.cornerBottomRight = '*'; // Get: -padding = table.cellPaddingRight; -// returns [ 3, 4 ] +var corner = table.cornerBottomRight; +// returns '*' ``` - + -#### UnicodeTable.prototype.columnSeparator +#### UnicodeTable.prototype.cornerBottomLeft -Column separator character(s). If provided a string with multiple graphmeme clusters, each grapheme cluster is rendered sequentially. No separator is rendered if provided an empty string. +Bottom-left table corner grapheme cluster (i.e., visual character). ```javascript var table = new UnicodeTable(); // Set: -table.columnSeparator = '|'; +table.cornerBottomLeft = '*'; // Get: -var separator = table.columnSeparator; -// returns '|' +var corner = table.cornerBottomLeft; +// returns '*' ``` #### UnicodeTable.prototype.corners -Corner characters. Must be an array of `four` grapheme clusters in the order `[ 'top-left', 'top-right', 'bottom-right', 'bottom-left' ]`. +Table corner grapheme clusters (i.e., visual characters) in the order `[ 'top-left', 'top-right', 'bottom-right', 'bottom-left' ]`. ```javascript var table = new UnicodeTable(); @@ -263,16 +404,18 @@ var corners = table.corners; #### UnicodeTable.prototype.data -Table data. Must be an array of arrays or a MatrixLike ndarray and should not exceed the `bufferSize`. +Table data. ```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + var table = new UnicodeTable(); // Set: table.data = [ [ 1, 2 ], [ 3, 4 ] ]; // Get: -var data = table.data; +var data = ndarray2array( table.data ); // returns [ [ 1, 2 ], [ 3, 4 ] ] ``` @@ -280,7 +423,7 @@ var data = table.data; #### UnicodeTable.prototype.headers -Table headers. Must be an array. +Table headers. ```javascript var table = new UnicodeTable(); @@ -297,7 +440,7 @@ var headers = table.headers; #### UnicodeTable.prototype.headerSeparator -Header separator character(s). If provided a string with multiple graphmeme clusters, each grapheme cluster is rendered sequentially. No separator is rendered if provided an empty string. +Header separator character(s). If provided a string with multiple grapheme clusters, each grapheme cluster is rendered sequentially. No separator is rendered if provided an empty string. ```javascript var table = new UnicodeTable(); @@ -314,11 +457,7 @@ var separator = table.headerSeparator; #### UnicodeTable.prototype.horizontalSeparatorMode -Horizontal line separator mode. The following modes are supported: - -- `resume`: resume line sequence after a joint. -- `interpolate`: skip line character at a joint. -- `repeat`: repeat line sequence after a joint. +Horizontal line separator mode. ```javascript var table = new UnicodeTable(); @@ -331,11 +470,102 @@ var mode = table.horizontalSeparatorMode; // returns 'interpolate' ``` +The following modes are supported: + +- **resume**: resume line sequence after a joint. +- **interpolate**: skip line character at a joint. +- **repeat**: repeat line sequence after a joint. + + + +#### UnicodeTable.prototype.jointMiddle + +Joint grapheme cluster (i.e., visual character) connecting cells within the middle of the table. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.jointMiddle = '*'; + +// Get: +var joint = table.jointMiddle; +// returns '*' +``` + + + +#### UnicodeTable.prototype.jointTop + +Joint grapheme cluster (i.e., visual character) connecting cells along the top of the table. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.jointTop = '*'; + +// Get: +var joint = table.jointTop; +// returns '*' +``` + + + +#### UnicodeTable.prototype.jointRight + +Joint grapheme cluster (i.e., visual character) connecting cells along the right side of the table. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.jointRight = '*'; + +// Get: +var joint = table.jointRight; +// returns '*' +``` + + + +#### UnicodeTable.prototype.jointBottom + +Joint grapheme cluster (i.e., visual character) connecting cells along the bottom of the table. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.jointBottom = '*'; + +// Get: +var joint = table.jointBottom; +// returns '*' +``` + + + +#### UnicodeTable.prototype.jointLeft + +Joint grapheme cluster (i.e., visual character) connecting cells along the left side of the table. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.jointLeft = '*'; + +// Get: +var joint = table.jointLeft; +// returns '*' +``` + #### UnicodeTable.prototype.joints -Joint characters. Must be an array of `five` grapheme clusters in the order `[ 'middle', 'top', 'right', 'bottom', 'left' ]`. +Joint grapheme clusters (i.e., visual characters) in the order `[ 'middle', 'top', 'right', 'bottom', 'left' ]`. ```javascript var table = new UnicodeTable(); @@ -348,45 +578,96 @@ var joints = table.joints; // returns [ '*', '*', '*', '*', '*' ] ``` - + + +#### UnicodeTable.prototype.marginTop + +Margin at the top of the table in units of blank lines. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.marginTop = 2; + +// Get: +var margin = table.marginTop; +// returns 2 +``` + + + +#### UnicodeTable.prototype.marginRight + +Margin to the right of the table in units of whitespace. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.marginRight = 2; + +// Get: +var margin = table.marginRight; +// returns 2 +``` + + -#### UnicodeTable.prototype.marginX +#### UnicodeTable.prototype.marginBottom -Horizontal output margin. This will add margin to both left and right of the output. +Margin at the bottom of the table in units of blank lines. ```javascript var table = new UnicodeTable(); // Set: -table.marginX = 2; +table.marginBottom = 2; // Get: -var margin = table.marginX; +var margin = table.marginBottom; // returns 2 ``` - + -#### UnicodeTable.prototype.marginY +#### UnicodeTable.prototype.marginLeft -Vertical output margin. This will add margin to both top and bottom of the output. +Margin to the left of the table in units of whitespace. ```javascript var table = new UnicodeTable(); // Set: -table.marginY = 2; +table.marginLeft = 2; // Get: -var margin = table.marginY; +var margin = table.marginLeft; // returns 2 ``` + + +#### UnicodeTable.prototype.margins + +Table margins in the order of `[ top, right, bottom, left ]`. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.margins = [ 2, 2, 2, 2 ]; + +// Get: +var margins = table.margins; +// returns [ 2, 2, 2, 2 ] +``` + #### UnicodeTable.prototype.maxCellWidth -Maximum cell width. If a datum is longer than the maximum cell width, it is truncated. Truncate each cell individually by providing an array of widhts. +Maximum cell width in units of grapheme clusters (i.e., visual characters). If cell data is longer than the maximum cell width, the rendered cell data is truncated. To specify the maximum cell width for each column of cells, provide an array of maximum cell widths. ```javascript var table = new UnicodeTable(); @@ -405,28 +686,76 @@ table.maxCellWidth = [ 10, 15 ]; width = table.maxCellWidth; ``` - + -#### UnicodeTable.prototype.maxOutputWidth +#### UnicodeTable.prototype.maxWidth -Maximum output width. If the output is longer than the maximum output width, it is wrapped into multiple tables. +Maximum table width in units of grapheme clusters (i.e., visual characters). If the generated table is longer than the maximum table width, a generated table is split into multiple tables. ```javascript var table = new UnicodeTable(); // Set: -table.maxOutputWidth = 200; +table.maxWidth = 200; // Get: -var width = table.maxOutputWidth; +var width = table.maxWidth; // returns 200 ``` + + +#### UnicodeTable.prototype.paddingLeft + +Cell left padding(s) in units of whitespace. To specify the padding of each column of table cells, provide an array of paddings. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.paddingLeft = 3; + +// Get: +var padding = table.paddingLeft; +// returns 3 + +// Set: +table.paddingLeft = [ 3, 4 ]; + +// Get: +padding = table.paddingLeft; +// returns [ 3, 4 ] +``` + + + +#### UnicodeTable.prototype.paddingRight + +Cell right padding(s) in units of whitespace. To specify the padding of each column of table cells, provide an array of paddings. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.paddingRight = 3; + +// Get: +var padding = table.paddingRight; +// returns 3 + +// Set: +table.paddingRight = [ 3, 4 ]; + +// Get: +padding = table.paddingRight; +// returns [ 3, 4 ] +``` + #### UnicodeTable.prototype.rowSeparator -Row separator character(s). If provided a string with multiple graphmeme clusters, each grapheme cluster is rendered sequentially. No separator is rendered if provided an empty string. +Row separator character(s). If provided a string with multiple grapheme clusters, each grapheme cluster is rendered sequentially. No separator is rendered if provided an empty string. ```javascript var table = new UnicodeTable(); @@ -443,11 +772,7 @@ var separator = table.rowSeparator; #### UnicodeTable.prototype.verticalSeparatorMode -Vertical line separator mode. The following modes are supported: - -- `resume`: resume line sequence after a joint. -- `interpolate`: skip line character at a joint. -- `repeat`: repeat line sequence after a joint. +Vertical line separator mode. ```javascript var table = new UnicodeTable(); @@ -460,28 +785,36 @@ var mode = table.verticalSeparatorMode; // returns 'interpolate' ``` +The following modes are supported: + +- **resume**: resume line sequence after a joint. +- **interpolate**: skip line character at a joint. +- **repeat**: repeat line sequence after a joint. + * * * ### Methods -#### UnicodeTable.prototype.push( row ) +#### UnicodeTable.prototype.push( data ) -Appends a row to table data. The row must have the same number of columns as existing data. +Appends one or more rows to table data. Each provided row must have the same number of columns as existing table data. ```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + var table = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); // Get: -var data = table.data; +var data = ndarray2array( table.data ); // returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] // Push: table.push( [ 7, 8, 9 ] ); // Get: -data = table.data; +data = ndarray2array( table.data ); // returns [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ``` @@ -492,13 +825,10 @@ data = table.data; Renders a Unicode table. ```javascript -var headers; -var table; -var data; +var headers = [ 'col1', 'col2', 'col3' ]; +var data = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; -headers = [ 'col1', 'col2', 'col3' ]; -data = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; -table = new UnicodeTable( data, headers ); +var table = new UnicodeTable( data, headers ); var str = table.render(); // returns '...' @@ -524,7 +854,7 @@ function onChange() { #### 'render' -Emitted whenever a sparkline is rendered. +Emitted whenever a table is rendered. ```javascript var table = new UnicodeTable(); @@ -542,6 +872,12 @@ function onRender( str ) {
+* * * + +## Notes + +- Once a table instance has resolved the number of table columns (e.g., by setting table headers, binding table data, specifying column paddings, or specifying column alignments), the number of table columns is fixed. In order to remove or add table columns, create a new table instance with the desired configuration. +
@@ -559,27 +895,29 @@ function onRender( str ) { ```javascript var uniform = require( '@stdlib/random/array/uniform' ); var array = require( '@stdlib/ndarray/array' ); -var ctor = require( '@stdlib/plot/table/unicode' ); - -var headers; -var table; -var data; -var str; +var UnicodeTable = require( '@stdlib/plot/table/unicode' ); -// Generate some random data... -data = uniform( 50, 1, 100 ); -data = array( data, { +// Generate a random data set: +var data = array( uniform( 50, 1.0, 100.0 ), { 'shape': [ 10, 5 ] }); -// Generate headers... -headers = [ 'A', 'B', 'C', 'D', 'E' ]; +// Define column headers: +var headers = [ 'A', 'B', 'C', 'D', 'E' ]; // Create a table: -table = ctor( data, headers ); +var table = new UnicodeTable( data, { + 'headers': headers, + 'rowSeparator': '-', + 'columnSeparator': '#$%', + 'maxWidth': 200, + 'marginLeft': 5, + 'marginRight': 5, + 'align': 'right' +}); // Render the table: -str = table.render(); +var str = table.render(); console.log( str ); // => '...' ``` @@ -588,9 +926,9 @@ console.log( str ); -* * * + -## See Also + @@ -600,6 +938,8 @@ console.log( str );