Skip to content

Commit

Permalink
Add Typescript definition and remove empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Planeshifter committed Apr 1, 2021
1 parent abd9678 commit f3f96d8
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* var bool = IS_ELECTRON_MAIN;
* // returns <boolean>
*/

declare const IS_ELECTRON_MAIN: boolean;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* var bool = IS_ELECTRON_RENDERER;
* // returns <boolean>
*/

declare const IS_ELECTRON_RENDERER: boolean;


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2019 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: 2.0

/**
* Interface defining `isNegativeNumberArray` with methods for testing for primitive and object arrays, respectively.
*/
interface CheckNegativeNumberArray {
/**
* Tests if a value is an array-like object containing only negative numbers.
*
* @param value - value to test
* @returns boolean indicating whether value is an array-like object containing only negative numbers
*
* @example
* var bool = isNegativeNumberArray( [ -3.7, new Number(-3.0) ] );
* // returns true
*
* @example
* var bool = isNegativeNumberArray( [ -3.0, '-3.0' ] );
* // returns false
*/
( value: any ): boolean;

/**
* Tests if a value is an array-like object containing only negative primitive number values.
*
* @param value - value to test
* @returns boolean indicating whether value is an array-like object containing only negative primitive number values
*
* @example
* var bool = isNegativeNumberArray.primitives( [ -1.0, -10.0 ] );
* // returns true
*
* @example
* var bool = isNegativeNumberArray.primitives( [ -1.0, 0.0, -10.0 ] );
* // returns false
*
* @example
* var bool = isNegativeNumberArray.primitives( [ -3.0, new Number(-1.0) ] );
* // returns false
*/
primitives( value: any ): boolean;

/**
* Tests if a value is an array-like object containing only number objects having negative number values.
*
* @param value - value to test
* @returns boolean indicating whether value is an array-like object containing only number objects having negative number values
*
* @example
* var bool = isNegativeNumberArray.objects( [ new Number(-1.3), new Number(-10.8) ] );
* // returns true
*
* @example
* var bool = isNegativeNumberArray.objects( [ -1.0, 0.0, -10.0 ] );
* // returns false
*
* @example
* var bool = isNegativeNumberArray.objects( [ -3.0, new Number(-1.0) ] );
* // returns false
*/
objects( value: any ): boolean;
}

/**
* Tests if a value is an array-like object containing only negative numbers.
*
* @param value - value to test
* @returns boolean indicating whether value is an array-like object containing only negative numbers
*
* @example
* var bool = isNegativeNumberArray( [ -3.7, new Number(-3.0) ] );
* // returns true
*
* @example
* var bool = isNegativeNumberArray( [ -3.7, '-3.0' ] );
* // returns false
*
* @example
* var bool = isNegativeNumberArray.primitives( [ -1.3, -10.0 ] );
* // returns true
*
* @example
* var bool = isNegativeNumberArray.objects( [ new Number(-1.3), new Number(-10.0) ] );
* // returns true
*/
declare var isNegativeNumberArray: CheckNegativeNumberArray;

This comment has been minimized.

Copy link
@kgryte

kgryte Apr 1, 2021

Member

Any reason to use CheckNegativeNumberArray and not IsNegativeNumberArray? Not clear to me that we need to use a different word.

This comment has been minimized.

Copy link
@Planeshifter

Planeshifter Apr 1, 2021

Author Member

Yes, Typescript does not allow interfaces starting with I.

This comment has been minimized.

Copy link
@Planeshifter


// EXPORTS //

export = isNegativeNumberArray;
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2021 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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 isNegativeNumberArray = require( './index' );


// TESTS //

// The function returns a boolean...
{
isNegativeNumberArray( [ 4 ] ); // $ExpectType boolean
isNegativeNumberArray( [ -2.9 ] ); // $ExpectType boolean
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
isNegativeNumberArray(); // $ExpectError
isNegativeNumberArray( [ -3 ], 123 ); // $ExpectError
}

// Attached to main export is a `primitives` method which returns a boolean...
{
// tslint:disable-next-line:no-construct
isNegativeNumberArray.primitives( [ new Number( -3 ) ] ); // $ExpectType boolean
isNegativeNumberArray.primitives( [ -3 ] ); // $ExpectType boolean
}

// The compiler throws an error if the `primitives` method is provided an unsupported number of arguments...
{
isNegativeNumberArray.primitives(); // $ExpectError
isNegativeNumberArray.primitives( [ -2 ], 123 ); // $ExpectError
}


// Attached to main export is an `objects` method which returns a boolean...
{
// tslint:disable-next-line:no-construct
isNegativeNumberArray.objects( [ new Number( -2 ) ] ); // $ExpectType boolean
isNegativeNumberArray.objects( [ -2 ] ); // $ExpectType boolean
}

// The compiler throws an error if the `objects` method is provided an unsupported number of arguments...
{
isNegativeNumberArray.objects(); // $ExpectError
isNegativeNumberArray.objects( [ -2 ], 123 ); // $ExpectError
}

0 comments on commit f3f96d8

Please sign in to comment.