Skip to content

Commit

Permalink
docs: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Sep 15, 2024
1 parent dea5a9b commit 6485a76
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
var view = new DataView( x.buffer );

var y = new Float64Array( x.length );
var out = readDataView.ndarray( y.length, view, 8, 0, y, 1, 0, true );
var out = readDataView.ndarray( x.length, view, 8, 0, y, 1, 0, true );
// e.g., returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]

var bool = ( out === y );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface Routine {
* var view = new DataView( x.buffer );
*
* var y = new Float64Array( x.length );
* var out = readDataView( y.length, view, 8, y, 1, true );
* var out = readDataView( x.length, view, 8, y, 1, true );
* // e.g., returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
*
* var bool = ( out === y );
Expand Down Expand Up @@ -74,7 +74,7 @@ interface Routine {
* var view = new DataView( x.buffer );
*
* var y = new Float64Array( x.length );
* var out = readDataView.ndarray( y.length, view, 8, 0, y, 1, 0, true );
* var out = readDataView.ndarray( x.length, view, 8, 0, y, 1, 0, true );
* // e.g., returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
*
* var bool = ( out === y );
Expand Down Expand Up @@ -102,7 +102,7 @@ interface Routine {
* var view = new DataView( x.buffer );
*
* var y = new Float64Array( x.length );
* var out = readDataView( y.length, view, 8, y, 1, true );
* var out = readDataView( x.length, view, 8, y, 1, true );
* // e.g., returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
*
* var bool = ( out === y );
Expand All @@ -116,7 +116,7 @@ interface Routine {
* var view = new DataView( x.buffer );
*
* var y = new Float64Array( x.length );
* var out = readDataView.ndarray( y.length, view, 8, 0, y, 1, 0, true );
* var out = readDataView.ndarray( x.length, view, 8, 0, y, 1, 0, true );
* // e.g., returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
*
* var bool = ( out === y );
Expand Down
186 changes: 92 additions & 94 deletions lib/node_modules/@stdlib/strided/base/read-dataview/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import readDataView = require( './index' );
const x = new DataView( new ArrayBuffer( 100 ) );
const y = new Float64Array( 10 );

readDataView( y.length, x, 1, y, 1, true ); // $ExpectType Float64Array
readDataView( x.length, x, 1, y, 1, true ); // $ExpectType Float64Array
}

// The compiler throws an error if the function is provided a first argument which is not a number...
Expand Down Expand Up @@ -64,57 +64,56 @@ import readDataView = require( './index' );
const x = new DataView( new ArrayBuffer( 100 ) );
const y = new Float64Array( 10 );

readDataView( y.length, x, '10', y, 1, true ); // $ExpectError
readDataView( y.length, x, true, y, 1, true ); // $ExpectError
readDataView( y.length, x, false, y, 1, true ); // $ExpectError
readDataView( y.length, x, null, y, 1, true ); // $ExpectError
readDataView( y.length, x, undefined, y, 1, true ); // $ExpectError
readDataView( y.length, x, [], y, 1, true ); // $ExpectError
readDataView( y.length, x, {}, y, 1, true ); // $ExpectError
readDataView( y.length, x, ( x: number ): number => x, y, 1, true ); // $ExpectError
readDataView( x.length, x, '10', y, 1, true ); // $ExpectError
readDataView( x.length, x, true, y, 1, true ); // $ExpectError
readDataView( x.length, x, false, y, 1, true ); // $ExpectError
readDataView( x.length, x, null, y, 1, true ); // $ExpectError
readDataView( x.length, x, undefined, y, 1, true ); // $ExpectError
readDataView( x.length, x, [], y, 1, true ); // $ExpectError
readDataView( x.length, x, {}, y, 1, true ); // $ExpectError
readDataView( x.length, x, ( x: number ): number => x, y, 1, true ); // $ExpectError
}

// The compiler throws an error if the function is provided a fourth argument which is not a collection...
{
const x = new DataView( new ArrayBuffer( 100 ) );
const y = new Float64Array( 10 );

readDataView( y.length, x, 1, 10, 1, true ); // $ExpectError
readDataView( y.length, x, 1, true, 1, true ); // $ExpectError
readDataView( y.length, x, 1, false, 1, true ); // $ExpectError
readDataView( y.length, x, 1, null, 1, true ); // $ExpectError
readDataView( y.length, x, 1, undefined, 1, true ); // $ExpectError
readDataView( y.length, x, 1, {}, 1, true ); // $ExpectError
readDataView( y.length, x, 1, ( x: number ): number => x, 1, true ); // $ExpectError
readDataView( x.length, x, 1, 10, 1, true ); // $ExpectError
readDataView( x.length, x, 1, true, 1, true ); // $ExpectError
readDataView( x.length, x, 1, false, 1, true ); // $ExpectError
readDataView( x.length, x, 1, null, 1, true ); // $ExpectError
readDataView( x.length, x, 1, undefined, 1, true ); // $ExpectError
readDataView( x.length, x, 1, {}, 1, true ); // $ExpectError
readDataView( x.length, x, 1, ( x: number ): number => x, 1, true ); // $ExpectError
}

// The compiler throws an error if the function is provided a fifth argument which is not a number...
{
const x = new DataView( new ArrayBuffer( 100 ) );
const y = new Float64Array( 10 );

readDataView( y.length, x, 1, y, '10', true ); // $ExpectError
readDataView( y.length, x, 1, y, true, true ); // $ExpectError
readDataView( y.length, x, 1, y, false, true ); // $ExpectError
readDataView( y.length, x, 1, y, null, true ); // $ExpectError
readDataView( y.length, x, 1, y, undefined, true ); // $ExpectError
readDataView( y.length, x, 1, y, [], true ); // $ExpectError
readDataView( y.length, x, 1, y, {}, true ); // $ExpectError
readDataView( y.length, x, 1, y, ( x: number ): number => x, true ); // $ExpectError
readDataView( x.length, x, 1, y, '10', true ); // $ExpectError
readDataView( x.length, x, 1, y, true, true ); // $ExpectError
readDataView( x.length, x, 1, y, false, true ); // $ExpectError
readDataView( x.length, x, 1, y, null, true ); // $ExpectError
readDataView( x.length, x, 1, y, undefined, true ); // $ExpectError
readDataView( x.length, x, 1, y, [], true ); // $ExpectError
readDataView( x.length, x, 1, y, {}, true ); // $ExpectError
readDataView( x.length, x, 1, y, ( x: number ): number => x, true ); // $ExpectError
}

// The compiler throws an error if the function is provided a sixth argument which is not a boolean...
{
const x = new DataView( new ArrayBuffer( 100 ) );
const y = new Float64Array( 10 );

readDataView( y.length, x, 1, y, 1, '10' ); // $ExpectError
readDataView( y.length, x, 1, y, 1, 0 ); // $ExpectError
readDataView( y.length, x, 1, y, 1, null ); // $ExpectError
readDataView( y.length, x, 1, y, 1, undefined ); // $ExpectError
readDataView( y.length, x, 1, y, 1, [] ); // $ExpectError
readDataView( y.length, x, 1, y, 1, {} ); // $ExpectError
readDataView( y.length, x, 1, y, 1, ( x: number ): number => x ); // $ExpectError
readDataView( x.length, x, 1, y, 1, '10' ); // $ExpectError
readDataView( x.length, x, 1, y, 1, 0 ); // $ExpectError
readDataView( x.length, x, 1, y, 1, null ); // $ExpectError
readDataView( x.length, x, 1, y, 1, undefined ); // $ExpectError
readDataView( x.length, x, 1, y, 1, [] ); // $ExpectError
readDataView( x.length, x, 1, y, 1, {} ); // $ExpectError
readDataView( x.length, x, 1, y, 1, ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
Expand All @@ -123,20 +122,20 @@ import readDataView = require( './index' );
const y = new Float64Array( 10 );

readDataView(); // $ExpectError
readDataView( y.length ); // $ExpectError
readDataView( y.length, x ); // $ExpectError
readDataView( y.length, x, 1 ); // $ExpectError
readDataView( y.length, x, 1, y ); // $ExpectError
readDataView( y.length, x, 1, y, 1 ); // $ExpectError
readDataView( y.length, x, 1, y, 1, true, 10 ); // $ExpectError
readDataView( x.length ); // $ExpectError
readDataView( x.length, x ); // $ExpectError
readDataView( x.length, x, 1 ); // $ExpectError
readDataView( x.length, x, 1, y ); // $ExpectError
readDataView( x.length, x, 1, y, 1 ); // $ExpectError
readDataView( x.length, x, 1, y, 1, true, 10 ); // $ExpectError
}

// Attached to main export is an `ndarray` method which returns a collection...
{
const x = new DataView( new ArrayBuffer( 100 ) );
const y = new Float64Array( 10 );

readDataView.ndarray( y.length, x, 1, 0, y, 1, 0, true ); // $ExpectType Float64Array
readDataView.ndarray( x.length, x, 1, 0, y, 1, 0, true ); // $ExpectType Float64Array
}

// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...
Expand Down Expand Up @@ -174,87 +173,86 @@ import readDataView = require( './index' );
const x = new DataView( new ArrayBuffer( 100 ) );
const y = new Float64Array( 10 );

readDataView.ndarray( y.length, x, '10', 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, true, 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, false, 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, null, 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, undefined, 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, [], 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, {}, 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, ( x: number ): number => x, 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, '10', 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, true, 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, false, 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, null, 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, undefined, 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, [], 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, {}, 0, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, ( x: number ): number => x, 0, y, 1, 0, true ); // $ExpectError
}

// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number...
{
const x = new DataView( new ArrayBuffer( 100 ) );
const y = new Float64Array( 10 );

readDataView.ndarray( y.length, x, 1, '10', y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, true, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, false, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, null, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, undefined, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, [], y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, {}, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, ( x: number ): number => x, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, '10', y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, true, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, false, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, null, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, undefined, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, [], y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, {}, y, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, ( x: number ): number => x, y, 1, 0, true ); // $ExpectError
}

// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a collection...
{
const x = new DataView( new ArrayBuffer( 100 ) );
const y = new Float64Array( 10 );

readDataView.ndarray( y.length, x, 1, 0, 10, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, true, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, false, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, null, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, undefined, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, {}, 1, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, ( x: number ): number => x, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, 10, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, true, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, false, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, null, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, undefined, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, {}, 1, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, ( x: number ): number => x, 1, 0, true ); // $ExpectError
}

// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number...
{
const x = new DataView( new ArrayBuffer( 100 ) );
const y = new Float64Array( 10 );

readDataView.ndarray( y.length, x, 1, 0, y, '10', 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, true, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, false, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, null, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, undefined, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, [], 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, {}, 0, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, ( x: number ): number => x, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, '10', 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, true, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, false, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, null, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, undefined, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, [], 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, {}, 0, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, ( x: number ): number => x, 0, true ); // $ExpectError
}

// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number...
{
const x = new DataView( new ArrayBuffer( 100 ) );
const y = new Float64Array( 10 );

readDataView.ndarray( y.length, x, 1, 0, y, 1, '10', true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, true, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, false, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, null, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, undefined, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, [], true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, {}, true ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, ( x: number ): number => x, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, '10', true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, true, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, false, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, null, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, undefined, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, [], true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, {}, true ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, ( x: number ): number => x, true ); // $ExpectError
}

// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a boolean...
{
const x = new DataView( new ArrayBuffer( 100 ) );
const y = new Float64Array( 10 );

readDataView.ndarray( y.length, x, 1, 0, y, 1, 0, '10' ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, 0, 0 ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, 0, null ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, 0, undefined ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, 0, [] ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, 0, {} ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, 0, ( x: number ): number => x ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, 0, '10' ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, 0, 0 ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, 0, null ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, 0, undefined ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, 0, [] ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, 0, {} ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, 0, ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments...
Expand All @@ -263,12 +261,12 @@ import readDataView = require( './index' );
const y = new Float64Array( 10 );

readDataView.ndarray(); // $ExpectError
readDataView.ndarray( y.length ); // $ExpectError
readDataView.ndarray( y.length, x ); // $ExpectError
readDataView.ndarray( y.length, x, 1 ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0 ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1 ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, 0 ); // $ExpectError
readDataView.ndarray( y.length, x, 1, 0, y, 1, 0, true, 10 ); // $ExpectError
readDataView.ndarray( x.length ); // $ExpectError
readDataView.ndarray( x.length, x ); // $ExpectError
readDataView.ndarray( x.length, x, 1 ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0 ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1 ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, 0 ); // $ExpectError
readDataView.ndarray( x.length, x, 1, 0, y, 1, 0, true, 10 ); // $ExpectError
}

0 comments on commit 6485a76

Please sign in to comment.