diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/README.md b/lib/node_modules/@stdlib/assert/has-same-constructor/README.md new file mode 100644 index 000000000000..80210213e841 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/README.md @@ -0,0 +1,138 @@ + + +# hasSameConstructor + +> Test whether two provided arguments have the same constructor. + +
+ +## Usage + +```javascript +var hasSameConstructor = require( '@stdlib/assert/has-same-constructor' ); +``` + +#### hasSameConstructor( x, y ) + +Tests if two arguments `x` and `y` have the same constructor. + +```javascript +var bool = hasSameConstructor( 5, 10 ); +// returns true + +bool = hasSameConstructor( 5, [] ); +// returns false + +bool = hasSameConstructor( [], [] ); +// returns true +``` + +
+ + + +
+ +## Notes + +- The function does **not** throw when provided `null` or `undefined`. Instead, the function returns `false`. + + ```javascript + var bool = hasSameConstructor(null, 5); + // returns false + + bool = hasSameConstructor(void 0, 5); + // returns false + ``` + +- Value arguments other than `null` or `undefined` are coerced to `objects`. + + ```javascript + var bool = hasSameConstructor( 'beep', 'length' ); + // returns true + ``` + +
+ + + +
+ +## Examples + + + + + +```javascript +var hasSameConstructor = require( '@stdlib/assert/has-same-constructor' ); + +var bool = hasSameConstructor([1, 2, 3], ['a', 'b', 'c']); +// returns true + +bool = hasSameConstructor([1, 2, 3], { 'key': 'value' }); +// returns false + +bool = hasSameConstructor({ 'name': 'Alice' }, { 'age': 30 }); +// returns true + +bool = hasSameConstructor({'name': 'Alice' }, new Date()); +// returns false + +bool = hasSameConstructor( new Date(), new Date() ); +// returns true + +bool = hasSameConstructor( null, { 'name': 'Alice' } ); +// returns false + +bool = hasSameConstructor( void 0, [1, 2, 3] ); +// returns false + +bool = hasSameConstructor( 42, 3.14 ); +// returns true + +bool = hasSameConstructor( 42, 'Hello' ); +// returns false +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/has-same-constructor/benchmark/benchmark.js new file mode 100644 index 000000000000..a1973456fed9 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable no-empty-function */ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var hasSameConstructor = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var bool; + var x; + var y; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + new Date(), + function noop() {} + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x = values[ i%values.length ]; + y = values[ (i+1)%values.length ]; + bool = hasSameConstructor( x, y ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/docs/repl.txt b/lib/node_modules/@stdlib/assert/has-same-constructor/docs/repl.txt new file mode 100644 index 000000000000..48e52abbb099 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/docs/repl.txt @@ -0,0 +1,28 @@ + +{{alias}}( x, y ) + Tests if two values have the same constructor. + + Parameters + ---------- + x: any + First input value. + + y: any + Second input value. + + Returns + ------- + bool: boolean + Boolean indicating whether two arguments have the same constructor. + + Examples + -------- + > var bool = {{alias}}( new Date(), new Date() ); + true + > bool = {{alias}}( new Date(), 'Hello'); + false + > bool = {{alias}}(new String('Hello'), 'World'); + true + + See Also + -------- \ No newline at end of file diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/has-same-constructor/docs/types/index.d.ts new file mode 100644 index 000000000000..18a9ec11b708 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/docs/types/index.d.ts @@ -0,0 +1,45 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 + +/** +* Test whether two provided values have the same constructor. +* +* @param x - first input value +* @param y - second input value +* @returns boolean indicating whether two arguments have the same constructor +* +* @example +* var bool = hasSameConstructor(new Date(), new Date()); +* // returns true +* +* @example +* var bool = hasSameConstructor("Hello", new Date()); +* // returns false +* +* @example +* var bool = hasSameConstructor(new String("Hello"), "World"); +* // returns true +*/ +declare function hasSameConstructor( x: any, y: any ): boolean; + + +// EXPORTS // + +export = hasSameConstructor; diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/docs/types/test.ts b/lib/node_modules/@stdlib/assert/has-same-constructor/docs/types/test.ts new file mode 100644 index 000000000000..14bf7ed72c37 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/docs/types/test.ts @@ -0,0 +1,34 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 hasSameConstructor = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + hasSameConstructor( new Date(), new String('Hello' ) ); // $ExpectType boolean + hasSameConstructor( new String('Hello'), 'World' ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + hasSameConstructor(); // $ExpectError + hasSameConstructor( new Date(), new Date(), new Date() ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/examples/index.js b/lib/node_modules/@stdlib/assert/has-same-constructor/examples/index.js new file mode 100644 index 000000000000..0c2964f5b36e --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/examples/index.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable object-curly-newline, no-empty-function, no-restricted-syntax */ + +'use strict'; + +var hasSameConstructor = require( './../lib' ); + +var bool = hasSameConstructor([1, 2, 3], ['a', 'b', 'c']); +console.log( bool ); +// => true + +bool = hasSameConstructor([1, 2, 3], { key: 'value' }); +console.log( bool ); +// => false + +bool = hasSameConstructor({ name: 'Alice' }, { age: 30 }); +console.log( bool ); +// => true + +bool = hasSameConstructor({ name: 'Alice' }, new Date()); +console.log( bool ); +// => false + +bool = hasSameConstructor( new Date(), new Date() ); +console.log( bool ); +// => true + +bool = hasSameConstructor(null, { name: 'Alice' }); +console.log( bool ); +// => false + +bool = hasSameConstructor(undefined, [1, 2, 3]); +console.log( bool ); +// => false + +bool = hasSameConstructor( 42, 3.14 ); +console.log( bool ); +// => true + +bool = hasSameConstructor( 42, 'Hello' ); +console.log( bool ); +// => false + +bool = hasSameConstructor(function () {}, () => {}); +console.log( bool ); +// => true diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/lib/index.js b/lib/node_modules/@stdlib/assert/has-same-constructor/lib/index.js new file mode 100644 index 000000000000..ee1ce1c5dbe8 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/lib/index.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 two provided values have the same constructor. +* +* @module @stdlib/assert/has-same-constructor +* +* @example +* var hasSameConstructor = require( '@stdlib/assert/has-same-constructor' ); +* +* var bool = hasSameConstructor( new Number(5), new Number(10) ); +* // returns true +* +* bool = hasSameConstructor( new Number(5), [] ); +* // returns false +* +* bool = hasSameConstructor( [], [] ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/lib/main.js b/lib/node_modules/@stdlib/assert/has-same-constructor/lib/main.js new file mode 100644 index 000000000000..9f267a024525 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/lib/main.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +// MAIN // + +/** +* Test whether two provided values have the same constructor. +* +* @param {*} x - first input value +* @param {*} y - second input value +* @returns {boolean} boolean indicating whether two arguments have the same native class +* +* @example +* var bool = hasSameConstructor( new Number(5), new Number(10) ); +* // returns true +* +* @example +* var bool = hasSameConstructor( new Number(5), [] ); +* // returns false +* +* @example +* var bool = hasSameConstructor( [], [] ); +* // returns true +*/ +function hasSameConstructor( x, y ) { + if ( x === null || y === null ) { + return false; + } + return x.constructor === y.constructor; +} + + +// EXPORTS // + +module.exports = hasSameConstructor; diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/package.json b/lib/node_modules/@stdlib/assert/has-same-constructor/package.json new file mode 100644 index 000000000000..7ebe5be0560a --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/assert/has-same-constructor", + "version": "0.0.0", + "description": "Check if two values have the same constructor.", + "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": "https://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdassert", + "assertion", + "assert", + "utilities", + "utility", + "utils", + "util", + "object", + "obj", + "has", + "hasown", + "hasownproperty", + "property", + "prop", + "test", + "check", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/test/test.js b/lib/node_modules/@stdlib/assert/has-same-constructor/test/test.js new file mode 100644 index 000000000000..cc8d3f2a4c77 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/test/test.js @@ -0,0 +1,76 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 hasSameConstructor = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof hasSameConstructor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided two arguments which have the same constructor', function test ( t ) { + var values; + var bool; + var i; + + values =[ + [ true, false ], + [ 1.0, 3.1 ], + [ new Number( 1.0 ), 3.1 ], + [ new Number( 0.0 ), new Number( 0.0 ) ], + [ new String( 'abc' ), 'abc' ], + [ JSON, Math ], + [ NaN, NaN ], + [ function() {}, () => {} ] + + ]; + + for ( i = 0; i < values.length; i++ ) { + bool = hasSameConstructor( values[ i ][ 0 ], values[ i ][ 1 ] ); + t.strictEqual( bool, true, 'returns true' ); + } + t.end(); +}); + +tape( 'the function returns `false` if not provided two arguments having the same constructor', function test( t ) { + var values; + var bool; + var i; + + values = [ + [ 1.0, '1.0' ], + [ null, null ], + [ [], {} ], + [ null, void 0 ], + ]; + + for ( i = 0; i < values.length; i++ ) { + bool = hasSameConstructor( values[ i ][ 0 ], values[ i ][ 1 ] ); + t.strictEqual( bool, false, 'returns false' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/assert/package.json b/lib/node_modules/@stdlib/assert/package.json index 6315d06dcd31..745d14cd6c9d 100644 --- a/lib/node_modules/@stdlib/assert/package.json +++ b/lib/node_modules/@stdlib/assert/package.json @@ -30,8 +30,10 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": {}, - "devDependencies": {}, + "dependencies": { + "doctest": "^0.21.0", + "tape": "^5.9.0" + }, "engines": { "node": ">=0.10.0", "npm": ">2.7.0"