Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Feb 11, 2024
1 parent c9cf45c commit 307581c
Show file tree
Hide file tree
Showing 17 changed files with 1,429 additions and 787 deletions.
59 changes: 55 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ v = y[ ':' ];
The function supports the following options:

- **strict**: boolean indicating whether to enforce strict bounds checking. Default: `false`.
- **cache**: cache for resolving array index objects. Default: [`ArrayIndex`][@stdlib/array/index].

By default, the function returns a fancy array which does **not** enforce strict bounds checking. For example,

Expand All @@ -170,16 +171,64 @@ var v = y[ 10 ];
// throws <RangeError>
```

#### array2fancy.factory( \[options] )

Returns a function for converting an array to an object supporting fancy indexing.

```javascript
var fcn = array2fancy.factory();

var x = [ 1, 2, 3, 4 ];

var y = fcn( x );
// returns <Array>

var v = y[ ':' ];
// returns [ 1, 2, 3, 4 ]
```

The function supports the following options:

- **strict**: boolean indicating whether to enforce strict bounds checking by default. Default: `false`.
- **cache**: cache for resolving array index objects. Default: [`ArrayIndex`][@stdlib/array/index].

By default, the function returns a function which, by default, does **not** enforce strict bounds checking. For example,

```javascript
var fcn = array2fancy.factory();

var y = fcn( [ 1, 2, 3, 4 ] );

var v = y[ 10 ];
// returns undefined
```

To enforce strict bounds checking by default, set the `strict` option to `true`.

<!-- run throws: true -->

```javascript
var fcn = array2fancy.factory({
'strict': true
});
var y = fcn( [ 1, 2, 3, 4 ] );

var v = y[ 10 ];
// throws <RangeError>
```

The returned function supports the same options as above. When the returned function is provided option values, those values override the factory method defaults.

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

* * *

<section class="notes">

## Notes

- A fancy array shares the **same** data as the provided input array. Hence, any mutations to the returned array will affect the underlying input array and vice versa.
Expand Down Expand Up @@ -346,10 +395,10 @@ y[ ':' ] = new Float64Array( [ 5.0, 6.0 ] ); // is this a single complex number

<!-- Package usage examples. -->

<section class="examples">

* * *

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->
Expand Down Expand Up @@ -489,6 +538,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].

[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64

[@stdlib/array/index]: https://github.com/stdlib-js/array-index

</section>

<!-- /.links -->
48 changes: 48 additions & 0 deletions benchmark/benchmark.factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench-harness' );
var isFunction = require( '@stdlib/assert-is-function' );
var pkg = require( './../package.json' ).name;
var array2fancy = require( './../lib' );


// MAIN //

bench( pkg+':factory', function benchmark( b ) {
var v;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = array2fancy.factory();
if ( typeof v !== 'function' ) {
b.fail( 'should return a function' );
}
}
b.toc();
if ( !isFunction( v ) ) {
b.fail( 'should return a function' );
}
b.pass( 'benchmark finished' );
b.end();
});
92 changes: 47 additions & 45 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/index.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 307581c

Please sign in to comment.