diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 26c41fe0..2f33708d 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -36,9 +36,11 @@ Ognjen Jevremović Philipp Burckhardt Prajwal Kulkarni Pranav Goswami +Pratik <97464067+Pratik772846@users.noreply.github.com> Ricky Reusser Robert Gislason Roman Stetsyk <25715951+romanstetsyk@users.noreply.github.com> +Rutam <138517416+performant23@users.noreply.github.com> Ryan Seal Seyyed Parsa Neshaei Shraddheya Shendre diff --git a/is-nonpositive-finite/README.md b/is-nonpositive-finite/README.md new file mode 100644 index 00000000..6859079b --- /dev/null +++ b/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/is-nonpositive-finite/benchmark/benchmark.js b/is-nonpositive-finite/benchmark/benchmark.js new file mode 100644 index 00000000..b23071fd --- /dev/null +++ b/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( './../../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/is-nonpositive-finite/docs/repl.txt b/is-nonpositive-finite/docs/repl.txt new file mode 100644 index 00000000..86baa02f --- /dev/null +++ b/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 + -------- + diff --git a/is-nonpositive-finite/docs/types/index.d.ts b/is-nonpositive-finite/docs/types/index.d.ts new file mode 100644 index 00000000..61c2aa00 --- /dev/null +++ b/is-nonpositive-finite/docs/types/index.d.ts @@ -0,0 +1,125 @@ +/* +* @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/is-nonpositive-finite/docs/types/test.ts b/is-nonpositive-finite/docs/types/test.ts new file mode 100644 index 00000000..f2b8a35a --- /dev/null +++ b/is-nonpositive-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 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 isObject 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 +} diff --git a/is-nonpositive-finite/examples/index.js b/is-nonpositive-finite/examples/index.js new file mode 100644 index 00000000..bdf0c8ce --- /dev/null +++ b/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/is-nonpositive-finite/lib/index.js b/is-nonpositive-finite/lib/index.js new file mode 100644 index 00000000..6b711e3e --- /dev/null +++ b/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 nonpositive finite number. +* +* @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/is-nonpositive-finite/lib/main.js b/is-nonpositive-finite/lib/main.js new file mode 100644 index 00000000..6a756700 --- /dev/null +++ b/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 nonpositive finite number. +* +* @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( -Infinity ); +* // returns false +*/ +function isNonPositiveFinite( value ) { + return ( + isPrimitive(value) || isObject(value)); +} + + +// EXPORTS // + +module.exports = isNonPositiveFinite; diff --git a/is-nonpositive-finite/lib/object.js b/is-nonpositive-finite/lib/object.js new file mode 100644 index 00000000..e79cd840 --- /dev/null +++ b/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( './../../is-number' ).isObject; + + +// MAIN // + +/** +* 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 +* +* @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/is-nonpositive-finite/lib/primitive.js b/is-nonpositive-finite/lib/primitive.js new file mode 100644 index 00000000..1a18c0ea --- /dev/null +++ b/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( './../../is-number' ).isPrimitive; + + +// MAIN // + +/** +* 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 +* +* @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/is-nonpositive-finite/package.json b/is-nonpositive-finite/package.json new file mode 100644 index 00000000..1a04748f --- /dev/null +++ b/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/is-nonpositive-finite/test/test.js b/is-nonpositive-finite/test/test.js new file mode 100644 index 00000000..504034e3 --- /dev/null +++ b/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 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 finite number value', function test( t ) { + t.equal( typeof isNonPositiveFinite.isObject, 'function', 'export is a function' ); + t.end(); +}); diff --git a/is-nonpositive-finite/test/test.main.js b/is-nonpositive-finite/test/test.main.js new file mode 100644 index 00000000..08544f3f --- /dev/null +++ b/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/is-nonpositive-finite/test/test.object.js b/is-nonpositive-finite/test/test.object.js new file mode 100644 index 00000000..d74803bb --- /dev/null +++ b/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/is-nonpositive-finite/test/test.primitive.js b/is-nonpositive-finite/test/test.primitive.js new file mode 100644 index 00000000..24af87b9 --- /dev/null +++ b/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(); +});