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 00000000000..d751c5869ae --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/README.md @@ -0,0 +1,121 @@ + + +# hasSameConstructor + +> Test if two values have same constructor. + +
+ +## Usage + +```javascript +var hasSameConstructor = require( '@stdlib/assert/has-same-constructor' ); +``` + +#### hasSameConstructor( v1, v2 ) + +Tests if two values have same constructor. + + + +```javascript +var obj1 = new Date(); +var obj2 = new Date(); +var bool = hasSameConstructor(obj1, obj2); +// returns true + +var obj1 = new Date(); +var obj3 = new String("Hello"); +bool = hasSameConstructor(obj1, obj3); +// returns false + +var obj3 = new String("Hello"); +var obj4 = "World"; +bool = hasSameConstructor(obj3, obj4); +// returns true +``` + +
+ + + + +
+ +## Examples + + + + + +```javascript +var DateObj1 = new Date(); +var DateObj2 = new Date(); +var FloatArrObj = new Float64Array( 10 ); +var IntArrObj = new Int32Array( [ 1, 2, 3 ] ); +var ComplexObj = new Complex64( 5.0, 3.0 ); + +var bool = hasSameConstructor( DateObj1, DateObj2 ); +// => true + +bool = hasSameConstructor( DateObj1, FloatArrObj ); +// => false + +bool = hasSameConstructor( FloatArrObj , IntArrObj ); +// => false + +bool = hasSameConstructor( ComplexObj , IntArrObj ); +// => 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 00000000000..c4e1afc10ab --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/benchmark/benchmark.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + new Date(), + function noop() {} + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = hasSameConstructor( values[ i % values.length ], values[ (i+1) % values.length ] ); + 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 00000000000..804e7e36669 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/docs/repl.txt @@ -0,0 +1,35 @@ +{{alias}}( value ) + Tests if two values have same constructor. + + If provided with two values with different constructors, the function returns `false`. + + Parameters + ---------- + value: any + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating whether two values have same constructor. + + Examples + -------- + > var obj1 = new Date(); + var obj2 = new Date(); + var bool = {{alias}}(obj1, obj2); + true + + > var obj1 = new Date(); + var obj3 = new String("Hello"); + bool = {{alias}}(obj1, obj3); + false + + > var obj3 = new String("Hello"); + var obj4 = "World"; + bool = {{alias}}(obj3, obj4); + true + + See Also + -------- + 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 00000000000..e3d91267570 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/docs/types/index.d.ts @@ -0,0 +1,50 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 {*} a - The first value to test. +* @param {*} b - The second value to test. +* @returns {boolean} Returns `true` if both values have the same constructor, else `false`. + +* @example +* var obj1 = new Date(); +* var obj2 = new Date(); +* var bool = hasSameConstructor(obj1, obj2); +* // returns true +* @example +* var obj1 = new Date(); +* var obj3 = new String("Hello"); +* var bool = hasSameConstructor(obj1, obj3); +* // returns false +* +* @example +* var obj3 = new String("Hello"); +* var obj4 = "World"; +* var bool = hasSameConstructor(obj3, obj4); +* // returns true +*/ + +declare function hasSameConstructor(a: any, b: any): boolean; + +// EXPORTS // + +export = hasSameConstructor; diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/docs/types/tests.ts b/lib/node_modules/@stdlib/assert/has-same-constructor/docs/types/tests.ts new file mode 100644 index 00000000000..e32696916c6 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/docs/types/tests.ts @@ -0,0 +1,34 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 from './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 00000000000..249a3a7e60a --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/examples/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Complex64 = require( '@stdlib/complex/float32' ); + +var DateObj1 = new Date(); +var DateObj2 = new Date(); +var FloatArrObj = new Float64Array( 10 ); +var IntArrObj = new Int32Array( [ 1, 2, 3 ] ); +var ComplexObj = new Complex64( 5.0, 3.0 ); + +console.log( hasSameConstructor( DateObj1, DateObj2 ) ); +// => true + +console.log( hasSameConstructor( DateObj1, FloatArrObj ) ); +// => false + +console.log( hasSameConstructor( FloatArrObj , IntArrObj ) ); +// => false + +console.log( hasSameConstructor( ComplexObj , IntArrObj ) ); +// => 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 00000000000..462a98ff458 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/lib/index.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* +* @param {*} a - The first value to test. +* @param {*} b - The second value to test. +* @returns {boolean} Returns `true` if both values have the same constructor, else `false`. +* +* @example +* var obj1 = new Date(); +* var obj2 = new Date(); +* var bool = hasSameConstructor(obj1, obj2); +* // returns true +* @example +* var obj1 = new Date(); +* var obj3 = new String("Hello"); +* var bool = hasSameConstructor(obj1, obj3); +* // returns false +* +* @example +* var obj3 = new String("Hello"); +* var obj4 = "World"; +* var bool = hasSameConstructor(obj3, obj4); +* // 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 00000000000..9e4f77a1cab --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/lib/main.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 {*} a - The first value to test. +* @param {*} b - The second value to test. +* @returns {boolean} Returns `true` if both values have the same constructor, else `false`. +* +* @example +* var obj1 = new Date(); +* var obj2 = new Date(); +* var bool = hasSameConstructor(obj1, obj2); +* // returns true +* @example +* var obj1 = new Date(); +* var obj3 = new String("Hello"); +* var bool = hasSameConstructor(obj1, obj3); +* // returns false +* +* @example +* var obj3 = new String("Hello"); +* var obj4 = "World"; +* var bool = hasSameConstructor(obj3, obj4); +* // returns true +*/ + +function hasSameConstructor(a, b) { + return a && b && a.constructor === b.constructor; +} + +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 00000000000..effcd9a5d47 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/assert/is-array-like-object", + "version": "0.0.0", + "description": "Test if a value is an array-like object.", + "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", + "stdassert", + "assertion", + "assert", + "utilities", + "utility", + "utils", + "util", + "array", + "array-like", + "is", + "isarraylike", + "object", + "obj", + "type", + "check", + "test", + "validate", + "isvalid" + ] +} + diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/test/tests.js b/lib/node_modules/@stdlib/assert/has-same-constructor/test/tests.js new file mode 100644 index 00000000000..c7be97b9f77 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/test/tests.js @@ -0,0 +1,87 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasSameConstructor = require( './../lib' ); + + +// TESTS // + +tape( 'the main export is a function', function test( t ) { + t.strictEqual( typeof hasSameConstructor, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided values with the same constructor', function test( t ) { + var values; + var i; + + values = [ + { value: new Date(), desc: 'Date objects' }, + { value: new String("Hello"), desc: 'String objects' }, + { value: new Boolean(true), desc: 'Boolean objects' }, + { value: new Number(3.14), desc: 'Number objects' }, + { value: new RegExp("\\w+"), desc: 'RegExp objects' } + ]; + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( hasSameConstructor( values[i].value, values[i].value ), true, 'returns true when provided ' + values[i].desc ); + } + t.end(); +}); + +tape( 'the function returns `false` if provided values with different constructors', function test( t ) { + var values; + var i; + + values = [ + { value1: new Date(), value2: "Not a Date object", desc: 'Date objects and string primitive' }, + { value1: new String("Hello"), value2: "World", desc: 'String objects and string primitive' }, + { value1: new Boolean(true), value2: false, desc: 'Boolean objects and boolean primitive' }, + { value1: new Number(3.14), value2: 42, desc: 'Number objects and number primitive' }, + { value1: new RegExp("\\w+"), value2: {}, desc: 'RegExp objects and object' } + ]; + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( hasSameConstructor( values[i].value1, values[i].value2 ), false, 'returns false when provided ' + values[i].desc ); + } + t.end(); +}); + +tape( 'the function returns `false` if provided values with one or both being `null` or `undefined`', function test( t ) { + t.strictEqual( hasSameConstructor( null, null ), false, 'returns false when provided null' ); + t.strictEqual( hasSameConstructor( null, undefined ), false, 'returns false when provided null and undefined' ); + t.strictEqual( hasSameConstructor( undefined, undefined ), false, 'returns false when provided undefined' ); + t.end(); +}); + +tape( 'the function returns `false` if provided values with one or both being primitive values', function test( t ) { + t.strictEqual( hasSameConstructor( 5, 5 ), false, 'returns false when provided two integer primitives' ); + t.strictEqual( hasSameConstructor( "foo", "bar" ), false, 'returns false when provided two string primitives' ); + t.strictEqual( hasSameConstructor( true, false ), false, 'returns false when provided two boolean primitives' ); + t.strictEqual( hasSameConstructor( 3.14, 2.718 ), false, 'returns false when provided two floating point primitives' ); + t.strictEqual( hasSameConstructor( null, 5 ), false, 'returns false when provided null and an integer primitive' ); + t.strictEqual( hasSameConstructor( undefined, "bar" ), false, 'returns false when provided undefined and a string primitive' ); + t.end(); +});