Skip to content

Commit b86c909

Browse files
committed
feat: add plot/vega/base/assert/is-axis-array
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: skipped - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent bbdef84 commit b86c909

File tree

10 files changed

+635
-0
lines changed

10 files changed

+635
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# isAxisArray
22+
23+
> Test if an input value is an array of [axes][@stdlib/plot/vega/axis].
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var isAxisArray = require( '@stdlib/plot/vega/base/assert/is-axis-array' );
41+
```
42+
43+
#### isAxisArray( value )
44+
45+
Tests if an input value is an array of [axes][@stdlib/plot/vega/axis].
46+
47+
```javascript
48+
var Axis = require( '@stdlib/plot/vega/axis' );
49+
50+
var v = new Axis({
51+
'scale': 'xScale',
52+
'orient': 'bottom'
53+
});
54+
var bool = isAxisArray( [ v ] );
55+
// returns true
56+
```
57+
58+
If provided an empty array, the function returns `false`.
59+
60+
```javascript
61+
var bool = isAxisArray( [] );
62+
// returns false
63+
```
64+
65+
</section>
66+
67+
<!-- /.usage -->
68+
69+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
70+
71+
<section class="notes">
72+
73+
</section>
74+
75+
<!-- /.notes -->
76+
77+
<!-- Package usage examples. -->
78+
79+
<section class="examples">
80+
81+
## Examples
82+
83+
<!-- eslint no-undef: "error" -->
84+
85+
```javascript
86+
var Axis = require( '@stdlib/plot/vega/axis' );
87+
var isAxisArray = require( '@stdlib/plot/vega/base/assert/is-axis-array' );
88+
89+
var v = new Axis({
90+
'scale': 'xScale',
91+
'orient': 'bottom'
92+
});
93+
var bool = isAxisArray( [ v ] );
94+
// returns true
95+
96+
bool = isAxisArray( {} );
97+
// returns false
98+
99+
bool = isAxisArray( 'foo' );
100+
// returns false
101+
```
102+
103+
</section>
104+
105+
<!-- /.examples -->
106+
107+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
108+
109+
<section class="references">
110+
111+
</section>
112+
113+
<!-- /.references -->
114+
115+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
116+
117+
<section class="related">
118+
119+
</section>
120+
121+
<!-- /.related -->
122+
123+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
124+
125+
<section class="links">
126+
127+
[@stdlib/plot/vega/axis]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/plot/vega/axis
128+
129+
</section>
130+
131+
<!-- /.links -->
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var Axis = require( '@stdlib/plot/vega/scale' );
26+
var pkg = require( './../package.json' ).name;
27+
var isAxisArray = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg+'::true', function benchmark( b ) {
33+
var values;
34+
var out;
35+
var i;
36+
37+
values = [
38+
new Axis({
39+
'scale': 'xScale',
40+
'orient': 'bottom'
41+
}),
42+
new Axis({
43+
'scale': 'yScale',
44+
'orient': 'bottom'
45+
})
46+
];
47+
48+
b.tic();
49+
for ( i = 0; i < b.iterations; i++ ) {
50+
out = isAxisArray( [ values[ i%values.length ] ] );
51+
if ( typeof out !== 'boolean' ) {
52+
b.fail( 'should return a boolean' );
53+
}
54+
}
55+
b.toc();
56+
if ( !isBoolean( out ) ) {
57+
b.fail( 'should return a boolean' );
58+
}
59+
b.pass( 'benchmark finished' );
60+
b.end();
61+
});
62+
63+
bench( pkg+'::false', function benchmark( b ) {
64+
var values;
65+
var out;
66+
var v;
67+
var i;
68+
69+
values = [
70+
'foo',
71+
'bar',
72+
'',
73+
'beep',
74+
'boop',
75+
[],
76+
{}
77+
];
78+
79+
b.tic();
80+
for ( i = 0; i < b.iterations; i++ ) {
81+
v = values[ i%values.length ];
82+
out = isAxisArray( v );
83+
if ( typeof out !== 'boolean' ) {
84+
b.fail( 'should return a boolean' );
85+
}
86+
}
87+
b.toc();
88+
if ( !isBoolean( out ) ) {
89+
b.fail( 'should return a boolean' );
90+
}
91+
b.pass( 'benchmark finished' );
92+
b.end();
93+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
{{alias}}( value )
3+
Tests if an input value is an array of axis instances.
4+
5+
Parameters
6+
----------
7+
value: any
8+
Value to test.
9+
10+
Returns
11+
-------
12+
bool: boolean
13+
Boolean indicating if an input value is an array of axis instances.
14+
15+
Examples
16+
--------
17+
> var opts = { 'scale': 'xScale', 'orient': 'bottom' };
18+
> var v = new {{alias:@stdlib/plot/vega/axis}}( opts );
19+
> var bool = {{alias}}( [ v ] )
20+
true
21+
> bool = {{alias}}( {} )
22+
false
23+
24+
See Also
25+
--------
26+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Tests whether an input value is an array of axis instances.
23+
*
24+
* @param v - value to test
25+
* @returns boolean indicating whether an input value is an array of axis instances
26+
*
27+
* @example
28+
* var Axis = require( '@stdlib/plot/vega/axis' );
29+
*
30+
* var v = new Axis({
31+
* 'scale': 'xScale',
32+
* 'orient': 'bottom'
33+
* });
34+
* var bool = isAxisArray( [ v ] );
35+
* // returns true
36+
*
37+
* bool = isAxisArray( {} );
38+
* // returns false
39+
*
40+
* bool = isAxisArray( 'foo' );
41+
* // returns false
42+
*/
43+
declare function isAxisArray( v: any ): boolean;
44+
45+
46+
// EXPORTS //
47+
48+
export = isAxisArray;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import isAxisArray = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isAxisArray( {} ); // $ExpectType boolean
27+
isAxisArray( 'foo' ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isAxisArray(); // $ExpectError
33+
isAxisArray( undefined, 123 ); // $ExpectError
34+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var Axis = require( '@stdlib/plot/vega/axis' );
22+
var isAxisArray = require( './../lib' );
23+
24+
var v = new Axis({
25+
'scale': 'xScale',
26+
'orient': 'bottom'
27+
});
28+
var bool = isAxisArray( [ v ] );
29+
console.log( bool );
30+
// => true
31+
32+
bool = isAxisArray( {} );
33+
console.log( bool );
34+
// => false
35+
36+
bool = isAxisArray( 'foo' );
37+
console.log( bool );
38+
// => false

0 commit comments

Comments
 (0)