Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions lib/node_modules/@stdlib/plot/vega/base/assert/is-compare/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# isCompare

> Test if an input value is an [compare][@stdlib/plot/vega/mark/compare] instance.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var isCompare = require( '@stdlib/plot/vega/base/assert/is-compare' );
```

#### isCompare( value )

Tests if an input value is an [compare][@stdlib/plot/vega/mark/compare] instance.

```javascript
var Compare = require( '@stdlib/plot/vega/mark/compare' );

var v = new Compare({
'field': 'amount'
});
var bool = isCompare( v );
// returns true

bool = isCompare( 'foo' );
// returns false
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Compare = require( '@stdlib/plot/vega/mark/compare' );
var isCompare = require( '@stdlib/plot/vega/base/assert/is-compare' );

var v = new Compare({
'field': 'amount'
});
var bool = isCompare( v );
// returns true

bool = isCompare( {} );
// returns false

bool = isCompare( 'foo' );
// returns false
```

</section>

<!-- /.examples -->

<!-- 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. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/plot/vega/mark/compare]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/plot/vega/mark/compare

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var Compare = require( '@stdlib/plot/vega/mark/compare' );
var pkg = require( './../package.json' ).name;
var isCompare = require( './../lib' );


// MAIN //

bench( pkg+'::true', function benchmark( b ) {
var values;
var out;
var v;
var i;

values = [
new Compare({
'field': 'amount'
}),
new Compare({
'field': 'amount',
'order': 'descending'
})
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = values[ i%values.length ];
out = isCompare( v );
if ( typeof out !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( out ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::false', function benchmark( b ) {
var values;
var out;
var v;
var i;

values = [
'foo',
'bar',
'',
'beep',
'boop',
[],
{}
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = values[ i%values.length ];
out = isCompare( v );
if ( typeof out !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( out ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

{{alias}}( value )
Tests if an input value is an compare instance.

Parameters
----------
value: any
Value to test.

Returns
-------
bool: boolean
Boolean indicating if an input value is an compare instance.

Examples
--------
> var Compare = {{alias:@stdlib/plot/vega/mark/compare}};
> var v = new Compare({ 'field': 'amount' });
> var bool = {{alias}}( v )
true
> bool = {{alias}}( {} )
false

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// TypeScript Version: 4.1

/**
* Tests whether an input value is an compare instance.
*
* @param v - value to test
* @returns boolean indicating whether an input value is an compare instance
*
* @example
* var Compare = require( '@stdlib/plot/vega/mark/compare' );
*
* var v = new Compare({
* 'field': 'amount'
* });
* var bool = isCompare( v );
* // returns true
*
* bool = isCompare( {} );
* // returns false
*
* bool = isCompare( 'foo' );
* // returns false
*/
declare function isCompare( v: any ): boolean;


// EXPORTS //

export = isCompare;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import isCompare = require( './index' );


// TESTS //

// The function returns a boolean...
{
isCompare( {} ); // $ExpectType boolean
isCompare( 'foo' ); // $ExpectType boolean
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
isCompare(); // $ExpectError
isCompare( undefined, 123 ); // $ExpectError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var Compare = require( '@stdlib/plot/vega/mark/compare' );
var isCompare = require( './../lib' );

var v = new Compare({
'field': 'amount'
});
var bool = isCompare( v );
console.log( bool );
// => true

bool = isCompare( {} );
console.log( bool );
// => false

bool = isCompare( 'foo' );
console.log( bool );
// => false
Loading
Loading