Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<!--

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

-->

# isDiscreteScale

> Test if an input value is a [discrete scale][@stdlib/plot/vega/scale/discrete].

<!-- 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 isDiscreteScale = require( '@stdlib/plot/vega/base/assert/is-discrete-scale' );
```

#### isDiscreteScale( value )

Tests if an input value is a [discrete scale][@stdlib/plot/vega/scale/discrete].

```javascript
var DiscreteScale = require( '@stdlib/plot/vega/scale/discrete' );

var v = new DiscreteScale({
'name': 'xScale',
'type': 'ordinal'
});
var bool = isDiscreteScale( v );
// returns true

bool = isDiscreteScale( {} );
// 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 DiscreteScale = require( '@stdlib/plot/vega/scale/discrete' );
var isDiscreteScale = require( '@stdlib/plot/vega/base/assert/is-discrete-scale' );

var v = new DiscreteScale({
'name': 'xScale',
'type': 'ordinal'
});
var bool = isDiscreteScale( v );
// returns true

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

bool = isDiscreteScale( '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/scale/discrete]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/plot/vega/scale/discrete

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* @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 DiscreteScale = require( '@stdlib/plot/vega/scale/discrete' );
var pkg = require( './../package.json' ).name;
var isDiscreteScale = require( './../lib' );


// MAIN //

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

values = [
new DiscreteScale({
'name': 'xScale',
'type': 'ordinal'
}),
new DiscreteScale({
'name': 'yScale',
'type': 'ordinal'
})
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = values[ i%values.length ];
out = isDiscreteScale( 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 = isDiscreteScale( 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 a discrete scale instance.

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

Returns
-------
bool: boolean
Boolean indicating if an input value is a discrete scale instance.

Examples
--------
> var opts = { 'name': 'xScale', 'type': 'ordinal' };
> var v = new {{alias:@stdlib/plot/vega/scale/discrete}}( opts );
> var bool = {{alias}}( v )
true
> bool = {{alias}}( {} )
false

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* @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 a discrete scale instance.
*
* @param v - value to test
* @returns boolean indicating whether an input value is a discrete scale instance
*
* @example
* var DiscreteScale = require( '@stdlib/plot/vega/scale/discrete' );
*
* var v = new DiscreteScale({
* 'name': 'xScale',
* 'type': 'ordinal'
* });
* var bool = isDiscreteScale( v );
* // returns true
*
* bool = isDiscreteScale( {} );
* // returns false
*
* bool = isDiscreteScale( 'foo' );
* // returns false
*/
declare function isDiscreteScale( v: any ): boolean;


// EXPORTS //

export = isDiscreteScale;
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 isDiscreteScale = require( './index' );


// TESTS //

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

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
isDiscreteScale(); // $ExpectError
isDiscreteScale( undefined, 123 ); // $ExpectError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @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';

var DiscreteScale = require( '@stdlib/plot/vega/scale/discrete' );
var isDiscreteScale = require( './../lib' );

var v = new DiscreteScale({
'name': 'xScale',
'type': 'ordinal'
});
var bool = isDiscreteScale( v );
console.log( bool );
// => true

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

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