diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/README.md b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/README.md new file mode 100644 index 000000000000..4a09a4404427 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/README.md @@ -0,0 +1,125 @@ + + +# isValueFieldDescriptor + +> Test if an input value is a [field descriptor][@stdlib/plot/vega/value/field-descriptor]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var isValueFieldDescriptor = require( '@stdlib/plot/vega/base/assert/is-value-field-descriptor' ); +``` + +#### isValueFieldDescriptor( value ) + +Tests if an input value is a [field descriptor][@stdlib/plot/vega/value/field-descriptor]. + +```javascript +var FieldDescriptor = require( '@stdlib/plot/vega/value/field-descriptor' ); + +var v = new FieldDescriptor({ + 'datum': 'price' +}); +var bool = isValueFieldDescriptor( v ); +// returns true + +bool = isValueFieldDescriptor( {} ); +// returns false +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var FieldDescriptor = require( '@stdlib/plot/vega/value/field-descriptor' ); +var isValueFieldDescriptor = require( '@stdlib/plot/vega/base/assert/is-value-field-descriptor' ); + +var v = new FieldDescriptor({ + 'datum': 'price' +}); +var bool = isValueFieldDescriptor( v ); +// returns true + +bool = isValueFieldDescriptor( {} ); +// returns false + +bool = isValueFieldDescriptor( 'foo' ); +// returns false +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/benchmark/benchmark.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/benchmark/benchmark.js new file mode 100644 index 000000000000..556a1714c766 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/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 FieldDescriptor = require( '@stdlib/plot/vega/value/field-descriptor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var isValueFieldDescriptor = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::true', pkg ), function benchmark( b ) { + var values; + var out; + var v; + var i; + + values = [ + new FieldDescriptor({ + 'datum': 'price' + }), + new FieldDescriptor({ + 'parent': 'price', + 'level': 2 + }) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = values[ i%values.length ]; + out = isValueFieldDescriptor( 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( format( '%s::false', pkg ), 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 = isValueFieldDescriptor( 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-field-descriptor/docs/repl.txt b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/docs/repl.txt new file mode 100644 index 000000000000..66f4c15dc6ca --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/docs/repl.txt @@ -0,0 +1,26 @@ + +{{alias}}( value ) + Tests if an input value is a field descriptor instance. + + Parameters + ---------- + value: any + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating if an input value is a field descriptor instance. + + Examples + -------- + > var opts = { 'datum': 'price' }; + > var v = new {{alias:@stdlib/plot/vega/value/field-descriptor}}( opts ); + > var bool = {{alias}}( v ) + true + > bool = {{alias}}( {} ) + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/docs/types/index.d.ts b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/docs/types/index.d.ts new file mode 100644 index 000000000000..addacd2cf74a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/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 field descriptor instance. +* +* @param v - value to test +* @returns boolean indicating whether an input value is a field descriptor instance +* +* @example +* var FieldDescriptor = require( '@stdlib/plot/vega/value/field-descriptor' ); +* +* var v = new FieldDescriptor({ +* 'datum': 'price' +* }); +* var bool = isValueFieldDescriptor( v ); +* // returns true +* +* bool = isValueFieldDescriptor( {} ); +* // returns false +* +* bool = isValueFieldDescriptor( 'foo' ); +* // returns false +*/ +declare function isValueFieldDescriptor( v: any ): boolean; + + +// EXPORTS // + +export = isValueFieldDescriptor; diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/docs/types/test.ts b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/docs/types/test.ts new file mode 100644 index 000000000000..905d3b18a5b5 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/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 isValueFieldDescriptor = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isValueFieldDescriptor( {} ); // $ExpectType boolean + isValueFieldDescriptor( 'foo' ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isValueFieldDescriptor(); // $ExpectError + isValueFieldDescriptor( undefined, 123 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/examples/index.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/examples/index.js new file mode 100644 index 000000000000..d912eed1636a --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/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 FieldDescriptor = require( '@stdlib/plot/vega/value/field-descriptor' ); +var isValueFieldDescriptor = require( './../lib' ); + +var v = new FieldDescriptor({ + 'datum': 'price' +}); +var bool = isValueFieldDescriptor( v ); +console.log( bool ); +// => true + +bool = isValueFieldDescriptor( {} ); +console.log( bool ); +// => false + +bool = isValueFieldDescriptor( 'foo' ); +console.log( bool ); +// => false diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/lib/index.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/lib/index.js new file mode 100644 index 000000000000..53dd734d8849 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/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 field descriptor instance. +* +* @module @stdlib/plot/vega/base/assert/is-value-field-descriptor +* +* @example +* var FieldDescriptor = require( '@stdlib/plot/vega/value/field-descriptor' ); +* var isValueFieldDescriptor = require( '@stdlib/plot/vega/base/assert/is-value-field-descriptor' ); +* +* var v = new FieldDescriptor({ +* 'datum': 'price' +* }); +* var bool = isValueFieldDescriptor( v ); +* // returns true +* +* bool = isValueFieldDescriptor( {} ); +* // returns false +* +* bool = isValueFieldDescriptor( '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-field-descriptor/lib/main.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/lib/main.js new file mode 100644 index 000000000000..237acf1b4ea2 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/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 isObject = require( '@stdlib/assert/is-object' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var FieldDescriptor = require( '@stdlib/plot/vega/value/field-descriptor' ); + + +// MAIN // + +/** +* Tests whether an input value is a field descriptor instance. +* +* @param {*} value - value to test +* @returns {boolean} boolean indicating whether an input value is a field descriptor instance +* +* @example +* var FieldDescriptor = require( '@stdlib/plot/vega/value/field-descriptor' ); +* +* var v = new FieldDescriptor({ +* 'datum': 'price' +* }); +* var bool = isValueFieldDescriptor( v ); +* // returns true +* +* bool = isValueFieldDescriptor( {} ); +* // returns false +* +* bool = isValueFieldDescriptor( 'foo' ); +* // returns false +*/ +function isValueFieldDescriptor( value ) { + return ( + value instanceof FieldDescriptor || + + // The following is a set of rather imperfect heuristics for handling instances originating in a different realm... + ( + isObject( value ) && + ( + hasProp( value, 'datum' ) || + hasProp( value, 'group' ) || + hasProp( value, 'parent' ) || + hasProp( value, 'signal' ) + ) + ) + ); +} + + +// EXPORTS // + +module.exports = isValueFieldDescriptor; diff --git a/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/package.json b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/package.json new file mode 100644 index 000000000000..3012c0891411 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/plot/vega/base/assert/is-value-field-descriptor", + "version": "0.0.0", + "description": "Test if an input value is a field descriptor 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-field-descriptor/test/test.js b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/test/test.js new file mode 100644 index 000000000000..0f732b9a04b7 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/assert/is-value-field-descriptor/test/test.js @@ -0,0 +1,79 @@ +/** +* @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 FieldDescriptor = require( '@stdlib/plot/vega/value/field-descriptor' ); +var isValueFieldDescriptor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isValueFieldDescriptor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided a field descriptor instance', function test( t ) { + var values; + var bool; + var i; + + values = [ + new FieldDescriptor({ + 'datum': 'price' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + bool = isValueFieldDescriptor( values[ i ] ); + t.strictEqual( bool, true, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +}); + +tape( 'the function returns `false` if not provided a field descriptor 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 = isValueFieldDescriptor( values[ i ] ); + t.strictEqual( bool, false, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +});