From a2a03221ae203fcc286f7755deff9fb5d3e55a7c Mon Sep 17 00:00:00 2001 From: orthodox-64 Date: Thu, 2 Apr 2026 01:12:32 +0530 Subject: [PATCH] feat: add plot/vega/base/assert/is-value --- .../plot/vega/base/assert/is-value/README.md | 121 ++++++++++++++++++ .../assert/is-value/benchmark/benchmark.js | 93 ++++++++++++++ .../vega/base/assert/is-value/docs/repl.txt | 25 ++++ .../assert/is-value/docs/types/index.d.ts | 45 +++++++ .../base/assert/is-value/docs/types/test.ts | 34 +++++ .../base/assert/is-value/examples/index.js | 35 +++++ .../vega/base/assert/is-value/lib/index.js | 48 +++++++ .../vega/base/assert/is-value/lib/main.js | 67 ++++++++++ .../vega/base/assert/is-value/package.json | 70 ++++++++++ .../vega/base/assert/is-value/test/test.js | 86 +++++++++++++ 10 files changed, 624 insertions(+) create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-value/README.md create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-value/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-value/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-value/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-value/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-value/examples/index.js create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-value/lib/index.js create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-value/lib/main.js create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-value/package.json create mode 100644 lib/node_modules/@stdlib/plot/vega/base/assert/is-value/test/test.js diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/README.md b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/README.md new file mode 100644 index 000000000000..784fe03bb695 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/README.md @@ -0,0 +1,121 @@ + + +# isValue + +> Test if an input value is a [value][@stdlib/plot/vega/value/base/ctor]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var isValue = require( '@stdlib/plot/vega/base/assert/is-value' ); +``` + +#### isValue( value ) + +Tests if an input value is a [value][@stdlib/plot/vega/value/base/ctor]. + +```javascript +var Value = require( '@stdlib/plot/vega/value/base/ctor' ); + +var v = new Value(); +var bool = isValue( v ); +// returns true + +bool = isValue( 'foo' ); +// returns false +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var Value = require( '@stdlib/plot/vega/value/base/ctor' ); +var isValue = require( '@stdlib/plot/vega/base/assert/is-value' ); + +var v = new Value(); +var bool = isValue( v ); +// returns true + +bool = isValue( {} ); +// returns false + +bool = isValue( 'foo' ); +// returns false +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/benchmark/benchmark.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/benchmark/benchmark.js new file mode 100644 index 000000000000..7a6c7159a735 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/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 Value = require( '@stdlib/plot/vega/value/base/ctor' ); +var pkg = require( './../package.json' ).name; +var isValue = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::true', function benchmark( b ) { + var values; + var out; + var v; + var i; + + values = [ + new Value({ + 'value': 5 + }), + new Value({ + 'field': 'price' + }) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = values[ i%values.length ]; + out = isValue( 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 = isValue( 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-value/docs/repl.txt b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/docs/repl.txt new file mode 100644 index 000000000000..cc966c8ce1fb --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/docs/repl.txt @@ -0,0 +1,25 @@ + +{{alias}}( value ) + Tests if an input value is a value instance. + + Parameters + ---------- + value: any + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating if an input value is a value instance. + + Examples + -------- + > var v = new {{alias:@stdlib/plot/vega/value/base/ctor}}(); + > var bool = {{alias}}( v ) + true + > bool = {{alias}}( {} ) + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/docs/types/index.d.ts b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/docs/types/index.d.ts new file mode 100644 index 000000000000..9f7e5605be97 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/docs/types/index.d.ts @@ -0,0 +1,45 @@ +/* +* @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 value instance. +* +* @param v - value to test +* @returns boolean indicating whether an input value is a value instance +* +* @example +* var Value = require( '@stdlib/plot/vega/value/base/ctor' ); +* +* var v = new Value(); +* var bool = isValue( v ); +* // returns true +* +* bool = isValue( {} ); +* // returns false +* +* bool = isValue( 'foo' ); +* // returns false +*/ +declare function isValue( v: any ): boolean; + + +// EXPORTS // + +export = isValue; diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/docs/types/test.ts b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/docs/types/test.ts new file mode 100644 index 000000000000..8287b5d7805b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/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 isValue = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isValue( {} ); // $ExpectType boolean + isValue( 'foo' ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isValue(); // $ExpectError + isValue( undefined, 123 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/examples/index.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/examples/index.js new file mode 100644 index 000000000000..90eb38b4bbe2 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/examples/index.js @@ -0,0 +1,35 @@ +/** +* @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 Value = require( '@stdlib/plot/vega/value/base/ctor' ); +var isValue = require( './../lib' ); + +var v = new Value(); +var bool = isValue( v ); +console.log( bool ); +// => true + +bool = isValue( {} ); +console.log( bool ); +// => false + +bool = isValue( 'foo' ); +console.log( bool ); +// => false diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/lib/index.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/lib/index.js new file mode 100644 index 000000000000..988d8e9f7415 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/lib/index.js @@ -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. +*/ + +'use strict'; + +/** +* Test whether an input value is a value instance. +* +* @module @stdlib/plot/vega/base/assert/is-value +* +* @example +* var Value = require( '@stdlib/plot/vega/value/base/ctor' ); +* var isValue = require( '@stdlib/plot/vega/base/assert/is-value' ); +* +* var v = new Value(); +* var bool = isValue( v ); +* // returns true +* +* bool = isValue( {} ); +* // returns false +* +* bool = isValue( '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-value/lib/main.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/lib/main.js new file mode 100644 index 000000000000..7a651c80b0cc --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/lib/main.js @@ -0,0 +1,67 @@ +/** +* @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 isObject = require( '@stdlib/assert/is-object' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var Value = require( '@stdlib/plot/vega/value/base/ctor' ); + + +// MAIN // + +/** +* Tests whether an input value is a value instance. +* +* @param {*} value - value to test +* @returns {boolean} boolean indicating whether an input value is a value instance +* +* @example +* var Value = require( '@stdlib/plot/vega/value/base/ctor' ); +* +* var v = new Value(); +* var bool = isValue( v ); +* // returns true +* +* bool = isValue( {} ); +* // returns false +* +* bool = isValue( 'foo' ); +* // returns false +*/ +function isValue( value ) { + return ( + value instanceof Value || + + // The following is a set of rather imperfect heuristics for handling instances originating in a different realm... + ( + isObject( value ) && + hasProp( value, 'signal' ) && + hasProp( value, 'color' ) && + hasProp( value, 'field' ) && + hasProp( value, 'value' ) + ) + ); +} + + +// EXPORTS // + +module.exports = isValue; diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/package.json b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/package.json new file mode 100644 index 000000000000..2a3168dc1446 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/plot/vega/base/assert/is-value", + "version": "0.0.0", + "description": "Test if an input value is a value 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-value/test/test.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/test/test.js new file mode 100644 index 000000000000..43ff279a57ed --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value/test/test.js @@ -0,0 +1,86 @@ +/** +* @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 Value = require( '@stdlib/plot/vega/value/base/ctor' ); +var isValue = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isValue, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided a value instance', function test( t ) { + var values; + var bool; + var i; + + values = [ + new Value({ + 'value': 5 + }), + new Value({ + 'field': 'price' + }), + new Value({ + 'signal': 'width' + }), + new Value() + ]; + for ( i = 0; i < values.length; i++ ) { + bool = isValue( values[ i ] ); + t.strictEqual( bool, true, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +}); + +tape( 'the function returns `false` if not provided a value instance', function test( t ) { + var values; + var bool; + var i; + + values = [ + '', + 'beep', + 'boop', + 'foo', + 'bar', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + bool = isValue( values[ i ] ); + t.strictEqual( bool, false, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +});