Skip to content

Commit c80cac5

Browse files
committed
Fix namespace name and add Typescript definition
1 parent c4ea2e1 commit c80cac5

File tree

3 files changed

+159
-1
lines changed

3 files changed

+159
-1
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
/* tslint:disable:max-line-length */
22+
/* tslint:disable:max-file-line-count */
23+
24+
import arrayfcn = require( '@stdlib/assert/tools/array-function' );
25+
import arraylikefcn = require( '@stdlib/assert/tools/array-like-function' );
26+
import typedarrayfcn = require( '@stdlib/assert/tools/typed-array-function' );
27+
28+
/**
29+
* Interface describing the `tools` namespace.
30+
*/
31+
interface TOOLS {
32+
/**
33+
* Returns a function which tests if every element in an array passes a test condition.
34+
*
35+
* ## Notes
36+
*
37+
* - The predicate function should accept a single argument: an array element. If the array element satisfies a test condition, the function should return `true`; otherwise, the function should return `false`.
38+
* - Given an input array, the returned function returns `true` if all elements pass the test and `false` otherwise.
39+
* - The returned function returns `false` if provided an empty array.
40+
* - The returned function returns `false` is not provided an array.
41+
*
42+
* @param predicate - function to apply
43+
* @returns an array function
44+
*
45+
* @example
46+
* var isOdd = require( `@stdlib/assert/is-odd` );
47+
*
48+
* var arr1 = [ 1, 3, 5, 7 ];
49+
* var arr2 = [ 3, 5, 8 ];
50+
*
51+
* var validate = arrayfcn( isOdd );
52+
*
53+
* var bool = validate( arr1 );
54+
* // returns true
55+
*
56+
* bool = validate( arr2 );
57+
* // returns false
58+
*/
59+
arrayfcn: typeof arrayfcn;
60+
61+
/**
62+
* Returns a function which tests if every element in an array-like object passes a test condition.
63+
*
64+
* ## Notes
65+
*
66+
* - The predicate function should accept a single argument: an element from an array-like object. If the element satisfies a test condition, the function should return `true`; otherwise, the function should return `false`.
67+
* - Given an input array-like object, the returned function returns `true` if all elements pass the test and `false` otherwise.
68+
* - The returned function returns `false` if provided an empty array-like object.
69+
* - The returned function returns `false` is not provided an array-like object.
70+
*
71+
* @param predicate - function to apply
72+
* @returns an array-like object function
73+
*
74+
* @example
75+
* var isOdd = require( `@stdlib/assert/is-odd` );
76+
*
77+
* var arr1 = [ 1, 3, 5, 7 ];
78+
* var arr2 = [ 3, 5, 8 ];
79+
*
80+
* var validate = arraylikefcn( isOdd );
81+
*
82+
* var bool = validate( arr1 );
83+
* // returns true
84+
*
85+
* bool = validate( arr2 );
86+
* // returns false
87+
*/
88+
arraylikefcn: typeof arraylikefcn;
89+
90+
/**
91+
* Returns a function which tests if every element in a typed array passes a test condition.
92+
*
93+
* ## Notes
94+
*
95+
* - The predicate function should accept a single argument: a typed array element. If the element satisfies a test condition, the function should return `true`; otherwise, the function should return `false`.
96+
* - Given an input typed array, the returned function returns `true` if all elements pass the test and `false` otherwise.
97+
* - The returned function returns `false` if provided an empty typed array.
98+
* - The returned function returns `false` is not provided a typed array.
99+
*
100+
* @param predicate - function to apply
101+
* @returns a typed array function
102+
*
103+
* @example
104+
* var isOdd = require( `@stdlib/assert/is-odd` );
105+
*
106+
* var arr1 = new Int32Array( [ 1, 3, 5, 7 ] );
107+
* var arr2 = new Int32Array( [ 1, 3, 5, 8 ] );
108+
*
109+
* var validate = typedarrayfcn( isOdd );
110+
*
111+
* var bool = validate( arr1 );
112+
* // returns true
113+
*
114+
* bool = validate( arr2 );
115+
* // returns false
116+
*/
117+
typedarrayfcn: typeof typedarrayfcn;
118+
}
119+
120+
/**
121+
* Standard library assertion utility tools.
122+
*/
123+
declare var tools: TOOLS;
124+
125+
126+
// EXPORTS //
127+
128+
export = tools;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* tslint:disable:no-unused-expression */
20+
21+
import tools = require( './index' );
22+
23+
24+
// TESTS //
25+
26+
// The exported value is the expected interface...
27+
{
28+
tools; // $ExpectType TOOLS
29+
}

lib/node_modules/@stdlib/assert/tools/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@stdlib/math/base/tools",
2+
"name": "@stdlib/assert/tools",
33
"version": "0.0.0",
44
"description": "Standard library assertion utility tools.",
55
"license": "Apache-2.0",
@@ -19,6 +19,7 @@
1919
"lib": "./lib",
2020
"test": "./test"
2121
},
22+
"types": "./docs/types",
2223
"scripts": {},
2324
"homepage": "https://github.com/stdlib-js/stdlib",
2425
"repository": {

0 commit comments

Comments
 (0)