Skip to content

Commit 45384f5

Browse files
committed
feat: add plot/vega/base/assert/is-mark-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 ea207e3 commit 45384f5

File tree

10 files changed

+621
-0
lines changed

10 files changed

+621
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
# isMarkArray
22+
23+
> Test if an input value is an array of [marks][@stdlib/plot/vega/mark/base/ctor].
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 isMarkArray = require( '@stdlib/plot/vega/base/assert/is-mark-array' );
41+
```
42+
43+
#### isMarkArray( value )
44+
45+
Tests if an input value is an array of [marks][@stdlib/plot/vega/mark/base/ctor].
46+
47+
```javascript
48+
var Mark = require( '@stdlib/plot/vega/mark/base/ctor' );
49+
50+
var v = new Mark({
51+
'type': 'line'
52+
});
53+
var bool = isMarkArray( [ v ] );
54+
// returns true
55+
```
56+
57+
If provided an empty array, the function returns `false`.
58+
59+
```javascript
60+
var bool = isMarkArray( [] );
61+
// returns false
62+
```
63+
64+
</section>
65+
66+
<!-- /.usage -->
67+
68+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
69+
70+
<section class="notes">
71+
72+
</section>
73+
74+
<!-- /.notes -->
75+
76+
<!-- Package usage examples. -->
77+
78+
<section class="examples">
79+
80+
## Examples
81+
82+
<!-- eslint no-undef: "error" -->
83+
84+
```javascript
85+
var Mark = require( '@stdlib/plot/vega/mark/base/ctor' );
86+
var isMarkArray = require( '@stdlib/plot/vega/base/assert/is-mark-array' );
87+
88+
var v = new Mark({
89+
'type': 'line'
90+
});
91+
var bool = isMarkArray( [ v ] );
92+
// returns true
93+
94+
bool = isMarkArray( {} );
95+
// returns false
96+
97+
bool = isMarkArray( 'foo' );
98+
// returns false
99+
```
100+
101+
</section>
102+
103+
<!-- /.examples -->
104+
105+
<!-- 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. -->
106+
107+
<section class="references">
108+
109+
</section>
110+
111+
<!-- /.references -->
112+
113+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
114+
115+
<section class="related">
116+
117+
</section>
118+
119+
<!-- /.related -->
120+
121+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
122+
123+
<section class="links">
124+
125+
[@stdlib/plot/vega/mark/base/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/plot/vega/mark/base/ctor
126+
127+
</section>
128+
129+
<!-- /.links -->
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 Mark = require( '@stdlib/plot/vega/mark/base/ctor' );
26+
var pkg = require( './../package.json' ).name;
27+
var isMarkArray = 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 Mark({
39+
'type': 'line'
40+
}),
41+
new Mark({
42+
'type': 'rect'
43+
})
44+
];
45+
46+
b.tic();
47+
for ( i = 0; i < b.iterations; i++ ) {
48+
out = isMarkArray( [ values[ i%values.length ] ] );
49+
if ( typeof out !== 'boolean' ) {
50+
b.fail( 'should return a boolean' );
51+
}
52+
}
53+
b.toc();
54+
if ( !isBoolean( out ) ) {
55+
b.fail( 'should return a boolean' );
56+
}
57+
b.pass( 'benchmark finished' );
58+
b.end();
59+
});
60+
61+
bench( pkg+'::false', function benchmark( b ) {
62+
var values;
63+
var out;
64+
var v;
65+
var i;
66+
67+
values = [
68+
'foo',
69+
'bar',
70+
'',
71+
'beep',
72+
'boop',
73+
[],
74+
{}
75+
];
76+
77+
b.tic();
78+
for ( i = 0; i < b.iterations; i++ ) {
79+
v = values[ i%values.length ];
80+
out = isMarkArray( v );
81+
if ( typeof out !== 'boolean' ) {
82+
b.fail( 'should return a boolean' );
83+
}
84+
}
85+
b.toc();
86+
if ( !isBoolean( out ) ) {
87+
b.fail( 'should return a boolean' );
88+
}
89+
b.pass( 'benchmark finished' );
90+
b.end();
91+
});
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 mark 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 mark instances.
14+
15+
Examples
16+
--------
17+
> var opts = { 'type': 'line' };
18+
> var v = new {{alias:@stdlib/plot/vega/mark/base/ctor}}( opts );
19+
> var bool = {{alias}}( [ v ] )
20+
true
21+
> bool = {{alias}}( {} )
22+
false
23+
24+
See Also
25+
--------
26+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 mark instances.
23+
*
24+
* @param v - value to test
25+
* @returns boolean indicating whether an input value is an array of mark instances
26+
*
27+
* @example
28+
* var Mark = require( '@stdlib/plot/vega/mark/base/ctor' );
29+
*
30+
* var v = new Mark({
31+
* 'type': 'line'
32+
* });
33+
* var bool = isMarkArray( [ v ] );
34+
* // returns true
35+
*
36+
* bool = isMarkArray( {} );
37+
* // returns false
38+
*
39+
* bool = isMarkArray( 'foo' );
40+
* // returns false
41+
*/
42+
declare function isMarkArray( v: any ): boolean;
43+
44+
45+
// EXPORTS //
46+
47+
export = isMarkArray;
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 isMarkArray = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isMarkArray( {} ); // $ExpectType boolean
27+
isMarkArray( 'foo' ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isMarkArray(); // $ExpectError
33+
isMarkArray( undefined, 123 ); // $ExpectError
34+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 Mark = require( '@stdlib/plot/vega/mark/base/ctor' );
22+
var isMarkArray = require( './../lib' );
23+
24+
var v = new Mark({
25+
'type': 'line'
26+
});
27+
var bool = isMarkArray( [ v ] );
28+
console.log( bool );
29+
// => true
30+
31+
bool = isMarkArray( {} );
32+
console.log( bool );
33+
// => false
34+
35+
bool = isMarkArray( 'foo' );
36+
console.log( bool );
37+
// => false

0 commit comments

Comments
 (0)