From 0c47250f0789e3b01c308b9daf8a67f757769ace Mon Sep 17 00:00:00 2001 From: Shubham Singh Date: Tue, 27 Feb 2024 04:06:53 +0530 Subject: [PATCH 1/4] feat: added `is-non-positive-finite` --- .../assert/is-nonpositive-finite/README.md | 166 +++++++++++++ .../benchmark/benchmark.js | 220 ++++++++++++++++++ .../is-nonpositive-finite/examples/index.js | 51 ++++ .../assert/is-nonpositive-finite/lib/index.js | 55 +++++ .../assert/is-nonpositive-finite/lib/main.js | 57 +++++ .../is-nonpositive-finite/lib/object.js | 51 ++++ .../is-nonpositive-finite/lib/primitive.js | 50 ++++ .../assert/is-nonpositive-finite/package.json | 71 ++++++ .../assert/is-nonpositive-finite/test/test.js | 43 ++++ .../is-nonpositive-finite/test/test.main.js | 64 +++++ .../is-nonpositive-finite/test/test.object.js | 67 ++++++ .../test/test.primitive.js | 64 +++++ 12 files changed, 959 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/README.md create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/examples/index.js create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/index.js create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/main.js create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/object.js create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/primitive.js create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/package.json create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.js create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.main.js create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.object.js create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.primitive.js diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/README.md b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/README.md new file mode 100644 index 000000000000..1b1765138258 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/README.md @@ -0,0 +1,166 @@ + + +# isNonPositiveFinite + +> Test if a value is a number having a nonpositive finite value. + +
+ +## Usage + +```javascript +var isNonPositiveFinite = require( '@stdlib/assert/is-nonpositive-finite' ); +``` + +#### isNonPositiveFinite( value ) + +Tests if a `value` is a `number` having a nonpositive finite value. + + + +```javascript +var Number = require( '@stdlib/number/ctor' ); +var NINF = require('@stdlib/constants/float64/ninf'); + +var bool = isNonPositiveFinite( -5.0 ); +// returns true + +bool = isNonPositiveFinite(NINF); +// returns false + +bool = isNonPositiveFinite( new Number( -5.0 ) ); +// returns true + +bool = isNonPositiveFinite( -3.14 ); +// returns true + +bool = isNonPositiveFinite( 5.0 ); +// returns false + +bool = isNonPositiveFinite( null ); +// returns false +``` + +#### isNonPositiveFinite.isPrimitive( value ) + +Tests if a `value` is a primitive `number` having a nonpositive finite value. + + + +```javascript +var Number = require( '@stdlib/number/ctor' ); + +var bool = isNonPositiveFinite.isPrimitive( -3.0 ); +// returns true + +bool = isNonPositiveFinite.isPrimitive( new Number( -3.0 ) ); +// returns false +``` + +#### isNonPositiveFinite.isObject( value ) + +Tests if a `value` is a `Number` object having a nonpositive finite value. + + + +```javascript +var Number = require( '@stdlib/number/ctor' ); + +var bool = isNonPositiveFinite.isObject( -3.0 ); +// returns false + +bool = isNonPositiveFinite.isObject( new Number( -3.0 ) ); +// returns true +``` + +
+ + + +
+ +## Examples + + + + + +```javascript +var Number = require( '@stdlib/number/ctor' ); +var isNonPositiveFinite = require( '@stdlib/assert/is-nonpositive-finite' ); +var NINF = require('@stdlib/constants/float64/ninf'); + +var bool = isNonPositiveFinite( -5.0 ); +// returns true + +bool = isNonPositiveFinite(NINF); +// returns false + +bool = isNonPositiveFinite( new Number( -5.0 ) ); +// returns true + +bool = isNonPositiveFinite( 0.0 ); +// returns true + +bool = isNonPositiveFinite( -3.14 ); +// returns true + +bool = isNonPositiveFinite( 5.0 ); +// returns false + +bool = isNonPositiveFinite( '-5' ); +// returns false + +bool = isNonPositiveFinite( null ); +// returns false +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/benchmark/benchmark.js new file mode 100644 index 000000000000..3234fee210f2 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/benchmark/benchmark.js @@ -0,0 +1,220 @@ +/** +* @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-undefined, no-empty-function */ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var Number = require( '@stdlib/number/ctor' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var isNonPositiveFinite = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::primitives', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + '5', + 5.0, + 4.0, + 3.14, + -5.0, + -4.0, + NaN, + true, + false, + null + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonPositiveFinite( values[ i % 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(); +}); + +bench( pkg+'::objects', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + [], + {}, + function noop() {}, + new Number( 2.0 ), + new Number( -3.0 ), + new Number( 3.14 ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonPositiveFinite( values[ i % 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(); +}); + +bench( pkg+'::primitives:isPrimitive', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + '5', + 5.0, + 4.0, + 3.14, + -5.0, + -4.0, + NaN, + true, + false, + null, + undefined + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonPositiveFinite.isPrimitive( values[ i % 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(); +}); + +bench( pkg+'::objects:isPrimitive', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + [], + {}, + function noop() {}, + new Number( 2.0 ), + new Number( -3.0 ), + new Number( 3.14 ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonPositiveFinite.isPrimitive( values[ i % 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(); +}); + +bench( pkg+'::primitives:isObject', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + '5', + 5.0, + 4.0, + 3.14, + -5.0, + -4.0, + NaN, + true, + false, + null, + undefined + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonPositiveFinite.isObject( values[ i % 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(); +}); + +bench( pkg+'::objects:isObject', function benchmark( b ) { + var values; + var bool; + var i; + + values = [ + [], + {}, + function noop() {}, + new Number( 2.0 ), + new Number( -3.0 ), + new Number( 3.14 ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonPositiveFinite.isObject( values[ i % 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/is-nonpositive-finite/examples/index.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/examples/index.js new file mode 100644 index 000000000000..41fd706bb9c7 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/examples/index.js @@ -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. +*/ + +/* eslint-disable no-empty-function, no-restricted-syntax */ + +'use strict'; + +var NINF = require('@stdlib/constants/float64/ninf'); +var isNonPositiveFinite = require( './../lib' ); + +console.log( isNonPositiveFinite( -2 )); +// => true + +console.log( isNonPositiveFinite( -2.99 )); +// => true + +console.log(isNonPositiveFinite(NINF)); +// => false + +console.log( isNonPositiveFinite( 'beep' ) ); +// => false + +console.log( isNonPositiveFinite( null ) ); +// => false + +console.log( isNonPositiveFinite( 5 ) ); +// => false + +console.log( isNonPositiveFinite( true ) ); +// => false + +console.log( isNonPositiveFinite( {} ) ); +// => false + +console.log( isNonPositiveFinite( function beep() {} ) ); +// => false diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/index.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/index.js new file mode 100644 index 000000000000..41a6cecca1ca --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/index.js @@ -0,0 +1,55 @@ +/** +* @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 if a value is a ragged nested array. +* +* @module @stdlib/assert/is-nonpositive-finite +* +* @example +* var isNonPositiveFinite = require( '@stdlib/assert/is-nonpositive-finite' ); +* +* var bool = isNonPositiveFinite(-2); +* // returns true +* +* bool = isNonPositiveFinite(3); +* // returns false +* +* bool = isNonPositiveFinite('beep'); +* // returns false +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var isPrimitive = require( './primitive.js' ); +var isObject = require( './object.js' ); + + +// MAIN // + +setReadOnly( main, 'isPrimitive', isPrimitive ); +setReadOnly( main, 'isObject', isObject ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/main.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/main.js new file mode 100644 index 000000000000..0d0ef87cda11 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/main.js @@ -0,0 +1,57 @@ +/** +* @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-unused-vars */ +'use strict'; + +// MODULES // + +var NINF = require('@stdlib/constants/float64/ninf'); +var isPrimitive = require( './primitive.js' ); +var isObject = require( './object.js' ); + + +// MAIN // + +/** +* Tests if a value is a number object has a non positive finite value. +* +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is non positive finite +* +* @example +* var bool = isNonPositiveFinite( -3.0 ); +* // returns true +* +* @example +* var bool = isNonPositiveFinite( new Number( -3.0 ) ); +* // returns true +* +* @example +* var bool = isNonPositiveFinite(NINF); +* // returns false +*/ +function isNonPositiveFinite( value ) { + return ( + isPrimitive(value) || isObject(value)); +} + + +// EXPORTS // + +module.exports = isNonPositiveFinite; diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/object.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/object.js new file mode 100644 index 000000000000..5e7fe712c127 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/object.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 NINF = require('@stdlib/constants/float64/ninf'); +var isNumber = require( '@stdlib/assert/is-number' ).isObject; + + +// MAIN // + +/** +* Tests if a value is a number object has a non positive finite value. +* +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is non positive finite +* +* @example +* var bool = isNonPositiveFinite( -3.0 ); +* // returns false +* +* @example +* var bool = isNonPositiveFinite( new Number( -3.0 ) ); +* // returns true +*/ +function isNonPositiveFinite( value ) { + return ( + isNumber( value ) && value.valueOf() <=0 && value.valueOf() !== NINF); +} + + +// EXPORTS // + +module.exports = isNonPositiveFinite; diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/primitive.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/primitive.js new file mode 100644 index 000000000000..326bf5062e17 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/primitive.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 NINF = require('@stdlib/constants/float64/ninf'); +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; + + +// MAIN // + +/** +* Tests if a value is a number primitive has a non positive finite value. +* +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is non positive finite +* +* @example +* var bool = isNonPositiveFinite( -3.0 ); +* // returns true +* +* @example +* var bool = isNonPositiveFinite( new Number( -3.0 ) ); +* // returns false +*/ +function isNonPositiveFinite( value ) { + return (isNumber( value ) && value <=0 && value !== NINF); +} + + +// EXPORTS // + +module.exports = isNonPositiveFinite; diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/package.json b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/package.json new file mode 100644 index 000000000000..1a04748f6126 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/assert/is-nonpositive-finite", + "version": "0.0.0", + "description": "Test if a value is a number having a nonpositive finite value.", + "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", + "number", + "numeric", + "nonpositive", + "is", + "isnumber", + "isnumeric", + "type", + "check", + "primitive", + "object" + ] + } \ No newline at end of file diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.js new file mode 100644 index 000000000000..cdbe481617b6 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 isNonPositiveFinite = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isNonPositiveFinite, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method to test for a primitive number having a nonpositive number value', function test( t ) { + t.equal( typeof isNonPositiveFinite.isPrimitive, 'function', 'export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method to test for a number object having a nonpositive number value', function test( t ) { + t.equal( typeof isNonPositiveFinite.isObject, 'function', 'export is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.main.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.main.js new file mode 100644 index 000000000000..08544f3fd113 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.main.js @@ -0,0 +1,64 @@ +/** +* @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 tape = require( 'tape' ); +var NINF = require('@stdlib/constants/float64/ninf'); +var Number = require( '@stdlib/number/ctor' ); +var isNonPositiveFinite = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isNonPositiveFinite, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided a number having a nonpositive finite number value', function test( t ) { + t.equal( isNonPositiveFinite( -5.0 ), true, 'returns true' ); + t.equal( isNonPositiveFinite( new Number( -5.0 ) ), true, 'returns true' ); + t.end(); +}); + +tape( 'the function returns `false` if not provided a number having a nonpositive finite number value', function test( t ) { + var values; + var i; + + values = [ + '5', + 3.14, + NINF, + 1.0, + null, + true, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.equal( isNonPositiveFinite( values[i] ), false, 'returns false when provided '+values[i] ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.object.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.object.js new file mode 100644 index 000000000000..d74803bbbaad --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.object.js @@ -0,0 +1,67 @@ +/** +* @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 tape = require( 'tape' ); +var Number = require( '@stdlib/number/ctor' ); +var isNonPositiveFinite = require( './../lib/object.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isNonPositiveFinite, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided a number object having a nonpositive finite number value', function test( t ) { + t.equal( isNonPositiveFinite( new Number( -5.0 ) ), true, 'returns true' ); + t.end(); +}); + +tape( 'the function returns `false` if provided a primitive number, even if the number is a nonpositive finite number value', function test( t ) { + t.equal( isNonPositiveFinite( -3.0 ), false, 'returns false' ); + t.end(); +}); + +tape( 'the function returns `false` if not provided a number', function test( t ) { + var values; + var i; + + values = [ + '5', + null, + true, + void 0, + [], + {}, + new Date(), + /./, + new RegExp( '.' ), // eslint-disable-line prefer-regex-literals + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.equal( isNonPositiveFinite( values[i] ), false, 'returns false when provided '+values[i] ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.primitive.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.primitive.js new file mode 100644 index 000000000000..24af87b95bc6 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.primitive.js @@ -0,0 +1,64 @@ +/** +* @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 tape = require( 'tape' ); +var Number = require( '@stdlib/number/ctor' ); +var isNonPositiveFinite = require( './../lib/primitive.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isNonPositiveFinite, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided a primitive number having a nonpositive finite number value', function test( t ) { + t.equal( isNonPositiveFinite( -3.0 ), true, 'returns true' ); + t.end(); +}); + +tape( 'the function returns `false` if provided a number object, even if the number has a nonpositive finite number value', function test( t ) { + t.equal( isNonPositiveFinite( new Number( -5.0 ) ), false, 'returns false' ); + t.end(); +}); + +tape( 'the function returns `false` if not provided a number', function test( t ) { + var values; + var i; + + values = [ + '-5', + null, + true, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.equal( isNonPositiveFinite( values[i] ), false, 'returns false when provided '+values[i] ); + } + t.end(); +}); From 5d6e3c965029e61ed324c75c218baa1e7f2d72ed Mon Sep 17 00:00:00 2001 From: Shubham Singh Date: Tue, 27 Feb 2024 04:12:17 +0530 Subject: [PATCH 2/4] feat: added `repl.txt` in `is-nonpositive-finite` --- .../is-nonpositive-finite/docs/repl.txt | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/repl.txt diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/repl.txt b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/repl.txt new file mode 100644 index 000000000000..86baa02ff13c --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/repl.txt @@ -0,0 +1,75 @@ + +{{alias}}( value ) + Tests if a value is a nonpositive finite number. + + Parameters + ---------- + value: any + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating whether value is a nonpositive finite number. + + Examples + -------- + > var bool = {{alias}}( -5.0 ) + true + > bool = {{alias}}( new Number( -5.0 ) ) + true + > bool = {{alias}}( -3.14 ) + true + > bool = {{alias}}( 5.0 ) + false + > bool = {{alias}}( null ) + false + + +{{alias}}.isPrimitive( value ) + Tests if a value is a number primitive having a nonpositive finite value. + + Parameters + ---------- + value: any + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating whether value is a number primitive having a + nonpositive finite value. + + Examples + -------- + > var bool = {{alias}}.isPrimitive( -3.0 ) + true + > bool = {{alias}}.isPrimitive( new Number( -3.0 ) ) + false + + +{{alias}}.isObject( value ) + Tests if a value is a number object having a nonpositive finite value. + + Parameters + ---------- + value: any + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating whether value is a number object having a nonpositive + finite value. + + Examples + -------- + > var bool = {{alias}}.isObject( -3.0 ) + false + > bool = {{alias}}.isObject( new Number( -3.0 ) ) + true + + + See Also + -------- + From 01831ef3a181663dcc11131a839862772cad753e Mon Sep 17 00:00:00 2001 From: Shubham Singh Date: Tue, 27 Feb 2024 04:20:59 +0530 Subject: [PATCH 3/4] feat: added types in `docs` in `is-nonpositive-finite` --- .../docs/types/index.d.ts | 126 ++++++++++++++++++ .../is-nonpositive-finite/docs/types/test.ts | 61 +++++++++ 2 files changed, 187 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/index.d.ts new file mode 100644 index 000000000000..4150a5462b26 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/index.d.ts @@ -0,0 +1,126 @@ +/* +* @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 + +/** +* Interface defining `isNonPositiveFinite` with methods for testing for primitives and objects, respectively. +*/ + +interface IsNonPositiveFinite { + /** + * Tests if a value is a nonpositive finite number. + * + * @param value - value to test + * @returns boolean indicating whether value is a nonpositive finite number + * + * @example + * var bool = isNonPositiveFinite( -5.0 ); + * // returns true + * + * @example + * var bool = isNonPositiveFinite( new Number( -5.0 ) ); + * // returns true + * + * @example + * var bool = isNonPositiveFinite( -3.14 ); + * // returns true + * + * @example + * var bool = isNonPositiveFinite( 5.0 ); + * // returns false + * + * @example + * var bool = isNonPositiveFinite( null ); + * // returns false + */ + ( value: any ): value is number | Number; + + /** + * Tests if a value is a number primitive having a nonpositive finite value. + * + * @param value - value to test + * @returns boolean indicating if a value is a number primitive having a nonpositive finite number value + * + * @example + * var bool = isNonPositiveFinite.isPrimitive( -3.0 ); + * // returns true + * + * @example + * var bool = isNonPositiveFinite.isPrimitive( new Number( -3.0 ) ); + * // returns false + */ + isPrimitive( value: any ): value is number; + + /** + * Tests if a value is a number object having a nonpositive finite value. + * + * @param value - value to test + * @returns boolean indicating if a value is a number object having a nonpositive number value + * + * @example + * var bool = isNonPositiveFinite.isObject( -3.0 ); + * // returns false + * + * @example + * var bool = isNonPositiveFinite.isObject( new Number( -3.0 ) ); + * // returns true + */ + isObject( value: any ): value is Number; +} + +/** +* Tests if a value is a nonpositive finite number. +* +* @param value - value to test +* @returns boolean indicating whether value is a nonpositive finite number +* +* @example +* var bool = isNonPositiveFinite( -5.0 ); +* // returns true +* +* @example +* var bool = isNonPositiveFinite( new Number( -5.0 ) ); +* // returns true +* +* @example +* var bool = isNonPositiveFinite( -3.14 ); +* // returns true +* +* @example +* var bool = isNonPositiveFinite( 5.0 ); +* // returns false +* +* @example +* var bool = isNonPositiveFinite( null ); +* // returns false +* +* @example +* var bool = isNonPositiveFinite.isPrimitive( -3.0 ); +* // returns true +* +* @example +* var bool = isNonPositiveFinite.isObject( new Number( -3.0 ) ); +* // returns true +*/ +declare var isNonPositiveFinite: IsNonPositiveFinite; + + +// EXPORTS // + +export = isNonPositiveFinite; diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/test.ts b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/test.ts new file mode 100644 index 000000000000..52379dca826f --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/test.ts @@ -0,0 +1,61 @@ +/* +* @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 isNonPositiveFinite = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isNonPositiveFinite( 1.2 ); // $ExpectType boolean + isNonPositiveFinite( -3 ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isNonPositiveFinite(); // $ExpectError + isNonPositiveFinite( -2, 123 ); // $ExpectError +} + +// Attached to main export is an isPrimitive method which returns a boolean... +{ + // eslint-disable-next-line no-new-wrappers + isNonPositiveFinite.isPrimitive( new Number( -2 ) ); // $ExpectType boolean + isNonPositiveFinite.isPrimitive( -2 ); // $ExpectType boolean +} + +// The compiler throws an error if the isPrimitive method is provided an unsupported number of arguments... +{ + isNonPositiveFinite.isPrimitive(); // $ExpectError + isNonPositiveFinite.isPrimitive( -2, 123 ); // $ExpectError +} + + +// Attached to main export is an isPrimitive method which returns a boolean... +{ + // eslint-disable-next-line no-new-wrappers + isNonPositiveFinite.isObject( new Number( -2 ) ); // $ExpectType boolean + isNonPositiveFinite.isObject( -2 ); // $ExpectType boolean +} + +// The compiler throws an error if the isObject method is provided an unsupported number of arguments... +{ + isNonPositiveFinite.isObject(); // $ExpectError + isNonPositiveFinite.isObject( -2, 123 ); // $ExpectError +} From b2477382bc17d7d8f4702aae044d39baaa55502a Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Mon, 26 Feb 2024 19:54:53 -0500 Subject: [PATCH 4/4] Apply suggestions from code review Signed-off-by: Philipp Burckhardt --- .../@stdlib/assert/is-nonpositive-finite/README.md | 4 ++-- .../assert/is-nonpositive-finite/docs/types/index.d.ts | 1 - .../assert/is-nonpositive-finite/docs/types/test.ts | 3 +-- .../assert/is-nonpositive-finite/examples/index.js | 2 +- .../@stdlib/assert/is-nonpositive-finite/lib/index.js | 8 ++++---- .../@stdlib/assert/is-nonpositive-finite/lib/main.js | 4 ++-- .../@stdlib/assert/is-nonpositive-finite/lib/object.js | 4 ++-- .../@stdlib/assert/is-nonpositive-finite/lib/primitive.js | 6 +++--- .../@stdlib/assert/is-nonpositive-finite/test/test.js | 4 ++-- 9 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/README.md b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/README.md index 1b1765138258..5e44831a626b 100644 --- a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/README.md +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/README.md @@ -43,7 +43,7 @@ var NINF = require('@stdlib/constants/float64/ninf'); var bool = isNonPositiveFinite( -5.0 ); // returns true -bool = isNonPositiveFinite(NINF); +bool = isNonPositiveFinite( NINF ); // returns false bool = isNonPositiveFinite( new Number( -5.0 ) ); @@ -111,7 +111,7 @@ var NINF = require('@stdlib/constants/float64/ninf'); var bool = isNonPositiveFinite( -5.0 ); // returns true -bool = isNonPositiveFinite(NINF); +bool = isNonPositiveFinite( NINF ); // returns false bool = isNonPositiveFinite( new Number( -5.0 ) ); diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/index.d.ts index 4150a5462b26..61c2aa00d5b4 100644 --- a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/index.d.ts @@ -21,7 +21,6 @@ /** * Interface defining `isNonPositiveFinite` with methods for testing for primitives and objects, respectively. */ - interface IsNonPositiveFinite { /** * Tests if a value is a nonpositive finite number. diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/test.ts b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/test.ts index 52379dca826f..f2b8a35a279a 100644 --- a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/test.ts +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/docs/types/test.ts @@ -46,8 +46,7 @@ import isNonPositiveFinite = require( './index' ); isNonPositiveFinite.isPrimitive( -2, 123 ); // $ExpectError } - -// Attached to main export is an isPrimitive method which returns a boolean... +// Attached to main export is an isObject method which returns a boolean... { // eslint-disable-next-line no-new-wrappers isNonPositiveFinite.isObject( new Number( -2 ) ); // $ExpectType boolean diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/examples/index.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/examples/index.js index 41fd706bb9c7..bdf0c8ce2b19 100644 --- a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/examples/index.js +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/examples/index.js @@ -29,7 +29,7 @@ console.log( isNonPositiveFinite( -2 )); console.log( isNonPositiveFinite( -2.99 )); // => true -console.log(isNonPositiveFinite(NINF)); +console.log( isNonPositiveFinite( NINF ) ); // => false console.log( isNonPositiveFinite( 'beep' ) ); diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/index.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/index.js index 41a6cecca1ca..6b711e3e60d6 100644 --- a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/index.js +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/index.js @@ -19,20 +19,20 @@ 'use strict'; /** -* Test if a value is a ragged nested array. +* Test if a value is a nonpositive finite number. * * @module @stdlib/assert/is-nonpositive-finite * * @example * var isNonPositiveFinite = require( '@stdlib/assert/is-nonpositive-finite' ); * -* var bool = isNonPositiveFinite(-2); +* var bool = isNonPositiveFinite( -2 ); * // returns true * -* bool = isNonPositiveFinite(3); +* bool = isNonPositiveFinite( 3 ); * // returns false * -* bool = isNonPositiveFinite('beep'); +* bool = isNonPositiveFinite( 'beep' ); * // returns false */ diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/main.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/main.js index 0d0ef87cda11..6a756700627c 100644 --- a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/main.js +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/main.js @@ -29,7 +29,7 @@ var isObject = require( './object.js' ); // MAIN // /** -* Tests if a value is a number object has a non positive finite value. +* Tests if a value is a nonpositive finite number. * * @param {*} value - value to test * @returns {boolean} boolean indicating if a value is non positive finite @@ -43,7 +43,7 @@ var isObject = require( './object.js' ); * // returns true * * @example -* var bool = isNonPositiveFinite(NINF); +* var bool = isNonPositiveFinite( -Infinity ); * // returns false */ function isNonPositiveFinite( value ) { diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/object.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/object.js index 5e7fe712c127..26dc0940cf4b 100644 --- a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/object.js +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/object.js @@ -20,14 +20,14 @@ // MODULES // -var NINF = require('@stdlib/constants/float64/ninf'); +var NINF = require( '@stdlib/constants/float64/ninf' ); var isNumber = require( '@stdlib/assert/is-number' ).isObject; // MAIN // /** -* Tests if a value is a number object has a non positive finite value. +* Tests if a value is a number object having a non positive finite value. * * @param {*} value - value to test * @returns {boolean} boolean indicating if a value is non positive finite diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/primitive.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/primitive.js index 326bf5062e17..17af6b4a58dd 100644 --- a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/primitive.js +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/lib/primitive.js @@ -20,14 +20,14 @@ // MODULES // -var NINF = require('@stdlib/constants/float64/ninf'); +var NINF = require( '@stdlib/constants/float64/ninf' ); var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; // MAIN // /** -* Tests if a value is a number primitive has a non positive finite value. +* Tests if a value is a number primitive having a non positive finite value. * * @param {*} value - value to test * @returns {boolean} boolean indicating if a value is non positive finite @@ -41,7 +41,7 @@ var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; * // returns false */ function isNonPositiveFinite( value ) { - return (isNumber( value ) && value <=0 && value !== NINF); + return ( isNumber( value ) && value <=0 && value !== NINF ); } diff --git a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.js b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.js index cdbe481617b6..504034e3e7a9 100644 --- a/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.js +++ b/lib/node_modules/@stdlib/assert/is-nonpositive-finite/test/test.js @@ -32,12 +32,12 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'attached to the main export is a method to test for a primitive number having a nonpositive number value', function test( t ) { +tape( 'attached to the main export is a method to test for a primitive number having a nonpositive finite number value', function test( t ) { t.equal( typeof isNonPositiveFinite.isPrimitive, 'function', 'export is a function' ); t.end(); }); -tape( 'attached to the main export is a method to test for a number object having a nonpositive number value', function test( t ) { +tape( 'attached to the main export is a method to test for a number object having a nonpositive finite number value', function test( t ) { t.equal( typeof isNonPositiveFinite.isObject, 'function', 'export is a function' ); t.end(); });