From ff647cbee9143212886f6c5244720151af11f7db Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Sun, 4 Jan 2026 20:05:35 +0530 Subject: [PATCH] feat: add vega/base/assert/is-discrete-scale --- .../base/assert/is-discrete-scale/README.md | 127 ++++++++++++++++++ .../is-discrete-scale/benchmark/benchmark.js | 95 +++++++++++++ .../assert/is-discrete-scale/docs/repl.txt | 26 ++++ .../is-discrete-scale/docs/types/index.d.ts | 48 +++++++ .../is-discrete-scale/docs/types/test.ts | 34 +++++ .../is-discrete-scale/examples/index.js | 38 ++++++ .../assert/is-discrete-scale/lib/index.js | 51 +++++++ .../base/assert/is-discrete-scale/lib/main.js | 71 ++++++++++ .../assert/is-discrete-scale/package.json | 70 ++++++++++ .../assert/is-discrete-scale/test/test.js | 89 ++++++++++++ 10 files changed, 649 insertions(+) create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/README.md create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/examples/index.js create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/lib/index.js create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/lib/main.js create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/package.json create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/test/test.js diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/README.md b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/README.md new file mode 100644 index 000000000000..6efed1bcbf7c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/README.md @@ -0,0 +1,127 @@ + + +# isDiscreteScale + +> Test if an input value is a [discrete scale][@stdlib/plot/vega/scale/discrete]. + + + +
+ +
+ + + + + +
+ +## 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 +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```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 +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/benchmark/benchmark.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/benchmark/benchmark.js new file mode 100644 index 000000000000..b11c7a8bbb3d --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/benchmark/benchmark.js @@ -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(); +}); diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/docs/repl.txt b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/docs/repl.txt new file mode 100644 index 000000000000..2820ff55f2ba --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/docs/repl.txt @@ -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 + -------- + diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/docs/types/index.d.ts b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/docs/types/index.d.ts new file mode 100644 index 000000000000..4252bd6dcc64 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/docs/types/index.d.ts @@ -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; diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/docs/types/test.ts b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/docs/types/test.ts new file mode 100644 index 000000000000..cf081ca6311a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/docs/types/test.ts @@ -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 +} diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/examples/index.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/examples/index.js new file mode 100644 index 000000000000..a9bdc4a4d63c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/examples/index.js @@ -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 diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/lib/index.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/lib/index.js new file mode 100644 index 000000000000..5049e0806983 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/lib/index.js @@ -0,0 +1,51 @@ +/** +* @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'; + +/** +* Test whether an input value is a discrete scale instance. +* +* @module @stdlib/plot/vega/base/assert/is-discrete-scale +* +* @example +* 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 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/lib/main.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/lib/main.js new file mode 100644 index 000000000000..8a1bf7402f7c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/lib/main.js @@ -0,0 +1,71 @@ +/** +* @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 isDiscreteScaleName = require( '@stdlib/plot/vega/base/assert/is-discrete-scale-name' ); +var isObject = require( '@stdlib/assert/is-object' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var DiscreteScale = require( '@stdlib/plot/vega/scale/discrete' ); + + +// MAIN // + +/** +* Tests whether an input value is a discrete scale instance. +* +* @param {*} value - value to test +* @returns {boolean} 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 +*/ +function isDiscreteScale( value ) { + return ( + value instanceof DiscreteScale || + + // The following is a set of rather imperfect heuristics for handling instances originating in a different realm... + ( + isObject( value ) && + isDiscreteScaleName( value.type ) && + hasProp( value, 'name' ) && + hasProp( value, 'domain' ) && + hasProp( value, 'range' ) + ) + ); +} + + +// EXPORTS // + +module.exports = isDiscreteScale; diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/package.json b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/package.json new file mode 100644 index 000000000000..caba7b3e2fb0 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/plot/vega/base/assert/is-discrete-scale", + "version": "0.0.0", + "description": "Test if an input value is a discrete scale instance.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "plot", + "base", + "vega", + "utilities", + "utility", + "utils", + "util", + "assert", + "test", + "check", + "is", + "valid", + "validate", + "validation", + "isvalid" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/test/test.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/test/test.js new file mode 100644 index 000000000000..5368dc7e9df1 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discrete-scale/test/test.js @@ -0,0 +1,89 @@ +/** +* @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 tape = require( 'tape' ); +var OrdinalScale = require( '@stdlib/plot/vega/scale/ordinal' ); +var DiscreteScale = require( '@stdlib/plot/vega/scale/discrete' ); +var Scale = require( '@stdlib/plot/vega/scale/base/ctor' ); +var isDiscreteScale = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isDiscreteScale, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided a discrete scale instance', function test( t ) { + var values; + var bool; + var i; + + values = [ + new OrdinalScale({ + 'name': 'yScale' + }), + new DiscreteScale({ + 'name': 'zScale', + 'type': 'ordinal' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + bool = isDiscreteScale( values[ i ] ); + t.strictEqual( bool, true, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +}); + +tape( 'the function returns `false` if not provided a discrete scale instance', function test( t ) { + var values; + var bool; + var i; + + values = [ + new Scale({ + 'name': 'xScale', + 'type': 'linear' + }), + '', + 'beep', + 'boop', + 'foo', + 'bar', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + bool = isDiscreteScale( values[ i ] ); + t.strictEqual( bool, false, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +});