diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/README.md b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/README.md new file mode 100644 index 000000000000..01e91823d2a4 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/README.md @@ -0,0 +1,125 @@ + + +# isDiscretizingScale + +> Test if an input value is a [discretizing scale][@stdlib/plot/vega/scale/discretizing]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var isDiscretizingScale = require( '@stdlib/plot/vega/base/assert/is-discretizing-scale' ); +``` + +#### isDiscretizingScale( value ) + +Tests if an input value is a [discretizing scale][@stdlib/plot/vega/scale/discretizing]. + +```javascript +var DiscretizingScale = require( '@stdlib/plot/vega/scale/discretizing' ); + +var v = new DiscretizingScale({ + 'name': 'xScale' +}); +var bool = isDiscretizingScale( v ); +// returns true + +bool = isDiscretizingScale( {} ); +// returns false +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var DiscretizingScale = require( '@stdlib/plot/vega/scale/discretizing' ); +var isDiscretizingScale = require( '@stdlib/plot/vega/base/assert/is-discretizing-scale' ); + +var v = new DiscretizingScale({ + 'name': 'xScale' +}); +var bool = isDiscretizingScale( v ); +// returns true + +bool = isDiscretizingScale( {} ); +// returns false + +bool = isDiscretizingScale( 'foo' ); +// returns false +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/benchmark/benchmark.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/benchmark/benchmark.js new file mode 100644 index 000000000000..ef7b96cf06fe --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/benchmark/benchmark.js @@ -0,0 +1,93 @@ +/** +* @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 DiscretizingScale = require( '@stdlib/plot/vega/scale/discretizing' ); +var pkg = require( './../package.json' ).name; +var isDiscretizingScale = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::true', function benchmark( b ) { + var values; + var out; + var v; + var i; + + values = [ + new DiscretizingScale({ + 'name': 'xScale' + }), + new DiscretizingScale({ + 'name': 'yScale' + }) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = values[ i%values.length ]; + out = isDiscretizingScale( 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 = isDiscretizingScale( 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-discretizing-scale/docs/repl.txt b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/docs/repl.txt new file mode 100644 index 000000000000..0b456662e4d2 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/docs/repl.txt @@ -0,0 +1,26 @@ + +{{alias}}( value ) + Tests if an input value is a discretizing scale instance. + + Parameters + ---------- + value: any + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating if an input value is a discretizing scale instance. + + Examples + -------- + > var opts = { 'name': 'xScale' }; + > var v = new {{alias:@stdlib/plot/vega/scale/discretizing}}( opts ); + > var bool = {{alias}}( v ) + true + > bool = {{alias}}( {} ) + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/docs/types/index.d.ts b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/docs/types/index.d.ts new file mode 100644 index 000000000000..590a5caef785 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/docs/types/index.d.ts @@ -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 a discretizing scale instance. +* +* @param v - value to test +* @returns boolean indicating whether an input value is a discretizing scale instance +* +* @example +* var DiscretizingScale = require( '@stdlib/plot/vega/scale/discretizing' ); +* +* var v = new DiscretizingScale({ +* 'name': 'xScale' +* }); +* var bool = isDiscretizingScale( v ); +* // returns true +* +* bool = isDiscretizingScale( {} ); +* // returns false +* +* bool = isDiscretizingScale( 'foo' ); +* // returns false +*/ +declare function isDiscretizingScale( v: any ): boolean; + + +// EXPORTS // + +export = isDiscretizingScale; diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/docs/types/test.ts b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/docs/types/test.ts new file mode 100644 index 000000000000..8277236fa367 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-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 isDiscretizingScale = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isDiscretizingScale( {} ); // $ExpectType boolean + isDiscretizingScale( 'foo' ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isDiscretizingScale(); // $ExpectError + isDiscretizingScale( undefined, 123 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/examples/index.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/examples/index.js new file mode 100644 index 000000000000..eba9ba2099b7 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 DiscretizingScale = require( '@stdlib/plot/vega/scale/discretizing' ); +var isDiscretizingScale = require( './../lib' ); + +var v = new DiscretizingScale({ + 'name': 'xScale' +}); +var bool = isDiscretizingScale( v ); +console.log( bool ); +// => true + +bool = isDiscretizingScale( {} ); +console.log( bool ); +// => false + +bool = isDiscretizingScale( 'foo' ); +console.log( bool ); +// => false diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/lib/index.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/lib/index.js new file mode 100644 index 000000000000..5b8b7794238c --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/lib/index.js @@ -0,0 +1,50 @@ +/** +* @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 discretizing scale instance. +* +* @module @stdlib/plot/vega/base/assert/is-discretizing-scale +* +* @example +* var DiscretizingScale = require( '@stdlib/plot/vega/scale/discretizing' ); +* var isDiscretizingScale = require( '@stdlib/plot/vega/base/assert/is-discretizing-scale' ); +* +* var v = new DiscretizingScale({ +* 'name': 'xScale' +* }); +* var bool = isDiscretizingScale( v ); +* // returns true +* +* bool = isDiscretizingScale( {} ); +* // returns false +* +* bool = isDiscretizingScale( '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-discretizing-scale/lib/main.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/lib/main.js new file mode 100644 index 000000000000..69cddcad9ac0 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/lib/main.js @@ -0,0 +1,70 @@ +/** +* @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 isDiscretizingScaleName = require( '@stdlib/plot/vega/base/assert/is-discretizing-scale-name' ); +var isObject = require( '@stdlib/assert/is-object' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var DiscretizingScale = require( '@stdlib/plot/vega/scale/discretizing' ); + + +// MAIN // + +/** +* Tests whether an input value is a discretizing scale instance. +* +* @param {*} value - value to test +* @returns {boolean} boolean indicating whether an input value is a discretizing scale instance +* +* @example +* var DiscretizingScale = require( '@stdlib/plot/vega/scale/discretizing' ); +* +* var v = new DiscretizingScale({ +* 'name': 'xScale' +* }); +* var bool = isDiscretizingScale( v ); +* // returns true +* +* bool = isDiscretizingScale( {} ); +* // returns false +* +* bool = isDiscretizingScale( 'foo' ); +* // returns false +*/ +function isDiscretizingScale( value ) { + return ( + value instanceof DiscretizingScale || + + // The following is a set of rather imperfect heuristics for handling instances originating in a different realm... + ( + isObject( value ) && + isDiscretizingScaleName( value.type ) && + hasProp( value, 'name' ) && + hasProp( value, 'domain' ) && + hasProp( value, 'range' ) + ) + ); +} + + +// EXPORTS // + +module.exports = isDiscretizingScale; diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/package.json b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/package.json new file mode 100644 index 000000000000..42b1cacbd207 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/plot/vega/base/assert/is-discretizing-scale", + "version": "0.0.0", + "description": "Test if an input value is a discretizing 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-discretizing-scale/test/test.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/test/test.js new file mode 100644 index 000000000000..7a7e9252155e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-discretizing-scale/test/test.js @@ -0,0 +1,88 @@ +/** +* @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 QuantileScale = require( '@stdlib/plot/vega/scale/quantile' ); +var DiscretizingScale = require( '@stdlib/plot/vega/scale/discretizing' ); +var Scale = require( '@stdlib/plot/vega/scale/base/ctor' ); +var isDiscretizingScale = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isDiscretizingScale, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided a discretizing scale instance', function test( t ) { + var values; + var bool; + var i; + + values = [ + new QuantileScale({ + 'name': 'yScale' + }), + new DiscretizingScale({ + 'name': 'zScale' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + bool = isDiscretizingScale( values[ i ] ); + t.strictEqual( bool, true, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +}); + +tape( 'the function returns `false` if not provided a discretizing 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 = isDiscretizingScale( values[ i ] ); + t.strictEqual( bool, false, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +});