Skip to content

Commit 2827f8a

Browse files
committed
feat: add plot/vega/base/assert/is-padding
--- 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 d92a00c commit 2827f8a

File tree

10 files changed

+620
-0
lines changed

10 files changed

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

0 commit comments

Comments
 (0)