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..4edd1d82c108 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/README.md @@ -0,0 +1,1162 @@ + + +# Unicode Table + +> Create a Unicode table. + +
+ +## Usage + +```javascript +var UnicodeTable = require( '@stdlib/plot/table/unicode' ); +``` + +#### UnicodeTable( \[data,] \[options] ) + +Returns a table instance. + +```javascript +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`: + +- **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 automatically re-render a table on a `change` event. Default: `false`. + +- **borderTop**: top table border character. Default: `'-'`. + +- **borderRight**: right table border character. Default: `'|'`. + +- **borderBottom**: bottom table border character. Default: `'-'`. + +- **borderLeft**: left table border character. 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: `'│'`. + +- **columnWidth**: table column width(s). When `null`, column widths are determined according to cell content. When set to a specific width, a column is rendered with the specified width, unless overridden by a `maxColumnWidth` option which is less than the specified width. Default: `null`. + +- **cornerTopLeft**: top-left table corner character. Default: `'┌'`. + +- **cornerTopRight**: top-right table corner character. Default: `'┌'`. + +- **cornerBottomRight**: bottom-right table corner character. Default: `'┘'`. + +- **cornerBottomLeft**: bottom-left table corner character. Default: `'└'`. + +- **corners**: table corner 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: `[ '┌', '┐', '┘', '└' ]`. + +- **format**: cell [format][@stdlib/string/format] string(s). Default: `'%s'`. + +- **headerAlign**: alignment of data within table header 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'`. + +- **headers**: table headers. + +- **headerSeparator**: header separator character(s). Default: `'─'`. + +- **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'`. + +- **jointMiddle**: joint character connecting table cells within the middle of the table. Default: `'┼'`. + +- **jointTop**: joint character connecting table cells along the top of the table. Default: `'┬'`. + +- **jointRight**: joint character connecting table cells along the right of the table. Default: `'┤'`. + +- **jointBottom**: joint character connecting table cells along the bottom of the table. Default: `'┴'`. + +- **jointLeft**: joint character connecting table cells along the left of the table. Default: `'├'`. + +- **joints**: joint 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: `[ '┼', '┬', '┤', '┴', '├' ]`. + +- **marginTop**: margin at the top of the table in units of blank lines. Default: `0`. + +- **marginRight**: margin to the right of the table in units of whitespace. Default: `0`. + +- **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 ]`. + +- **maxColumnWidth**: maximum table cell width(s). If less than a column's specified width, this option overrides the `columnWidth` option. Default: `+infinity`. + +- **maxWidth**: maximum table width. 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. 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'`. + +* * * + +### Writable Properties + + + +#### UnicodeTable.prototype.align + +Alignment(s) of data within table cells. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.align = 'center'; + +// Get: +var v = table.align; +// returns 'center' + +// Set: +table.align = [ 'left', 'right', 'center' ]; + +// Get: +v = 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. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.autoRender = false; + +// Get: +var v = table.autoRender; +// returns false +``` + +If `true`, an instance automatically re-renders a table on each `'change'` event; otherwise, rendering must be triggered manually. + + + +#### UnicodeTable.prototype.borderTop + +Top table border character. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.borderTop = '='; + +// Get: +var v = table.borderTop; +// returns '=' +``` + + + +#### UnicodeTable.prototype.borderRight + +Right table border character. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.borderRight = '!'; + +// Get: +var v = table.borderRight; +// returns '!' +``` + + + +#### UnicodeTable.prototype.borderBottom + +Bottom table border character. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.borderBottom = '='; + +// Get: +var v = table.borderBottom; +// returns '=' +``` + + + +#### UnicodeTable.prototype.borderLeft + +Left table border character. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.borderLeft = '!'; + +// Get: +var v = table.borderLeft; +// returns '!' +``` + + + +#### UnicodeTable.prototype.borders + +Table border characters in the order `[ 'top', 'right', 'bottom', 'left' ]`. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.borders = [ '=', '!', '=', '!' ]; + +// Get: +var v = table.borders; +// returns [ '=', '!', '=', '!' ] +``` + + + +#### UnicodeTable.prototype.bufferSize + +Data buffer size. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var table = new UnicodeTable(); + +// Set: +table.bufferSize = 3; + +// Get: +var v = table.bufferSize; +// returns 3 + +table.data = [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]; + +var data = ndarray2array( table.data ); +// returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] + +table.push( [ 7, 8 ] ); + +data = ndarray2array( table.data ); +// returns [ [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ] +``` + +If set, this specifies the maximum number of table rows which can be rendered. Once an internal data buffer is full, each new table row results in the oldest table row being removed. + +Setting a data buffer size is useful when rendering data streams. + + + +#### UnicodeTable.prototype.columnSeparator + +Table column separator character(s). + +```javascript +var table = new UnicodeTable(); + +// Set: +table.columnSeparator = '|'; + +// Get: +var v = table.columnSeparator; +// returns '|' +``` + +If provided a string with multiple grapheme clusters, each grapheme cluster is rendered sequentially. No separator is rendered if provided an empty string. + + + +#### UnicodeTable.prototype.columnWidth + +Table column width. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.columnWidth = 10; + +// Get: +var v = table.columnWidth; +// returns 10 + +// Set: +table.columnWidth = [ 10, 15 ]; + +// Get: +v = table.columnWidth; +// returns [ 10, 15 ] +``` + +When `null`, table column widths are determined according to cell content. When set to a specific width, a table column is rendered with the specified width, unless overridden by a [`maxColumnWidth`](#prop-max-column-width) which is less than the specified width. + +If table column data is longer than a specified column width, the rendered column data is truncated. + +To specify a table column width for each column, provide an array of widths. + + + +#### UnicodeTable.prototype.cornerTopLeft + +Top-left table corner character. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.cornerTopLeft = '*'; + +// Get: +var v = table.cornerTopLeft; +// returns '*' +``` + + + +#### UnicodeTable.prototype.cornerTopRight + +Top-right table corner character. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.cornerTopRight = '*'; + +// Get: +var v = table.cornerTopRight; +// returns '*' +``` + + + +#### UnicodeTable.prototype.cornerBottomRight + +Bottom-right table corner character. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.cornerBottomRight = '*'; + +// Get: +var v = table.cornerBottomRight; +// returns '*' +``` + + + +#### UnicodeTable.prototype.cornerBottomLeft + +Bottom-left table corner character. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.cornerBottomLeft = '*'; + +// Get: +var v = table.cornerBottomLeft; +// returns '*' +``` + + + +#### UnicodeTable.prototype.corners + +Table corner characters in the order `[ 'top-left', 'top-right', 'bottom-right', 'bottom-left' ]`. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.corners = [ '*', '*', '*', '*' ]; + +// Get: +var v = table.corners; +// returns [ '*', '*', '*', '*' ] +``` + + + +#### UnicodeTable.prototype.data + +Table data. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var table = new UnicodeTable(); + +// Set: +table.data = [ [ 1, 2 ], [ 3, 4 ] ]; + +// Get: +var data = ndarray2array( table.data ); +// returns [ [ 1, 2 ], [ 3, 4 ] ] +``` + +The returned [ndarray][@stdlib/ndarray/ctor] is a **read-only** view of table data. + + + +#### UnicodeTable.prototype.format + +Cell [format][@stdlib/string/format] string(s) for rendering cell contents. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.format = '%d'; + +// Get: +var v = table.format; +// returns '%d' + +// Set: +table.format = [ '%s', '%d' ]; + +// Get: +v = table.format; +// returns [ '%s', '%d' ] +``` + + + +#### UnicodeTable.prototype.headerAlign + +Alignment(s) of data within table header cells. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.headerAlign = 'center'; + +// Get: +var v = table.headerAlign; +// returns 'center' + +// Set: +table.headerAlign = [ 'left', 'right', 'center' ]; + +// Get: +v = table.headerAlign; +// returns [ 'left', 'right', 'center' ] +``` + +By default and when set to `null`, the alignment of header cell data matches that of [`table.align`](#prop-align). To specify an alignment which diverges from data cell alignment, specify an alternative alignment. + +The following alignments are supported: + +- **right**: right-aligned. +- **left**: left-aligned. +- **center**: center-aligned. + +To specify the alignment for each header column individually, set to an array of alignment values. + + + +#### UnicodeTable.prototype.headers + +Table headers. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.headers = [ 'A', 'B' ]; + +// Get: +var v = table.headers; +// returns [ 'A', 'B' ] +``` + + + +#### UnicodeTable.prototype.headerSeparator + +Header separator character(s). + +```javascript +var table = new UnicodeTable(); + +// Set: +table.headerSeparator = '-'; + +// Get: +var v = table.headerSeparator; +// returns '-' +``` + +If provided a string with multiple grapheme clusters, each grapheme cluster is rendered sequentially. No separator is rendered if provided an empty string. + + + +#### UnicodeTable.prototype.horizontalSeparatorMode + +Horizontal line separator mode. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.horizontalSeparatorMode = 'interpolate'; + +// Get: +var v = 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 character connecting cells within the middle of the table. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.jointMiddle = '*'; + +// Get: +var v = table.jointMiddle; +// returns '*' +``` + + + +#### UnicodeTable.prototype.jointTop + +Joint character connecting cells along the top of the table. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.jointTop = '*'; + +// Get: +var v = table.jointTop; +// returns '*' +``` + + + +#### UnicodeTable.prototype.jointRight + +Joint character connecting cells along the right side of the table. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.jointRight = '*'; + +// Get: +var v = table.jointRight; +// returns '*' +``` + + + +#### UnicodeTable.prototype.jointBottom + +Joint character connecting cells along the bottom of the table. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.jointBottom = '*'; + +// Get: +var v = table.jointBottom; +// returns '*' +``` + + + +#### UnicodeTable.prototype.jointLeft + +Joint character connecting cells along the left side of the table. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.jointLeft = '*'; + +// Get: +var v = table.jointLeft; +// returns '*' +``` + + + +#### UnicodeTable.prototype.joints + +Joint characters in the order `[ 'middle', 'top', 'right', 'bottom', 'left' ]`. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.joints = [ '*', '*', '*', '*', '*' ]; + +// Get: +var v = 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 v = 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 v = table.marginRight; +// returns 2 +``` + + + +#### UnicodeTable.prototype.marginBottom + +Margin at the bottom of the table in units of blank lines. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.marginBottom = 2; + +// Get: +var v = table.marginBottom; +// returns 2 +``` + + + +#### UnicodeTable.prototype.marginLeft + +Margin to the left of the table in units of whitespace. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.marginLeft = 2; + +// Get: +var v = 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 v = table.margins; +// returns [ 2, 2, 2, 2 ] +``` + + + +#### UnicodeTable.prototype.maxColumnWidth + +Maximum table column width. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.maxColumnWidth = 10; + +// Get: +var v = table.maxColumnWidth; +// returns 10 + +// Set: +table.maxColumnWidth = [ 10, 15 ]; + +// Get: +v = table.maxColumnWidth; +// returns [ 10, 15 ] +``` + +If table column data is longer than the maximum column width, the rendered column data is truncated. To specify the maximum column width for each table column, provide an array of maximum widths. + +If set to a value which is less than a column's specified width, the maximum table column width takes precedence over [`columnWidth`](#prop-column-width). + + + +#### UnicodeTable.prototype.maxWidth + +Maximum table width. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.maxWidth = 200; + +// Get: +var v = table.maxWidth; +// returns 200 +``` + +If the generated table is longer than the maximum table width, a generated table is split into multiple tables. + + + +#### UnicodeTable.prototype.paddingLeft + +Cell left padding(s) in units of whitespace. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.paddingLeft = 3; + +// Get: +var v = table.paddingLeft; +// returns 3 + +// Set: +table.paddingLeft = [ 3, 4 ]; + +// Get: +v = table.paddingLeft; +// returns [ 3, 4 ] +``` + +To specify the padding of each column of table cells, provide an array of paddings. + + + +#### UnicodeTable.prototype.paddingRight + +Cell right padding(s) in units of whitespace. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.paddingRight = 3; + +// Get: +var v = table.paddingRight; +// returns 3 + +// Set: +table.paddingRight = [ 3, 4 ]; + +// Get: +v = table.paddingRight; +// returns [ 3, 4 ] +``` + +To specify the padding of each column of table cells, provide an array of paddings. + + + +#### UnicodeTable.prototype.rowSeparator + +Row separator character(s). + +```javascript +var table = new UnicodeTable(); + +// Set: +table.rowSeparator = '-'; + +// Get: +var v = table.rowSeparator; +// returns '-' +``` + +If provided a string with multiple grapheme clusters, each grapheme cluster is rendered sequentially. No separator is rendered if provided an empty string. + + + +#### UnicodeTable.prototype.verticalSeparatorMode + +Vertical line separator mode. + +```javascript +var table = new UnicodeTable(); + +// Set: +table.verticalSeparatorMode = 'interpolate'; + +// Get: +var v = 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.get( i, j ) + +Retrieves the data for a specified table cell. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var table = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); + +// Retrieve individual cell data: +var v = table.get( 0, 0 ); +// returns 1 + +v = table.get( 1, 2 ); +// returns 6 +``` + + + +#### UnicodeTable.prototype.push( 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 = ndarray2array( table.data ); +// returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] + +// Push: +table.push( [ 7, 8, 9 ] ); + +// Get: +data = ndarray2array( table.data ); +// returns [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] +``` + + + +#### UnicodeTable.prototype.render() + +Renders a Unicode table. + +```javascript +var headers = [ 'col1', 'col2', 'col3' ]; +var data = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; + +var table = new UnicodeTable( data, { + 'headers': headers +}); + +var str = table.render(); +// returns '...' +``` + + + +#### UnicodeTable.prototype.set( i, j, value ) + +Sets the data for a specified table cell to a provided value. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var table = new UnicodeTable( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); + +// Retrieve individual cell data: +var v = table.get( 1, 1 ); +// returns 5 + +table.set( 1, 1, 7 ); + +v = table.get( 1, 1 ); +// returns 7 +``` + +* * * + +### 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 table is rendered. + +```javascript +var table = new UnicodeTable(); + +table.on( 'render', onRender ); + +function onRender( str ) { + console.log( 'Rendered table: %s', 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. +- When rendering a Unicode table to terminals, be advised that emojis can cause alignment issues due to variability in how many terminal columns an emoji occupies. This is particularly true for emoji using skin tones. + +
+ + + +
+ +* * * + +## Examples + + + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var array = require( '@stdlib/ndarray/array' ); +var UnicodeTable = require( '@stdlib/plot/table/unicode' ); + +// Generate a random data set: +var data = array( uniform( 50, 1.0, 100.0 ), { + 'shape': [ 10, 5 ] +}); + +// Define column headers: +var headers = [ 'A', 'B', 'C', 'D', 'E' ]; + +// Create a table: +var table = new UnicodeTable( data, { + 'headers': headers, + 'rowSeparator': '-', + 'columnSeparator': '#$%', + 'maxWidth': 200, + 'marginLeft': 5, + 'marginRight': 5, + 'align': 'right', + 'headerAlign': [ + 'left', + 'center', + 'right', + 'center', + 'left' + ], + 'format': '%0.5f' +}); + +// Render the table: +var str = table.render(); +console.log( str ); +// => '...' + +// Push new data to the table: +table.push( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + +// Re-render the table: +str = table.render(); +console.log( str ); +// => '...' + +// Limit the number of table rows: +table.bufferSize = 10; + +// Re-render the table: +str = table.render(); +console.log( str ); +// => '...' + +// Push new data to the table: +table.push( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + +// Re-render the table: +str = table.render(); +console.log( str ); +// => '...' + +// Increase the number of allowed table rows: +table.bufferSize = 15; + +// Push new data to the table: +table.push( [ 11.0, 12.0, 13.0, 14.0, 15.0 ] ); + +// Re-render the table: +str = table.render(); +console.log( str ); +// => '...' +``` + +
+ + + + + + + + + + + + + + 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..fea52d4b6355 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.js @@ -0,0 +1,1433 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var isArray = require( '@stdlib/assert/is-array' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +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 ] ] ); + 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 = { + 'align': 'left', + 'autoRender': false, + 'borderTop': '1', + 'borderRight': '23', + 'borderBottom': '456', + 'borderLeft': '7890', + 'borders': [ '1', '23', '456', '7890' ], + 'bufferSize': 10, + 'columnWidth': null, + 'columnSeparator': 'None', + 'cornerTopLeft': '*', + 'cornerTopRight': '*', + 'cornerBottomLeft': '*', + 'cornerBottomRight': '*', + 'corners': [ '*', '*', '*', '*' ], + 'format': '%d', + 'headerAlign': 'center', + 'headers': [ 'col1', 'col2', 'col3' ], + 'headerSeparator': '-=', + 'horizontalSeparatorMode': 'repeat', + 'jointMiddle': '*', + 'jointTop': '*', + 'jointRight': '*', + 'jointBottom': '*', + 'jointLeft': '*', + 'joints': [ '*', '*', '*', '*', '*' ], + 'marginTop': 4, + 'marginRight': 2, + 'marginBottom': 4, + 'marginLeft': 2, + 'margins': [ 4, 2, 4, 2 ], + 'maxColumnWidth': 10, + 'maxWidth': 60, + 'paddingLeft': 2, + 'paddingRight': [ 2, 3, 4 ], + 'rowSeparator': '_-', + 'verticalSeparatorMode': 'resume' + }; + 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+'::set,get:align:value=string', 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.align = values[ i % values.length ]; + if ( !isString( v.align ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.align ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:align:value=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.align = values[ i % values.length ]; + if ( !isArray( v.align ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v.align ) ) { + 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 ( !isBoolean( v.autoRender ) ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( v.autoRender ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:borderTop', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '1', + '2' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.borderTop = values[ i % values.length ]; + if ( !isString( v.borderTop ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.borderTop ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:borderRight', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '1', + '2' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.borderRight = values[ i % values.length ]; + if ( !isString( v.borderRight ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.borderRight ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:borderBottom', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '1', + '2' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.borderBottom = values[ i % values.length ]; + if ( !isString( v.borderBottom ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.borderBottom ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:borderLeft', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '1', + '2' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.borderLeft = values[ i % values.length ]; + if ( !isString( v.borderLeft ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.borderLeft ) ) { + 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', '23', '456', '7890' ], + [ '', '', '', '' ], + [ '🌹', '🥀', '🔥', '👍' ] + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.borders = values[ i % values.length ]; + if ( !isArray( v.borders ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v.borders ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +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 ( !isNumber( v.bufferSize ) ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v.bufferSize ) ) { + 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 = [ + '|', + '123', + '🥀', + '' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.columnSeparator = values[ i % values.length ]; + if ( !isString( v.columnSeparator ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.columnSeparator ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:columnWidth:value=number', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 10, + 20, + 30, + 40 + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.columnWidth = values[ i % values.length ]; + if ( !isNumber( v.columnWidth ) ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v.columnWidth ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:columnWidth:value=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.columnWidth = values[ i % values.length ]; + if ( !isArray( v.columnWidth ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v.columnWidth ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:cornerTopLeft', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '-', + '*' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.cornerTopLeft = values[ i % values.length ]; + if ( !isString( v.cornerTopLeft ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.cornerTopLeft ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:cornerTopRight', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '-', + '*' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.cornerTopRight = values[ i % values.length ]; + if ( !isString( v.cornerTopRight ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.cornerTopRight ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:cornerBottomRight', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '-', + '*' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.cornerBottomRight = values[ i % values.length ]; + if ( !isString( v.cornerBottomRight ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.cornerBottomRight ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:cornerBottomLeft', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '-', + '*' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.cornerBottomLeft = values[ i % values.length ]; + if ( !isString( v.cornerBottomLeft ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.cornerBottomLeft ) ) { + 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 = [ + [ '-', '|', '-', '|' ], + [ '🌹', '🥀', '🔥', '👍' ] + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.corners = values[ i % values.length ]; + if ( !isArray( v.corners ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v.corners ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:data:value=nested_array', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], + [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.data = values[ i % values.length ]; + if ( typeof v.data !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v.data ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:data:value=dictionary_of_columns', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + { + 'a': [ 1, 2, 3 ], + 'b': [ 4, 5, 6 ] + }, + { + 'a': [ 1, 2, 3 ], + 'b': [ 4, 5, 6 ] + } + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.data = values[ i % values.length ]; + if ( typeof v.data !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v.data ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:data:value=ndarray', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + ndarray( 'generic', [ 1, 2, 3, 4, 5, 6 ], [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ), + 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' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v.data ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:format:value=string', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '%d', + '%f' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.format = values[ i % values.length ]; + if ( !isString( v.format ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.format ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:format:value=array', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + [ '%d' ], + [ '%f' ] + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.format = values[ i % values.length ]; + if ( !isArray( v.format ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v.format ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:headerAlign:value=string', 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.headerAlign = values[ i % values.length ]; + if ( !isString( v.headerAlign ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.headerAlign ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:headerAlign:value=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.headerAlign = values[ i % values.length ]; + if ( !isArray( v.headerAlign ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v.headerAlign ) ) { + 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 ( !isArray( v.headers ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v.headers ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:headerSeparator', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '|', + '123', + '🥀', + '' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.headerSeparator = values[ i % values.length ]; + if ( !isString( v.headerSeparator ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.headerSeparator ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:horizontalSeparatorMode', 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.horizontalSeparatorMode = values[ i % values.length ]; + if ( !isString( v.horizontalSeparatorMode ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.horizontalSeparatorMode ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:jointMiddle', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '-', + '*' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.jointMiddle = values[ i % values.length ]; + if ( !isString( v.jointMiddle ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.jointMiddle ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:jointTop', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '-', + '*' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.jointTop = values[ i % values.length ]; + if ( !isString( v.jointTop ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.jointTop ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:jointRight', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '-', + '*' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.jointRight = values[ i % values.length ]; + if ( !isString( v.jointRight ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.jointRight ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:jointBottom', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '-', + '*' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.jointBottom = values[ i % values.length ]; + if ( !isString( v.jointBottom ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.jointBottom ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:jointLeft', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '-', + '*' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.jointLeft = values[ i % values.length ]; + if ( !isString( v.jointLeft ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.jointLeft ) ) { + 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 ( !isArray( v.joints ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v.joints ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:marginTop', 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.marginTop = values[ i % values.length ]; + if ( !isNumber( v.marginTop ) ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v.marginTop ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:marginRight', 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.marginRight = values[ i % values.length ]; + if ( !isNumber( v.marginRight ) ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v.marginRight ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:marginBottom', 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.marginBottom = values[ i % values.length ]; + if ( !isNumber( v.marginBottom ) ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v.marginBottom ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:marginLeft', 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.marginLeft = values[ i % values.length ]; + if ( !isNumber( v.marginLeft ) ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v.marginLeft ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:margins', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + [ 0, 0, 0, 0 ], + [ 1, 2, 3, 4 ] + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.margins = values[ i % values.length ]; + if ( !isArray( v.margins ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v.margins ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:maxColumnWidth:value=number', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 10, + 20, + 30, + null + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.maxColumnWidth = values[ i % values.length ]; + if ( !isNumber( v.maxColumnWidth ) ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v.maxColumnWidth ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:maxColumnWidth:value=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.maxColumnWidth = values[ i % values.length ]; + if ( !isArray( v.maxColumnWidth ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v.maxColumnWidth ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:maxWidth', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + 100, + 200, + 300, + null + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.maxWidth = values[ i % values.length ]; + if ( !isNumber( v.maxWidth ) ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v.maxWidth ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:paddingLeft:value=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.paddingLeft = values[ i % values.length ]; + if ( !isNumber( v.paddingLeft ) ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v.paddingLeft ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:paddingLeft:value=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.paddingLeft = values[ i % values.length ]; + if ( !isArray( v.paddingLeft ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v.paddingLeft ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:paddingRight:value=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.paddingRight = values[ i % values.length ]; + if ( !isNumber( v.paddingRight ) ) { + b.fail( 'should return a number' ); + } + } + b.toc(); + if ( !isNumber( v.paddingRight ) ) { + b.fail( 'should return a number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:paddingRight:value=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.paddingRight = values[ i % values.length ]; + if ( !isArray( v.paddingRight ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v.paddingRight ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::set,get:rowSeparator', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + '|', + '123', + '🥀', + '' + ]; + v = new UnicodeTable(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v.rowSeparator = values[ i % values.length ]; + if ( !isString( v.rowSeparator ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.rowSeparator ) ) { + b.fail( 'should return a string' ); + } + 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 ( !isString( v.verticalSeparatorMode ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( v.verticalSeparatorMode ) ) { + 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..581b31276824 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.render.js @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 random = require( '@stdlib/random/array/discrete-uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +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 {UnicodeTable} table - table instance +* @returns {Function} benchmark function +*/ +function createBenchmark( rows, columns, table ) { + var data; + + data = random( rows*columns, 0, 100, { + 'dtype': 'float64' + }); + table.data = array( data, { + 'shape': [ rows, columns ] + }); + table.headers = random( columns, 0, columns, { + 'dtype': 'generic' + }); + return benchmark; + + /** + * 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.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(); + table.bufferSize = rows; + 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..3d21d410caf0 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/docs/repl.txt @@ -0,0 +1,308 @@ + +{{alias}}( [data,] [options] ) + Returns a Unicode table instance. + + Parameters + ---------- + data: Object|Array|Array|ndarray (optional) + Table data. + + options: Object (optional) + Table options. + + options.align: Array|string (optional) + Cell alignment(s). Must be one of the following: + + - left: left-aligned. + - center: center-aligned. + - right: right-aligned. + + Default: 'right'. + + options.autoRender: boolean (optional) + Boolean indicating whether to automatically re-render on a 'change' + event. Default: false. + + options.borderTop: string (optional) + Top table border character. Default: '-'. + + options.borderRight: string (optional) + Right table border character. Default: '|'. + + options.borderBottom: string (optional) + Bottom table border character. Default: '-'. + + options.borderLeft: string (optional) + Left table border character. Default: '|'. + + options.borders: Array (optional) + Table border characters in the order [top, right, bottom, left]. + Default: [ '─', '│', '─', '│' ]. + + options.bufferSize: integer|null (optional) + 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. + + options.columnSeparator: string (optional) + Column separator character(s). Default: '│'. + + options.columnWidth: Array|integer|null (optional) + Table column width(s). When `null`, column widths are determined + according to cell content. When set to a specific width, a column is + rendered with the specified width, unless overridden by a + `maxColumnWidth` option which is less than the specified width. Default: + null. + + options.cornerTopLeft: string (optional) + Top-left table corner character. Default: '┌'. + + options.cornerTopRight: string (optional) + Top-right table corner character. Default: '┐'. + + options.cornerBottomRight: string (optional) + Bottom-right table corner character. Default: '┘'. + + options.cornerBottomLeft: string (optional) + Bottom-left table corner character. Default: '└'. + + options.corners: Array (optional) + Table corner characters in the order [top-left, top-right, bottom-right, + bottom-left]. Default: [ '┌', '┐', '┘', '└' ]. + + options.format: Array|string (optional) + Cell format string(s). Default: '%s'. + + options.headerAlign: Array|string|null (optional) + Header cell alignment(s). Must be one of the following: + + - left: left-aligned. + - center: center-aligned. + - right: right-aligned. + + Default: 'right'. + + options.headers: Array (optional) + Table headers. + + options.headerSeparator: string (optional) + Header separator character(s). Default: '─'. + + options.horizontalSeparatorMode: string (optional) + 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'. + + options.jointMiddle: string (optional) + Joint character connecting cells within the middle of the table. + Default: '┼'. + + options.jointTop: string (optional) + Joint character connecting cells along the top of the table. Default: + '┬'. + + options.jointRight: string (optional) + Joint character connecting cells along the right side of the table. + Default: '┤'. + + options.jointBottom: string (optional) + Joint character connecting cells along the bottom of the table. Default: + '┴'. + + options.jointLeft: string (optional) + Joint character connecting cells along the left side of the table. + Default: '├'. + + options.joints: Array (optional) + Joint characters in the order [middle, top, right, bottom, left]. + Default: [ '┼', '┬', '┤', '┴', '├' ]. + + options.marginTop: integer (optional) + Margin at the top of the table in units of blank lines. Default: 0. + + options.marginRight: integer (optional) + Margin to the right of the table in units of whitespace. Default: 0. + + options.marginBottom: integer (optional) + Margin at the bottom of the table in units of blank lines. Default: 0. + + options.marginLeft: integer (optional) + Margin to the left of the table in units of whitespace. Default: 0. + + options.margins: Array (optional) + Table margins in the order [top, right, bottom, left]. Default: + [ 0, 0, 0, 0 ]. + + options.maxColumnWidth: Array|integer|null (optional) + Maximum table column width(s). If less than a column's specified width, + this option overrides the `columnWidth` option. Default: +infinity. + + options.maxWidth: integer|null (optional) + Maximum table width. Default: +infinity. + + options.paddingLeft: Array|integer (optional) + Cell left padding(s) in units of whitespace characters. Default: 1. + + options.paddingRight: Array|integer (optional) + Cell right padding(s) in units of whitespace characters. Default: 1. + + options.rowSeparator: string (optional) + Row separator character(s). Default: ''. + + options.verticalSeparatorMode: string (optional) + 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'. + + Returns + ------- + table: Table + Table instance. + + table.align + Cell alignment(s). + + table.autoRender + Rendering mode. If `true`, an instance automatically re-renders on each + 'change' event; otherwise, rendering must be triggered manually. + + table.borderTop + Top table border character. + + table.borderRight + Right table border character. + + table.borderBottom + Bottom table border character. + + table.borderLeft + Left table border character. + + table.borders + Table border characters in the order [top, right, bottom, left]. + + table.bufferSize + Data buffer size. + + table.columnSeparator + Column separator character(s). + + table.columnWidth + Column width(s). + + table.cornerTopLeft + Top-left table corner character. + + table.cornerTopRight + Top-right table corner character. + + table.cornerBottomRight + Bottom-right table corner character. + + table.cornerBottomLeft + Bottom-left table corner character. + + table.corners + Corner characters in the order [top-left, top-right, bottom-right, + bottom-left]. + + table.data + Table data. + + table.format + Cell format. + + table.get( i, j ) + Retrieves the data for a specified table cell. + + table.headerAlign + Header cell alignment(s). + + table.headers + Table headers. + + table.headerSeparator + Header separator character(s). + + table.horizontalSeparatorMode + Horizontal line separator mode. + + table.jointMiddle + Joint character connecting cells within the middle of the table. + + table.jointTop + Joint character connecting cells along the top of the table. + + table.jointRight + Joint character connecting cells along the right side of the table. + + table.jointBottom + Joint character connecting cells along the bottom of the table. + + table.jointLeft + Joint character connecting cells along the left side of the table. + + table.joints + Joint characters in the order [middle, top, right, bottom, left]. + + table.marginTop + Top table margin. + + table.marginRight + Right table margin. + + table.marginBottom + Bottom table margin. + + table.marginLeft + Left table margin. + + table.margins + Table margins in the order [top, right, bottom, left]. + + table.maxColumnWidth + Maximum column width. + + table.maxWidth + Maximum table width. + + table.paddingLeft + Cell left padding. + + table.paddingRight + Cell right padding. + + table.push( row ) + Appends a row to table data. + + table.render() + Renders a table. + + table.rowSeparator + Row separator character(s). + + table.set( i, j, value ) + Sets the data for a specified table cell to a provided value. + + table.verticalSeparatorMode + Vertical line separator mode. + + Examples + -------- + > var data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + > var headers = [ 'col1', 'col2', 'col3' ]; + > var table = new {{alias}}( data, { 'headers': headers } ); + > table.render() + '...' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/plot/table/unicode/examples/ansi_styling.js b/lib/node_modules/@stdlib/plot/table/unicode/examples/ansi_styling.js new file mode 100644 index 000000000000..f69dea88806b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/examples/ansi_styling.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isArray = require( '@stdlib/assert/is-array' ); +var UnicodeTable = require( './../lib' ); + +function styleGreen( value ) { + var i; + if ( isArray( value ) ) { + for ( i = 0; i < value.length; i++ ) { + value[ i ] = '\u001b[32m' + value[ i ] + '\u001b[0m'; + } + return value; + } + return '\u001b[32m' + value + '\u001b[0m'; +} + +// Define a data set: +var data = [ + [ + '\u001b[31mbeep\u001b[0m', // red + '\u001b[1mboop\u001b[0m', // bold + '\u001b[44mfoo\u001b[0m', // blue_bg + '\u001b[4;47mbar\u001b[0m' // underline, white_bg + ] +]; + +// Define column headers: +var headers = [ 'A', 'B', 'C', 'D' ]; + +// Create a table: +var table = new UnicodeTable( data, { + 'headers': headers, + 'marginLeft': 5, + 'marginRight': 5, + 'align': 'right', + 'maxColumnWidth': 10 +}); + +table.rowSeparator = styleGreen( table.rowSeparator ); +table.columnSeparator = styleGreen( table.columnSeparator ); +table.headerSeparator = styleGreen( table.headerSeparator ); + +table.borders = styleGreen( table.borders ); +table.corners = styleGreen( table.corners ); +table.joints = styleGreen( table.joints ); + +// Render the table: +var str = table.render(); +console.log( str ); +// => '...' diff --git a/lib/node_modules/@stdlib/plot/table/unicode/examples/ansi_styling_values.js b/lib/node_modules/@stdlib/plot/table/unicode/examples/ansi_styling_values.js new file mode 100644 index 000000000000..24b55954baaa --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/examples/ansi_styling_values.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-restricted-syntax, max-len */ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filled2dBy = require( '@stdlib/array/base/filled2d-by' ); +var map2d = require( '@stdlib/array/base/map2d' ); +var UnicodeTable = require( './../lib' ); + +function styleRed( value ) { + return '\u001b[31m' + value + '\u001b[0m'; +} + +function styleGreen( value ) { + return '\u001b[32m' + value + '\u001b[0m'; +} + +function Value( value ) { + this._value = value; + return this; +} + +Value.prototype.toString = function toString() { + if ( this._value > 0 ) { + return styleGreen( this._value.toString() ); + } + if ( this._value < 0 ) { + return styleRed( this._value.toString() ); + } + return this._value.toString(); +}; + +function toValue( value ) { + return new Value( value ); +} + +// Define a data set: +var shape = [ 5, 4 ]; +var data = map2d( filled2dBy( shape, discreteUniform( -3, 3 ) ), shape, toValue ); + +// Define column headers: +var headers = [ 'A', 'B', 'C', 'D' ]; + +// Create a table: +var table = new UnicodeTable( data, { + 'headers': headers, + 'rowSeparator': '-', + 'marginLeft': 5, + 'marginRight': 5, + 'align': 'right', + 'maxColumnWidth': 10 +}); + +// Render the table: +var str = table.render(); +console.log( str ); +// => '...' diff --git a/lib/node_modules/@stdlib/plot/table/unicode/examples/complex.js b/lib/node_modules/@stdlib/plot/table/unicode/examples/complex.js new file mode 100644 index 000000000000..631897b7e66d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/examples/complex.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 random = require( '@stdlib/random/base/discrete-uniform' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var filled2dBy = require( '@stdlib/array/base/filled2d-by' ); +var UnicodeTable = require( './../lib' ); + +function clbk( indices ) { + if ( indices[ 1 ] === 0 ) { + return indices[ 0 ]; + } + return new Complex128( random( 0, 10 ), random( 0, 10 ) ); +} + +// Generate a random data set: +var data = filled2dBy( [ 10, 4 ], clbk ); + +// Define column headers: +var headers = [ 'Row', 'Col 0', 'Col 1', 'Col 2' ]; + +// Create a table: +var table = new UnicodeTable( data, { + 'headers': headers, + 'rowSeparator': '-' +}); + +// Render the table: +var str = table.render(); +console.log( str ); +// => '...' diff --git a/lib/node_modules/@stdlib/plot/table/unicode/examples/emoji.js b/lib/node_modules/@stdlib/plot/table/unicode/examples/emoji.js new file mode 100644 index 000000000000..0fe9457f0dad --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/examples/emoji.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 UnicodeTable = require( './../lib' ); + +// Define a data set containing emoji: +var data = [ + [ '😀', '🙌🏼', '👩🏾‍🚀', '👑', '🐇' ], + [ '🙏🏻', '👉', '👏', '🤙', '☝🏿' ] +]; + +// Define column headers: +var headers = [ '1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣' ]; + +// Create a table: +var table = new UnicodeTable( data, { + 'headers': headers, + 'corners': [ '🤣', '🤣', '🤣', '🤣' ], + 'joints': [ '🐥', '🐥', '🐥', '🐥', '🐥' ], + 'borders': [ '🦋', '🦋', '🦋', '🦋' ], + 'headerSeparator': '👑', + 'rowSeparator': '🐞', + 'columnSeparator': '✨', + 'cellWidth': 10, + 'marginLeft': 5, + 'marginRight': 5, + 'align': 'right' +}); + +// Render the table: +var str = table.render(); +console.log( str ); +// => '...' 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..cc915f0ff984 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/examples/index.js @@ -0,0 +1,91 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 uniform = require( '@stdlib/random/array/uniform' ); +var array = require( '@stdlib/ndarray/array' ); +var UnicodeTable = require( './../lib' ); + +// Generate a random data set: +var data = array( uniform( 50, 1.0, 100.0 ), { + 'shape': [ 10, 5 ] +}); + +// Define column headers: +var headers = [ 'A', 'B', 'C', 'D', 'E' ]; + +// Create a table: +var table = new UnicodeTable( data, { + 'headers': headers, + 'rowSeparator': '-', + 'columnSeparator': '#$%', + 'maxWidth': 200, + 'columnWidth': 15, + 'marginLeft': 5, + 'marginRight': 5, + 'align': 'right', + 'headerAlign': [ + 'left', + 'center', + 'right', + 'center', + 'left' + ], + 'format': '%0.5f' +}); + +// Render the table: +var str = table.render(); +console.log( str ); +// => '...' + +// Push new data to the table: +table.push( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + +// Re-render the table: +str = table.render(); +console.log( str ); +// => '...' + +// Limit the number of table rows: +table.bufferSize = 10; + +// Re-render the table: +str = table.render(); +console.log( str ); +// => '...' + +// Push new data to the table: +table.push( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + +// Re-render the table: +str = table.render(); +console.log( str ); +// => '...' + +// Increase the number of allowed table rows: +table.bufferSize = 15; + +// Push new data to the table: +table.push( [ 11.0, 12.0, 13.0, 14.0, 15.0 ] ); + +// Re-render the table: +str = table.render(); +console.log( str ); +// => '...' diff --git a/lib/node_modules/@stdlib/plot/table/unicode/examples/sparklines.js b/lib/node_modules/@stdlib/plot/table/unicode/examples/sparklines.js new file mode 100644 index 000000000000..3e1d9c4834e5 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/examples/sparklines.js @@ -0,0 +1,160 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 randi = require( '@stdlib/random/base/discrete-uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var filled2dBy = require( '@stdlib/array/base/filled2d-by' ); +var ColumnChart = require( '@stdlib/plot/sparklines/unicode/column' ); +var TristateChart = require( '@stdlib/plot/sparklines/unicode/tristate' ); +var LineChart = require( '@stdlib/plot/sparklines/unicode/line' ); +var stdout = require( '@stdlib/streams/node/stdout' ); +var UnicodeTable = require( './../lib' ); + +// Generate some random data sets: +var x0 = discreteUniform( 10, 0, 100, { + 'dtype': 'float64' +}); +var x1 = discreteUniform( 10, -1, 1, { + 'dtype': 'int8' +}); +var x2 = discreteUniform( 10, 0, 100, { + 'dtype': 'float64' +}); + +// Create various sparkline charts: +var chart0 = new ColumnChart( x0, { + 'yMin': 0, + 'yMax': 100, + 'bufferSize': 10 +}); +var chart1 = new TristateChart( x1, { + 'bufferSize': 10 +}); +var chart2 = new LineChart( x2, { + 'yMin': 0, + 'yMax': 100, + 'bufferSize': 10 +}); + +// Add the charts to a hash: +var charts = [ + chart0, + chart1, + chart2 +]; + +// Define the number of table rows and columns: +var nrows = 3; +var ncols = 4; + +// Define a callback for generating a data set: +function clbk( indices ) { + if ( indices[ 1 ] < ncols-1 ) { + return indices[ 0 ]; + } + return charts[ indices[ 0 ] ].render(); +} + +// Create a data set: +var data = filled2dBy( [ nrows, ncols ], clbk ); + +// Define column headers: +var headers = [ 'Row', 'Col 1', 'Col 2', 'Sparkline' ]; + +// Create a table: +var table = new UnicodeTable( data, { + 'headers': headers, + 'rowSeparator': '-', + 'align': 'right', + 'marginLeft': 5 +}); + +// Render the table: +var str = table.render(); +stdout.write( str+'\n' ); + +// Compute the number of lines: +var N = str.split( '\n' ).length; + +// Created a throttled event listener: +var listener = throttledListener( onUpdate, 250 ); + +// Listen for change events: +var i; +for ( i = 0; i < charts.length; i++ ) { + charts[ i ].on( 'change', listener ); +} + +// Periodically update the sparkline charts with new data: +var id = setInterval( update, 1000 ); + +// After some time, stop updating and close: +setTimeout( onTimeout, 11000 ); + +function throttledListener( clbk, limit ) { + var flg = false; + return listener; + + function listener() { + if ( flg ) { + return; + } + flg = true; + setTimeout( onTimeout, limit ); + } + + function onTimeout() { + flg = false; + clbk(); + } +} + +function update() { + // Push data to the individual charts: + chart0.push( randi( 0, 100 ) ); + chart1.push( randi( -1, 1 ) ); + chart2.push( randi( 0, 100 ) ); +} + +function onUpdate() { + var i; + + // Re-render the sparklines: + for ( i = 0; i < charts.length; i++ ) { + table.set( i, ncols-1, charts[ i ].render() ); + } + // Remove the previously rendered table: + clearPreviousLines( N ); + + // Re-render the table: + stdout.write( table.render()+'\n' ); +} + +function onTimeout() { + clearInterval( id ); +} + +function clearPreviousLines( count ) { + var i; + for ( i = 0; i < count; i++ ) { + stdout.write( '\x1b[F' ); // move cursor up one line + stdout.write( '\x1b[2K' ); // clear entire line + } +} diff --git a/lib/node_modules/@stdlib/plot/table/unicode/examples/streaming.js b/lib/node_modules/@stdlib/plot/table/unicode/examples/streaming.js new file mode 100644 index 000000000000..e9fd48d8ea83 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/examples/streaming.js @@ -0,0 +1,92 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 linspace = require( '@stdlib/array/base/linspace' ); +var array = require( '@stdlib/ndarray/array' ); +var stdout = require( '@stdlib/streams/node/stdout' ); +var UnicodeTable = require( './../lib' ); + +// Define the number of table rows and columns: +var nrows = 10; +var ncols = 5; + +// Define initial bounds for generated data: +var start = 0; +var end = 49; + +// Generate a data set: +var data = array( linspace( start, end, nrows*ncols ), { + 'shape': [ nrows, ncols ] +}); + +// Define column headers: +var headers = [ 'A', 'B', 'C', 'D', 'E' ]; + +// Create a table: +var table = new UnicodeTable( data, { + 'headers': headers, + 'rowSeparator': '-', + 'columnSeparator': '#$%', + 'maxWidth': 200, + 'marginLeft': 5, + 'marginRight': 5, + 'align': 'right', + 'bufferSize': nrows +}); + +// Render the table: +var str = table.render(); +stdout.write( str+'\n' ); + +// Compute the number of lines: +var N = str.split( '\n' ).length; + +// Periodically update the table with new data: +var id = setInterval( update, 2000 ); + +// After some time, stop updating and close: +setTimeout( onTimeout, 11000 ); + +function update() { + // Update data bounds: + start = end; + end += ncols - 1; + + // Push a new row to the table: + table.push( linspace( start, end, ncols ) ); + + // Remove the previously rendered table: + clearPreviousLines( N ); + + // Re-render the table: + stdout.write( table.render()+'\n' ); +} + +function onTimeout() { + clearInterval( id ); +} + +function clearPreviousLines( count ) { + var i; + for ( i = 0; i < count; i++ ) { + stdout.write( '\x1b[F' ); // move cursor up one line + stdout.write( '\x1b[2K' ); // clear entire line + } +} diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/ansi_regexp.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/ansi_regexp.js new file mode 100644 index 000000000000..cdbfd22378c9 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/ansi_regexp.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 // + +/** +* Regular expression to match ANSI escape sequences. +* +* @private +* @type {RegExp} +*/ +var RE = /([\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?(?:\u0007|\u001B\u005C|\u009C))|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~])))/g; // eslint-disable-line no-control-regex, no-useless-escape + + +// EXPORTS // + +module.exports = RE; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/array2matrix.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/array2matrix.js new file mode 100644 index 000000000000..5fd3360237ce --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/array2matrix.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var FifoArray = require( './fifo.js' ); + + +// VARIABLES // + +var DTYPE = 'generic'; +var ORDER = 'row-major'; + + +// MAIN // + +/** +* Creates a two-dimensional ndarray having a specified data buffer and shape. +* +* @private +* @param {Collection} buffer - data buffer +* @param {NonNegativeIntegerArray} shape - shape +* @returns {ndarray} two-dimensional ndarray +*/ +function array2matrix( buffer, shape ) { + return new ndarray( DTYPE, new FifoArray( buffer ), shape, shape2strides( shape, ORDER ), 0, ORDER ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = array2matrix; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/column_widths.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/column_widths.js new file mode 100644 index 000000000000..94e913471159 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/column_widths.js @@ -0,0 +1,83 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeros = require( '@stdlib/array/base/zeros' ); + + +// MAIN // + +/** +* Resolves individual column widths based on table data and specified paddings. +* +* @private +* @param {NonNegativeInteger} nrows - number of table rows +* @param {NonNegativeInteger} ncols - number of table columns +* @param {ndarray} data - table data +* @param {(ndarray|null)} headers - table headers +* @param {NonNegativeIntegerArray} leftPadding - left padding +* @param {NonNegativeIntegerArray} rightPadding - right padding +* @returns {NonNegativeIntegerArray} column widths +*/ +function columnWidths( nrows, ncols, data, headers, leftPadding, rightPadding ) { // eslint-disable-line max-len + var lpad; + var rpad; + var out; + var len; + var M; + var N; + var v; + var i; + var j; + + M = leftPadding.length; + N = rightPadding.length; + + out = zeros( ncols ); + if ( headers ) { + for ( j = 0; j < ncols; j++ ) { + lpad = leftPadding[ j%M ]; + rpad = rightPadding[ j%N ]; + v = headers.get( 0, j ); + len = lpad + v.width + rpad; + if ( len > out[ j ] ) { + out[ j ] = len; + } + } + } + for ( i = 0; i < nrows; i++ ) { + for ( j = 0; j < ncols; j++ ) { + lpad = leftPadding[ j%M ]; + rpad = rightPadding[ j%N ]; + v = data.get( i, j ); + len = lpad + v.width + rpad; + if ( len > out[ j ] ) { + out[ j ] = len; + } + } + } + return out; +} + + +// EXPORTS // + +module.exports = columnWidths; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/convert_collection.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/convert_collection.js new file mode 100644 index 000000000000..9f076cc4743e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/convert_collection.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var flatten2d = require( '@stdlib/array/base/flatten2d' ); +var shape = require( '@stdlib/array/shape' ); +var objectKeys = require( '@stdlib/utils/keys' ); +var array2matrix = require( './array2matrix.js' ); + + +// FUNCTIONS // + +/** +* Converts table data provided as an array-like object. +* +* @private +* @param {Collection} data - input data +* @param {(ObjectArray|null)} headers - table headers +* @throws {TypeError} invalid input data +* @returns {Object} table data +*/ +function convertCollection( data, headers ) { + var keys; + var out; + var flg; + var obj; + var sh; + var d; + var i; + var j; + var k; + + obj = { + 'data': null, + 'headers': null, + 'code': '' + }; + + sh = shape( data ); + + // If we were provided a nested array, flatten in row-major order... + if ( sh.length >= 2 ) { + sh = [ sh[ 0 ], sh[ 1 ] ]; // only concern ourselves with the first two dimensions + obj.data = array2matrix( flatten2d( data, sh, false ), sh ); + return obj; + } + // If we were provided a one-dimensional array, assume that we were provided a list of objects... + + // If we don't already have headers, infer the headers from the first array element... + if ( headers === null ) { + keys = objectKeys( data[ 0 ] ); + flg = true; + } else { + keys = headers; + } + out = []; + for ( i = 0; i < sh[ 0 ]; i++ ) { + d = data[ i ]; + for ( j = 0; j < keys.length; j++ ) { + k = keys[ j ]; + if ( hasOwnProp( d, k ) ) { + out.push( d[ k ] ); + } else { + obj.headers = keys; + obj.code = 'ERR_MISSING_COLUMNS'; + return obj; + } + } + } + obj.data = array2matrix( out, [ sh[ 0 ], keys.length ] ); + obj.headers = ( flg ) ? keys : null; + return obj; +} + + +// EXPORTS // + +module.exports = convertCollection; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/convert_dictionary.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/convert_dictionary.js new file mode 100644 index 000000000000..8f8318782641 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/convert_dictionary.js @@ -0,0 +1,104 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isCollection = require( '@stdlib/assert/is-collection' ); +var objectKeys = require( '@stdlib/utils/keys' ); +var array2matrix = require( './array2matrix.js' ); + + +// MAIN // + +/** +* Converts table data provided as a dictionary of columns. +* +* @private +* @param {*} data - input data +* @param {(ObjectArray|null)} headers - table headers +* @throws {TypeError} invalid input data +* @returns {Object} table data +*/ +function convertDictionary( data, headers ) { + var keys; + var out; + var flg; + var obj; + var col; + var M; + var N; + var i; + var j; + var k; + + obj = { + 'data': null, + 'headers': null, + 'code': '' + }; + + // If we don't already have headers, infer the headers from the provided object... + if ( headers === null ) { + keys = objectKeys( data ); + flg = true; + } else { + keys = headers; + } + // If provided an empty object (or an object without enumerable properties), likely a user error... + if ( keys.length === 0 ) { + obj.code = 'ERR_EMPTY_OBJECT'; + return obj; + } + // Validate that property value is a collection (column) of data having the same length... + col = data[ keys[ 0 ] ]; + if ( !isCollection( col ) ) { + obj.code = 'ERR_INVALID_OBJECT'; + return obj; + } + M = col.length; + N = keys.length; + for ( i = 1; i < N; i++ ) { + col = data[ keys[ i ] ]; + if ( !isCollection( col ) ) { + obj.code = 'ERR_INVALID_OBJECT'; + return obj; + } + if ( col.length !== M ) { + obj.code = 'ERR_UNEQUAL_COLUMN_LENGTHS'; + return obj; + } + } + // Flatten the dictionary of columns into a row-major linear buffer... + out = []; + for ( i = 0; i < M; i++ ) { + for ( j = 0; j < N; j++ ) { + k = keys[ j ]; + out.push( data[ k ][ i ] ); + } + } + obj.data = array2matrix( out, [ M, N ] ); + obj.headers = ( flg ) ? keys : null; + return obj; +} + + +// EXPORTS // + +module.exports = convertDictionary; 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..9c6eaecf5ba1 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/defaults.js @@ -0,0 +1,121 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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' ); +var normalizeString = require( './normalize_string.js' ); + + +// MAIN // + +/** +* Returns default options. +* +* @private +* @returns {Object} default options +*/ +function defaults() { + var out = {}; + + // Width "units": + out.widthUnits = 'columns'; // 'graphemes' || 'columns' + + // Cell alignment: + out.align = [ 'right' ]; // 'left' || 'right' || 'center' + + // Boolean indicating whether to automatically re-render on a `change` event: + out.autoRender = false; + + // Border characters: + out.borders = [ + normalizeString( '-', out.widthUnits ), + normalizeString( '|', out.widthUnits ), + normalizeString( '-', out.widthUnits ), + normalizeString( '|', out.widthUnits ) + ]; + + // Buffer size: + out.bufferSize = FLOAT64_MAX; + + // Column separator: + out.columnSeparator = normalizeString( '|', out.widthUnits ); + + // Column widths: + out.columnWidth = null; // by default, automatically size based on content + + // Corner characters: + out.corners = [ + normalizeString( '┌', out.widthUnits ), + normalizeString( '┐', out.widthUnits ), + normalizeString( '┘', out.widthUnits ), + normalizeString( '└', out.widthUnits ) + ]; + + // Cell format string: + out.format = [ '%s' ]; + + // Header alignment: + out.headerAlign = null; + + // Column headers: + out.headers = null; + + // Header separator: + out.headerSeparator = normalizeString( '-', out.widthUnits ); + + // Horizontal line separator mode: + out.horizontalSeparatorMode = 'resume'; // 'interpolate' || 'repeat' || 'resume' + + // Joint characters: + out.joints = [ + normalizeString( '┼', out.widthUnits ), + normalizeString( '┬', out.widthUnits ), + normalizeString( '┤', out.widthUnits ), + normalizeString( '┴', out.widthUnits ), + normalizeString( '├', out.widthUnits ) + ]; + + // Table margins: + out.margins = [ 0, 0, 0, 0 ]; + + // Maximum column width: + out.maxColumnWidth = [ FLOAT64_MAX ]; + + // Maximum table width: + out.maxWidth = FLOAT64_MAX; + + // Cell padding: + out.paddingLeft = [ 1 ]; + out.paddingRight = [ 1 ]; + + // Row separator: + out.rowSeparator = normalizeString( '', out.widthUnits ); + + // Vertical line separator mode: + out.verticalSeparatorMode = 'resume'; // 'interpolate' || 'repeat' || 'resume' + + return out; +} + + +// EXPORTS // + +module.exports = defaults; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/every_by2.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/every_by2.js new file mode 100644 index 000000000000..7ce28c7872ed --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/every_by2.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 // + +/** +* Tests whether all element pairs from two arrays pass a test implemented by a binary predicate function. +* +* @private +* @param {Collection} x - first input array +* @param {Collection} y - second input array +* @param {Function} predicate - predicate function +* @param {*} thisArg - predicate function execution context +* @returns {boolean} boolean indicating whether all elements pass a test +*/ +function everyBy2( x, y, predicate, thisArg ) { // FIXME: move to array/base + var len; + var i; + + len = x.length; + if ( len !== y.length ) { + return false; + } + for ( i = 0; i < len; i++ ) { + if ( !predicate.call( thisArg, x[ i ], y[ i ], i, [ x, y ] ) ) { + return false; + } + } + return true; +} + + +// EXPORTS // + +module.exports = everyBy2; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/fifo.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/fifo.js new file mode 100644 index 000000000000..e69f1a781941 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/fifo.js @@ -0,0 +1,896 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isArray = require( '@stdlib/assert/is-array' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); +var setNonEnumerableProperty = require( '@stdlib/utils/define-nonenumerable-property' ); +var min = require( '@stdlib/math/base/special/fast/min' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var resolveGetter = require( '@stdlib/array/base/resolve-getter' ); +var format = require( '@stdlib/string/format' ); + + +// FUNCTIONS // + +/** +* Returns a boolean indicating if a value is a FIFO array. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is a FIFO array +*/ +function isFifoArray( value ) { + return ( + value instanceof FifoArray || + ( + typeof value === 'object' && + value !== null && + value.constructor.name === 'FifoArray' && + typeof value._length === 'number' && // eslint-disable-line no-underscore-dangle + typeof value._offset === 'number' && // eslint-disable-line no-underscore-dangle + typeof value._buffer === 'object' // eslint-disable-line no-underscore-dangle + ) + ); +} + +/** +* Resolves an index into the underlying buffer. +* +* @private +* @param {NonNegativeInteger} size - capacity +* @param {NonNegativeInteger} offset - index of the first indexed element +* @param {NonNegativeInteger} idx - view index +* @returns {NonNegativeInteger} buffer index +*/ +function toIndex( size, offset, idx ) { + return ( offset+idx ) % size; +} + + +// MAIN // + +/** +* FIFO queue array constructor. +* +* @private +* @constructor +* @param {(NonNegativeInteger|Array)} [arg] - queue capacity or an array-like object containing initial values +* @throws {TypeError} invalid first argument +* @returns {FifoArray} FIFO array +* +* @example +* var arr = new FifoArray( 10 ); +* // returns +*/ +function FifoArray() { // TODO: move to array/generic-fifo + var nargs; + var arg; + var buf; + var len; + + nargs = arguments.length; + if ( !( this instanceof FifoArray ) ) { + if ( nargs === 0 ) { + return new FifoArray(); + } + return new FifoArray( arguments[ 0 ] ); + } + if ( nargs === 0 ) { + buf = []; + len = 0; + } else { + arg = arguments[ 0 ]; + if ( isNonNegativeInteger( arg ) ) { + buf = zeros( arg ); + len = 0; + } else if ( isArray( arg ) ) { + buf = arg; // NOTE: not copying is intentional in order to allow creating a FIFO view; however, it does mean that an input argument will be mutated! + len = arg.length; + } else { + throw new TypeError( format( 'invalid argument. Unsupported argument type. Value: `%s`.', arg ) ); + } + } + setReadOnly( this, '_buffer', buf ); + setNonEnumerableProperty( this, '_size', buf.length ); + setNonEnumerableProperty( this, '_length', len ); + setNonEnumerableProperty( this, '_offset', 0 ); + return this; +} + +/** +* Constructor name. +* +* @name name +* @memberof FifoArray +* @readonly +* @type {string} +* @default 'FifoArray' +* +* @example +* var name = FifoArray.name; +* // returns 'FifoArray' +*/ +setReadOnly( FifoArray, 'name', 'FifoArray' ); + +/** +* Converts a view index to an index into the underlying data buffer. +* +* @private +* @name _idx +* @memberof FifoArray.prototype +* @type {Function} +* @param {NonNegativeInteger} idx - view index +* @returns {NonNegativeInteger} buffer index +*/ +setReadOnly( FifoArray.prototype, '_idx', function get( idx ) { + return toIndex( this._size, this._offset, idx ); +}); + +/** +* Increments the pointer to the first indexed element (i.e., the "oldest" element) in the underlying data buffer. +* +* @private +* @name _nextOffset +* @memberof FifoArray.prototype +* @type {Function} +* @returns {NonNegativeInteger} index offset +*/ +setReadOnly( FifoArray.prototype, '_nextOffset', function nextOffset() { + return ( this._offset+1 ) % this._size; +}); + +/** +* Decrements the pointer to the first indexed element (i.e., the "oldest" element) in the underlying data buffer. +* +* @private +* @name _prevOffset +* @memberof FifoArray.prototype +* @type {Function} +* @returns {NonNegativeInteger} index offset +*/ +setReadOnly( FifoArray.prototype, '_prevOffset', function prevOffset() { + var idx = this._offset - 1; + if ( idx < 0 ) { + idx = this._size - 1; + } + return idx; +}); + +/** +* Returns a queue element located at integer position (index) `i`, with support for both nonnegative and negative integer indices. +* +* @name at +* @memberof FifoArray.prototype +* @type {Function} +* @param {integer} idx - element index +* @throws {TypeError} `this` must be a FIFO array +* @throws {TypeError} must provide an integer +* @returns {(*|void)} queue element +* +* @example +* var arr = new FifoArray( [ 0, 0, 0 ] ); +* +* arr.set( 1, 0 ); +* arr.set( 2, 1 ); +* arr.set( 3, 2 ); +* +* var v = arr.at( 0 ); +* // returns 1 +* +* v = arr.at( -1 ); +* // returns 3 +* +* v = arr.at( 100 ); +* // returns undefined +*/ +setReadOnly( FifoArray.prototype, 'at', function at( idx ) { + var buf; + var len; + + if ( !isFifoArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a FIFO array.' ); + } + if ( !isInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Must provide an integer. Value: `%s`.', idx ) ); + } + len = this._length; + buf = this._buffer; + if ( idx < 0 ) { + idx += len; + } + if ( idx < 0 || idx >= len ) { + return; + } + return buf[ this._idx( idx ) ]; +}); + +/** +* Clears a queue. +* +* @name clear +* @memberof FifoArray.prototype +* @type {Function} +* @throws {TypeError} `this` must be a FIFO array +* @returns {FifoArray} Fifo array +* +* @example +* var arr = new FifoArray( [ 1, 2, 3 ] ); +* +* var len = arr.length; +* // returns 3 +* +* arr.clear(); +* +* len = arr.length; +* // returns 0 +*/ +setReadOnly( FifoArray.prototype, 'clear', function clear() { + var i; + if ( !isFifoArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a FIFO array.' ); + } + // Reset buffer elements in order to free up references... + for ( i = 0; i < this._length; i++ ) { + this._buffer[ this._idx( i ) ] = 0; + } + // Reset the queue: + this._length = 0; + this._offset = 0; + + return this; +}); + +/** +* Returns an element from the queue. +* +* @name get +* @memberof FifoArray.prototype +* @type {Function} +* @param {NonNegativeInteger} idx - element index +* @throws {TypeError} `this` must be a FIFO array +* @throws {TypeError} must provide a nonnegative integer +* @returns {(*|void)} array element +* +* @example +* var arr = new FifoArray( [ 1, 2, 3 ] ); +* +* var v = arr.get( 0 ); +* // returns 1 +* +* arr.set( [ 5, 6 ], 0 ); +* +* v = arr.get( 0 ); +* // returns 5 +* +* v = arr.get( 100 ); +* // returns undefined +*/ +setReadOnly( FifoArray.prototype, 'get', function get( idx ) { + if ( !isFifoArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a FIFO array.' ); + } + if ( !isNonNegativeInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', idx ) ); + } + if ( idx >= this._length ) { + return; + } + return this._buffer[ this._idx( idx ) ]; +}); + +/** +* Number of queued elements. +* +* @name length +* @memberof FifoArray.prototype +* @readonly +* @type {NonNegativeInteger} +* +* @example +* var arr = new FifoArray( [ 1, 2, 3 ] ); +* +* var len = arr.length; +* // returns 3 +*/ +setReadOnlyAccessor( FifoArray.prototype, 'length', function get() { + return this._length; +}); + +/** +* Removes the oldest element from the queue and returns that removed element. +* +* ## Notes +* +* - If the queue is empty, the method returns `undefined`. +* +* @name pop +* @memberof FifoArray.prototype +* @type {Function} +* @throws {TypeError} `this` must be a FIFO array +* @returns {(*|void)} queue element +* +* @example +* var arr = new FifoArray( [ 1, 2, 3 ] ); +* +* var v = arr.get( 0 ); +* // returns 1 +* +* var len = arr.length; +* // returns 3 +* +* v = arr.pop(); +* // returns 1 +* +* len = arr.length; +* // returns 2 +* +* v = arr.get( 0 ); +* // returns 2 +*/ +setReadOnly( FifoArray.prototype, 'pop', function pop() { + var v; + if ( !isFifoArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a FIFO array.' ); + } + if ( this._length === 0 ) { + return; + } + // Retrieve the oldest element: + v = this._buffer[ this._offset ]; + + // Reset the buffer element in order to free up references: + this._buffer[ this._offset ] = 0; + + // Increment the pointer to the first indexed element to point to the next oldest element in the queue: + this._offset = this._nextOffset(); + + // Decrement the queue length: + this._length -= 1; + + return v; +}); + +/** +* Adds one or more elements to the end of the queue and returns the number of queued elements. +* +* @name push +* @memberof FifoArray.prototype +* @type {Function} +* @param {...*} value - one or more values to queue +* @throws {TypeError} `this` must be a FIFO array +* @returns {NonNegativeInteger} number of queued elements +* +* @example +* var arr = new FifoArray( [ 1, 2, 3 ] ); +* +* var v = arr.get( 0 ); +* // returns 1 +* +* var len = arr.length; +* // returns 3 +* +* // Push a single element to an already full queue: +* len = arr.push( 4 ); +* // returns 3 +* +* len = arr.length; +* // returns 3 +* +* v = arr.get( 0 ); +* // returns 2 +* +* v = arr.get( arr.length-1 ); +* // returns 4 +* +* // Push multiple elements to an already full queue: +* len = arr.push( 5, 6 ); +* // returns 3 +* +* v = arr.get( 0 ); +* // returns 4 +* +* v = arr.get( arr.length-1 ); +* // returns 6 +* +* // Resize the queue to allow more queued elements: +* arr.resize( 10 ); +* +* len = arr.length; +* // returns 3 +* +* // Push multiple elements to a partially full queue: +* len = arr.push( 7, 8, 9 ); +* // returns 6 +* +* v = arr.get( 0 ); +* // returns 4 +* +* v = arr.get( arr.length-1 ); +* // returns 9 +* +* len = arr.length; +* // returns 6 +* +* // Push multiple elements to fill the queue: +* len = arr.push( 10, 11, 12, 13, 14 ); +* // returns 10 +* +* v = arr.get( 0 ); +* // returns 5 +* +* v = arr.get( arr.length-1 ); +* // returns 14 +* +* // Shrink the queue: +* arr.resize( 3 ); +* +* len = arr.length; +* // returns 3 +* +* v = arr.get( 0 ); +* // returns 12 +* +* v = arr.get( arr.length-1 ); +* // returns 14 +*/ +setReadOnly( FifoArray.prototype, 'push', function push() { + var nargs; + var len; + var N; + var M; + var i; + if ( !isFifoArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a FIFO array.' ); + } + nargs = arguments.length; + len = this._length; + + // Check for trivial cases in which there is nothing to queue... + if ( this._size === 0 || nargs === 0 ) { + return len; + } + // Check whether we have yet to fill the queue and don't need to worry about replacing previously queued elements... + N = this._size - len; + if ( N > 0 ) { + M = min( nargs, N ); + for ( i = 0; i < M; i++ ) { + this._buffer[ this._idx( len+i ) ] = arguments[ i ]; + } + } else { + M = 0; + } + // If the queue is full, we need to replace previously queued elements... + for ( i = M; i < nargs; i++ ) { + this._buffer[ this._offset ] = arguments[ i ]; + this._offset = this._nextOffset(); + } + this._length += M; + return this._length; +}); + +/** +* Resizes the queue capacity. +* +* @name resize +* @memberof FifoArray.prototype +* @type {Function} +* @param {NonNegativeInteger} size - queue capacity +* @throws {TypeError} `this` must be a FIFO array +* @throws {TypeError} must provide a nonnegative integer +* @returns {FifoArray} Fifo array +* +* @example +* var arr = new FifoArray( [ 1, 2, 3 ] ); +* +* var size = arr.size; +* // returns 3 +* +* arr.resize( 10 ); +* +* size = arr.size; +* // returns 10 +* +* arr.resize( 2 ); +* +* size = arr.size; +* // returns 2 +* +* var v = arr.get( 0 ); +* // returns 2 +*/ +setReadOnly( FifoArray.prototype, 'resize', function resize( size ) { + var buf; + var tmp; + var S; + var N; + var M; + var i; + if ( !isFifoArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a FIFO array.' ); + } + if ( !isNonNegativeInteger( size ) ) { + throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', size ) ); + } + buf = this._buffer; + S = this._size; + N = this._length; + + // Case: no resizing necessary + if ( size === S ) { + return this; + } + // Case: queue has not reached capacity, so queue should be contiguous, and we are asked to simply increase the queue capacity + if ( this._offset+N <= S && size > S ) { + // We can just extend the underlying buffer... + for ( i = 0; i < size-S; i++ ) { + buf.push( 0 ); + } + this._size = size; + return this; + } + // Case: queue has either reached capacity, in which case the queue is no longer guaranteed to be contiguous, or we need to shrink the queue capacity; in either case, copy to a temporary copy in order to allow for shrinking/growing the buffer without losing references to buffer data + tmp = []; + for ( i = 0; i < N; i++ ) { + tmp.push( buf[ this._idx( i ) ] ); + } + // Case: grow the queue + if ( size > S ) { + for ( i = 0; i < size-S; i++ ) { + buf.push( 0 ); + } + // Copy over all previously queued elements... + for ( i = 0; i < N; i++ ) { + buf[ i ] = tmp[ i ]; + } + // Reset the offset given that we just copied: + this._offset = 0; + + // Update the queue size: + this._size = size; + + return this; + } + // Case: shrink the queue + this._size = size; + buf.length = size; + S = size; + + // Determine the number of queued elements to keep... + if ( S >= N ) { + M = N; + } else { + M = S; + } + // Copy over only the most recently queued elements... + for ( i = 0; i < M; i++ ) { + buf[ i ] = tmp[ N-M+i ]; + } + // Reset the offset given that we just copied: + this._offset = 0; + + // Update the queue size: + this._size = size; + + // Update the number of queued elements: + this._length = M; + + return this; +}); + +/** +* Sets a queue element. +* +* ## Notes +* +* - When provided an array, we must check whether the source array shares the same buffer as the target array and whether the underlying memory overlaps. In particular, we are concerned with the following scenario: +* +* ```text +* buf: --------------------- +* src: --------------------- +* ``` +* +* In the above, as we copy values from `src`, we will overwrite values in the `src` view, resulting in duplicated values copied into the end of `buf`, which is not intended. Hence, to avoid overwriting source values, we must **copy** source values to a temporary array. +* +* In the other overlapping scenario, +* +* ```text +* buf: --------------------- +* src: --------------------- +* ``` +* +* by the time we begin copying into the overlapping region, we are copying from the end of `src`, a non-overlapping region, which means we don't run the risk of copying copied values, rather than the original `src` values, as intended. +* +* @name set +* @memberof FifoArray.prototype +* @type {Function} +* @param {(Collection|FifoArray|*)} value - value(s) +* @param {NonNegativeInteger} [i=0] - element index at which to start writing values +* @throws {TypeError} `this` must be a FIFO array +* @throws {TypeError} index argument must be a nonnegative integer +* @throws {RangeError} index argument is out-of-bounds +* @throws {RangeError} target array lacks sufficient storage to accommodate source values +* @returns {void} +* +* @example +* var arr = new FifoArray( [ 1, 2, 3 ] ); +* +* var v = arr.get( 0 ); +* // returns 1 +* +* arr.set( [ 5, 6 ], 0 ); +* +* v = arr.get( 0 ); +* // returns 5 +*/ +setReadOnly( FifoArray.prototype, 'set', function set( value ) { + var sbuf; + var idx; + var buf; + var tmp; + var get; + var N; + var i; + + if ( !isFifoArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a FIFO array.' ); + } + if ( arguments.length > 1 ) { + idx = arguments[ 1 ]; + if ( !isNonNegativeInteger( idx ) ) { + throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) ); + } + } else { + idx = 0; + } + buf = this._buffer; + if ( isCollection( value ) ) { + N = value.length; + if ( idx+N > this._length ) { + throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' ); + } + if ( isFifoArray( value ) ) { + sbuf = value._buffer; // eslint-disable-line no-underscore-dangle + } else { + sbuf = value; + } + // Check for potentially overlapping memory... + if ( sbuf === buf ) { + // We need to copy source values... (note: we are being conservative here given that FIFO arrays have additional indexing misdirection complexity and figuring out whether there is actual overlap is likely more trouble than it is worth) + get = resolveGetter( sbuf ); + tmp = []; + for ( i = 0; i < sbuf.length; i++ ) { + tmp.push( get( sbuf, i ) ); + } + sbuf = tmp; + } + get = resolveGetter( sbuf ); + for ( i = 0; i < N; idx++, i++ ) { + buf[ this._idx( idx ) ] = get( sbuf, i ); + } + return; + } + if ( idx >= this._length ) { + throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) ); + } + buf[ this._idx( idx ) ] = value; +}); + +/** +* Queue capacity. +* +* @name size +* @memberof FifoArray.prototype +* @readonly +* @type {NonNegativeInteger} +* +* @example +* var arr = new FifoArray( 10 ); +* +* var len = arr.length; +* // returns 0 +* +* var size = arr.size; +* // returns 10 +*/ +setReadOnlyAccessor( FifoArray.prototype, 'size', function get() { + return this._size; +}); + +/** +* Removes the newest element from the queue and returns that removed element. +* +* ## Notes +* +* - If the queue is empty, the method returns `undefined`. +* +* @name shift +* @memberof FifoArray.prototype +* @type {Function} +* @throws {TypeError} `this` must be a FIFO array +* @returns {(*|void)} queue element +* +* @example +* var arr = new FifoArray( [ 1, 2, 3 ] ); +* +* var len = arr.length; +* // returns 3 +* +* var v = arr.shift(); +* // returns 3 +* +* len = arr.length; +* // returns 2 +*/ +setReadOnly( FifoArray.prototype, 'shift', function shift() { + var v; + var i; + if ( !isFifoArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a FIFO array.' ); + } + if ( this._length === 0 ) { + return; + } + // Resolve the buffer index of the newest element: + i = this._idx( this._length-1 ); + + // Retrieve the newest element: + v = this._buffer[ i ]; + + // Reset the buffer element in order to free up references: + this._buffer[ i ] = 0; + + // Decrement the queue length: + this._length -= 1; + + return v; +}); + +/** +* Adds one or more elements to the beginning of the queue and returns the number of queued elements. +* +* ## Notes +* +* - If provided multiple elements, the method queues those elements in the reverse order as they are provided, such that the first element is considered the "oldest" element and each subsequent element is considered "newer". The ensures that the first indexed element is the "oldest" queued element and matches `Array.prototype.unshift` behavior in which multiple provided elements are inserted as a chunk at the beginning of an array, in the exact same order in which the elements were passed in. +* - Calling this method `n` times with a single argument does **not** yield the same results as calling this method one time with `n` arguments. +* +* @name unshift +* @memberof FifoArray.prototype +* @type {Function} +* @param {...*} value - one or more values to queue +* @throws {TypeError} `this` must be a FIFO array +* @returns {NonNegativeInteger} number of queued elements +* +* @example +* var arr = new FifoArray( [ 1, 2, 3 ] ); +* +* var v = arr.get( 0 ); +* // returns 1 +* +* var len = arr.length; +* // returns 3 +* +* // Add a single element to an already full queue: +* len = arr.unshift( 4 ); +* // returns 3 +* +* len = arr.length; +* // returns 3 +* +* v = arr.get( 0 ); +* // returns 4 +* +* v = arr.get( arr.length-1 ); +* // returns 2 +* +* // Add multiple elements to an already full queue: +* len = arr.unshift( 5, 6 ); +* // returns 3 +* +* v = arr.get( 0 ); +* // returns 5 +* +* v = arr.get( arr.length-1 ); +* // returns 4 +* +* // Resize the queue to allow more queued elements: +* arr.resize( 10 ); +* +* len = arr.length; +* // returns 3 +* +* // Add multiple elements to a partially full queue: +* len = arr.unshift( 7, 8, 9 ); +* // returns 6 +* +* v = arr.get( 0 ); +* // returns 7 +* +* v = arr.get( arr.length-1 ); +* // returns 4 +* +* len = arr.length; +* // returns 6 +* +* // Add multiple elements to fill the queue: +* len = arr.unshift( 10, 11, 12, 13, 14 ); +* // returns 10 +* +* v = arr.get( 0 ); +* // returns 10 +* +* v = arr.get( arr.length-1 ); +* // returns 6 +* +* // Shrink the queue: +* arr.resize( 3 ); +* +* len = arr.length; +* // returns 3 +* +* v = arr.get( 0 ); +* // returns 9 +* +* v = arr.get( arr.length-1 ); +* // returns 6 +*/ +setReadOnly( FifoArray.prototype, 'unshift', function unshift() { + var nargs; + var len; + var N; + var M; + var i; + if ( !isFifoArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a FIFO array.' ); + } + nargs = arguments.length; + len = this._length; + + // Check for trivial cases in which there is nothing to queue... + if ( this._size === 0 || nargs === 0 ) { + return len; + } + // Compute the queue length adjustment... + N = this._size - len; + if ( N > 0 ) { + M = min( nargs, N ); + } else { + M = 0; + } + // Insert elements in the queue in reverse order to match `Array.prototype.unshift` behavior... + for ( i = 0; i < nargs; i++ ) { + this._offset = this._prevOffset(); + this._buffer[ this._offset ] = arguments[ nargs-1-i ]; + } + this._length += M; + return this._length; +}); + + +// EXPORTS // + +module.exports = FifoArray; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/get.js new file mode 100644 index 000000000000..b5e2a75b2868 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/get.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Retrieves the data for a specified table cell. +* +* @private +* @param {NonNegativeInteger} i - index for the first dimension (i.e., zero-based row number) +* @param {NonNegativeInteger} j - index for the second dimension (i.e., zero-based column number) +* @throws {TypeError} first argument must be a nonnegative integer +* @throws {TypeError} second argument must be a nonnegative integer +* @throws {RangeError} index is out-of-bounds +* @returns {*} data element +*/ +function get( i, j ) { + var nrows; + var ncols; + if ( !isNonNegativeInteger( i ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', i ) ); + } + if ( !isNonNegativeInteger( j ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', j ) ); + } + nrows = numelDimension( this._data, 0 ); + if ( i >= nrows ) { + throw new RangeError( format( 'invalid argument. First argument must be on the interval: [0,%u]. Value: `%s`.', nrows-1, i ) ); + } + ncols = numelDimension( this._data, 1 ); + if ( j >= ncols ) { + throw new RangeError( format( 'invalid argument. Second argument must be on the interval: [0,%u]. Value: `%s`.', ncols-1, j ) ); + } + return this._data.get( i, j ).raw; +} + + +// EXPORTS // + +module.exports = get; 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..b26a88326868 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/index.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 +* +* @example +* var UnicodeTable = require( '@stdlib/plot/table/unicode' ); +* +* var data = [ [ 1, 2 ], [ 3, 4 ] ]; +* var headers = [ 'A', 'B' ]; +* +* var table = UnicodeTable( data, { +* 'headers': headers +* }); +* +* var str = table.render(); +* // returns '...' +*/ + +// 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..8295f8aa7336 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/main.js @@ -0,0 +1,1245 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 EventEmitter = require( 'events' ).EventEmitter; +var logger = require( 'debug' ); +var setReadWriteAccessor = require( '@stdlib/utils/define-nonenumerable-read-write-accessor' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var defineProperty = require( '@stdlib/utils/define-property' ); +var objectKeys = require( '@stdlib/utils/keys' ); +var inherit = require( '@stdlib/utils/inherit' ); +var isObject = require( '@stdlib/assert/is-plain-object' ); +var pick = require( '@stdlib/utils/pick' ); +var format = require( '@stdlib/string/format' ); +var setAlign = require( './props/align/set.js' ); +var getAlign = require( './props/align/get.js' ); +var setAutoRender = require( './props/auto-render/set.js' ); +var getAutoRender = require( './props/auto-render/get.js' ); +var setBorderTop = require( './props/border-top/set.js' ); +var getBorderTop = require( './props/border-top/get.js' ); +var setBorderRight = require( './props/border-right/set.js' ); +var getBorderRight = require( './props/border-right/get.js' ); +var setBorderBottom = require( './props/border-bottom/set.js' ); +var getBorderBottom = require( './props/border-bottom/get.js' ); +var setBorderLeft = require( './props/border-left/set.js' ); +var getBorderLeft = require( './props/border-left/get.js' ); +var setBorders = require( './props/borders/set.js' ); +var getBorders = require( './props/borders/get.js' ); +var setBufferSize = require( './props/buffer-size/set.js' ); +var getBufferSize = require( './props/buffer-size/get.js' ); +var setCornerTopLeft = require( './props/corner-top-left/set.js' ); +var getCornerTopLeft = require( './props/corner-top-left/get.js' ); +var setCornerTopRight = require( './props/corner-top-right/set.js' ); +var getCornerTopRight = require( './props/corner-top-right/get.js' ); +var setCornerBottomRight = require( './props/corner-bottom-right/set.js' ); +var getCornerBottomRight = require( './props/corner-bottom-right/get.js' ); +var setCornerBottomLeft = require( './props/corner-bottom-left/set.js' ); +var getCornerBottomLeft = require( './props/corner-bottom-left/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 setColumnWidth = require( './props/column-width/set.js' ); +var getColumnWidth = require( './props/column-width/get.js' ); +var setData = require( './props/data/set.js' ); +var getData = require( './props/data/get.js' ); +var setFormat = require( './props/format/set.js' ); +var getFormat = require( './props/format/get.js' ); +var setHeaders = require( './props/headers/set.js' ); +var getHeaders = require( './props/headers/get.js' ); +var setHeaderAlign = require( './props/header-align/set.js' ); +var getHeaderAlign = require( './props/header-align/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 setJointMiddle = require( './props/joint-middle/set.js' ); +var getJointMiddle = require( './props/joint-middle/get.js' ); +var setJointTop = require( './props/joint-top/set.js' ); +var getJointTop = require( './props/joint-top/get.js' ); +var setJointRight = require( './props/joint-right/set.js' ); +var getJointRight = require( './props/joint-right/get.js' ); +var setJointBottom = require( './props/joint-bottom/set.js' ); +var getJointBottom = require( './props/joint-bottom/get.js' ); +var setJointLeft = require( './props/joint-left/set.js' ); +var getJointLeft = require( './props/joint-left/get.js' ); +var setJoints = require( './props/joints/set.js' ); +var getJoints = require( './props/joints/get.js' ); +var setMarginTop = require( './props/margin-top/set.js' ); +var getMarginTop = require( './props/margin-top/get.js' ); +var setMarginRight = require( './props/margin-right/set.js' ); +var getMarginRight = require( './props/margin-right/get.js' ); +var setMarginBottom = require( './props/margin-bottom/set.js' ); +var getMarginBottom = require( './props/margin-bottom/get.js' ); +var setMarginLeft = require( './props/margin-left/set.js' ); +var getMarginLeft = require( './props/margin-left/get.js' ); +var setMargins = require( './props/margins/set.js' ); +var getMargins = require( './props/margins/get.js' ); +var setMaxColumnWidth = require( './props/max-column-width/set.js' ); +var getMaxColumnWidth = require( './props/max-column-width/get.js' ); +var setMaxWidth = require( './props/max-width/set.js' ); +var getMaxWidth = require( './props/max-width/get.js' ); +var setPaddingLeft = require( './props/padding-left/set.js' ); +var getPaddingLeft = require( './props/padding-left/get.js' ); +var setPaddingRight = require( './props/padding-right/set.js' ); +var getPaddingRight = require( './props/padding-right/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 push = require( './push.js' ); +var getter = require( './get.js' ); +var setter = require( './set.js' ); + + +// VARIABLES // + +var debug = logger( 'table:unicode:main' ); + +// List of private properties (note: keep in alphabetical order): +var PRIVATE_PROPS = [ + '_align', + '_autoRender', + '_borders', + '_bufferSize', + '_corners', + '_columnSeparator', + '_columnWidth', + '_data', + '_format', + '_headerAlign', + '_headers', + '_headerSeparator', + '_horizontalSeparatorMode', + '_joints', + '_margins', + '_maxColumnWidth', + '_maxWidth', + '_numColumns', + '_paddingLeft', + '_paddingRight', + '_quiet', + '_rowSeparator', + '_verticalSeparatorMode', + '_widthUnits' +]; + +// List of options properties (note: keep in alphabetical order): +var OPTIONS_PROPS = [ + 'align', + 'autoRender', + 'borderBottom', + 'borderLeft', + 'borderRight', + 'borders', + 'borderTop', + 'bufferSize', + 'columnSeparator', + 'columnWidth', + 'cornerBottomLeft', + 'cornerBottomRight', + 'corners', + 'cornerTopLeft', + 'cornerTopRight', + 'format', + 'headerAlign', + 'headers', + 'headerSeparator', + 'horizontalSeparatorMode', + 'jointBottomLeft', + 'jointBottomRight', + 'jointMiddle', + 'joints', + 'jointTopLeft', + 'jointTopRight', + 'marginBottom', + 'marginLeft', + 'marginRight', + 'marginTop', + 'margins', + 'maxColumnWidth', + 'maxWidth', + 'paddingLeft', + 'paddingRight', + 'rowSeparator', + 'verticalSeparatorMode' +]; + + +// FUNCTIONS // + +/** +* Initializes private instance properties. +* +* @private +* @param {UnicodeTable} table - table instance +* @param {Object} defaults - default property values +* @returns {UnicodeTable} table instance +*/ +function initializePrivateProperties( table, defaults ) { // eslint-disable-line id-length + var i; + + for ( i = 0; i < PRIVATE_PROPS.length; i++ ) { + defineProperty( table, PRIVATE_PROPS[ i ], { + 'configurable': false, + 'enumerable': false, + 'writable': true, + 'value': defaults[ PRIVATE_PROPS[ i ].substring( 1 ) ] || null + }); + } + return table; +} + + +// MAIN // + +/** +* Unicode table constructor. +* +* @constructor +* @param {(Object|Collection|Collection|MatrixLike)} [data] - table data +* @param {Options} [options] - table options +* @param {(Collection|string)} [options.align='right'] - cell alignment(s) +* @param {boolean} [options.autoRender=false] - boolean indicating whether to re-render on each `change` event +* @param {string} [options.borderTop='-'] - top table border character +* @param {string} [options.borderRight='|'] - right table border character +* @param {string} [options.borderBottom='-'] - bottom table border character +* @param {string} [options.borderLeft='|'] - left table border character +* @param {Collection} [options.borders=[ '─', '│', '─', '│' ]] - table border characters +* @param {(PositiveInteger|null)} [options.bufferSize] - size of data buffer +* @param {string} [options.columnSeparator='│'] - column separator character(s) +* @param {(Collection|NonNegativeInteger|null)} [options.columnWidth] - column width(s) +* @param {string} [options.cornerTopLeft='┌'] - top-left table corner character +* @param {string} [options.cornerTopRight='┐'] - top-right table corner character +* @param {string} [options.cornerBottomRight='┘''] - bottom-right table corner character +* @param {string} [options.cornerBottomLeft='└'] - bottom-left table corner character +* @param {Collection} [options.corners=[ '┌', '┐', '┘', '└' ]] - table corner characters +* @param {(string|StringArray)} [options.format='%s'] - cell format string(s) +* @param {Collection} [options.headers] - table headers +* @param {string} [options.headerSeparator='─'] - header separator character(s) +* @param {string} [options.horizontalSeparatorMode='resume'] - horizontal line separator mode +* @param {string} [options.jointMiddle='┼'] - joint character connecting cells within the middle of the table +* @param {string} [options.jointTop='┬'] - joint character connecting cells along the top of the table +* @param {string} [options.jointRight='┤'] - joint character connecting cells along the right side of the table +* @param {string} [options.jointBottom='┴'] - joint character connecting cells along the bottom of the table +* @param {string} [options.jointLeft='├'] - joint character connecting cells along the left side of the table +* @param {Collection} [options.joints=[ '┼', '┬', '┤', '┴', '├' ]] - joint characters +* @param {NonNegativeInteger} [options.marginTop=0] - margin at the top of the table in units of blank lines +* @param {NonNegativeInteger} [options.marginRight=0] - margin to the right of the table in units of whitespace +* @param {NonNegativeInteger} [options.marginBottom=0] - margin at the bottom of the table in units of blank lines +* @param {NonNegativeInteger} [options.marginLeft=0] - margin to the left of the table in units of whitespace +* @param {NonNegativeIntegerArray} [options.margins=[0, 0, 0, 0]] - table margins +* @param {(Collection|NonNegativeInteger|null)} [options.maxColumnWidth] - maximum column width(s) +* @param {NonNegativeInteger} [options.maxWidth] - maximum table width +* @param {(NonNegativeIntegerArray|NonNegativeInteger)} [options.paddingLeft=1] - cell left padding in units of whitespace +* @param {(NonNegativeIntegerArray|NonNegativeInteger)} [options.paddingRight=1] - cell right padding in units of whitespace +* @param {string} [options.rowSeparator=''] - row separator character(s) +* @param {string} [options.verticalSeparatorMode='resume'] - vertical line separator mode +* @throws {TypeError} data argument must be an object, an array of objects, an array of arrays, or a two-dimensional ndarray +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @returns {UnicodeTable} table instance +* +* @example +* var data = [ [ 1, 2 ], [ 3, 4 ] ]; +* var headers = [ 'A', 'B' ]; +* +* var table = UnicodeTable( data, { +* 'headers': headers +* }); +* +* var str = table.render(); +* // returns '...' +*/ +function UnicodeTable() { + var options; + var nargs; + var opts; + var keys; + var self; + var key; + var flg; + var i; + + nargs = arguments.length; + if ( !( this instanceof UnicodeTable ) ) { + if ( nargs === 0 ) { + return new UnicodeTable(); + } + if ( nargs === 1 ) { + return new UnicodeTable( arguments[ 0 ] ); + } + return new UnicodeTable( arguments[ 0 ], arguments[ 1 ] ); + } + // Initialize private instance properties: + initializePrivateProperties( this, defaults() ); + this._quiet = false; + + // Resolve input arguments... + if ( nargs === 0 ) { + flg = false; + options = {}; + } else if ( nargs === 1 ) { + flg = true; + options = {}; + } else { + flg = true; + options = arguments[ 1 ]; + if ( !isObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + } + // Extract provided options while ignoring any extraneous/unsupported options properties: + opts = pick( options, OPTIONS_PROPS ); + + debug( 'Creating an instance with the following configuration: %s.', JSON.stringify( opts ) ); + + // Validate provided options by assigning values to table properties... + keys = objectKeys( opts ); + for ( i = 0; i < keys.length; i++ ) { + key = keys[ i ]; + this[ key ] = opts[ key ]; + } + // If we were provided a data argument, initialize table data... + if ( flg ) { + this.data = arguments[ 0 ]; + } + // Add event listeners: + this.on( 'change', onChange ); + this.on( 'render', onRender ); + + self = this; + 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(s) of data within in each table cell. +* +* @name align +* @memberof UnicodeTable.prototype +* @type {(Array|string)} +* @throws {TypeError} must be a supported alignment string or an array of alignment strings +* @throws {RangeError} must provide the correct number of table columns +* @default 'right' +* +* @example +* var table = new UnicodeTable(); +* +* table.align = 'left'; +* +* var v = table.align; +* // returns 'left' +* +* @example +* var table = new UnicodeTable(); +* +* table.align = [ 'left', 'right', 'center' ]; +* +* var v = table.align; +* // returns [ 'left', 'right', 'center' ] +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'align', getAlign, setAlign ); + +/** +* Rendering mode. +* +* ## Notes +* +* - If `true`, an instance automatically re-renders a table 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 v = table.autoRender; +* // returns true +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'autoRender', getAutoRender, setAutoRender ); + +/** +* Top table border character. +* +* @name borderTop +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '-' +* +* @example +* var table = new UnicodeTable(); +* +* table.borderTop = '='; +* +* var v = table.borderTop; +* // returns '=' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'borderTop', getBorderTop, setBorderTop ); + +/** +* Right table border character. +* +* @name borderRight +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '-' +* +* @example +* var table = new UnicodeTable(); +* +* table.borderRight = '|'; +* +* var v = table.borderRight; +* // returns '|' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'borderRight', getBorderRight, setBorderRight ); + +/** +* Bottom table border character. +* +* @name borderBottom +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '-' +* +* @example +* var table = new UnicodeTable(); +* +* table.borderBottom = '='; +* +* var v = table.borderBottom; +* // returns '=' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'borderBottom', getBorderBottom, setBorderBottom ); + +/** +* Left table border character. +* +* @name borderLeft +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '-' +* +* @example +* var table = new UnicodeTable(); +* +* table.borderLeft = '|'; +* +* var v = table.borderLeft; +* // returns '|' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'borderLeft', getBorderLeft, setBorderLeft ); + +/** +* Border characters in the order of `[top, right, bottom, left]`. +* +* @name borders +* @memberof UnicodeTable.prototype +* @type {Array} +* @throws {TypeError} must be an array of four strings +* @default [ "─", "│", "─", "│" ] +* +* @example +* var table = new UnicodeTable(); +* +* table.borders = [ '=', '!', '=', '!' ]; +* +* var v = table.borders; +* // returns [ '=', '!', '=', '!' ] +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'borders', getBorders, setBorders ); + +/** +* Size of internal data buffer. +* +* @name bufferSize +* @memberof UnicodeTable.prototype +* @type {(PositiveInteger|null)} +* @throws {TypeError} must be a positive integer or null +* +* @example +* var table = new UnicodeTable(); +* +* table.bufferSize = 20; +* +* var v = table.bufferSize; +* // returns 20 +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'bufferSize', getBufferSize, setBufferSize ); + +/** +* Column separator character(s). +* +* @name columnSeparator +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '│' +* +* @example +* var table = new UnicodeTable(); +* +* table.columnSeparator = '$='; +* +* var v = table.columnSeparator; +* // returns '$=' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'columnSeparator', getColumnSeparator, setColumnSeparator ); + +/** +* Column width(s). +* +* @name columnWidth +* @memberof UnicodeTable.prototype +* @type {(Array|NonNegativeInteger|null)} +* @throws {TypeError} must be null, a nonnegative integer, an array of nonnegative integers and/or nulls +* @default null +* +* @example +* var table = new UnicodeTable(); +* +* table.columnWidth = 10; +* +* var v = table.columnWidth; +* // returns 10 +* +* @example +* var table = new UnicodeTable(); +* +* table.columnWidth = [ 10, 8 ]; +* +* var v = table.columnWidth; +* // returns [ 10, 8 ] +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'columnWidth', getColumnWidth, setColumnWidth ); + +/** +* Top-left table corner character. +* +* @name cornerTopLeft +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '┌' +* +* @example +* var table = new UnicodeTable(); +* +* table.cornerTopLeft = '*'; +* +* var v = table.cornerTopLeft; +* // returns '*' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'cornerTopLeft', getCornerTopLeft, setCornerTopLeft ); + +/** +* Top-right table corner character. +* +* @name cornerTopRight +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '┐' +* +* @example +* var table = new UnicodeTable(); +* +* table.cornerTopRight = '*'; +* +* var v = table.cornerTopRight; +* // returns '*' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'cornerTopRight', getCornerTopRight, setCornerTopRight ); + +/** +* Bottom-right table corner character. +* +* @name cornerBottomRight +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '┘' +* +* @example +* var table = new UnicodeTable(); +* +* table.cornerBottomRight = '*'; +* +* var v = table.cornerBottomRight; +* // returns '*' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'cornerBottomRight', getCornerBottomRight, setCornerBottomRight ); + +/** +* Bottom-left table corner character. +* +* @name cornerBottomLeft +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '└' +* +* @example +* var table = new UnicodeTable(); +* +* table.cornerBottomLeft = '*'; +* +* var v = table.cornerBottomLeft; +* // returns '*' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'cornerBottomLeft', getCornerBottomLeft, setCornerBottomLeft ); + +/** +* Table corner characters in the order of `[top-left, top-right, bottom-right, bottom-left]`. +* +* @name corners +* @memberof UnicodeTable.prototype +* @type {Array} +* @throws {TypeError} must be an array of four strings +* @default [ "┌", "┐", "┘", "└" ] +* +* @example +* var table = new UnicodeTable(); +* +* table.corners = [ '*', '*', '*', '*' ]; +* +* var v = table.corners; +* // returns [ '*', '*', '*', '*' ] +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'corners', getCorners, setCorners ); + +/** +* Table data. +* +* @name data +* @memberof UnicodeTable.prototype +* @type {ndarray} +* @throws {TypeError} must be an object, an array of objects, an array of arrays or a two-dimensional ndarray +* @throws {RangeError} must provide the correct number of columns +* @throws {RangeError} number of rows must not exceed the maximum data buffer size +* +* @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var table = new UnicodeTable(); +* +* table.data = [ [ 'a', 'b' ], [ 1, 2 ] ]; +* +* var v = ndarray2array( table.data ); +* // returns [ [ 'a', 'b' ], [ 1, 2 ] ] +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'data', getData, setData ); + +/** +* Cell format string(s). +* +* @name format +* @memberof UnicodeTable.prototype +* @type {(string|StringArray)} +* @throws {TypeError} must be a string or an array of strings +* @throws {RangeError} must provide the correct number of table columns +* @default '%s' +* +* @example +* var table = new UnicodeTable(); +* +* table.format = '%d'; +* +* var v = table.format; +* // returns '%d' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'format', getFormat, setFormat ); + +/** +* Alignment(s) of data within in each table header cell. +* +* @name headerAlign +* @memberof UnicodeTable.prototype +* @type {(Array|string)} +* @throws {TypeError} must be a supported alignment string or an array of alignment strings +* @throws {RangeError} must provide the correct number of table columns +* @default 'right' +* +* @example +* var table = new UnicodeTable(); +* +* table.headerAlign = 'left'; +* +* var v = table.headerAlign; +* // returns 'left' +* +* @example +* var table = new UnicodeTable(); +* +* table.headerAlign = [ 'left', 'right', 'center' ]; +* +* var v = table.headerAlign; +* // returns [ 'left', 'right', 'center' ] +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'headerAlign', getHeaderAlign, setHeaderAlign ); + +/** +* Table headers. +* +* @name headers +* @memberof UnicodeTable.prototype +* @type {Collection} +* @throws {TypeError} must be an array-like object +* @throws {RangeError} must provide the correct number of table columns +* +* @example +* var table = new UnicodeTable(); +* +* table.headers = [ 'name', 'age' ]; +* +* var v = table.headers; +* // returns [ 'name', 'age' ] +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'headers', getHeaders, setHeaders ); + +/** +* Header separator character(s). +* +* @name headerSeparator +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '─' +* +* @example +* var table = new UnicodeTable(); +* +* table.headerSeparator = '$='; +* +* var v = table.headerSeparator; +* // returns '$=' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'headerSeparator', getHeaderSeparator, setHeaderSeparator ); + +/** +* Horizontal line separator mode. +* +* @name horizontalSeparatorMode +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a supported line separator mode +* @default 'resume' +* +* @example +* var table = new UnicodeTable(); +* +* table.horizontalSeparatorMode = 'repeat'; +* +* var v = table.horizontalSeparatorMode; +* // returns 'repeat' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'horizontalSeparatorMode', getHorizontalSeparatorMode, setHorizontalSeparatorMode ); + +/** +* Joint character connecting cells within the middle of the table. +* +* @name jointMiddle +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '┼' +* +* @example +* var table = new UnicodeTable(); +* +* table.jointMiddle = '*'; +* +* var v = table.jointMiddle; +* // returns '*' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'jointMiddle', getJointMiddle, setJointMiddle ); + +/** +* Joint character connecting cells at the top of the table. +* +* @name jointTop +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '┬' +* +* @example +* var table = new UnicodeTable(); +* +* table.jointTop = '*'; +* +* var v = table.jointTop; +* // returns '*' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'jointTop', getJointTop, setJointTop ); + +/** +* Joint character connecting cells along the right side of the table. +* +* @name jointRight +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '┤' +* +* @example +* var table = new UnicodeTable(); +* +* table.jointRight = '*'; +* +* var v = table.jointRight; +* // returns '*' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'jointRight', getJointRight, setJointRight ); + +/** +* Joint character connecting cells at the bottom of the table. +* +* @name jointBottom +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '┴' +* +* @example +* var table = new UnicodeTable(); +* +* table.jointBottom = '*'; +* +* var v = table.jointBottom; +* // returns '*' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'jointBottom', getJointBottom, setJointBottom ); + +/** +* Joint character connecting cells along the left side of the table. +* +* @name jointLeft +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '├' +* +* @example +* var table = new UnicodeTable(); +* +* table.jointLeft = '*'; +* +* var v = table.jointLeft; +* // returns '*' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'jointLeft', getJointLeft, setJointLeft ); + +/** +* Joint characters in the order of `[middle, top, right, bottom, left]`. +* +* @name joints +* @memberof UnicodeTable.prototype +* @type {Array} +* @throws {TypeError} must be an array of five strings +* @default [ "┼", "┬", "┤", "┴", "├" ] +* +* @example +* var table = new UnicodeTable(); +* +* table.joints = [ '*', '*', '*', '*', '*' ]; +* +* var v = table.joints; +* // returns [ '*', '*', '*', '*', '*' ] +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'joints', getJoints, setJoints ); + +/** +* Margin at the top of the table in units of blank lines. +* +* @name marginTop +* @memberof UnicodeTable.prototype +* @type {NonNegativeInteger} +* @throws {TypeError} must be a nonnegative integer +* @default 0 +* +* @example +* var table = new UnicodeTable(); +* +* table.marginTop = 2; +* +* var v = table.marginTop; +* // returns 2 +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'marginTop', getMarginTop, setMarginTop ); + +/** +* Margin to the right of the table in units of whitespace. +* +* @name marginRight +* @memberof UnicodeTable.prototype +* @type {NonNegativeInteger} +* @throws {TypeError} must be a nonnegative integer +* @default 0 +* +* @example +* var table = new UnicodeTable(); +* +* table.marginRight = 2; +* +* var v = table.marginRight; +* // returns 2 +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'marginRight', getMarginRight, setMarginRight ); + +/** +* Margin at the bottom of the table in units of blank lines. +* +* @name marginBottom +* @memberof UnicodeTable.prototype +* @type {NonNegativeInteger} +* @throws {TypeError} must be a nonnegative integer +* @default 0 +* +* @example +* var table = new UnicodeTable(); +* +* table.marginBottom = 2; +* +* var v = table.marginBottom; +* // returns 2 +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'marginBottom', getMarginBottom, setMarginBottom ); + +/** +* Margin to the left of the table in units of whitespace. +* +* @name marginLeft +* @memberof UnicodeTable.prototype +* @type {NonNegativeInteger} +* @throws {TypeError} must be a nonnegative integer +* @default 0 +* +* @example +* var table = new UnicodeTable(); +* +* table.marginLeft = 2; +* +* var v = table.marginLeft; +* // returns 2 +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'marginLeft', getMarginLeft, setMarginLeft ); + +/** +* Table margins in order of `[top, right, bottom, left]`. +* +* @name margins +* @memberof UnicodeTable.prototype +* @type {NonNegativeIntegerArray} +* @throws {TypeError} must be an array of nonnegative integers +* @throws {RangeError} must provide the correct number of table columns +* @default [ 0, 0, 0, 0 ] +* +* @example +* var table = new UnicodeTable(); +* +* table.margins = [ 2, 2, 2, 2 ]; +* +* var v = table.margins; +* // returns [ 2, 2, 2, 2 ] +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'margins', getMargins, setMargins ); + +/** +* Maximum column width(s). +* +* @name maxColumnWidth +* @memberof UnicodeTable.prototype +* @type {(Array|NonNegativeInteger|null)} +* @throws {TypeError} must be null, a nonnegative integer, an array of nonnegative integers and/or nulls +* @default +infinity +* +* @example +* var table = new UnicodeTable(); +* +* table.maxColumnWidth = 10; +* +* var v = table.maxColumnWidth; +* // returns 10 +* +* @example +* var table = new UnicodeTable(); +* +* table.maxColumnWidth = [ 10, 8 ]; +* +* var v = table.maxColumnWidth; +* // returns [ 10, 8 ] +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'maxColumnWidth', getMaxColumnWidth, setMaxColumnWidth ); + +/** +* Maximum table width. +* +* @name maxWidth +* @memberof UnicodeTable.prototype +* @type {(NonNegativeInteger|null)} +* @throws {TypeError} must be a nonnegative integer or null +* @default +infinity +* +* @example +* var table = new UnicodeTable(); +* +* table.maxWidth = 50; +* +* var v = table.maxWidth; +* // returns 50 +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'maxWidth', getMaxWidth, setMaxWidth ); + +/** +* Cell left padding(s) in units of whitespace. +* +* @name paddingLeft +* @memberof UnicodeTable.prototype +* @type {(Collection|NonNegativeInteger)} +* @throws {TypeError} must be a nonnegative integer or an array of nonnegative integers +* @default 1 +* +* @example +* var table = new UnicodeTable(); +* +* table.paddingLeft = 3; +* +* var v = table.paddingLeft; +* // returns 3 +* +* @example +* var table = new UnicodeTable(); +* +* table.paddingLeft = [ 3, 2 ]; +* +* var v = table.paddingLeft; +* // returns [ 3, 2 ] +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'paddingLeft', getPaddingLeft, setPaddingLeft ); + +/** +* Cell right padding(s) in units of whitespace. +* +* @name paddingRight +* @memberof UnicodeTable.prototype +* @type {(Collection|NonNegativeInteger)} +* @throws {TypeError} must be a nonnegative integer or an array of nonnegative integers +* @default 1 +* +* @example +* var table = new UnicodeTable(); +* +* table.paddingRight = 3; +* +* var v = table.paddingRight; +* // returns 3 +* +* @example +* var table = new UnicodeTable(); +* +* table.paddingRight = [ 3, 2 ]; +* +* var v = table.paddingRight; +* // returns [ 3, 2 ] +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'paddingRight', getPaddingRight, setPaddingRight ); + +/** +* Row separator character(s). +* +* @name rowSeparator +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a string +* @default '' +* +* @example +* var table = new UnicodeTable(); +* +* table.rowSeparator = '$='; +* +* var v = table.rowSeparator; +* // returns '$=' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'rowSeparator', getRowSeparator, setRowSeparator ); + +/** +* Vertical line separator mode. +* +* @name verticalSeparatorMode +* @memberof UnicodeTable.prototype +* @type {string} +* @throws {TypeError} must be a supported line separator mode +* @default 'resume' +* +* @example +* var table = new UnicodeTable(); +* +* table.verticalSeparatorMode = 'repeat'; +* +* var v = table.verticalSeparatorMode; +* // returns 'repeat' +*/ +setReadWriteAccessor( UnicodeTable.prototype, 'verticalSeparatorMode', getVerticalSeparatorMode, setVerticalSeparatorMode ); + +/** +* Retrieves the data for a specified table cell. +* +* @name get +* @memberof UnicodeTable.prototype +* @type {Function} +* @param {NonNegativeInteger} i - index for the first dimension (i.e., zero-based row number) +* @param {NonNegativeInteger} j - index for the second dimension (i.e., zero-based column number) +* @throws {TypeError} first argument must be a nonnegative integer +* @throws {TypeError} second argument must be a nonnegative integer +* @throws {RangeError} index is out-of-bounds +* @returns {*} data element +* +* @example +* var table = new UnicodeTable( [ [ 1, 2 ], [ 3, 4 ] ], { +* 'headers': [ 'A', 'B' ] +* }); +* +* var v = table.get( 0, 0 ); +* // returns 1 +* +* v = table.get( 1, 1 ); +* // returns 4 +*/ +setReadOnly( UnicodeTable.prototype, 'get', getter ); + +/** +* Appends one or more rows to a table. +* +* @name push +* @memberof UnicodeTable.prototype +* @type {Function} +* @param {(Object|Collection|VectorLike|MatrixLike)} data - row(s) to add +* @throws {TypeError} must provide an object, an array-like object, or an ndarray +* @throws {TypeError} must provide data containing the correct number of columns +* @returns {UnicodeTable} table instance +* +* @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var table = new UnicodeTable( [ [ 1, 2 ], [ 3, 4 ] ] ); +* var data = ndarray2array( table.data ); +* // returns [ [ 1, 2 ], [ 3, 4 ] ] +* +* table.push( [ 5, 6 ] ); +* data = ndarray2array( table.data ); +* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] +*/ +setReadOnly( UnicodeTable.prototype, 'push', push ); + +/** +* Renders a table. +* +* @name render +* @memberof UnicodeTable.prototype +* @type {Function} +* @throws {Error} unable to accommodate all table columns within maximum table width +* @returns {string} rendered table +* +* @example +* var table = new UnicodeTable( [ [ 1, 2 ], [ 3, 4 ] ], { +* 'headers': [ 'A', 'B' ] +* }); +* +* var v = table.render(); +* // returns '...' +*/ +setReadOnly( UnicodeTable.prototype, 'render', render ); + +/** +* Sets a single data element in a table to a specified value. +* +* @name set +* @memberof UnicodeTable.prototype +* @type {Function} +* @param {NonNegativeInteger} i - index for the first dimension (i.e., zero-based row number) +* @param {NonNegativeInteger} j - index for the second dimension (i.e., zero-based column number) +* @param {*} value - value to set +* @throws {TypeError} first argument must be a nonnegative integer +* @throws {TypeError} second argument must be a nonnegative integer +* @throws {RangeError} index is out-of-bounds +* @returns {UnicodeTable} table instance +* +* @example +* var table = new UnicodeTable( [ [ 1, 2 ], [ 3, 4 ] ], { +* 'headers': [ 'A', 'B' ] +* }); +* +* var v = table.get( 1, 0 ); +* // returns 3 +* +* table.set( 1, 0, 5 ); +* +* v = table.get( 1, 0 ); +* // returns 5 +*/ +setReadOnly( UnicodeTable.prototype, 'set', setter ); + + +// EXPORTS // + +module.exports = UnicodeTable; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/normalize.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/normalize.js new file mode 100644 index 000000000000..71ff8d6f8517 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/normalize.js @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 accessors = require( '@stdlib/array/base/accessors' ); +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './normalize_string.js' ); + + +// MAIN // + +/** +* Normalizes table data. +* +* @private +* @param {Collection} buffer - linear data buffer +* @param {NonNegativeIntegerArray} shape - table data shape +* @param {StringArray} fmts - format strings +* @param {string} units - width units +* @returns {Collection} modified data buffer +*/ +function normalize( buffer, shape, fmts, units ) { + var obj; + var get; + var set; + var raw; + var tmp; + var v; + var i; + var j; + var k; + + obj = accessors( buffer ); + get = obj.accessors[ 0 ]; + set = obj.accessors[ 1 ]; + + k = 0; + for ( i = 0; i < shape[ 0 ]; i++ ) { + for ( j = 0; j < shape[ 1 ]; j++ ) { + raw = get( buffer, k ); + + // Generate a formatted string: + v = format( fmts[ j%fmts.length ], raw ); + + // Normalize the string to a data object: + tmp = normalizeString( v, units ); + + // Cache the original datum: + tmp.raw = raw; + + // Replace the element in the data buffer: + set( buffer, k, tmp ); + k += 1; + } + } + return buffer; +} + + +// EXPORTS // + +module.exports = normalize; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/normalize_string.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/normalize_string.js new file mode 100644 index 000000000000..657952954845 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/normalize_string.js @@ -0,0 +1,211 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 splitGraphemeClusters = require( '@stdlib/string/split-grapheme-clusters' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +var gsum = require( '@stdlib/blas/ext/base/gsum' ); +var wcswidth = require( './wcswidth.js' ); // TODO: replace with string/base/wcswidth +var RE_ANSI = require( './ansi_regexp.js' ); // TODO: replace with regexp/ansi-escape-sequence + + +// FUNCTIONS // + +/** +* Removes empty strings from a list of strings. +* +* @private +* @param {StringArray} arr - array of strings +* @returns {StringArray} mutated input array +* +* @example +* var arr = [ '', 'a', 'b', '', 'c', '' ]; +* +* var out = compress( arr ); +* // returns [ 'a', 'b', 'c' ] +* +* @example +* var arr = [ '', '' ]; +* +* var out = compress( arr ); +* // returns [] +*/ +function compress( arr ) { // TODO: consider make this an array/base utility (e.g., remove falsy values; array/base/remove-falsy?) + var i; + var j; + + j = 0; + for ( i = 0; i < arr.length; i++ ) { + if ( arr[ i ] ) { + arr[ j ] = arr[ i ]; + j += 1; + } + } + arr.length = j; + return arr; +} + +/** +* Returns a mask indicating whether an element is an ANSI escape sequence. +* +* @private +* @param {StringArray} arr - array of strings +* @returns {NonNegativeIntegerArray} mask array +*/ +function ansiMask( arr ) { + var out; + var i; + + out = []; + for ( i = 0; i < arr.length; i++ ) { + out.push( ( RE_ANSI.test( arr[ i ] ) ) ? 1 : 0 ); + } + return out; +} + +/** +* Splits each string into individual grapheme clusters according to a provided mask array. +* +* @private +* @param {StringArray} arr - input array +* @param {NonNegativeIntegerArray} msk - mask array +* @returns {Array} output arrays +*/ +function splitGraphemes( arr, msk ) { + var tmp; + var oa; + var om; + var i; + var j; + + oa = []; + om = []; + for ( i = 0; i < arr.length; i++ ) { + // Check whether the string is "masked"... + if ( msk[ i ] === 1 ) { + // Copy over without splitting into grapheme clusters... + oa.push( arr[ i ] ); + om.push( msk[ i ] ); + continue; + } + tmp = splitGraphemeClusters( arr[ i ] ); + for ( j = 0; j < tmp.length; j++ ) { + oa.push( tmp[ j ] ); + om.push( msk[ i ] ); + } + } + return [ oa, om ]; +} + +/** +* Computes column widths for a list of strings according to a provided mask array. +* +* @private +* @param {StringArray} arr - input array +* @param {NonNegativeIntegerArray} msk - mask array +* @param {string} units - width units +* @returns {NonNegativeIntegerArray} list of column widths +*/ +function computeWidths( arr, msk, units ) { // TODO: eventually make this into a separate string utility package + var out; + var f; + var i; + + if ( units === 'graphemes' ) { + f = constantFunction( 1 ); + } else { // units === 'columns' + f = wcswidth; + } + + out = []; + for ( i = 0; i < arr.length; i++ ) { + if ( msk[ i ] ) { + out.push( 0 ); + } else { + out.push( f( arr[ i ] ) ); + } + } + return out; +} + +/** +* Computes the sum of an array according to a provided mask array. +* +* @private +* @param {NonNegativeIntegerArray} arr - input array +* @param {NonNegativeIntegerArray} msk - mask array +* @returns {NonNegativeInteger} sum +*/ +function sum( arr, msk ) { // TODO: replace with blas/ext/base/* msk sum package + var s; + var i; + + s = 0; + for ( i = 0; i < arr.length; i++ ) { + if ( msk[ i ] === 0 ) { + s += arr[ i ]; + } + } + return s; +} + + +// MAIN // + +/** +* Normalizes data belonging to a single table cell. +* +* @private +* @param {string} value - input string +* @param {string} units - width units +* @returns {Object} normalized results +*/ +function normalize( value, units ) { + var tmp; + var msk; + var w; + + // Split the formatted string according to whether a substring is an ANSI escape sequence: + tmp = compress( value.split( RE_ANSI ) ); + + // Create a mask array which flags whether a substring is an ANSI escape sequence: + msk = ansiMask( tmp ); + + // Expand each non-ANSI escape sequence into individual grapheme clusters: + tmp = splitGraphemes( tmp, msk ); + + // For each grapheme cluster, compute the expected width: + w = computeWidths( tmp[ 0 ], tmp[ 1 ], units ); + + return { + 'value': value, + 'graphemes': tmp[ 0 ], + 'ngraphemes': tmp[ 0 ].length - gsum( tmp[ 1 ].length, tmp[ 1 ], 1 ), + 'mask': tmp[ 1 ], + 'columnWidths': w, + 'width': sum( w, tmp[ 1 ] ) + }; +} + + +// EXPORTS // + +module.exports = normalize; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/align/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/align/get.js new file mode 100644 index 000000000000..853a535cda3e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/align/get.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the alignment(s) of data within table cells. +* +* @private +* @returns {(Array|string)} cell alignment(s) +*/ +function get() { + if ( this._align.length > 1 ) { + return this._align.slice(); + } + return this._align[ 0 ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/align/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/align/set.js new file mode 100644 index 000000000000..3085aa188805 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/align/set.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isCollection = require( '@stdlib/assert/is-collection' ); +var isEqualArray = require( '@stdlib/assert/is-equal-array' ); +var copy = require( '@stdlib/array/base/copy' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var isAlignment = contains( [ 'right', 'center', 'left' ] ); + + +// MAIN // + +/** +* Sets the alignment(s) of data within table cells. +* +* @private +* @param {(Array|string)} value - cell alignment(s) +* @throws {TypeError} must be a supported alignment or an array of alignments +* @throws {RangeError} must provide the correct number of table columns +*/ +function set( value ) { + var tmp; + var i; + if ( isString( value ) ) { + if ( !isAlignment( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a supported alignment. Value: `%s`.', 'align', value ) ); + } + value = [ value ]; + if ( !isEqualArray( value, this._align ) ) { + this._align = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } + return; + } + if ( !isCollection( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string or an array of strings. Value: `%s`.', 'align', value ) ); + } + tmp = []; + for ( i = 0; i < value.length; i++ ) { + if ( !isAlignment( value[ i ] ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of supported alignments. Value: `["%s"]`.', 'align', copy( value ) ).join( '", "' ) ); + } + // Explicitly copy to a new array to avoid external mutation: + tmp.push( value[ i ] ); + } + if ( this._numColumns ) { + if ( tmp.length !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have a length of %d in order to match the number of table columns. Value: `["%s"]`.', 'align', this._numColumns, tmp.join( '", "' ) ) ); + } + } else { + this._numColumns = tmp.length; + } + if ( !isEqualArray( tmp, this._align ) ) { + this._align = tmp; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/auto-render/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/auto-render/get.js new file mode 100644 index 000000000000..cdb60cfc9c29 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/auto-render/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the rendering mode. +* +* @private +* @returns {boolean} rendering mode +*/ +function get() { + return this._autoRender; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/auto-render/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/auto-render/set.js new file mode 100644 index 000000000000..90f0e2c275ff --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/auto-render/set.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the rendering mode. +* +* @private +* @param {boolean} value - boolean indicating whether to automatically re-render on a `change` event +* @throws {TypeError} must be a boolean +*/ +function set( value ) { + if ( !isBoolean( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a boolean. Value: `%s`.', 'autoRender', value ) ); + } + if ( value !== this._autoRender ) { + this._autoRender = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-bottom/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-bottom/get.js new file mode 100644 index 000000000000..22be478f7e66 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-bottom/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the table bottom border character. +* +* @private +* @returns {string} border character +*/ +function get() { + return this._borders[ 2 ].value; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-bottom/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-bottom/set.js new file mode 100644 index 000000000000..56b67cb0b89a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-bottom/set.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the table bottom border character. +* +* @private +* @param {string} value - border character +* @throws {TypeError} must be a string +*/ +function set( value ) { + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'borderBottom', value ) ); + } + if ( value !== this._borders[ 2 ].value ) { + this._borders[ 2 ] = normalizeString( value, this._widthUnits ); + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-left/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-left/get.js new file mode 100644 index 000000000000..ceacf6567ebd --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-left/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the table left border character. +* +* @private +* @returns {string} border character +*/ +function get() { + return this._borders[ 3 ].value; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-left/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-left/set.js new file mode 100644 index 000000000000..a93c137fba63 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-left/set.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the table left border character. +* +* @private +* @param {string} value - border character +* @throws {TypeError} must be a string +*/ +function set( value ) { + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string which contains one and only one character. Value: `%s`.', 'borderLeft', value ) ); + } + if ( value !== this._borders[ 3 ].value ) { + this._borders[ 3 ] = normalizeString( value, this._widthUnits ); + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-right/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-right/get.js new file mode 100644 index 000000000000..0e936d2a1d6a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-right/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the table right border character. +* +* @private +* @returns {string} border character +*/ +function get() { + return this._borders[ 1 ].value; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-right/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-right/set.js new file mode 100644 index 000000000000..a7a6d910564e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-right/set.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the table right border character. +* +* @private +* @param {string} value - border character +* @throws {TypeError} must be a string +*/ +function set( value ) { + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'borderRight', value ) ); + } + if ( value !== this._borders[ 1 ].value ) { + this._borders[ 1 ] = normalizeString( value, this._widthUnits ); + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-top/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-top/get.js new file mode 100644 index 000000000000..16208ead9d49 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-top/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the table top border character. +* +* @private +* @returns {string} border character +*/ +function get() { + return this._borders[ 0 ].value; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-top/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-top/set.js new file mode 100644 index 000000000000..a34f01b3193a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/border-top/set.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the table top border character. +* +* @private +* @param {string} value - border character +* @throws {TypeError} must be a string +*/ +function set( value ) { + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'borderTop', value ) ); + } + if ( value !== this._borders[ 0 ].value ) { + this._borders[ 0 ] = normalizeString( value, this._widthUnits ); + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// 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..750b41958a9d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/get.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var pluck = require( '@stdlib/utils/pluck' ); // TODO: replace with array/base utility + + +// MAIN // + +/** +* Returns table border characters. +* +* @private +* @returns {Array} borders +*/ +function get() { + return pluck( this._borders, 'value' ); +} + + +// 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..018fbeac8400 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/borders/set.js @@ -0,0 +1,92 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isCollection = require( '@stdlib/assert/is-collection' ); +var copy = require( '@stdlib/array/base/copy' ); +var format = require( '@stdlib/string/format' ); +var everyBy2 = require( './../../every_by2.js' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// VARIABLES // + +var NUM_BORDERS = 4; + + +// FUNCTIONS // + +/** +* Predicate function which tests whether two elements are equal. +* +* @private +* @param {Object} v1 - first value +* @param {Object} v2 - second value +* @returns {boolean} boolean indicating whether two elements are equal +*/ +function predicate( v1, v2 ) { + return ( v1.value === v2.value ); +} + + +// MAIN // + +/** +* Sets the table border characters in the order `[top, right, bottom, left]`. +* +* @private +* @param {Collection} values - border characters +* @throws {TypeError} must be an array of strings +* @throws {RangeError} must provide four strings +*/ +function set( values ) { + var data; + var v; + var i; + if ( !isCollection( values ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of strings. Value: `%s`.', 'borders', values ) ); + } + if ( values.length !== NUM_BORDERS ) { + throw new RangeError( format( 'invalid assignment. `%s` must have a length of %d. Value: `["%s"]`.', 'borders', NUM_BORDERS, copy( values ).join( '", "' ) ) ); + } + data = []; + for ( i = 0; i < NUM_BORDERS; i++ ) { + v = values[ i ]; + if ( !isString( v ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of strings in which each array element is a string containing one and only one character. Value: `["%s"]`.', 'borders', copy( values ).join( '", "' ) ) ); + } + data.push( normalizeString( v, this._widthUnits ) ); + } + if ( !everyBy2( data, this._borders, predicate ) ) { + this._borders = data; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/buffer-size/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/buffer-size/get.js new file mode 100644 index 000000000000..6ebd438a2dd5 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/buffer-size/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the internal data buffer size. +* +* @private +* @returns {PositiveInteger} data buffer size +*/ +function get() { + return this._bufferSize; +} + + +// EXPORTS // + +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..bb7d98801a25 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/buffer-size/set.js @@ -0,0 +1,87 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var isNull = require( '@stdlib/assert/is-null' ); +var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStrides = require( '@stdlib/ndarray/base/strides' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var getDType = require( '@stdlib/ndarray/base/dtype' ); +var getOrder = require( '@stdlib/ndarray/base/order' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var FLOAT64_MAX = require( '@stdlib/constants/float64/max' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the data buffer size. +* +* @private +* @param {(PositiveInteger|null)} value - data buffer size +* @throws {TypeError} must be a positive integer or null +*/ +function set( value ) { + var ncols; + var data; + var buf; + var sh; + var s; + if ( isNull( value ) ) { + s = FLOAT64_MAX; + } else if ( isPositiveInteger( value ) ) { + s = value; + } else { + throw new TypeError( format( 'invalid assignment. `%s` must be a positive integer or null. Value: `%s`.', 'bufferSize', value ) ); + } + if ( s !== this._bufferSize ) { + data = this._data; + + // Check whether we need to shrink the internal FIFO queue... + if ( data && s < numelDimension( data, 0 ) ) { + ncols = numelDimension( data, 1 ); + buf = getData( data ); // FIFO queue + + // Resize the FIFO queue to hold only enough elements to support the current table size: + buf.resize( s*ncols ); + sh = [ s, ncols ]; + + // Create a new ndarray view, where we assume that the previous view was in row-major order, thus leaving strides the same: + this._data = new ndarray( getDType( data ), buf, sh, getStrides( data, false ), getOffset( data ), getOrder( data ) ); // eslint-disable-line max-len + } + // Otherwise, if we need to grow the internal FIFO queue, wait to do that until new data is pushed to the table... + + this._bufferSize = s; + if ( !this._quiet ) { + 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 new file mode 100644 index 000000000000..3c7d942d1993 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the column separator character(s). +* +* @private +* @returns {string} column separator +*/ +function get() { + return this._columnSeparator.value; +} + + +// 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..1e0c69a64b1c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-separator/set.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the column separator character(s). +* +* @private +* @param {string} value - column separator +* @throws {TypeError} must be a string +*/ +function set( value ) { + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'columnSeparator', value ) ); + } + if ( value !== this._columnSeparator.value ) { + this._columnSeparator = normalizeString( value, this._widthUnits ); + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-width/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-width/get.js new file mode 100644 index 000000000000..d3660ceea726 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-width/get.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNull = require( '@stdlib/assert/is-null' ); + + +// MAIN // + +/** +* Returns the column width(s) for each table column. +* +* @private +* @returns {(Array|NonNegativeInteger|null)} column width(s) +*/ +function get() { + if ( isNull( this._columnWidth ) ) { + return this._columnWidth; + } + if ( this._columnWidth.length > 1 ) { + return this._columnWidth.slice(); + } + return this._columnWidth[ 0 ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-width/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-width/set.js new file mode 100644 index 000000000000..9cc7a422c464 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/column-width/set.js @@ -0,0 +1,91 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var isCollection = require( '@stdlib/assert/is-collection' ); +var isNull = require( '@stdlib/assert/is-null' ); +var isEqualArray = require( '@stdlib/assert/is-equal-array' ); +var copy = require( '@stdlib/array/base/copy' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the column width(s) for each table column. +* +* @private +* @param {(Collection|NonNegativeInteger|null)} value - column width(s) +* @throws {TypeError} must be null, a nonnegative integer, an array of nonnegative integers and/or nulls +* @throws {RangeError} must provide the correct number of table columns +*/ +function set( value ) { + var out; + var len; + var v; + var i; + + if ( !isCollection( value ) ) { + if ( isNull( value ) || isNonNegativeInteger( value ) ) { + out = [ value ]; + } else { + throw new TypeError( format( 'invalid assignment. `%s` must be either null, a nonnegative integer, or an array of nonnegative integers and/or nulls. Value: `%s`.', 'columnWidth', value ) ); + } + if ( !isEqualArray( out, this._columnWidth ) ) { + this._columnWidth = out; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } + return; + } + len = value.length; + if ( this._numColumns ) { + if ( len !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have a length of %d in order to match the number of table columns. Value: `["%s"]`.', 'columnWidth', this._numColumns, copy( value ).join( '", "' ) ) ); + } + } else { + this._numColumns = len; + } + out = []; + for ( i = 0; i < len; i++ ) { + v = value[ i ]; + if ( isNull( v ) || isNonNegativeInteger( v ) ) { + out.push( v ); + continue; + } + throw new TypeError( format( 'invalid assignment. `%s` must be either null, a nonnegative integer, or an array of nonnegative integers and/or nulls. Value: `["%s"]`.', 'columnWidth', copy( value ).join( '", "' ) ) ); + } + if ( !isEqualArray( out, this._columnWidth ) ) { + this._columnWidth = out; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-left/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-left/get.js new file mode 100644 index 000000000000..465667144c22 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-left/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the bottom-left table corner character. +* +* @private +* @returns {string} character +*/ +function get() { + return this._corners[ 3 ].value; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-left/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-left/set.js new file mode 100644 index 000000000000..3df9d0e081f1 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-left/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the bottom-left table corner character. +* +* @private +* @param {string} value - character +* @throws {TypeError} must be a string +*/ +function set( value ) { + var v; + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'cornerBottomLeft', value ) ); + } + if ( value !== this._corners[ 3 ].value ) { + v = normalizeString( value, this._widthUnits ); + if ( v.ngraphemes > 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string containing one and only one grapheme cluster. Value: `%s`.', 'cornerBottomLeft', value ) ); + } + this._corners[ 3 ] = v; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-right/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-right/get.js new file mode 100644 index 000000000000..a2a7fc099e7a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-right/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the bottom-right table corner character. +* +* @private +* @returns {string} character +*/ +function get() { + return this._corners[ 2 ].value; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-right/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-right/set.js new file mode 100644 index 000000000000..29b48389f53e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-bottom-right/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the bottom-right table corner character. +* +* @private +* @param {string} value - character +* @throws {TypeError} must be a string +*/ +function set( value ) { + var v; + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'cornerBottomRight', value ) ); + } + if ( value !== this._corners[ 2 ].value ) { + v = normalizeString( value, this._widthUnits ); + if ( v.ngraphemes > 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string containing one and only one grapheme cluster. Value: `%s`.', 'cornerBottomRight', value ) ); + } + this._corners[ 2 ] = v; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-left/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-left/get.js new file mode 100644 index 000000000000..134333efe244 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-left/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the top-left table corner character. +* +* @private +* @returns {string} character +*/ +function get() { + return this._corners[ 0 ].value; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-left/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-left/set.js new file mode 100644 index 000000000000..ad3048461951 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-left/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the top-left table corner character. +* +* @private +* @param {string} value - character +* @throws {TypeError} must be a string +*/ +function set( value ) { + var v; + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'cornerTopLeft', value ) ); + } + if ( value !== this._corners[ 0 ].value ) { + v = normalizeString( value, this._widthUnits ); + if ( v.ngraphemes > 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string containing one and only one grapheme cluster. Value: `%s`.', 'cornerTopLeft', value ) ); + } + this._corners[ 0 ] = v; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-right/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-right/get.js new file mode 100644 index 000000000000..696d0b12b064 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-right/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the top-right table corner character. +* +* @private +* @returns {string} character +*/ +function get() { + return this._corners[ 1 ].value; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-right/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-right/set.js new file mode 100644 index 000000000000..bad05789de63 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corner-top-right/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the top-right table corner character. +* +* @private +* @param {string} value - character +* @throws {TypeError} must be a string +*/ +function set( value ) { + var v; + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'cornerTopRight', value ) ); + } + if ( value !== this._corners[ 1 ].value ) { + v = normalizeString( value, this._widthUnits ); + if ( v.ngraphemes > 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string containing one and only one grapheme cluster. Value: `%s`.', 'cornerTopRight', value ) ); + } + this._corners[ 1 ] = v; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// 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..0fbf6c389bf9 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/get.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var pluck = require( '@stdlib/utils/pluck' ); // TODO: replace with array/base utility + + +// MAIN // + +/** +* Returns the table corner characters in the order `[top-left, top-right, bottom-right, bottom-left]`. +* +* @private +* @returns {Array} list of characters +*/ +function get() { + return pluck( this._corners, 'value' ); +} + + +// 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..c8e42756a98e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/corners/set.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isCollection = require( '@stdlib/assert/is-collection' ); +var copy = require( '@stdlib/array/base/copy' ); +var format = require( '@stdlib/string/format' ); +var everyBy2 = require( './../../every_by2.js' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// VARIABLES // + +var NUM_CORNERS = 4; + + +// FUNCTIONS // + +/** +* Predicate function which tests whether two elements are equal. +* +* @private +* @param {Object} v1 - first value +* @param {Object} v2 - second value +* @returns {boolean} boolean indicating whether two elements are equal +*/ +function predicate( v1, v2 ) { + return ( v1.value === v2.value ); +} + + +// MAIN // + +/** +* Sets the table corner characters in the order `[top-left, top-right, bottom-right, bottom-left]`. +* +* @private +* @param {Array} values - list of characters +* @throws {TypeError} must be an array of strings +* @throws {RangeError} must provide four strings +*/ +function set( values ) { + var data; + var v; + var i; + + if ( !isCollection( values ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of strings. Value: `%s`.', 'corners', values ) ); + } + if ( values.length !== NUM_CORNERS ) { + throw new RangeError( format( 'invalid assignment. `%s` must have a length of %d. Value: `["%s"]`.', 'corners', NUM_CORNERS, copy( values ).join( '", "' ) ) ); + } + data = []; + for ( i = 0; i < NUM_CORNERS; i++ ) { + v = values[ i ]; + if ( !isString( v ) || v.ngraphemes > 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of strings in which each array element is a string containing one and only one grapheme cluster. Value: `["%s"]`.', 'corners', copy( values ).join( '", "' ) ) ); + } + v = normalizeString( v, this._widthUnits ); + if ( v.ngraphemes > 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of strings in which each array element is a string containing one and only one grapheme cluster. Value: `["%s"]`.', 'corners', copy( values ).join( '", "' ) ) ); + } + data.push( v ); + } + if ( !everyBy2( data, this._corners, predicate ) ) { + this._corners = data; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; 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..0901dbec926f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/data/get.js @@ -0,0 +1,85 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNull = require( '@stdlib/assert/is-null' ); +var resolveGetter = require( '@stdlib/array/base/resolve-getter' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var getDType = require( '@stdlib/ndarray/base/dtype' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var getOrder = require( '@stdlib/ndarray/base/order' ); +var getStrides = require( '@stdlib/ndarray/base/strides' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); + + +// FUNCTIONS // + +/** +* Extracts a property value from each element in an array of objects. +* +* @private +* @param {Collection} arr - input array +* @param {(string|symbol)} prop - property value +* @returns {Array} output array +*/ +function pluck( arr, prop ) { // TODO: considering moving to array/base/pluck; added here in order to support accessor arrays; however, it does make certain assumptions that utils/base/pluck does not. + var out; + var get; + var i; + + get = resolveGetter( arr ); + out = []; + for ( i = 0; i < arr.length; i++ ) { + out.push( get( arr, i )[ prop ] ); + } + return out; +} + + +// MAIN // + +/** +* Returns table data as a read-only ndarray view. +* +* @private +* @returns {(ndarray|null)} table data +*/ +function get() { + var view; + var buf; + + view = this._data; + if ( isNull( view ) ) { + return null; + } + buf = pluck( getData( view ), 'raw' ); + return new ndarray( getDType( view ), buf, getShape( view ), getStrides( view ), getOffset( view ), getOrder( view ), { // eslint-disable-line max-len + 'readonly': true + }); +} + + +// 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..4c70740da881 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/data/set.js @@ -0,0 +1,132 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isMatrixLike = require( '@stdlib/assert/is-matrix-like' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var assign = require( '@stdlib/ndarray/base/assign' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getBaseShape = require( '@stdlib/ndarray/base/shape' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var format = require( '@stdlib/string/format' ); +var normalizeData = require( './../../normalize.js' ); +var convertDictionary = require( './../../convert_dictionary.js' ); +var convertCollection = require( './../../convert_collection.js' ); +var FifoArray = require( './../../fifo.js' ); + + +// VARIABLES // + +var DTYPE = 'generic'; +var ORDER = 'row-major'; + + +// MAIN // + +/** +* Sets the table data. +* +* @private +* @param {(Object|Collection|Collection|MatrixLike)} data - table data +* @throws {TypeError} must be an object, an array of objects, an array of arrays, or a two-dimensional ndarray +* @throws {RangeError} must provide the correct number of columns +* @throws {RangeError} number of rows must not exceed the maximum data buffer size +*/ +function set( data ) { + var headers; + var out; + var tmp; + var sh; + + // If provided an ndarray, explicitly copy ndarray data to a new contiguous ndarray in order to allow mutation of the underlying buffer and for the purposes of maintaining an internal FIFO queue... + if ( isMatrixLike( data ) ) { + sh = getShape( data ); + out = new FifoArray( zeros( sh[0]*sh[1] ) ); + out = new ndarray( DTYPE, out, sh, shape2strides( sh, ORDER ), 0, ORDER ); // eslint-disable-line max-len + assign( [ data, out ] ); + } + // If provided a collection, convert to an ndarray... + else if ( isCollection( data ) ) { + out = convertCollection( data, this.headers ); // NOTE: the use of `this.headers`, rather than `this._headers`, is intentional, as we only want the list of header values (if they exist) + if ( out.code ) { // out.code === 'ERR_MISSING_COLUMNS' + throw new TypeError( format( 'invalid assignment. `%s` must be either an object, an array of objects, an array of arrays, or a two-dimensional ndarray. One or more of the provided data elements is missing expected column data. Expected columns: ["%s"]. Value: `%s`.', 'data', out.headers.join( '", "' ), JSON.stringify( data ) ) ); + } + if ( out.headers ) { + headers = out.headers; + } + out = out.data; // ndarray + } + // If provided anything else, process as a dictionary of columns... + else { + out = convertDictionary( data, this.headers ); // NOTE: the use of `this.headers`, rather than `this._headers`, is intentional, as we only want the list of header values (if they exist) + if ( out.code ) { + if ( out.code === 'ERR_EMPTY_OBJECT' ) { + throw new TypeError( format( 'invalid assignment. `%s` must be either an object containing columns of data, an array of objects, an array of arrays, or a two-dimensional ndarray. Value: `%s`.', 'data', JSON.stringify( data ) ) ); + } + if ( out.code === 'ERR_INVALID_OBJECT' ) { + throw new TypeError( format( 'invalid assignment. `%s` must be either an object containing columns of data, an array of objects, an array of arrays, or a two-dimensional ndarray. Value: `%s`.', 'data', JSON.stringify( data ) ) ); + } + // out.code === 'ERR_UNEQUAL_COLUMN_LENGTHS' + throw new TypeError( format( 'invalid assignment. `%s` must be either an object containing columns of data, an array of objects, an array of arrays, or a two-dimensional ndarray. Each provided data column must have the same number of rows. Value: `%s`.', 'data', JSON.stringify( data ) ) ); + } + if ( out.headers ) { + headers = out.headers; + } + out = out.data; // ndarray + } + // Ensure that the provided data does not have too many rows... + sh = getBaseShape( out, false ); + if ( sh[ 0 ] > this._bufferSize ) { + throw new RangeError( format( 'invalid assignment. `%s` exceeds maximum data buffer size. Either increase the table buffer size or provide fewer rows of data. Buffer size: %u. Number of rows: %u.', 'data', this._bufferSize, sh[ 0 ] ) ); + } + // Ensure that the provided data has the expected number of columns... + if ( this._numColumns ) { + if ( sh[ 1 ] !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have %d columns in order to match the number of table columns. Number of columns: %u.', 'data', this._numColumns, sh[ 1 ] ) ); + } + } else { + this._numColumns = sh[ 1 ]; + } + // Normalize the underlying table data buffer: + normalizeData( getData( out ), sh, this._format, this._widthUnits ); + + // Anytime a user sets table data, assume that the data has changed (note: performing a deep equality check is likely too expensive and not worth the effort) and thus, if not in "quiet" mode, always emit a 'change' event... + this._data = out; + if ( headers !== void 0 ) { + tmp = this._quiet; + this._quiet = true; // avoid triggering a 'change' event + this.headers = headers; // NOTE: assigning to `this.headers` is intentional in order to ensure proper processing of headers + this._quiet = tmp; + } + if ( !this._quiet ) { + this.emit( 'change' ); + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/format/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/format/get.js new file mode 100644 index 000000000000..50f4d79a82de --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/format/get.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the cell format string(s). +* +* @private +* @returns {(StringArray|string)} cell format string(s) +*/ +function get() { + if ( this._format.length > 1 ) { + return this._format.slice(); + } + return this._format[ 0 ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/format/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/format/set.js new file mode 100644 index 000000000000..6efa9f64aac6 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/format/set.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var isEqualArray = require( '@stdlib/assert/is-equal-array' ); +var copy = require( '@stdlib/array/base/copy' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the table cell format string(s). +* +* @private +* @param {(StringArray|string)} value - cell format string(s) +* @throws {TypeError} must provide a string or an array of strings +* @throws {RangeError} must provide the correct number of columns +*/ +function set( value ) { + if ( isString( value ) ) { + value = [ value ]; + if ( !isEqualArray( value, this._format ) ) { + this._format = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } + return; + } + if ( !isStringArray( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string or an array of strings. Value: `%s`.', 'format', value ) ); + } + if ( this._numColumns ) { + if ( value.length !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have a length of %d in order to match the number of table columns. Value: `[%s]`.', 'format', this._numColumns, copy( value ).join( ', ' ) ) ); + } + } else { + this._numColumns = value.length; + } + value = copy( value ); + if ( !isEqualArray( value, this._format ) ) { + this._format = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-align/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-align/get.js new file mode 100644 index 000000000000..91db26f5665d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-align/get.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the alignment(s) of data within table header cells. +* +* @private +* @returns {(Array|string|null)} cell alignment(s) +*/ +function get() { + if ( this._headerAlign === null ) { + return this.align; + } + if ( this._headerAlign.length > 1 ) { + return this._headerAlign.slice(); + } + return this._headerAlign[ 0 ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-align/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-align/set.js new file mode 100644 index 000000000000..19cd5409c2eb --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-align/set.js @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isNull = require( '@stdlib/assert/is-null' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var isEqualArray = require( '@stdlib/assert/is-equal-array' ); +var copy = require( '@stdlib/array/base/copy' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var isAlignment = contains( [ 'right', 'center', 'left' ] ); + + +// MAIN // + +/** +* Sets the alignment(s) of data within table header cells. +* +* @private +* @param {(Array|string|null)} value - cell alignment(s) +* @throws {TypeError} must be a supported alignment or an array of alignments +* @throws {RangeError} must provide the correct number of table columns +*/ +function set( value ) { + var tmp; + var i; + if ( isNull( value ) ) { + if ( value !== this._headerAlign ) { + this._headerAlign = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } + return; + } + if ( isString( value ) ) { + if ( !isAlignment( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a supported alignment. Value: `%s`.', 'headerAlign', value ) ); + } + value = [ value ]; + if ( !isEqualArray( value, this._align ) ) { + this._align = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } + return; + } + if ( !isCollection( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string or an array of strings. Value: `%s`.', 'align', value ) ); + } + tmp = []; + for ( i = 0; i < value.length; i++ ) { + if ( !isAlignment( value[ i ] ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of supported alignments. Value: `["%s"]`.', 'align', copy( value ) ).join( '", "' ) ); + } + // Explicitly copy to a new array to avoid external mutation: + tmp.push( value[ i ] ); + } + if ( this._numColumns ) { + if ( tmp.length !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have a length of %d in order to match the number of table columns. Value: `["%s"]`.', 'align', this._numColumns, tmp.join( '", "' ) ) ); + } + } else { + this._numColumns = tmp.length; + } + if ( !isEqualArray( tmp, this._align ) ) { + this._align = tmp; + if ( !this._quiet ) { + 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 new file mode 100644 index 000000000000..06ca94fedf78 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the header separator character(s). +* +* @private +* @returns {string} header separator +*/ +function get() { + return this._headerSeparator.value; +} + + +// 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..85888a7ac429 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/header-separator/set.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ); +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the header separator character(s). +* +* @private +* @param {string} value - header separator +* @throws {TypeError} must be a string +*/ +function set( value ) { + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'headerSeparator', value ) ); + } + if ( value !== this._headerSeparator.value ) { + this._headerSeparator = normalizeString( value, this._widthUnits ); + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; 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..cad5aaab7349 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/get.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isArray = require( '@stdlib/assert/is-array' ); +var pluck = require( '@stdlib/utils/pluck' ); // TODO: replace with array/base utility + + +// MAIN // + +/** +* Returns table headers. +* +* @private +* @returns {(Array|null)} table headers +*/ +function get() { + if ( isArray( this._headers ) ) { + return pluck( this._headers, 'value' ); + } + 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..b0fc63038543 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/headers/set.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isCollection = require( '@stdlib/assert/is-collection' ); +var copy = require( '@stdlib/array/base/copy' ); +var format = require( '@stdlib/string/format' ); +var everyBy2 = require( './../../every_by2.js' ); +var normalize = require( './../../normalize.js' ); + + +// FUNCTIONS // + +/** +* Predicate function which tests whether two elements are equal. +* +* @private +* @param {Object} v1 - first value +* @param {Object} v2 - second value +* @returns {boolean} boolean indicating whether two elements are equal +*/ +function predicate( v1, v2 ) { + return ( v1.value === v2.value ); +} + + +// MAIN // + +/** +* Sets the table headers. +* +* @private +* @param {Collection} values - table headers +* @throws {TypeError} must be a collection +* @throws {RangeError} must provide the correct number of table columns +*/ +function set( values ) { + var data; + var len; + if ( !isCollection( values ) ) { + throw new TypeError( format( 'invalid argument. `%s` must be an array-like object. Value: `%s`.', 'headers', values ) ); + } + data = copy( values ); + len = data.length; + if ( this._numColumns ) { + if ( len !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have a length of %d in order to match the number of table columns. Value: `["%s"]`.', 'headers', this._numColumns, data.join( '", "' ) ) ); + } + } else { + this._numColumns = len; + } + data = normalize( data, [ 1, len ], [ '%s' ], this._widthUnits ); + if ( this._headers === null || !everyBy2( data, this._headers, predicate ) ) { // eslint-disable-line max-len + this._headers = data; + if ( !this._quiet ) { + 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..5fe60b31a75d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/horizontal-separator-mode/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the horizontal line separator mode. +* +* @private +* @returns {string} line separator mode +*/ +function get() { + 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..7437153f0a3f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/horizontal-separator-mode/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var MODES = [ 'resume', 'interpolate', 'repeat' ]; +var isMode = contains( MODES ); + + +// MAIN // + +/** +* Sets the horizontal line separator mode. +* +* @private +* @param {string} mode - line separator mode +* @throws {TypeError} must be a supported line separator mode +*/ +function set( mode ) { + if ( !isMode( mode ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', 'horizontalSeparatorMode', MODES.join( '", "' ), mode ) ); + } + if ( mode !== this._horizontalSeparatorMode ) { + this._horizontalSeparatorMode = mode; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-bottom/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-bottom/get.js new file mode 100644 index 000000000000..13ee47f23d89 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-bottom/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the joint character connecting cells along the bottom of the table. +* +* @private +* @returns {string} character +*/ +function get() { + return this._joints[ 3 ].value; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-bottom/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-bottom/set.js new file mode 100644 index 000000000000..23eaf18cb61d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-bottom/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the joint character connecting cells along the bottom of the table. +* +* @private +* @param {string} value - character +* @throws {TypeError} must be a string containing a single character +*/ +function set( value ) { + var v; + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'jointBottom', value ) ); + } + if ( value !== this._joints[ 3 ].value ) { + v = normalizeString( value, this._widthUnits ); + if ( v.ngraphemes > 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string containing one and only one grapheme cluster. Value: `%s`.', 'jointBottom', value ) ); + } + this._joints[ 3 ] = v; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-left/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-left/get.js new file mode 100644 index 000000000000..1c695cbf8bcf --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-left/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the joint character connecting cells along the left side of the table. +* +* @private +* @returns {string} character +*/ +function get() { + return this._joints[ 4 ].value; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-left/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-left/set.js new file mode 100644 index 000000000000..4388e410b966 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-left/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the joint character connecting cells along the left side of the table. +* +* @private +* @param {string} value - character +* @throws {TypeError} must be a string +*/ +function set( value ) { + var v; + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'jointLeft', value ) ); + } + if ( value !== this._joints[ 4 ].value ) { + v = normalizeString( value, this._widthUnits ); + if ( v.ngraphemes > 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string containing one and only one grapheme cluster. Value: `%s`.', 'jointLeft', value ) ); + } + this._joints[ 4 ] = v; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-middle/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-middle/get.js new file mode 100644 index 000000000000..c8925b223add --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-middle/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the joint character connecting cells within the middle of the table. +* +* @private +* @returns {string} character +*/ +function get() { + return this._joints[ 0 ].value; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-middle/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-middle/set.js new file mode 100644 index 000000000000..3af8f8a97c54 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-middle/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the joint character connecting cells within the middle of the table. +* +* @private +* @param {string} value - character +* @throws {TypeError} must be a string +*/ +function set( value ) { + var v; + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'jointMiddle', value ) ); + } + if ( value !== this._joints[ 0 ].value ) { + v = normalizeString( value, this._widthUnits ); + if ( v.ngraphemes > 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string containing one and only one grapheme cluster. Value: `%s`.', 'jointMiddle', value ) ); + } + this._joints[ 0 ] = v; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-right/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-right/get.js new file mode 100644 index 000000000000..d803c50d44da --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-right/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the joint character connecting cells along the right side of the table. +* +* @private +* @returns {string} character +*/ +function get() { + return this._joints[ 2 ].value; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-right/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-right/set.js new file mode 100644 index 000000000000..5bf78ede8ef5 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-right/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the joint character connecting cells along the right side of the table. +* +* @private +* @param {string} value - character +* @throws {TypeError} must be a string +*/ +function set( value ) { + var v; + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'jointRight', value ) ); + } + if ( value !== this._joints[ 2 ].value ) { + v = normalizeString( value, this._widthUnits ); + if ( v.ngraphemes > 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string containing one and only one grapheme cluster. Value: `%s`.', 'jointRight', value ) ); + } + this._joints[ 2 ] = v; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-top/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-top/get.js new file mode 100644 index 000000000000..35f51dcf6fa1 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-top/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the joint character connecting cells along the top of the table. +* +* @private +* @returns {string} character +*/ +function get() { + return this._joints[ 1 ].value; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-top/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-top/set.js new file mode 100644 index 000000000000..aba7986a064a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joint-top/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the joint character connecting cells along the top of the table. +* +* @private +* @param {string} value - character +* @throws {TypeError} must be a string +*/ +function set( value ) { + var v; + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'jointTop', value ) ); + } + if ( value !== this._joints[ 1 ].value ) { + v = normalizeString( value, this._widthUnits ); + if ( v.ngraphemes > 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string containing one and only one grapheme cluster. Value: `%s`.', 'jointTop', value ) ); + } + this._joints[ 1 ] = v; + if ( !this._quiet ) { + 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 new file mode 100644 index 000000000000..35342a1f8a09 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/get.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var pluck = require( '@stdlib/utils/pluck' ); // TODO: use array/base utility + + +// MAIN // + +/** +* Returns the joint characters. +* +* @private +* @returns {Array} joint characters +*/ +function get() { + return pluck( this._joints, 'value' ); +} + + +// 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..7f1a17f55dd4 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/joints/set.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isCollection = require( '@stdlib/assert/is-collection' ); +var copy = require( '@stdlib/array/base/copy' ); +var format = require( '@stdlib/string/format' ); +var everyBy2 = require( './../../every_by2.js' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// VARIABLES // + +var NUM_JOINTS = 5; + + +// FUNCTIONS // + +/** +* Predicate function which tests whether two elements are equal. +* +* @private +* @param {Object} v1 - first value +* @param {Object} v2 - second value +* @returns {boolean} boolean indicating whether two elements are equal +*/ +function predicate( v1, v2 ) { + return ( v1.value === v2.value ); +} + + +// MAIN // + +/** +* Sets the joint characters in the order `[middle, top, right, bottom, left ]`. +* +* @private +* @param {Array} values - joint characters +* @throws {TypeError} must be an array of strings +* @throws {RangeError} must provide five strings +*/ +function set( values ) { + var data; + var v; + var i; + + if ( !isCollection( values ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of strings. Value: `%s`.', 'joints', values ) ); + } + if ( values.length !== NUM_JOINTS ) { + throw new RangeError( format( 'invalid assignment. `%s` must have a length of %d. Value: `["%s"]`.', 'joints', NUM_JOINTS, copy( values ).join( '", "' ) ) ); + } + data = []; + for ( i = 0; i < NUM_JOINTS; i++ ) { + v = values[ i ]; + if ( !isString( v ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of strings in which each array element is a string containing one and only one grapheme cluster. Value: `["%s"]`.', 'joints', copy( values ).join( '", "' ) ) ); + } + v = normalizeString( v, this._widthUnits ); + if ( v.ngraphemes > 1 ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of strings in which each array element is a string containing one and only one grapheme cluster. Value: `["%s"]`.', 'joints', copy( values ).join( '", "' ) ) ); + } + data.push( v ); + } + if ( !everyBy2( data, this._joints, predicate ) ) { + this._joints = data; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-bottom/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-bottom/get.js new file mode 100644 index 000000000000..cca4ecf1f1d5 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-bottom/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the table's bottom margin in units of blank lines. +* +* @private +* @returns {NonNegativeInteger} bottom margin +*/ +function get() { + return this._margins[ 2 ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-bottom/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-bottom/set.js new file mode 100644 index 000000000000..20d947b126d9 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-bottom/set.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the table's bottom margin in units of blank lines. +* +* @private +* @param {NonNegativeInteger} value - bottom margin +* @throws {TypeError} must provide a nonnegative integer +*/ +function set( value ) { + if ( !isNonNegativeInteger( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a nonnegative integer. Value: `%s`.', 'marginBottom', value ) ); + } + if ( value !== this._margins[ 2 ] ) { + this._margins[ 2 ] = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-left/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-left/get.js new file mode 100644 index 000000000000..60d07ab925b7 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-left/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the table's left margin in units of whitespace. +* +* @private +* @returns {NonNegativeInteger} left margin +*/ +function get() { + return this._margins[ 3 ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-left/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-left/set.js new file mode 100644 index 000000000000..5d963ae81725 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-left/set.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the table's left margin in units of whitespace. +* +* @private +* @param {NonNegativeInteger} value - left margin +* @throws {TypeError} must provide a nonnegative integer +*/ +function set( value ) { + if ( !isNonNegativeInteger( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a nonnegative integer. Value: `%s`.', 'marginLeft', value ) ); + } + if ( value !== this._margins[ 3 ] ) { + this._margins[ 3 ] = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-right/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-right/get.js new file mode 100644 index 000000000000..2a44f953ec4f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-right/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the table's right margin in units of whitespace. +* +* @private +* @returns {NonNegativeInteger} right margin +*/ +function get() { + return this._margins[ 1 ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-right/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-right/set.js new file mode 100644 index 000000000000..55de5f768ba6 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-right/set.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the table's right margin in units of whitespace. +* +* @private +* @param {NonNegativeInteger} value - right margin +* @throws {TypeError} must provide a nonnegative integer +*/ +function set( value ) { + if ( !isNonNegativeInteger( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a nonnegative integer. Value: `%s`.', 'marginRight', value ) ); + } + if ( value !== this._margins[ 1 ] ) { + this._margins[ 1 ] = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-top/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-top/get.js new file mode 100644 index 000000000000..c04cd9c5e295 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-top/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the table's top margin in units of blank lines. +* +* @private +* @returns {NonNegativeInteger} top margin +*/ +function get() { + return this._margins[ 0 ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-top/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-top/set.js new file mode 100644 index 000000000000..d3083b291e9d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margin-top/set.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the table's top margin in units of blank lines. +* +* @private +* @param {NonNegativeInteger} value - top margin +* @throws {TypeError} must provide a nonnegative integer +*/ +function set( value ) { + if ( !isNonNegativeInteger( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a nonnegative integer. Value: `%s`.', 'marginTop', value ) ); + } + if ( value !== this._margins[ 0 ] ) { + this._margins[ 0 ] = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margins/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margins/get.js new file mode 100644 index 000000000000..3ec4f567c710 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margins/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns table margins. +* +* @private +* @returns {NonNegativeIntegerArray} margins +*/ +function get() { + return this._margins.slice(); +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margins/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margins/set.js new file mode 100644 index 000000000000..8b6b11113436 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/margins/set.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ).primitives; +var copy = require( '@stdlib/array/base/copy' ); +var isEqualArray = require( '@stdlib/assert/is-equal-array' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var NUM_MARGINS = 4; + + +// MAIN // + +/** +* Sets the table margins in the order `[top, right, bottom, left]`. +* +* @private +* @param {Collection} values - margins +* @throws {TypeError} must be an array of nonnegative integers +* @throws {RangeError} must provide four nonnegative integers +*/ +function set( values ) { + var data; + if ( !isNonNegativeIntegerArray( values ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be an array of nonnegative integers. Value: `%s`.', 'margins', values ) ); + } + data = copy( values ); + if ( data.length !== NUM_MARGINS ) { + throw new RangeError( format( 'invalid assignment. `%s` must have a length of %d. Value: `[%s]`.', 'margins', NUM_MARGINS, data.join( ', ' ) ) ); + } + if ( !isEqualArray( data, this._margins ) ) { + this._margins = data; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-column-width/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-column-width/get.js new file mode 100644 index 000000000000..5147327c3bcd --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-column-width/get.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the maximum column width(s) for each table column. +* +* @private +* @returns {(NonNegativeIntegerArray|NonNegativeInteger)} maximum column width(s) +*/ +function get() { + if ( this._maxColumnWidth.length > 1 ) { + return this._maxColumnWidth.slice(); + } + return this._maxColumnWidth[ 0 ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-column-width/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-column-width/set.js new file mode 100644 index 000000000000..0373e4488501 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-column-width/set.js @@ -0,0 +1,98 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var isCollection = require( '@stdlib/assert/is-collection' ); +var isNull = require( '@stdlib/assert/is-null' ); +var isEqualArray = require( '@stdlib/assert/is-equal-array' ); +var copy = require( '@stdlib/array/base/copy' ); +var FLOAT64_MAX = require( '@stdlib/constants/float64/max' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the maximum column width(s) for each table column. +* +* @private +* @param {(Collection|NonNegativeInteger|null)} value - maximum column width(s) +* @throws {TypeError} must be null, a nonnegative integer, an array of nonnegative integers and/or nulls +* @throws {RangeError} must provide the correct number of table columns +*/ +function set( value ) { + var out; + var len; + var v; + var i; + + if ( !isCollection( value ) ) { + if ( isNull( value ) ) { + out = [ FLOAT64_MAX ]; + } else if ( isNonNegativeInteger( value ) ) { + out = [ value ]; + } else { + throw new TypeError( format( 'invalid assignment. `%s` must be either null, a nonnegative integer, or an array of nonnegative integers and/or nulls. Value: `%s`.', 'maxColumnWidth', value ) ); + } + if ( !isEqualArray( out, this._maxColumnWidth ) ) { + this._maxColumnWidth = out; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } + return; + } + len = value.length; + if ( this._numColumns ) { + if ( len !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have a length of %d in order to match the number of table columns. Value: `["%s"]`.', 'maxColumnWidth', this._numColumns, copy( value ).join( '", "' ) ) ); + } + } else { + this._numColumns = len; + } + out = []; + for ( i = 0; i < len; i++ ) { + v = value[ i ]; + if ( isNull( v ) ) { + out.push( FLOAT64_MAX ); + continue; + } + if ( isNonNegativeInteger( v ) ) { + out.push( v ); + continue; + } + throw new TypeError( format( 'invalid assignment. `%s` must be either null, a nonnegative integer, or an array of nonnegative integers and/or nulls. Value: `["%s"]`.', 'maxColumnWidth', copy( value ).join( '", "' ) ) ); + } + if ( !isEqualArray( out, this._maxColumnWidth ) ) { + this._maxColumnWidth = out; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-width/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-width/get.js new file mode 100644 index 000000000000..d8fe66e3c786 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-width/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the maximum table width. +* +* @private +* @returns {NonNegativeInteger} maximum width +*/ +function get() { + return this._maxWidth; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-width/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-width/set.js new file mode 100644 index 000000000000..4448644a2717 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/max-width/set.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var isNull = require( '@stdlib/assert/is-null' ); +var FLOAT64_MAX = require( '@stdlib/constants/float64/max' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the maximum table width. +* +* @private +* @param {(NonNegativeInteger|null)} value - maximum width +* @throws {TypeError} must provide a nonnegative integer or null +*/ +function set( value ) { + var w; + if ( isNull( value ) ) { + w = FLOAT64_MAX; + } else if ( isNonNegativeInteger( value ) ) { + w = value; + } else { + throw new TypeError( format( 'invalid assignment. `%s` must be a nonnegative integer or null. Value: `%s`.', 'maxWidth', w ) ); + } + if ( w !== this._maxWidth ) { + this._maxWidth = w; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-left/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-left/get.js new file mode 100644 index 000000000000..6a6de580238a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-left/get.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the cell left padding(s) in units of whitespace characters. +* +* @private +* @returns {(NonNegativeIntegerArray|NonNegativeInteger)} cell left padding(s) +*/ +function get() { + if ( this._paddingLeft.length > 1 ) { + return this._paddingLeft.slice(); + } + return this._paddingLeft[ 0 ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-left/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-left/set.js new file mode 100644 index 000000000000..be6dfdf09bee --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-left/set.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ).primitives; +var isEqualArray = require( '@stdlib/assert/is-equal-array' ); +var copy = require( '@stdlib/array/base/copy' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the table cell left padding(s) in units of whitespace characters. +* +* @private +* @param {(Array|NonNegativeInteger)} value - cell left padding(s) +* @throws {TypeError} must provide a nonnegative integer or an array of nonnegative integers +* @throws {RangeError} must provide the correct number of columns +*/ +function set( value ) { + if ( isNonNegativeInteger( value ) ) { + value = [ value ]; + if ( !isEqualArray( value, this._paddingLeft ) ) { + this._paddingLeft = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } + return; + } + if ( !isNonNegativeIntegerArray( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a nonnegative integer or an array of nonnegative integers. Value: `%s`.', 'paddingLeft', value ) ); + } + if ( this._numColumns ) { + if ( value.length !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have a length of %d in order to match the number of table columns. Value: `[%s]`.', 'paddingLeft', this._numColumns, copy( value ).join( ', ' ) ) ); + } + } else { + this._numColumns = value.length; + } + value = copy( value ); + if ( !isEqualArray( value, this._paddingLeft ) ) { + this._paddingLeft = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-right/get.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-right/get.js new file mode 100644 index 000000000000..b3b0467803f5 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-right/get.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the cell right padding(s) in units of whitespace characters. +* +* @private +* @returns {(NonNegativeIntegerArray|NonNegativeInteger)} cell right padding(s) +*/ +function get() { + if ( this._paddingRight.length > 1 ) { + return this._paddingRight.slice(); + } + return this._paddingRight[ 0 ]; +} + + +// EXPORTS // + +module.exports = get; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-right/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-right/set.js new file mode 100644 index 000000000000..c03f6a97a6d6 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/padding-right/set.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ).primitives; +var isEqualArray = require( '@stdlib/assert/is-equal-array' ); +var copy = require( '@stdlib/array/base/copy' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sets the table cell right padding(s) in units of whitespace characters. +* +* @private +* @param {(Array|NonNegativeInteger)} value - cell right padding(s) +* @throws {TypeError} must provide a nonnegative integer or an array of nonnegative integers +* @throws {RangeError} must provide the correct number of columns +*/ +function set( value ) { + if ( isNonNegativeInteger( value ) ) { + value = [ value ]; + if ( !isEqualArray( value, this._paddingRight ) ) { + this._paddingRight = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } + return; + } + if ( !isNonNegativeIntegerArray( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a nonnegative integer or an array of nonnegative integers. Value: `%s`.', 'paddingRight', value ) ); + } + if ( this._numColumns ) { + if ( value.length !== this._numColumns ) { + throw new RangeError( format( 'invalid assignment. `%s` must have a length of %d in order to match the number of table columns. Value: `[%s]`.', 'paddingRight', this._numColumns, copy( value ).join( ', ' ) ) ); + } + } else { + this._numColumns = value.length; + } + value = copy( value ); + if ( !isEqualArray( value, this._paddingRight ) ) { + this._paddingRight = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// 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..288229454f76 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the row separator character(s). +* +* @private +* @returns {string} row separator +*/ +function get() { + return this._rowSeparator.value; +} + + +// 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..a417b0040c38 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/row-separator/set.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var normalizeString = require( './../../normalize_string.js' ); + + +// MAIN // + +/** +* Sets the row separator character(s). +* +* @private +* @param {string} value - row separator +* @throws {TypeError} must be a string +*/ +function set( value ) { + if ( !isString( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', 'rowSeparator', value ) ); + } + if ( value !== this._rowSeparator.value ) { + this._rowSeparator = normalizeString( value, this._widthUnits ); + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; 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..27e5dd3b4a3f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/vertical-separator-mode/get.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MAIN // + +/** +* Returns the vertical line separator mode. +* +* @private +* @returns {string} line separator mode +*/ +function get() { + 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..3caa819734a3 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/props/vertical-separator-mode/set.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var MODES = [ 'resume', 'interpolate', 'repeat' ]; +var isMode = contains( MODES ); + + +// MAIN // + +/** +* Sets the vertical line separator mode. +* +* @private +* @param {string} value - line separator mode +* @throws {TypeError} must be a supported line separator mode +*/ +function set( value ) { + if ( !isMode( value ) ) { + throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', 'verticalSeparatorMode', MODES.join( '", "' ), value ) ); + } + if ( value !== this._verticalSeparatorMode ) { + this._verticalSeparatorMode = value; + if ( !this._quiet ) { + this.emit( 'change' ); + } + } +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/push.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/push.js new file mode 100644 index 000000000000..f1eaa3641416 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/push.js @@ -0,0 +1,207 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var isPlainObjectArray = require( '@stdlib/assert/is-plain-object-array' ); +var isObject = require( '@stdlib/assert/is-object' ); +var ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var getStrides = require( '@stdlib/ndarray/base/strides' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getOrder = require( '@stdlib/ndarray/base/order' ); +var getDType = require( '@stdlib/ndarray/base/dtype' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var emptyLike = require( '@stdlib/ndarray/empty-like' ); +var expandDims = require( '@stdlib/ndarray/base/expand-dimensions' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var assign = require( '@stdlib/ndarray/base/assign' ); +var arrayShape = require( '@stdlib/array/shape' ); +var format = require( '@stdlib/string/format' ); +var convertDictionary = require( './convert_dictionary.js' ); +var convertCollection = require( './convert_collection.js' ); +var normalizeData = require( './normalize.js' ); + + +// MAIN // + +/** +* Appends one or more rows to table data. +* +* @private +* @param {(Object|Collection|VectorLike|MatrixLike)} data - row to add +* @throws {TypeError} must provide an object, an array-like object, a one-dimensional ndarray, or a two-dimensional ndarray +* @throws {RangeError} must provide the correct number of columns +* @returns {UnicodeTable} class instance +*/ +function push( data ) { + var headers; + var view; + var out; + var arr; + var tmp; + var flg; + var buf; + var ash; + var csh; + var N; + var i; + var j; + + if ( isndarrayLike( data ) ) { + arr = ndarraylike2ndarray( data ); + ash = getShape( arr, false ); + if ( ash.length > 2 ) { + throw new TypeError( 'invalid argument. Input ndarray has too many dimensions. Must provide either a one-dimensional or a two-dimensional ndarray.' ); + } + // Convert a one-dimensional ndarray to a two-dimensional ndarray... + if ( ash.length === 1 ) { + arr = expandDims( arr, 0 ); + } + // Record that we have not yet copied the underlying data buffer: + flg = false; + } + // If provided a collection, convert to an ndarray... + else if ( isCollection( data ) ) { + ash = arrayShape( data ); + + // Check whether we were provided a one-dimensional array... + if ( ash.length === 1 ) { + if ( !isPlainObjectArray( data ) ) { + // Assume that we were provided an array of column values belonging to a single row: + data = [ data ]; + } + // Otherwise, assume that we were provided a list of objects... + } + out = convertCollection( data, this.headers ); // NOTE: the use of `this.headers`, rather than `this._headers`, is intentional, as we only want the list of header values (if they exist) + if ( out.code ) { // out.code === 'ERR_MISSING_COLUMNS' + throw new TypeError( format( 'invalid argument. Must provide either an object, an array of column values, an array of objects, an array of arrays, a one-dimensional ndarray, or a two-dimensional ndarray. One or more of the provided data elements is missing expected column data. Expected columns: ["%s"]. Value: `%s`.', 'data', out.headers.join( '", "' ), JSON.stringify( data ) ) ); + } + if ( out.headers ) { + headers = out.headers; + } + arr = out.data; // ndarray + + // Record that we have copied provided table data to a new data buffer: + flg = false; + } + // If provided anything else, try to either process as an object containing unordered column data or a dictionary of columns... + else { + out = convertDictionary( data, this.headers ); // NOTE: the use of `this.headers`, rather than `this._headers`, is intentional, as we only want the list of header values (if they exist) + if ( out.code ) { + // Ensure that we were provided an object... + if ( !isObject( data ) ) { + throw new TypeError( format( 'invalid argument. Must provide either an object, an array of column values, an array of objects, an array of arrays, a one-dimensional ndarray, or a two-dimensional ndarray. Value: `%s`.', JSON.stringify( data ) ) ); + } + // If we failed to process as a dictionary of columns, attempt to process as a single object containing key-value pairs: + tmp = convertCollection( [ data ], this.headers ); // NOTE: the use of `this.headers`, rather than `this._headers`, is intentional, as we only want the list of header values (if they exist) + if ( tmp.code ) { + if ( out.code === 'ERR_EMPTY_OBJECT' ) { + throw new TypeError( format( 'invalid argument. Must provide either an object, an array of column values, an array of objects, an array of arrays, a one-dimensional ndarray, or a two-dimensional ndarray. Value: `%s`.', JSON.stringify( data ) ) ); + } + if ( out.code === 'ERR_INVALID_OBJECT' ) { + throw new TypeError( format( 'invalid argument. Must provide either an object, an array of objects, an array of arrays, or a two-dimensional ndarray. Value: `%s`.', JSON.stringify( data ) ) ); + } + // out.code === 'ERR_UNEQUAL_COLUMN_LENGTHS' + throw new TypeError( format( 'invalid argument. Must provide either an object, an array of column values, an array of objects, an array of arrays, a one-dimensional ndarray, or a two-dimensional ndarray. Each provided data column must have the same number of rows. Value: `%s`.', JSON.stringify( data ) ) ); + } + // If we made it here, we were successful in treating the data as unordered column data: + out = tmp; + } + if ( out.headers ) { + headers = out.headers; + } + arr = out.data; // ndarray + + // Record that we have copied provided table data to a new data buffer: + flg = false; + } + // Check whether to initialize table data... + view = this._data; + if ( view === null ) { + this.data = arr; + return; + } + // Ensure that the provided data does not have too many rows... + ash = getShape( arr, false ); + if ( ash[ 0 ] > this._bufferSize ) { + // In principle, we could apply the FIFO queue here, but, if a table is limited to, e.g., 5 rows and a user is providing 10 rows of data, they are probably doing something wrong... + throw new RangeError( format( 'invalid argument. Input argument exceeds maximum data buffer size. Buffer size: %u. Number of rows: %u.', this._bufferSize, ash[ 0 ] ) ); + } + // Ensure that the provided data has the expected number of columns... + if ( ash[ 1 ] !== this._numColumns ) { + throw new RangeError( format( 'invalid argument. Input argument must have %d columns in order to match the number of table columns. Number of columns: %u.', this._numColumns, ash[ 1 ] ) ); + } + // If we have yet to copy provided table data to a new data buffer, do so now in order to prevent mutation of input data... + if ( !flg ) { + out = emptyLike( arr, { + 'dtype': 'generic' + }); + assign( [ arr, out ] ); + arr = out; + } + // Normalize the incoming table data: + normalizeData( getData( arr ), ash, this._format, this._widthUnits ); + + // Get the current number of table rows and columns: + csh = getShape( view ); + + // Compute the number of combined rows based on the current number of table rows and the incoming data: + N = csh[ 0 ] + ash[ 0 ]; + + // If the number of combined rows exceeds the maximum buffer size, cap the number of rows to the buffer size limit... + if ( N > this._bufferSize ) { + N = this._bufferSize; + } + // Resolve the underlying FIFO queue: + buf = getData( view ); + + // Adjust the capacity of the underlying FIFO queue to accommodate table data: + buf.resize( N * csh[1] ); + + // Push provided data directly to the queue... + for ( i = 0; i < ash[ 0 ]; i++ ) { + for ( j = 0; j < ash[ 1 ]; j++ ) { + buf.push( arr.get( i, j ) ); + } + } + // Create a new ndarray view atop the underlying FIFO queue: + this._data = new ndarray( getDType( view ), buf, [ N, csh[1] ], getStrides( view, false ), getOffset( view ), getOrder( view ) ); // eslint-disable-line max-len + + if ( this._headers === null && headers !== void 0 ) { + tmp = this._quiet; + this._quiet = true; // avoid triggering a 'change' event + this.headers = headers; // NOTE: assigning to `this.headers` is intentional in order to ensure proper processing of headers + this._quiet = tmp; + } + if ( !this._quiet ) { + this.emit( 'change' ); + } + return this; +} + + +// EXPORTS // + +module.exports = push; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/remove_ansi.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/remove_ansi.js new file mode 100644 index 000000000000..1f7574f6ce0b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/remove_ansi.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 replace = require( '@stdlib/string/base/replace' ); +var RE_ANSI = require( './ansi_regexp.js' ); + + +// MAIN // + +/** +* Removes ANSI escape sequences from a string. +* +* @private +* @param {string} str - input string +* @returns {string} output string +*/ +function removeANSI( str ) { + return replace( str, RE_ANSI, '' ); +} + + +// EXPORTS // + +module.exports = removeANSI; 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..15b1d298759f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/render.js @@ -0,0 +1,607 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var ceil = require( '@stdlib/math/base/special/ceil' ); +var min = require( '@stdlib/math/base/special/fast/min' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var repeat = require( '@stdlib/string/repeat' ); +var format = require( '@stdlib/string/format' ); +var array2matrix = require( './array2matrix.js' ); +var columnWidths = require( './column_widths.js' ); + + +// FUNCTIONS // + +/** +* Returns the width of a specified grapheme cluster according to a mask array. +* +* @private +* @param {NonNegativeIntegerArray} widths - column widths +* @param {NonNegativeIntegerArray} mask - mask array +* @param {NonNegativeInteger} idx - index of grapheme cluster (unmasked) +* @returns {NonNegativeInteger} column width +*/ +function graphemeWidth( widths, mask, idx ) { + var cnt; + var i; + + cnt = -1; + for ( i = 0; i < widths.length; i++ ) { + if ( mask[ i ] === 1 ) { + continue; + } + cnt += 1; + if ( cnt === idx ) { + break; + } + } + return widths[ i ]; +} + +/** +* Computes a column width. +* +* @private +* @param {NonNegativeInteger} len - number of character columns +* @param {NonNegativeInteger} maxWidth - maximum column width (in units of character columns) +* @returns {NonNegativeInteger} width (in units of character columns) +*/ +function columnWidth( len, maxWidth ) { + return min( len, maxWidth ); +} + +/** +* Resolves the column indices at which to wrap table rows. +* +* @private +* @param {Object} ctx - context object +* @param {NonNegativeInteger} ctx.maxWidth - maximum table width (in units of character columns) +* @param {Array} ctx.fixedWidths - fixed column widths (in units of character columns) +* @param {NonNegativeIntegerArray} ctx.computedWidths - column widths (in units of character columns) +* @param {NonNegativeIntegerArray} ctx.maxColumnWidths - maximum column widths (in units of character columns) +* @param {NonNegativeInteger} ctx.marginL - left table margin +* @param {NonNegativeInteger} ctx.marginR - right table margin +* @param {NonNegativeInteger} ctx.borderL - left border length (in units of character columns) +* @param {NonNegativeInteger} ctx.borderR - right border length (in units of character columns) +* @param {Object} ctx.columnSeparator - column separator +* @returns {(NonNegativeIntegerArray|Error)} list of column indices or an error +*/ +function wrappedColumnIndices( ctx ) { + var indices; + var width; + var ncols; + var len; + var mw; + var fw; + var w; + var i; + + ncols = ctx.computedWidths.length; + + // Initialize an array of indices at which to wrap table rows: + indices = [ 0 ]; + + // Calculate fixed horizontal length: + len = ctx.marginL + ctx.borderR + ctx.borderL + ctx.marginR; + + // Resolve the column breakpoints... + width = 0; + for ( i = 0; i < ncols; i++ ) { + mw = ctx.maxColumnWidths[ i%ctx.maxColumnWidths.length ]; + fw = ctx.fixedWidths[ i%ctx.fixedWidths.length ]; + if ( fw === null ) { + w = columnWidth( ctx.computedWidths[ i ], mw ); + } else { + w = min( fw, mw ); + } + if ( w > ctx.maxWidth ) { + // The column cannot be accommodated according to the current table configuration, as the column widths exceeds the maximum allowed table width... + return new Error( format( 'invalid operation. The resolved column width for column %d exceeds the maximum allowed table width. Consider either increasing `maxWidth` or decreasing `maxColumnWidth`. Maximum width: %d. Maximum cell width: %d. Column width: %d.', ctx.maxWidth, mw, ctx.computedWidths[ i ] ) ); + } + width += w; + + // If the computed width exceeds the maximum table width, we need to wrap table rows to a new table... + if ( width+len > ctx.maxWidth ) { + indices.push( i ); + width = 0; + continue; + } + // For all columns apart from the last (which has a border, not a column separator), include the width of the column separator... + if ( i < ncols-1 ) { + width += ctx.columnSeparator.width; + } + } + // Include a final "index" to serve as the index upper bound: + indices.push( ncols ); + + return indices; +} + +/** +* Joins a sequence of grapheme clusters according to an ANSI escape sequence mask array. +* +* @private +* @param {StringArray} arr - input array +* @param {NonNegativeIntegerArray} widths - grapheme cluster column widths +* @param {NonNegativeIntegerArray} msk - mask array +* @param {NonNegativeInteger} skip - number of grapheme clusters to skip before starting to join subsequent grapheme clusters +* @param {NonNegativeInteger} max - maximum output width (inclusive) +* @returns {Array} output string and column width +*/ +function join( arr, widths, msk, skip, max ) { + var width; + var out; + var cnt; + var w; + var i; + + out = ''; + width = 0; + cnt = 0; + for ( i = 0; i < arr.length; i++ ) { + // Check whether the current element is an ANSI escape sequence... + if ( msk[ i ] === 1 ) { + // As ANSI escape sequences do not contribute to the visual width, we can just append to the output string without incrementing the output width... + out += arr[ i ]; + continue; + } + // Avoid rendering an incomplete grapheme cluster and ensure that we do not exceed the maximum output width... + w = widths[ i ]; + if ( width+w > max ) { + break; + } + // Avoid rendering any grapheme clusters which should be skipped... + if ( cnt < skip ) { + cnt += 1; + continue; + } + // The grapheme cluster can be completely rendered and is safe to include in the output string: + out += arr[ i ]; + width += w; + } + // Append any remaining ANSI escape sequences in order to ensure that all matching resets are included in the output string... + for ( ; i < arr.length; i++ ) { + if ( msk[ i ] === 1 ) { + out += arr[ i ]; + } + } + return [ out, width ]; +} + +/** +* Renders a specified number of whitespace characters. +* +* @private +* @param {NonNegativeInteger} len - number of whitespace characters +* @returns {string} output string +*/ +function renderWhitespace( len ) { + if ( len <= 0 ) { + return ''; + } + return repeat( ' ', len ); +} + +/** +* Renders a vertical margin. +* +* @private +* @param {Array} out - output array +* @param {NonNegativeInteger} margin - vertical margin +* @returns {Array} output array +*/ +function renderVerticalMargin( out, margin ) { + var i; + for ( i = 0; i < margin; i++ ) { + out.push( '' ); + } + return out; +} + +/** +* Renders a table line. +* +* @private +* @param {NonNegativeInteger} start - starting table column index (inclusive) +* @param {NonNegativeInteger} end - ending table column index (exclusive) +* @param {ObjectArray} ch - line characters +* @param {Object} ctx - context object +* @param {Array} ctx.fixedWidths - fixed column widths (in units of character columns) +* @param {NonNegativeIntegerArray} ctx.computedWidths - column widths (in units of character columns) +* @param {NonNegativeIntegerArray} ctx.maxColumnWidths - maximum column widths (in units of character columns) +* @param {NonNegativeInteger} ctx.marginL - left table margin +* @param {NonNegativeInteger} ctx.marginR - right table margin +* @param {NonNegativeInteger} ctx.borderL - left border length (in units of character columns) +* @param {NonNegativeInteger} ctx.borderR - right border length (in units of character columns) +* @param {Object} ctx.jointL - left joint +* @param {Object} ctx.jointM - middle joint +* @param {Object} ctx.jointR - right joint +* @param {Object} ctx.columnSeparator - column separator +* @param {string} ctx.mode - horizontal separator mode +* @returns {string} rendered line +*/ +function renderLine( start, end, ch, ctx ) { + var hidx; + var out; + var tmp; + var mw; + var fw; + var w; + var i; + var j; + var k; + + // Initialize an index variable for determining how to handle horizontal separators: + hidx = 0; + + // Render left margin: + out = renderWhitespace( ctx.marginL ); + + // Render left joint: + if ( ctx.borderL > 0 ) { + k = 0; + tmp = join( ctx.jointL.graphemes, ctx.jointL.columnWidths, ctx.jointL.mask, k, graphemeWidth( ctx.jointL.columnWidths, ctx.jointL.mask, k ) ); // eslint-disable-line max-len + out += tmp[ 0 ]; + if ( ctx.mode === 'interpolate' ) { + hidx += 1; + } + } + // Render a table line... + for ( i = start; i < end; i++ ) { + // If columns are separated by a column separator, render the middle joint... + if ( i > start && ctx.columnSeparator.width > 0 ) { + k = 0; + tmp = join( ctx.jointM.graphemes, ctx.jointM.columnWidths, ctx.jointM.mask, k, graphemeWidth( ctx.jointM.columnWidths, ctx.jointM.mask, k ) ); // eslint-disable-line max-len + out += tmp[ 0 ]; + if ( ctx.mode === 'interpolate' ) { + hidx += 1; + } else if ( ctx.mode === 'repeat' ) { + hidx = 0; + } + } + // Render as many of the line characters as can visually fit across a column... + mw = ctx.maxColumnWidths[ i%ctx.maxColumnWidths.length ]; + fw = ctx.fixedWidths[ i%ctx.fixedWidths.length ]; + if ( fw === null ) { + w = columnWidth( ctx.computedWidths[ i ], mw ); + } else { + w = min( fw, mw ); + } + for ( j = 0; j < w; j++ ) { + k = hidx % ch.ngraphemes; + tmp = join( ch.graphemes, ch.columnWidths, ch.mask, k, graphemeWidth( ch.columnWidths, ch.mask, k ) ); // eslint-disable-line max-len + out += tmp[ 0 ]; + hidx += 1; + } + } + // Render right joint: + if ( ctx.borderR > 0 ) { + k = 0; + tmp = join( ctx.jointR.graphemes, ctx.jointR.columnWidths, ctx.jointR.mask, k, graphemeWidth( ctx.jointR.columnWidths, ctx.jointR.mask, k ) ); // eslint-disable-line max-len + out += tmp[ 0 ]; + } + // Render right margin: + out += renderWhitespace( ctx.marginR ); + + return out; +} + +/** +* Renders a data row. +* +* @private +* @param {NonNegativeInteger} row - row index +* @param {NonNegativeInteger} start - starting column index (inclusive) +* @param {NonNegativeInteger} end - ending column index (exclusive) +* @param {ndarray} data - table data +* @param {Object} ctx - context object +* @param {Array} ctx.fixedWidths - fixed column widths (in units of character columns) +* @param {NonNegativeInteger} ctx.computedWidths - column widths (in units of character columns) +* @param {NonNegativeIntegerArray} ctx.maxColumnWidths - maximum column widths (in units of character columns) +* @param {NonNegativeInteger} ctx.marginL - left table margin +* @param {NonNegativeInteger} ctx.marginR - right table margin +* @param {NonNegativeIntegerArray} ctx.paddingL - left cell padding +* @param {NonNegativeIntegerArray} ctx.paddingR - right cell padding +* @param {Object} ctx.borderL - left border object +* @param {Object} ctx.borderR - right border object +* @param {Object} ctx.columnSeparator - column separator +* @param {StringArray} ctx.alignments - cell alignments +* @param {NonNegativeInteger} vidx - vertical line index +* @returns {string} rendered line +*/ +function renderRow( row, start, end, data, ctx, vidx ) { + var lpad; + var rpad; + var out; + var len; + var tmp; + var mw; + var fw; + var w; + var d; + var n; + var v; + var i; + var k; + + // Render left margin: + out = renderWhitespace( ctx.marginL ); + + // Render left border: + if ( ctx.borderL.width > 0 ) { + k = vidx % ctx.borderL.ngraphemes; + tmp = join( ctx.borderL.graphemes, ctx.borderL.columnWidths, ctx.borderL.mask, k, graphemeWidth( ctx.borderL.columnWidths, ctx.borderL.mask, k ) ); // eslint-disable-line max-len + out += tmp[ 0 ]; + } + for ( i = start; i < end; i++ ) { + // Render column separator: + if ( i > start && ctx.columnSeparator.width > 0 ) { + k = vidx % ctx.columnSeparator.ngraphemes; + tmp = join( ctx.columnSeparator.graphemes, ctx.columnSeparator.columnWidths, ctx.columnSeparator.mask, k, graphemeWidth( ctx.columnSeparator.columnWidths, ctx.columnSeparator.mask, k ) ); // eslint-disable-line max-len + out += tmp[ 0 ]; + } + // Resolve cell paddings: + lpad = ctx.paddingL[ i%ctx.paddingL.length ]; + rpad = ctx.paddingR[ i%ctx.paddingR.length ]; + + // Render left cell padding: + out += renderWhitespace( lpad ); + + // Resolve cell data: + v = data.get( row, i ); + len = lpad + v.width + rpad; // number of character columns + + // Determine whether we need to truncate rendered data: + mw = ctx.maxColumnWidths[ i%ctx.maxColumnWidths.length ]; + fw = ctx.fixedWidths[ i%ctx.fixedWidths.length ]; + w = ctx.computedWidths[ i ]; + if ( fw !== null ) { + mw = min( fw, mw ); + w = max( fw, w ); + } + if ( w > mw ) { + // Truncate rendered data: + n = mw - lpad - rpad; + tmp = join( v.graphemes, v.columnWidths, v.mask, 0, n ); + w = mw + ( n - tmp[ 1 ] ); // adjusted by a fudge factor to allow additional whitespace padding to be rendered if we were unable to render a string having the full desired width + d = tmp[ 0 ]; + } else { + d = v.value; + } + // Render cell contents: + switch ( ctx.alignments[ i%ctx.alignments.length ] ) { + case 'left': + out += d; + out += renderWhitespace( w-len ); + break; + case 'center': + out += renderWhitespace( ceil( (w-len)/2 ) ); + out += d; + out += renderWhitespace( floor( (w-len)/2 ) ); + break; + case 'right': + out += renderWhitespace( w-len ); + out += d; + break; + default: + break; + } + // Render right cell padding: + out += renderWhitespace( rpad ); + } + // Render right border: + if ( ctx.borderR.width > 0 ) { + k = vidx % ctx.borderR.ngraphemes; + tmp = join( ctx.borderR.graphemes, ctx.borderR.columnWidths, ctx.borderR.mask, k, graphemeWidth( ctx.borderR.columnWidths, ctx.borderR.mask, k ) ); // eslint-disable-line max-len + out += tmp[ 0 ]; + } + // Render right margin: + out += renderWhitespace( ctx.marginR ); + + return out; +} + + +// MAIN // + +/** +* Renders a table. +* +* @private +* @throws {Error} output must be able to accommodate every table column individually +* @returns {string} rendered table +*/ +function render() { + var computedWidths; + var fixedWidths; + var headers; + var start; + var nrows; + var ncols; + var vidx; + var lctx; + var rctx; + var line; + var end; + var out; + var idx; + var tmp; + var i; + var j; + + if ( this._data === null && this._headers === null ) { + return ''; + } + nrows = numelDimension( this._data, 0 ); + ncols = numelDimension( this._data, 1 ); + + // Convert the list of headers to a two-dimensional ndarray: + headers = ( this._headers ) ? array2matrix( this._headers, [ 1, ncols ] ) : null; // eslint-disable-line max-len + + // Resolve the column widths needed to fit column data: + computedWidths = columnWidths( nrows, ncols, this._data, headers, this._paddingLeft, this._paddingRight ); // eslint-disable-line max-len + + // Resolve fixed-width column widths: + fixedWidths = this._columnWidth || [ null ]; + + // Resolve the indices of columns at which to wrap table rows: + idx = wrappedColumnIndices({ + 'maxWidth': this._maxWidth, + 'fixedWidths': fixedWidths, + 'computedWidths': computedWidths, + 'maxColumnWidths': this._maxColumnWidth, + 'marginL': this._margins[ 3 ], + 'marginR': this._margins[ 1 ], + 'borderL': this._borders[ 3 ].width, + 'borderR': this._borders[ 1 ].width, + 'columnSeparator': this._columnSeparator + }); + if ( idx instanceof Error ) { + throw idx; + } + + // Define a "line" context for rendering non-data content: + lctx = { + 'fixedWidths': fixedWidths, + 'computedWidths': computedWidths, + 'maxColumnWidths': this._maxColumnWidth, + 'marginL': this._margins[ 3 ], + 'marginR': this._margins[ 1 ], + 'borderL': this._borders[ 3 ].width, + 'borderR': this._borders[ 1 ].width, + 'jointL': null, + 'jointM': null, + 'jointR': null, + 'columnSeparator': this._columnSeparator, + 'mode': this._horizontalSeparatorMode + }; + + // Define a "row" context for rendering column data: + rctx = { + 'fixedWidths': fixedWidths, + 'computedWidths': computedWidths, + 'maxColumnWidths': this._maxColumnWidth, + 'marginL': this._margins[ 3 ], + 'marginR': this._margins[ 1 ], + 'paddingL': this._paddingLeft, + 'paddingR': this._paddingRight, + 'borderL': this._borders[ 3 ], + 'borderR': this._borders[ 1 ], + 'columnSeparator': this._columnSeparator, + 'alignments': this._align + }; + + // Initialize an array for pushing rendered lines: + out = []; + + // Render top margin: + out = renderVerticalMargin( out, this._margins[ 0 ] ); + + // Render one or more tables... + for ( j = 0; j < idx.length-1; j++ ) { + start = idx[ j ]; + end = idx[ j+1 ]; + vidx = 0; + + // Render top border: + if ( this._borders[ 0 ].width > 0 ) { + lctx.jointL = this._corners[ 0 ]; + lctx.jointM = this._joints[ 1 ]; + lctx.jointR = this._corners[ 1 ]; + line = renderLine( start, end, this._borders[ 0 ], lctx ); + out.push( line ); + if ( this._verticalSeparatorMode === 'interpolate' ) { + vidx += 1; + } + } + // Render headers: + if ( this._headers ) { + tmp = rctx.alignments; + rctx.alignments = this._headerAlign || this._align; + line = renderRow( 0, start, end, headers, rctx, vidx ); + out.push( line ); + vidx += 1; + rctx.alignments = tmp; + } + // Render header separator: + if ( this._headers && this._headerSeparator.width !== 0 ) { + lctx.jointL = this._joints[ 4 ]; + lctx.jointM = this._joints[ 0 ]; + lctx.jointR = this._joints[ 2 ]; + line = renderLine( start, end, this._headerSeparator, lctx ); + out.push( line ); + if ( this._verticalSeparatorMode === 'interpolate' ) { + vidx += 1; + } else if ( this._verticalSeparatorMode === 'repeat' ) { + vidx = 0; + } + } + // Render table rows: + if ( this._data ) { + for ( i = 0; i < nrows; i++ ) { + // Render a row of table data: + line = renderRow( i, start, end, this._data, rctx, vidx ); + out.push( line ); + vidx += 1; + + // Render row separator: + if ( this._rowSeparator.width > 0 && i < nrows-1 ) { + lctx.jointL = this._joints[ 4 ]; + lctx.jointM = this._joints[ 0 ]; + lctx.jointR = this._joints[ 2 ]; + line = renderLine( start, end, this._rowSeparator, lctx ); + out.push( line ); + if ( this._verticalSeparatorMode === 'interpolate' ) { + vidx += 1; + } else if ( this._verticalSeparatorMode === 'repeat' ) { + vidx = 0; + } + } + } + } + // Render bottom border: + if ( this._borders[ 2 ].width > 0 ) { + lctx.jointL = this._corners[ 3 ]; + lctx.jointM = this._joints[ 3 ]; + lctx.jointR = this._corners[ 2 ]; + line = renderLine( start, end, this._borders[ 2 ], lctx ); + out.push( line ); + } + } + // Render bottom margin: + out = renderVerticalMargin( out, this._margins[ 2 ] ); + + // Convert the output array to a newline-delimited string: + out = out.join( '\n' ); + + this.emit( 'render', out ); + return out; +} + + +// EXPORTS // + +module.exports = render; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/set.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/set.js new file mode 100644 index 000000000000..47965a9f2eb7 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/set.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-invalid-this */ + +'use strict'; + +// MODULES // + +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var format = require( '@stdlib/string/format' ); +var normalizeData = require( './normalize.js' ); + + +// MAIN // + +/** +* Sets the data for a specified table cell to a provided value. +* +* @private +* @param {NonNegativeInteger} i - index for the first dimension (i.e., zero-based row number) +* @param {NonNegativeInteger} j - index for the second dimension (i.e., zero-based column number) +* @param {*} value - value to set +* @throws {TypeError} first argument must be a nonnegative integer +* @throws {TypeError} second argument must be a nonnegative integer +* @throws {RangeError} index is out-of-bounds +* @returns {UnicodeTable} table instance +*/ +function set( i, j, value ) { + var nrows; + var ncols; + var fmt; + var v; + if ( !isNonNegativeInteger( i ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', i ) ); + } + if ( !isNonNegativeInteger( j ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', j ) ); + } + nrows = numelDimension( this._data, 0 ); + if ( i >= nrows ) { + throw new RangeError( format( 'invalid argument. First argument must be on the interval: [0,%u]. Value: `%s`.', nrows-1, i ) ); + } + ncols = numelDimension( this._data, 1 ); + if ( j >= ncols ) { + throw new RangeError( format( 'invalid argument. Second argument must be on the interval: [0,%u]. Value: `%s`.', ncols-1, j ) ); + } + // Assume that, if a user is setting a new value, that means the data is different... (note: this provides an escape hatch for the same instance of a mutable class to be provided and have that instance trigger a 'change' event when its internal data/state has changed without the **reference** to that class instance having changed; meaning, two values may strictly compare as equal, but are allowed to render differently due to internal state changes) + fmt = this._format[ j%this._format.length ]; + v = normalizeData( [ value ], [ 1, 1 ], [ fmt ], this._widthUnits ); + this._data.set( i, j, v[ 0 ] ); + if ( !this._quiet ) { + this.emit( 'change' ); + } + return this; +} + + +// EXPORTS // + +module.exports = set; diff --git a/lib/node_modules/@stdlib/plot/table/unicode/lib/wcswidth.js b/lib/node_modules/@stdlib/plot/table/unicode/lib/wcswidth.js new file mode 100644 index 000000000000..46998e14e985 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/lib/wcswidth.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 removeANSI = require( './remove_ansi.js' ); + + +// MAIN // + +/** +* Returns the width of a Unicode string when rendered to a terminal. +* +* @private +* @param {string} str - input string +* @returns {NonNegativeInteger} number of columns +*/ +function wcswidth( str ) { + return removeANSI( str ).length; // FIXME: implement wcswidth! +} + + +// EXPORTS // + +module.exports = wcswidth; 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.alignment.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.alignment.js new file mode 100644 index 000000000000..ab0ab2bf4c0c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.alignment.js @@ -0,0 +1,149 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 `alignment` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + '1234', + 'middle', + [ 4, 'hello', null ], + [ 'beep', 'boop' ] + ]; + + 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 arr; + + table = ctor( null, { + 'alignment': 'right' + }); + table.render = noop; + + 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' ); + + 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..7d97b96eb9dd --- /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) 2025 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 new file mode 100644 index 000000000000..2db9916b098c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.borders.js @@ -0,0 +1,125 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 `borders` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + 'beep', + [ 4, 'hello', null, 'world' ], + [ 'beep', 'boop', 'foo' ] + ]; + + 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 arr; + + arr = [ '-', '|', '=', '!' ]; + table = ctor( null, { + 'borders': arr + }); + t.notEqual( table.borders, arr, 'returns a new reference' ); + t.deepEqual( table.borders, arr, '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' ); + + 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..077b4d703f1f --- /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) 2025 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_left.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.cell_padding_left.js new file mode 100644 index 000000000000..a959f06f3da0 --- /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) 2025 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..a55c1efea2ff --- /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) 2025 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 new file mode 100644 index 000000000000..40e584a68748 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.column_separator.js @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 `columnSeparator` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + 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 = '!/1'; + t.strictEqual( table.columnSeparator, '!/1', '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 new file mode 100644 index 000000000000..7dbb7456af15 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.corners.js @@ -0,0 +1,125 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 `corners` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + 'beep', + [ 4, 'hello', null, 'world' ], + [ 'beep', 'boop', 'foo', '' ] + ]; + + 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 arr; + + arr = [ '1', '2', '3', '4' ]; + table = ctor( null, { + 'corners': [ '1', '2', '3', '4' ] + }); + t.notEqual( table.corners, arr, 'returns a new reference' ); + t.deepEqual( table.corners, arr, 'returns expected value' ); + + arr = [ '*', '&', '-', '=' ]; + table.corners = arr; + t.notEqual( table.corners, arr, 'returns a new reference' ); + t.deepEqual( table.corners, arr, '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..f331b64e3c4e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.data.js @@ -0,0 +1,177 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 new file mode 100644 index 000000000000..684fbf0e9f7f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.header_separator.js @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 `headerSeparator` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + 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 = '!/1'; + t.strictEqual( table.headerSeparator, '!/1', '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..0e97e5d6cb65 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.headers.js @@ -0,0 +1,138 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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..aead2f2fde37 --- /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) 2025 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 new file mode 100644 index 000000000000..2cb31f24cb16 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.joints.js @@ -0,0 +1,125 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 `joints` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + 'beep', + [ 4, 'hello', null, 'world' ], + [ 'beep', 'boop', 'foo', '', 'bar' ] + ]; + + 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 arr; + + arr = [ '1', '2', '3', '4', '5' ]; + table = ctor( null, { + 'joints': arr + }); + t.notEqual( table.joints, arr, 'returns a new reference' ); + t.deepEqual( table.joints, arr, 'returns expected value' ); + + arr = [ '&', '#', '*', '^', '@' ]; + table.joints = arr; + t.notEqual( table.corners, arr, 'returns a new reference' ); + t.deepEqual( table.joints, arr, '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.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.js new file mode 100644 index 000000000000..55df92cea146 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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..bd34ab6fad03 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.main.js @@ -0,0 +1,227 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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', + 'autoRender': false, + 'borders': [ '1', '23', '456', '7890' ], + 'bufferSize': 10, + 'cellPaddingLeft': 2, + 'cellPaddingRight': [ 2, 3, 4 ], + 'columnSeparator': 'None', + 'corners': [ '*', '*', '*', '*' ], + 'headerSeparator': '-=', + 'horizontalSeparatorMode': 'repeat', + 'joints': [ '*', '*', '*', '*', '*' ], + 'marginX': 2, + 'marginY': 4, + 'maxColumnWidth': 10, + 'maxOutputWidth': 60, + 'rowSeparator': '_-', + 'verticalSeparatorMode': 'resume' + }); + + 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', + 'autoRender': false, + 'borders': [ '1', '23', '456', '7890' ], + 'bufferSize': 10, + 'cellPaddingLeft': 2, + 'cellPaddingRight': [ 2, 3, 4 ], + 'columnSeparator': 'None', + 'corners': [ '*', '*', '*', '*' ], + 'headerSeparator': '-=', + 'horizontalSeparatorMode': 'repeat', + 'joints': [ '*', '*', '*', '*', '*' ], + 'marginX': 2, + 'marginY': 4, + 'maxColumnWidth': 10, + 'maxOutputWidth': 60, + 'rowSeparator': '_-', + 'verticalSeparatorMode': 'resume' + }); + + 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 `push` method for adding a row', function test( t ) { + var table = new UnicodeTable(); + t.strictEqual( typeof table.push, 'function', 'has addRow 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..d65a35e89699 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_x.js @@ -0,0 +1,118 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 `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; + + table = ctor( null, { + 'marginX': 2 + }); + table.render = noop; + + 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(); +}); + +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 new file mode 100644 index 000000000000..ffdb0621d548 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.margin_y.js @@ -0,0 +1,118 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 `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; + + table = ctor( null, { + 'marginY': 2 + }); + table.render = noop; + + 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(); +}); + +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_column_width.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_column_width.js new file mode 100644 index 000000000000..3ca7b72a553a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_column_width.js @@ -0,0 +1,150 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 `maxColumnWidth` value', function test( t ) { + var values; + var i; + + values = [ + '5', + 2.4, + -3, + true, + 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.maxColumnWidth = value; + }; + } +}); + +tape( 'an instance supports setting and getting the property value', function test( t ) { + var table; + var arr; + + table = ctor( null, { + 'maxColumnWidth': 2 + }); + t.strictEqual( table.maxColumnWidth, 2, 'returns expected value' ); + + table.maxColumnWidth = 3; + t.strictEqual( table.maxColumnWidth, 3, 'returns expected value' ); + + table.maxColumnWidth = null; + t.strictEqual( table.maxColumnWidth, FLOAT64_MAX, 'returns expected value' ); + + arr = [ 0, 5 ]; + table.maxColumnWidth = arr; + t.notEqual( table.maxColumnWidth, arr, 'returns a new reference' ); + t.deepEqual( table.maxColumnWidth, arr, 'returns expected value' ); + + arr = [ null, 5 ]; + table.maxColumnWidth = arr; + t.notEqual( table.maxColumnWidth, arr, 'returns a new reference' ); + t.deepEqual( table.maxColumnWidth, [ FLOAT64_MAX, 5 ], 'returns expected value' ); + + t.end(); +}); + +tape( 'an instance throws an error if provided a `maxColumnWidth` 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.maxColumnWidth = [ 1, 2 ]; // 2 columns + } +}); + +tape( 'settings the `maxColumnWidth` 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, { + 'maxColumnWidth': [ 1, 2, 3 ] // 3 columns + }); + table.data = [ [ 1, 2 ], [ 4, 5 ] ]; // 2 columns + } +}); + +tape( 'setting the `maxColumnWidth` property to a new value triggers a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'maxColumnWidth': 2 + }); + table.render = noop; + + table.on( 'change', onChange ); + table.maxColumnWidth = [ 1, 2 ]; + + function onChange() { + t.ok( true, 'triggers event' ); + t.end(); + } +}); + +tape( 'setting the `maxColumnWidth` property to its current value does not trigger a `change` event', function test( t ) { + var table; + + table = ctor( null, { + 'maxColumnWidth': [ 2, 3 ] + }); + table.render = noop; + + table.on( 'change', onChange ); + table.maxColumnWidth = [ 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 new file mode 100644 index 000000000000..15f6142322ff --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.max_output_width.js @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 `maxOutputWidth` value', function test( t ) { + var values; + var i; + + values = [ + '5', + 2.4, + -3, + true, + 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(); +}); + +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..da2618b5e101 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.parse.js @@ -0,0 +1,337 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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.push.js b/lib/node_modules/@stdlib/plot/table/unicode/test/test.push.js new file mode 100644 index 000000000000..35c842a5a2f0 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.push.js @@ -0,0 +1,133 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 new file mode 100644 index 000000000000..ed18a9cb8f72 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.render.js @@ -0,0 +1,486 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 table; + var str; + + table = ctor(); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; + + 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 str; + + table = ctor(); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + + 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 table; + var str; + + table = ctor(); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; + 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 table; + var str; + + table = ctor(); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; + table.borders = [ '', '', '', '' ]; + + 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 table; + var str; + + table = ctor(); + + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; + table.columnSeparator = ''; + + 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 table; + var str; + + table = ctor(); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; + table.headerSeparator = ''; + + 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 different cell paddings', 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.cellPaddingLeft = 2; + table.cellPaddingRight = 1; + expected = [ + '┌────────┬───────┬────────┐', + '│ col1 │ col2 │ col3 │', + '├────────┼───────┼────────┤', + '│ 45 │ 33 │ hello │', + '│ 32.54 │ true │ null │', + '└────────┴───────┴────────┘' + ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + table.cellPaddingLeft = [ 2, 0, 3 ]; + table.cellPaddingRight = [ 0, 1, 2 ]; + 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 table; + var str; + + table = ctor(); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; + 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 table; + var str; + + table = ctor(); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; + + table.maxColumnWidth = 6; + expected = [ + '┌──────┬──────┬──────┐', + '│ col1 │ col2 │ col3 │', + '├──────┼──────┼──────┤', + '│ 45 │ 33 │ h... │', + '│ 3... │ true │ null │', + '└──────┴──────┴──────┘' + ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns rendered table' ); + + table.maxColumnWidth = [ 6, 3, 5 ]; + expected = [ + '┌──────┬───┬─────┐', + '│ col1 │ . │ ... │', + '├──────┼───┼─────┤', + '│ 45 │ . │ ... │', + '│ 3... │ . │ ... │', + '└──────┴───┴─────┘' + ].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 table; + var str; + + table = ctor(); + table.data = [ [ 45, 33, 'hello' ], [ 32.54, true, null ] ]; + table.headers = [ 'col1', 'col2', 'col3' ]; + + table.alignment = 'right'; + expected = [ + '┌───────┬──────┬───────┐', + '│ col1 │ col2 │ col3 │', + '├───────┼──────┼───────┤', + '│ 45 │ 33 │ hello │', + '│ 32.54 │ true │ null │', + '└───────┴──────┴───────┘' + ].join( '\n' ); + str = table.render(); + t.strictEqual( str, expected, 'returns 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 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 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 table with different horizontal 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.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' ); + + 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 = [ + '┌───────┬──────┐', + '│ 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..7648decfa8f8 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/table/unicode/test/test.row_separator.js @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 `rowSeparator` value', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + 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 = '!/1'; + t.strictEqual( table.rowSeparator, '!/1', '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..c36f603764ce --- /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) 2025 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' ); + } +});