|
| 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; |
0 commit comments