From 40f15f4c6e53f705441d2da3d4f482780f5072d6 Mon Sep 17 00:00:00 2001 From: kaushiktak19 Date: Fri, 23 Feb 2024 21:01:23 +0530 Subject: [PATCH 01/12] adding main.js with core function --- lib/node_modules/@stdlib/assert/has-same-constructor/lib/main.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/node_modules/@stdlib/assert/has-same-constructor/lib/main.js 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..e69de29bb2d1 From 45fe0f9ea89bd6cc731bd0ea32e5998e78318d67 Mon Sep 17 00:00:00 2001 From: kaushiktak19 Date: Fri, 23 Feb 2024 21:04:40 +0530 Subject: [PATCH 02/12] adding index.js in lib --- .../assert/has-same-constructor/lib/index.js | 54 +++++++++++++++++++ .../assert/has-same-constructor/lib/main.js | 53 ++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/has-same-constructor/lib/index.js 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..64cb51b59f65 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/lib/index.js @@ -0,0 +1,54 @@ +/** +* @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(); +* console.log(hasSameConstructor(obj1, obj2)); +* // returns true, both are instances of Date +* +* @example +* var obj1 = new Date(); +* var obj3 = new String("Hello"); +* console.log(hasSameConstructor(obj1, obj3)); +* // returns false +* +* @example +* var obj3 = new String("Hello"); +* var obj4 = "World"; +* console.log(hasSameConstructor(obj3, obj4)); +* // returns true, one is String, the other is primitive string; but has same String constructor +*/ + +// 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 index e69de29bb2d1..d7ac528fb9ad 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/lib/main.js +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/lib/main.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'; + +// 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(); +* console.log(hasSameConstructor(obj1, obj2)); +* // returns true, both are instances of Date +* +* @example +* var obj1 = new Date(); +* var obj3 = new String("Hello"); +* console.log(hasSameConstructor(obj1, obj3)); +* // returns false +* +* @example +* var obj3 = new String("Hello"); +* var obj4 = "World"; +* console.log(hasSameConstructor(obj3, obj4)); +* // returns true, one is String, the other is primitive string; but has same String constructor +*/ + +function hasSameConstructor(a, b) { + return a && b && a.constructor === b.constructor; +} + +module.exports = hasSameConstructor; \ No newline at end of file From e9646fa1c97560acd2a4c8fa25836eea28fe2bcd Mon Sep 17 00:00:00 2001 From: kaushiktak19 Date: Fri, 23 Feb 2024 21:28:16 +0530 Subject: [PATCH 03/12] initializing package.json and adding benchmark file --- .../benchmark/benchmark.js | 92 +++++++++++++++++++ .../assert/has-same-constructor/package.json | 73 +++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/has-same-constructor/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/assert/has-same-constructor/package.json 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..bec4371bca97 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/benchmark/benchmark.js @@ -0,0 +1,92 @@ +/** +* @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'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pkg = require( './../package.json' ).name; +var hasSameConstructor = require( './../lib' ); + + +// MAIN // + +/** +* Benchmark the hasSameConstructor function when provided with same value types. +*/ +bench( pkg, function benchmark( b ) { + var obj1; + var obj2; + var bool; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj1 = new Date(); + obj2 = new Date(); + bool = hasSameConstructor( obj1, obj2 ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +/** +* Benchmark the hasSameConstructor function when provided with other value types. +*/ +bench( pkg+':other_types', function benchmark( b ) { + var obj1; + var obj2; + var obj3; + var obj4; + var bool; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj1 = new Date(); + obj2 = new Date(); + obj3 = new String( "Hello" ); + obj4 = "World"; + bool = hasSameConstructor( obj1, obj2 ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + bool = hasSameConstructor( obj1, obj3 ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + bool = hasSameConstructor( obj3, obj4 ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); 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..effcd9a5d478 --- /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" + ] +} + From 549425d1632029c194ee34a57ad9795f869f8d8a Mon Sep 17 00:00:00 2001 From: kaushiktak19 Date: Fri, 23 Feb 2024 21:33:35 +0530 Subject: [PATCH 04/12] adding index.js with examples in it --- .../@stdlib/assert/has-same-constructor/examples/index.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/node_modules/@stdlib/assert/has-same-constructor/examples/index.js 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..e69de29bb2d1 From c9018dd42a6dd724bfe656b89c689bb9fc0d4c8e Mon Sep 17 00:00:00 2001 From: kaushiktak19 Date: Fri, 23 Feb 2024 21:41:26 +0530 Subject: [PATCH 05/12] adding text.js file --- .../has-same-constructor/examples/index.js | 42 +++++++++ .../assert/has-same-constructor/test/tests.js | 87 +++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/has-same-constructor/test/tests.js 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 index e69de29bb2d1..43c69bc77341 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/examples/index.js +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/examples/index.js @@ -0,0 +1,42 @@ +/** +* @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 DateObject1 = new Date(); +var DateObject2 = new Date(); +var StringObject = new String("Hello"); +var StringPrimitive = "World"; + +console.log( hasSameConstructor( DateObject1, DateObject2 ) ); +// => true + +console.log( hasSameConstructor( DateObject1, StringObject ) ); +// => false + +console.log( hasSameConstructor( StringObject, StringPrimitive ) ); +// => true + +console.log( (function test() { + return hasSameConstructor( arguments, StringObject ); +})() ); +// => false \ No newline at end of file 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 000000000000..61f593a725ac --- /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, no-unused-vars */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasSameConstructor = require( './../main.js' ); // Importing the main function + + +// 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(); +}); From a30b853fb9d25f163461c42b1c0a878a710c2c6f Mon Sep 17 00:00:00 2001 From: kaushiktak19 Date: Fri, 23 Feb 2024 21:48:32 +0530 Subject: [PATCH 06/12] adding index.d.ts and tests.ts, i.e. typescript files for importing and running tests --- .../assert/has-same-constructor/docs/repl.txt | 0 .../docs/types/index.d.ts | 51 +++++++++++++++++++ .../has-same-constructor/docs/types/tests.ts | 34 +++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/has-same-constructor/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/assert/has-same-constructor/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/assert/has-same-constructor/docs/types/tests.ts 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..e69de29bb2d1 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..e60949fb4be5 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/docs/types/index.d.ts @@ -0,0 +1,51 @@ +/* +* @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(); +* console.log(hasSameConstructor(obj1, obj2)); +* // returns true, both are instances of Date +* +* @example +* var obj1 = new Date(); +* var obj3 = new String("Hello"); +* console.log(hasSameConstructor(obj1, obj3)); +* // returns false +* +* @example +* var obj3 = new String("Hello"); +* var obj4 = "World"; +* console.log(hasSameConstructor(obj3, obj4)); +* // returns true, one is String, the other is primitive string; but has same String constructor +*/ + +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 000000000000..55b0062ac0d1 --- /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 +// } + From d881d6129e72c13b129072034b5a1d5fe58171c8 Mon Sep 17 00:00:00 2001 From: kaushiktak19 Date: Fri, 23 Feb 2024 21:51:48 +0530 Subject: [PATCH 07/12] adding alias --- .../assert/has-same-constructor/docs/types/tests.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 index 55b0062ac0d1..e32696916c6c 100644 --- 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 @@ -27,8 +27,8 @@ import hasSameConstructor from './index'; } // 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 -// } +{ + hasSameConstructor(); // $ExpectError + hasSameConstructor(new Date(), new Date(), new Date()); // $ExpectError +} From d4b91056a3a8894d63892fc611f2ffee34720922 Mon Sep 17 00:00:00 2001 From: kaushiktak19 Date: Fri, 23 Feb 2024 21:55:25 +0530 Subject: [PATCH 08/12] adding readme.md --- lib/node_modules/@stdlib/assert/has-same-constructor/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/node_modules/@stdlib/assert/has-same-constructor/README.md 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..e69de29bb2d1 From a377318e0727bd842f8e436b57384c5c79140273 Mon Sep 17 00:00:00 2001 From: kaushiktak19 Date: Fri, 23 Feb 2024 22:01:58 +0530 Subject: [PATCH 09/12] update --- .../assert/has-same-constructor/README.md | 93 +++++++++++++++++++ .../assert/has-same-constructor/docs/repl.txt | 35 +++++++ 2 files changed, 128 insertions(+) diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/README.md b/lib/node_modules/@stdlib/assert/has-same-constructor/README.md index e69de29bb2d1..49fc8e077bbd 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/README.md +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/README.md @@ -0,0 +1,93 @@ + + +# hasSameConstructor + +> Test if two values have same constructor. + +
+ +## Usage + +```javascript +var isArrayLikeObject = require( '@stdlib/assert/has-same-constructor' ); +``` + +#### hasSameConstructor( value , value ) + +Tests if two values have same `constructor`. + + + +```javascript +> var obj1 = new Date(); + var obj2 = new Date(); + console.log(hasSameConstructor(obj1, obj2)); + true + + > var obj1 = new Date(); + var obj3 = new String("Hello"); + console.log(hasSameConstructor(obj1, obj3)); + false + + > var obj3 = new String("Hello"); + var obj4 = "World"; + console.log(hasSameConstructor(obj3, obj4)); + true +``` + +If provided with two values with different `constructors`, the function returns `false`. + +
+ + + +
+ +## Examples + + + + + +```javascript +var hasSameConstructor = require( './../lib' ); + +var DateObject1 = new Date(); +var DateObject2 = new Date(); +var StringObject = new String("Hello"); +var StringPrimitive = "World"; + +console.log( hasSameConstructor( DateObject1, DateObject2 ) ); +// => true + +console.log( hasSameConstructor( DateObject1, StringObject ) ); +// => false + +console.log( hasSameConstructor( StringObject, StringPrimitive ) ); +// => true + +console.log( (function test() { + return hasSameConstructor( arguments, StringObject ); +})() ); +// => false +``` + +
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 index e69de29bb2d1..000a3ce8d5ec 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/docs/repl.txt +++ 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(); + console.log({{alias}}(obj1, obj2)); + true + + > var obj1 = new Date(); + var obj3 = new String("Hello"); + console.log({{alias}}tor(obj1, obj3)); + false + + > var obj3 = new String("Hello"); + var obj4 = "World"; + console.log({{alias}}(obj3, obj4)); + true + + See Also + -------- + From 81c2e81eaed8856dd7f158ea84eeba1e9be6f94f Mon Sep 17 00:00:00 2001 From: kaushiktak19 Date: Fri, 23 Feb 2024 22:11:09 +0530 Subject: [PATCH 10/12] update readme --- lib/node_modules/@stdlib/assert/has-same-constructor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/README.md b/lib/node_modules/@stdlib/assert/has-same-constructor/README.md index 49fc8e077bbd..dca7cb84411d 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/README.md +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/README.md @@ -37,7 +37,7 @@ Tests if two values have same `constructor`. ```javascript -> var obj1 = new Date(); + > var obj1 = new Date(); var obj2 = new Date(); console.log(hasSameConstructor(obj1, obj2)); true From d97cacb38bac2c2d18409d487a95a0948f589c39 Mon Sep 17 00:00:00 2001 From: kaushiktak19 Date: Sat, 24 Feb 2024 12:42:19 +0530 Subject: [PATCH 11/12] required updates --- .../assert/has-same-constructor/README.md | 96 ++++++++++++------- .../benchmark/benchmark.js | 69 ++++--------- .../assert/has-same-constructor/docs/repl.txt | 6 +- .../docs/types/index.d.ts | 11 +-- .../has-same-constructor/examples/index.js | 26 ++--- .../assert/has-same-constructor/lib/index.js | 11 +-- .../assert/has-same-constructor/lib/main.js | 13 ++- .../assert/has-same-constructor/test/tests.js | 4 +- 8 files changed, 118 insertions(+), 118 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/README.md b/lib/node_modules/@stdlib/assert/has-same-constructor/README.md index dca7cb84411d..0e23f5187cb8 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/README.md +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/README.md @@ -27,67 +27,95 @@ limitations under the License. ## Usage ```javascript -var isArrayLikeObject = require( '@stdlib/assert/has-same-constructor' ); +var hasSameConstructor = require( '@stdlib/assert/has-same-constructor' ); ``` -#### hasSameConstructor( value , value ) +#### hasSameConstructor( v1, v2 ) -Tests if two values have same `constructor`. +Tests if two values have same constructor. - + ```javascript - > var obj1 = new Date(); - var obj2 = new Date(); - console.log(hasSameConstructor(obj1, obj2)); - true - - > var obj1 = new Date(); - var obj3 = new String("Hello"); - console.log(hasSameConstructor(obj1, obj3)); - false - - > var obj3 = new String("Hello"); - var obj4 = "World"; - console.log(hasSameConstructor(obj3, obj4)); - true +var obj1 = new Date(); +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 ``` -If provided with two values with different `constructors`, the function returns `false`. - +
## Examples - + ```javascript -var hasSameConstructor = require( './../lib' ); - -var DateObject1 = new Date(); -var DateObject2 = new Date(); -var StringObject = new String("Hello"); -var StringPrimitive = "World"; +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( DateObject1, DateObject2 ) ); +console.log( hasSameConstructor( DateObj1, DateObj2 ) ); // => true -console.log( hasSameConstructor( DateObject1, StringObject ) ); +console.log( hasSameConstructor( DateObj1, FloatArrObj ) ); // => false -console.log( hasSameConstructor( StringObject, StringPrimitive ) ); -// => true +console.log( hasSameConstructor( FloatArrObj , IntArrObj ) ); +// => false -console.log( (function test() { - return hasSameConstructor( arguments, StringObject ); -})() ); +console.log( 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 index bec4371bca97..d5f30163a5ac 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The stdlib Authors. +* Copyright (c) 2021 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. @@ -16,75 +16,48 @@ * 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 // -/** -* Benchmark the hasSameConstructor function when provided with same value types. -*/ bench( pkg, function benchmark( b ) { - var obj1; - var obj2; + var values; var bool; var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - obj1 = new Date(); - obj2 = new Date(); - bool = hasSameConstructor( obj1, obj2 ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -/** -* Benchmark the hasSameConstructor function when provided with other value types. -*/ -bench( pkg+':other_types', function benchmark( b ) { - var obj1; - var obj2; - var obj3; - var obj4; - 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++ ) { - obj1 = new Date(); - obj2 = new Date(); - obj3 = new String( "Hello" ); - obj4 = "World"; - bool = hasSameConstructor( obj1, obj2 ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - bool = hasSameConstructor( obj1, obj3 ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - bool = hasSameConstructor( obj3, obj4 ); + bool = hasSameConstructor( values[ i % values.length ], values[ (i+1) % values.length ] ); if ( typeof bool !== 'boolean' ) { b.fail( 'should return a boolean' ); } } b.toc(); - if ( typeof bool !== 'boolean' ) { + + if ( !isBoolean( bool ) ) { b.fail( 'should return a boolean' ); } b.pass( 'benchmark finished' ); 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 index 000a3ce8d5ec..804e7e366699 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/docs/repl.txt +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/docs/repl.txt @@ -17,17 +17,17 @@ -------- > var obj1 = new Date(); var obj2 = new Date(); - console.log({{alias}}(obj1, obj2)); + var bool = {{alias}}(obj1, obj2); true > var obj1 = new Date(); var obj3 = new String("Hello"); - console.log({{alias}}tor(obj1, obj3)); + bool = {{alias}}(obj1, obj3); false > var obj3 = new String("Hello"); var obj4 = "World"; - console.log({{alias}}(obj3, obj4)); + 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 index e60949fb4be5..e3d912675700 100644 --- 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 @@ -28,20 +28,19 @@ * @example * var obj1 = new Date(); * var obj2 = new Date(); -* console.log(hasSameConstructor(obj1, obj2)); -* // returns true, both are instances of Date -* +* var bool = hasSameConstructor(obj1, obj2); +* // returns true * @example * var obj1 = new Date(); * var obj3 = new String("Hello"); -* console.log(hasSameConstructor(obj1, obj3)); +* var bool = hasSameConstructor(obj1, obj3); * // returns false * * @example * var obj3 = new String("Hello"); * var obj4 = "World"; -* console.log(hasSameConstructor(obj3, obj4)); -* // returns true, one is String, the other is primitive string; but has same String constructor +* var bool = hasSameConstructor(obj3, obj4); +* // returns true */ declare function hasSameConstructor(a: any, b: any): boolean; 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 index 43c69bc77341..249a3a7e60ab 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/examples/index.js +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/examples/index.js @@ -21,22 +21,24 @@ '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 DateObject1 = new Date(); -var DateObject2 = new Date(); -var StringObject = new String("Hello"); -var StringPrimitive = "World"; +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( DateObject1, DateObject2 ) ); +console.log( hasSameConstructor( DateObj1, DateObj2 ) ); // => true -console.log( hasSameConstructor( DateObject1, StringObject ) ); +console.log( hasSameConstructor( DateObj1, FloatArrObj ) ); // => false -console.log( hasSameConstructor( StringObject, StringPrimitive ) ); -// => true +console.log( hasSameConstructor( FloatArrObj , IntArrObj ) ); +// => false -console.log( (function test() { - return hasSameConstructor( arguments, StringObject ); -})() ); -// => false \ No newline at end of file +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 index 64cb51b59f65..462a98ff4582 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/lib/index.js +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/lib/index.js @@ -28,20 +28,19 @@ * @example * var obj1 = new Date(); * var obj2 = new Date(); -* console.log(hasSameConstructor(obj1, obj2)); -* // returns true, both are instances of Date -* +* var bool = hasSameConstructor(obj1, obj2); +* // returns true * @example * var obj1 = new Date(); * var obj3 = new String("Hello"); -* console.log(hasSameConstructor(obj1, obj3)); +* var bool = hasSameConstructor(obj1, obj3); * // returns false * * @example * var obj3 = new String("Hello"); * var obj4 = "World"; -* console.log(hasSameConstructor(obj3, obj4)); -* // returns true, one is String, the other is primitive string; but has same String constructor +* var bool = hasSameConstructor(obj3, obj4); +* // returns true */ // MODULES // 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 index d7ac528fb9ad..9e4f77a1cabd 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/lib/main.js +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/lib/main.js @@ -30,24 +30,23 @@ * @example * var obj1 = new Date(); * var obj2 = new Date(); -* console.log(hasSameConstructor(obj1, obj2)); -* // returns true, both are instances of Date -* +* var bool = hasSameConstructor(obj1, obj2); +* // returns true * @example * var obj1 = new Date(); * var obj3 = new String("Hello"); -* console.log(hasSameConstructor(obj1, obj3)); +* var bool = hasSameConstructor(obj1, obj3); * // returns false * * @example * var obj3 = new String("Hello"); * var obj4 = "World"; -* console.log(hasSameConstructor(obj3, obj4)); -* // returns true, one is String, the other is primitive string; but has same String constructor +* var bool = hasSameConstructor(obj3, obj4); +* // returns true */ function hasSameConstructor(a, b) { return a && b && a.constructor === b.constructor; } -module.exports = hasSameConstructor; \ No newline at end of file +module.exports = hasSameConstructor; 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 index 61f593a725ac..c7be97b9f77a 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/test/tests.js +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/test/tests.js @@ -16,14 +16,14 @@ * limitations under the License. */ -/* eslint-disable object-curly-newline, no-unused-vars */ +/* eslint-disable object-curly-newline */ 'use strict'; // MODULES // var tape = require( 'tape' ); -var hasSameConstructor = require( './../main.js' ); // Importing the main function +var hasSameConstructor = require( './../lib' ); // TESTS // From 10d857cc9b8968588aaf8740f40bcb3847dd66d0 Mon Sep 17 00:00:00 2001 From: kaushiktak19 Date: Sat, 24 Feb 2024 13:01:56 +0530 Subject: [PATCH 12/12] additional changes --- .../@stdlib/assert/has-same-constructor/README.md | 10 +++++----- .../assert/has-same-constructor/benchmark/benchmark.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/has-same-constructor/README.md b/lib/node_modules/@stdlib/assert/has-same-constructor/README.md index 0e23f5187cb8..d751c5869aeb 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/README.md +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/README.md @@ -38,7 +38,7 @@ Tests if two values have same constructor. ```javascript var obj1 = new Date(); -obj2 = new Date(); +var obj2 = new Date(); var bool = hasSameConstructor(obj1, obj2); // returns true @@ -73,16 +73,16 @@ 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 ) ); +var bool = hasSameConstructor( DateObj1, DateObj2 ); // => true -console.log( hasSameConstructor( DateObj1, FloatArrObj ) ); +bool = hasSameConstructor( DateObj1, FloatArrObj ); // => false -console.log( hasSameConstructor( FloatArrObj , IntArrObj ) ); +bool = hasSameConstructor( FloatArrObj , IntArrObj ); // => false -console.log( hasSameConstructor( ComplexObj , IntArrObj ) ); +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 index d5f30163a5ac..c4e1afc10abe 100644 --- a/lib/node_modules/@stdlib/assert/has-same-constructor/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/assert/has-same-constructor/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2021 The Stdlib Authors. +* 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.