Skip to content

Commit b830dae

Browse files
Sachinn-64kgryte
andauthored
feat: add plot/vega/base/assert/is-signal-name
PR-URL: #10868 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 4621e98 commit b830dae

File tree

10 files changed

+633
-0
lines changed

10 files changed

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

0 commit comments

Comments
 (0)