Skip to content

Commit ea207e3

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

File tree

10 files changed

+632
-0
lines changed

10 files changed

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

0 commit comments

Comments
 (0)