From 10cb9db33766d2d480f87d0a0ee59135e736b4ae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 23 Feb 2024 19:33:36 +0000 Subject: [PATCH] Auto-generated commit --- .github/workflows/npm_downloads.yml | 4 +- .github/workflows/test_bundles.yml | 4 +- CONTRIBUTORS | 1 + is-nonnegative-finite/README.md | 163 +++++++++++++ is-nonnegative-finite/benchmark/benchmark.js | 228 +++++++++++++++++++ is-nonnegative-finite/docs/repl.txt | 77 +++++++ is-nonnegative-finite/docs/types/index.d.ts | 142 ++++++++++++ is-nonnegative-finite/docs/types/test.ts | 60 +++++ is-nonnegative-finite/examples/index.js | 49 ++++ is-nonnegative-finite/lib/index.js | 85 +++++++ is-nonnegative-finite/lib/main.js | 66 ++++++ is-nonnegative-finite/lib/object.js | 61 +++++ is-nonnegative-finite/lib/primitive.js | 61 +++++ is-nonnegative-finite/package.json | 73 ++++++ is-nonnegative-finite/test/test.js | 43 ++++ is-nonnegative-finite/test/test.main.js | 64 ++++++ is-nonnegative-finite/test/test.object.js | 74 ++++++ is-nonnegative-finite/test/test.primitive.js | 76 +++++++ 18 files changed, 1327 insertions(+), 4 deletions(-) create mode 100644 is-nonnegative-finite/README.md create mode 100644 is-nonnegative-finite/benchmark/benchmark.js create mode 100644 is-nonnegative-finite/docs/repl.txt create mode 100644 is-nonnegative-finite/docs/types/index.d.ts create mode 100644 is-nonnegative-finite/docs/types/test.ts create mode 100644 is-nonnegative-finite/examples/index.js create mode 100644 is-nonnegative-finite/lib/index.js create mode 100644 is-nonnegative-finite/lib/main.js create mode 100644 is-nonnegative-finite/lib/object.js create mode 100644 is-nonnegative-finite/lib/primitive.js create mode 100644 is-nonnegative-finite/package.json create mode 100644 is-nonnegative-finite/test/test.js create mode 100644 is-nonnegative-finite/test/test.main.js create mode 100644 is-nonnegative-finite/test/test.object.js create mode 100644 is-nonnegative-finite/test/test.primitive.js diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml index 53312a04..c4357c66 100644 --- a/.github/workflows/npm_downloads.yml +++ b/.github/workflows/npm_downloads.yml @@ -86,8 +86,8 @@ jobs: # Upload the download data: - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 + # Pin action to full length commit SHA + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 with: # Define a name for the uploaded artifact (ensuring a unique name for each job): name: npm_downloads diff --git a/.github/workflows/test_bundles.yml b/.github/workflows/test_bundles.yml index 0c4e0610..5c9dc95a 100644 --- a/.github/workflows/test_bundles.yml +++ b/.github/workflows/test_bundles.yml @@ -168,8 +168,8 @@ jobs: # Install Deno: - name: 'Install Deno' - # Pin action to full length commit SHA corresponding to v1.1.2 - uses: denoland/setup-deno@61fe2df320078202e33d7d5ad347e7dcfa0e8f31 + # Pin action to full length commit SHA + uses: denoland/setup-deno@041b854f97b325bd60e53e9dc2de9cb9f9ac0cba # v1.1.4 with: deno-version: vx.x.x diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 726c1ec4..4d10e1be 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -21,6 +21,7 @@ Joey Reed Jordan Gallivan <115050475+Jordan-Gallivan@users.noreply.github.com> Joris Labie Justin Dennison +Karthik Prakash <116057817+skoriop@users.noreply.github.com> Marcus Fantham Matt Cochrane Milan Raj diff --git a/is-nonnegative-finite/README.md b/is-nonnegative-finite/README.md new file mode 100644 index 00000000..74518ca4 --- /dev/null +++ b/is-nonnegative-finite/README.md @@ -0,0 +1,163 @@ + + +# isNonNegativeFinite + +> Test if a value is a number having a nonnegative finite value. + +
+ +## Usage + +```javascript +var isNonNegativeFinite = require( '@stdlib/assert/is-nonnegative-finite' ); +``` + +#### isNonNegativeFinite( value ) + +Tests if a `value` is a `number` having a nonnegative finite value. + + + +```javascript +var Number = require( '@stdlib/number/ctor' ); + +var bool = isNonNegativeFinite( 5.0 ); +// returns true + +bool = isNonNegativeFinite( new Number( 5.0 ) ); +// returns true + +bool = isNonNegativeFinite( 3.14 ); +// returns true + +bool = isNonNegativeFinite( -5.0 ); +// returns false + +bool = isNonNegativeFinite( null ); +// returns false + +bool = isNonNegativeFinite( Infinity ); +// returns false +``` + +#### isNonNegativeFinite.isPrimitive( value ) + +Tests if a `value` is a primitive `number` having a nonnegative finite value. + + + +```javascript +var Number = require( '@stdlib/number/ctor' ); + +var bool = isNonNegativeFinite.isPrimitive( 3.0 ); +// returns true + +bool = isNonNegativeFinite.isPrimitive( new Number( 3.0 ) ); +// returns false +``` + +#### isNonNegativeFinite.isObject( value ) + +Tests if a `value` is a `Number` object having a nonnegative finite value. + + + +```javascript +var Number = require( '@stdlib/number/ctor' ); + +var bool = isNonNegativeFinite.isObject( 3.0 ); +// returns false + +bool = isNonNegativeFinite.isObject( new Number( 3.0 ) ); +// returns true +``` + +
+ + + +
+ +## Examples + + + + + +```javascript +var Number = require( '@stdlib/number/ctor' ); +var isNonNegativeFinite = require( '@stdlib/assert/is-nonnegative-finite' ); + +var bool = isNonNegativeFinite( 5.0 ); +// returns true + +bool = isNonNegativeFinite( new Number( 5.0 ) ); +// returns true + +bool = isNonNegativeFinite( 0.0 ); +// returns true + +bool = isNonNegativeFinite( 3.14 ); +// returns true + +bool = isNonNegativeFinite( -5.0 ); +// returns false + +bool = isNonNegativeFinite( '5' ); +// returns false + +bool = isNonNegativeFinite( null ); +// returns false +``` + +
+ + + + + + + + + + + + + + diff --git a/is-nonnegative-finite/benchmark/benchmark.js b/is-nonnegative-finite/benchmark/benchmark.js new file mode 100644 index 00000000..349797e2 --- /dev/null +++ b/is-nonnegative-finite/benchmark/benchmark.js @@ -0,0 +1,228 @@ +/** +* @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( './../../is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var isNonNegativeFinite = 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, + Infinity, + -Infinity, + undefined + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonNegativeFinite( 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 = isNonNegativeFinite( 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, + Infinity, + -Infinity + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonNegativeFinite.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 = isNonNegativeFinite.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, + Infinity, + -Infinity + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonNegativeFinite.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 ), + new Number( Infinity ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isNonNegativeFinite.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/is-nonnegative-finite/docs/repl.txt b/is-nonnegative-finite/docs/repl.txt new file mode 100644 index 00000000..0d802253 --- /dev/null +++ b/is-nonnegative-finite/docs/repl.txt @@ -0,0 +1,77 @@ + +{{alias}}( value ) + Tests if a value is a nonnegative finite number. + + Parameters + ---------- + value: any + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating whether value is a nonnegative 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 + > bool = {{alias}}( Infinity ) + false + + +{{alias}}.isPrimitive( value ) + Tests if a value is a number primitive having a nonnegative finite value. + + Parameters + ---------- + value: any + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating whether value is a number primitive having a + nonnegative 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 nonnegative finite value. + + Parameters + ---------- + value: any + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating whether value is a number object having a + nonnegative finite value. + + Examples + -------- + > var bool = {{alias}}.isObject( 3.0 ) + false + > bool = {{alias}}.isObject( new Number( 3.0 ) ) + true + + + See Also + -------- + diff --git a/is-nonnegative-finite/docs/types/index.d.ts b/is-nonnegative-finite/docs/types/index.d.ts new file mode 100644 index 00000000..fab36f9a --- /dev/null +++ b/is-nonnegative-finite/docs/types/index.d.ts @@ -0,0 +1,142 @@ +/* +* @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 `isNonNegativeFinite` with methods for testing for primitives and objects, respectively. +*/ +interface IsNonNegativeFinite { + /** + * Tests if a value is a nonnegative finite number. + * + * @param {*} value - value to test + * @returns {boolean} boolean indicating whether value is a nonnegative number + * + * @example + * var bool = isNonNegativeFinite( 5.0 ); + * // returns true + * + * @example + * var bool = isNonNegativeFinite( new Number( 5.0 ) ); + * // returns true + * + * @example + * var bool = isNonNegativeFinite( 3.14 ); + * // returns true + * + * @example + * var bool = isNonNegativeFinite( Infinity ); + * // returns false + * + * @example + * var bool = isNonNegativeFinite( -5.0 ); + * // returns false + * + * @example + * var bool = isNonNegativeFinite( null ); + * // returns false + */ + ( value: any ): value is number | Number; + + /** + * Tests if a value is a number primitive having a nonnegative finite value. + * + * @param {*} value - value to test + * @returns {boolean} boolean indicating if a value is a number primitive having a nonnegative finite value + * + * @example + * var bool = isNonNegativeNumber( 3.0 ); + * // returns true + * + * @example + * var bool = isNonNegativeNumber( new Number( 3.0 ) ); + * // returns false + * + * @example + * var bool = isNonNegativeFinite( new Number( -5.0 ) ); + * // returns false + * + * @example + * var bool = isNonNegativeFinite( Infinity ); + * // returns false + */ + isPrimitive( value: any ): value is number; + + /** + * Tests if a value is a finite number object having a nonnegative value. + * + * @param {*} value - value to test + * @returns {boolean} boolean indicating if a value is a number object having a nonnegative finite number value + * + * @example + * var bool = isNonNegativeFinite( 3.0 ); + * // returns false + * + * @example + * var bool = isNonNegativeFinite( new Number( 3.0 ) ); + * // returns true + * + * @example + * var bool = isNonNegativeFinite( new Number( -5.0 ) ); + * // returns false + * + * @example + * var bool = isNonNegativeFinite( Infinity ); + * // returns false + */ + isObject( value: any ): value is Number; +} + +/** +* Tests if a value is a nonnegative finite number. +* +* @param {*} value - value to test +* @returns {boolean} boolean indicating whether value is a nonnegative number +* +* @example +* var bool = isNonNegativeFinite( 5.0 ); +* // returns true +* +* @example +* var bool = isNonNegativeFinite( new Number( 5.0 ) ); +* // returns true +* +* @example +* var bool = isNonNegativeFinite( 3.14 ); +* // returns true +* +* @example +* var bool = isNonNegativeFinite( Infinity ); +* // returns false +* +* @example +* var bool = isNonNegativeFinite( -5.0 ); +* // returns false +* +* @example +* var bool = isNonNegativeFinite( null ); +* // returns false +*/ + +declare var isNonNegativeFinite: IsNonNegativeFinite; + + +// EXPORTS // + +export = isNonNegativeFinite; diff --git a/is-nonnegative-finite/docs/types/test.ts b/is-nonnegative-finite/docs/types/test.ts new file mode 100644 index 00000000..22b80824 --- /dev/null +++ b/is-nonnegative-finite/docs/types/test.ts @@ -0,0 +1,60 @@ +/* +* @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 isNonNegativeFinite = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isNonNegativeFinite( 1.2 ); // $ExpectType boolean + isNonNegativeFinite( -1.2 ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isNonNegativeFinite(); // $ExpectError + isNonNegativeFinite( 2, 123 ); // $ExpectError +} + +// Attached to main export is an isPrimitive method which returns a boolean... +{ + // eslint-disable-next-line no-new-wrappers + isNonNegativeFinite.isPrimitive( new Number( 2 ) ); // $ExpectType boolean + isNonNegativeFinite.isPrimitive( 2 ); // $ExpectType boolean +} + +// The compiler throws an error if the isPrimitive method is provided an unsupported number of arguments... +{ + isNonNegativeFinite.isPrimitive(); // $ExpectError + isNonNegativeFinite.isPrimitive( 2, 123 ); // $ExpectError +} + +// Attached to main export is an isObject method which returns a boolean... +{ + // eslint-disable-next-line no-new-wrappers + isNonNegativeFinite.isObject( new Number( 2 ) ); // $ExpectType boolean + isNonNegativeFinite.isObject( 2 ); // $ExpectType boolean +} + +// The compiler throws an error if the isObject method is provided an unsupported number of arguments... +{ + isNonNegativeFinite.isObject(); // $ExpectError + isNonNegativeFinite.isObject( 2, 123 ); // $ExpectError +} diff --git a/is-nonnegative-finite/examples/index.js b/is-nonnegative-finite/examples/index.js new file mode 100644 index 00000000..d54f4834 --- /dev/null +++ b/is-nonnegative-finite/examples/index.js @@ -0,0 +1,49 @@ +/** +* @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'; + +var Number = require( '@stdlib/number/ctor' ); +var isNonNegativeFinite = require( './../lib' ); + +console.log( isNonNegativeFinite( 5.0 ) ); +// => true + +console.log( isNonNegativeFinite( new Number( 5.0 ) ) ); +// => true + +console.log( isNonNegativeFinite( new Number( Infinity ) ) ); +// => false + +console.log( isNonNegativeFinite( Infinity ) ); +// => false + +console.log( isNonNegativeFinite( 0.0 ) ); +// => true + +console.log( isNonNegativeFinite( 3.14 ) ); +// => true + +console.log( isNonNegativeFinite( -5.0 ) ); +// => false + +console.log( isNonNegativeFinite( '5' ) ); +// => false + +console.log( isNonNegativeFinite( null ) ); +// => false diff --git a/is-nonnegative-finite/lib/index.js b/is-nonnegative-finite/lib/index.js new file mode 100644 index 00000000..706d596d --- /dev/null +++ b/is-nonnegative-finite/lib/index.js @@ -0,0 +1,85 @@ +/** +* @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 nonnegative finite number. +* +* @module @stdlib/assert/is-nonnegative-finite +* +* @example +* var isNonNegativeFinite = require( '@stdlib/assert/is-nonnegative-finite' ); +* +* var bool = isNonNegativeFinite( 5.0 ); +* // returns true +* +* bool = isNonNegativeFinite( new Number( 5.0 ) ); +* // returns true +* +* bool = isNonNegativeFinite( 3.14 ); +* // returns true +* +* var bool = isNonNegativeFinite( Infinity ); +* // returns false +* +* bool = isNonNegativeFinite( -5.0 ); +* // returns false +* +* bool = isNonNegativeFinite( null ); +* // returns false +* +* @example +* var isNonNegativeFinite = require( '@stdlib/assert/is-nonnegative-finite' ).isPrimitive; +* +* var bool = isNonNegativeFinite( 3.0 ); +* // returns true +* +* bool = isNonNegativeFinite( new Number( 3.0 ) ); +* // returns false +* +* @example +* var isNonNegativeFinite = require( '@stdlib/assert/is-nonnegative-finite' ).isObject; +* +* var bool = isNonNegativeFinite( 3.0 ); +* // returns false +* +* var bool = isNonNegativeFinite( Infinity ); +* // returns false +* +* bool = isNonNegativeFinite( new Number( 3.0 ) ); +* // returns true +*/ + +// 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/is-nonnegative-finite/lib/main.js b/is-nonnegative-finite/lib/main.js new file mode 100644 index 00000000..cf2e9c51 --- /dev/null +++ b/is-nonnegative-finite/lib/main.js @@ -0,0 +1,66 @@ +/** +* @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 isPrimitive = require( './primitive.js' ); +var isObject = require( './object.js' ); + + +// MAIN // + +/** +* Tests if a value is a nonnegative finite number. +* +* @param {*} value - value to test +* @returns {boolean} boolean indicating whether value is a nonnegative number +* +* @example +* var bool = isNonNegativeFinite( 5.0 ); +* // returns true +* +* @example +* var bool = isNonNegativeFinite( new Number( 5.0 ) ); +* // returns true +* +* @example +* var bool = isNonNegativeFinite( 3.14 ); +* // returns true +* +* @example +* var bool = isNonNegativeFinite( Infinity ); +* // returns false +* +* @example +* var bool = isNonNegativeFinite( -5.0 ); +* // returns false +* +* @example +* var bool = isNonNegativeFinite( null ); +* // returns false +*/ +function isNonNegativeFinite( value ) { + return ( isPrimitive( value ) || isObject( value ) ); +} + + +// EXPORTS // + +module.exports = isNonNegativeFinite; diff --git a/is-nonnegative-finite/lib/object.js b/is-nonnegative-finite/lib/object.js new file mode 100644 index 00000000..6f447f7e --- /dev/null +++ b/is-nonnegative-finite/lib/object.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var isNonNegativeNumber = require( './../../is-nonnegative-number').isObject; +var isFinite = require( './../../is-finite' ).isObject; // eslint-disable-line stdlib/no-redeclare + + +// MAIN // + +/** +* Tests if a value is a finite number object having a nonnegative value. +* +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is a number object having a nonnegative finite number value +* +* @example +* var bool = isNonNegativeFinite( 3.0 ); +* // returns false +* +* @example +* var bool = isNonNegativeFinite( new Number( 3.0 ) ); +* // returns true +* +* @example +* var bool = isNonNegativeFinite( new Number( -5.0 ) ); +* // returns false +* +* @example +* var bool = isNonNegativeFinite( Infinity ); +* // returns false +*/ +function isNonNegativeFinite( value ) { + return ( + isNonNegativeNumber( value ) && + isFinite( value ) + ); +} + + +// EXPORTS // + +module.exports = isNonNegativeFinite; diff --git a/is-nonnegative-finite/lib/primitive.js b/is-nonnegative-finite/lib/primitive.js new file mode 100644 index 00000000..3f3a97cb --- /dev/null +++ b/is-nonnegative-finite/lib/primitive.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var isNonNegativeNumber = require( './../../is-nonnegative-number' ).isPrimitive; +var isFinite = require( './../../is-finite' ).isPrimitive; // eslint-disable-line stdlib/no-redeclare + + +// MAIN // + +/** +* Tests if a value is a number primitive having a nonnegative finite value. +* +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is a number primitive having a nonnegative finite value +* +* @example +* var bool = isNonNegativeNumber( 3.0 ); +* // returns true +* +* @example +* var bool = isNonNegativeNumber( new Number( 3.0 ) ); +* // returns false +* +* @example +* var bool = isNonNegativeFinite( new Number( -5.0 ) ); +* // returns false +* +* @example +* var bool = isNonNegativeFinite( Infinity ); +* // returns false +*/ +function isNonNegativeFinite( value ) { + return ( + isNonNegativeNumber( value ) && + isFinite( value ) + ); +} + + +// EXPORTS // + +module.exports = isNonNegativeFinite; diff --git a/is-nonnegative-finite/package.json b/is-nonnegative-finite/package.json new file mode 100644 index 00000000..6473813d --- /dev/null +++ b/is-nonnegative-finite/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/assert/is-nonnegative-finite", + "version": "0.0.0", + "description": "Test if a value is a number having a nonnegative 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", + "nonnegative", + "finite", + "nonnegativefinite", + "is", + "isnumber", + "isnumeric", + "type", + "check", + "primitive", + "object" + ] +} diff --git a/is-nonnegative-finite/test/test.js b/is-nonnegative-finite/test/test.js new file mode 100644 index 00000000..8ff3134e --- /dev/null +++ b/is-nonnegative-finite/test/test.js @@ -0,0 +1,43 @@ +/** +* @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 isNonNegativeFinite = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isNonNegativeFinite, '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 nonnegative number value', function test( t ) { + t.equal( typeof isNonNegativeFinite.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 nonnegative number value', function test( t ) { + t.equal( typeof isNonNegativeFinite.isObject, 'function', 'export is a function' ); + t.end(); +}); diff --git a/is-nonnegative-finite/test/test.main.js b/is-nonnegative-finite/test/test.main.js new file mode 100644 index 00000000..414c2921 --- /dev/null +++ b/is-nonnegative-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 Number = require( '@stdlib/number/ctor' ); +var isNonNegativeFinite = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isNonNegativeFinite, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided a number having a nonnegative number value', function test( t ) { + t.equal( isNonNegativeFinite( 5.0 ), true, 'returns true' ); + t.equal( isNonNegativeFinite( new Number( 5.0 ) ), true, 'returns true' ); + t.end(); +}); + +tape( 'the function returns `false` if not provided a number having a nonnegative finite value', function test( t ) { + var values; + var i; + + values = [ + '5', + -3.14, + -1.0, + null, + true, + void 0, + [], + {}, + function noop() {}, + Infinity, + -Infinity + ]; + + for ( i = 0; i < values.length; i++ ) { + t.equal( isNonNegativeFinite( values[i] ), false, 'returns false when provided '+values[i] ); + } + t.end(); +}); diff --git a/is-nonnegative-finite/test/test.object.js b/is-nonnegative-finite/test/test.object.js new file mode 100644 index 00000000..a4451887 --- /dev/null +++ b/is-nonnegative-finite/test/test.object.js @@ -0,0 +1,74 @@ +/** +* @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 isNonNegativeFinite = require( './../lib/object.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isNonNegativeFinite, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided a number object having a nonnegative number value', function test( t ) { + t.equal( isNonNegativeFinite( new Number( 5.0 ) ), true, 'returns true' ); + t.end(); +}); + +tape( 'the function returns `false` if provided Infinity, even if it is positive infinity', function test( t ) { + t.equal( isNonNegativeFinite( Infinity ), false, 'returns false' ); + t.end(); +}); + +tape( 'the function returns `false` if provided Infinity, even if it is positive infinity', function test( t ) { + t.equal( isNonNegativeFinite( Infinity ), false, 'returns false' ); + t.end(); +}); + +tape( 'the function returns `false` if not provided a nonnegative number', function test( t ) { + var values; + var i; + + values = [ + '5', + new Number( -2.0 ), + -3.14, + 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( isNonNegativeFinite( values[i] ), false, 'returns false when provided '+values[i] ); + } + t.end(); +}); diff --git a/is-nonnegative-finite/test/test.primitive.js b/is-nonnegative-finite/test/test.primitive.js new file mode 100644 index 00000000..66a22b95 --- /dev/null +++ b/is-nonnegative-finite/test/test.primitive.js @@ -0,0 +1,76 @@ +/** +* @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 isNonNegativeFinite = require( './../lib/primitive.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isNonNegativeFinite, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided a primitive number having a nonnegative finite value', function test( t ) { + t.equal( isNonNegativeFinite( 3.0 ), true, 'returns true' ); + t.end(); +}); + +tape( 'the function returns `false` if provided a number object, even if the number has a nonnegative finite value', function test( t ) { + t.equal( isNonNegativeFinite( new Number( 5.0 ) ), false, 'returns false' ); + t.end(); +}); + +tape( 'the function returns `false` if provided Infinity, even if it is positive infinity', function test( t ) { + t.equal( isNonNegativeFinite( Infinity ), false, 'returns false' ); + t.end(); +}); + +tape( 'the function returns `false` if provided a number object with Infinity', function test( t ) { + t.equal( isNonNegativeFinite( new Number( Infinity ) ), false, 'returns false' ); + t.end(); +}); + +tape( 'the function returns `false` if not provided a nonnegative finite number', function test( t ) { + var values; + var i; + + values = [ + '5', + new Number( -1.0 ), + -3.14, + null, + true, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.equal( isNonNegativeFinite( values[i] ), false, 'returns false when provided '+values[i] ); + } + t.end(); +});