|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# noneInBy |
| 22 | + |
| 23 | +> Test whether every property of an object fails a test implemented by a predicate function. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var noneInBy = require( '@stdlib/object/none-in-by' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### noneInBy( object, predicate\[, thisArg ] ) |
| 44 | + |
| 45 | +Tests whether every property of an `object` fails a test implemented by a `predicate` function. |
| 46 | + |
| 47 | +```javascript |
| 48 | +function isUnderage( age ) { |
| 49 | + return ( age < 18 ); |
| 50 | +} |
| 51 | + |
| 52 | +var obj = { |
| 53 | + 'a': 28, |
| 54 | + 'b': 22, |
| 55 | + 'c': 25 |
| 56 | +}; |
| 57 | + |
| 58 | +var bool = noneInBy( obj, isUnderage ); |
| 59 | +// returns true |
| 60 | +``` |
| 61 | + |
| 62 | +If a `predicate` function returns a truthy value, the function **immediately** returns `false`. |
| 63 | + |
| 64 | +```javascript |
| 65 | +function isUnderage( age ) { |
| 66 | + return ( age < 18 ); |
| 67 | +} |
| 68 | + |
| 69 | +var obj = { |
| 70 | + 'a': 12, |
| 71 | + 'b': 22, |
| 72 | + 'c': 25 |
| 73 | +}; |
| 74 | + |
| 75 | +var bool = noneInBy( obj, isUnderage ); |
| 76 | +// returns false |
| 77 | +``` |
| 78 | + |
| 79 | +The invoked `function` is provided three agruments: |
| 80 | + |
| 81 | +- **value**: property value. |
| 82 | +- **key**: property key. |
| 83 | +- **object**: input object. |
| 84 | + |
| 85 | +To set the function execution context, provide a `thisArg`. |
| 86 | + |
| 87 | +```javascript |
| 88 | +function sum( value ) { |
| 89 | + if ( value < 0 ) { |
| 90 | + return true; |
| 91 | + } |
| 92 | + this.sum += value; |
| 93 | + this.count += 1; |
| 94 | + return false; |
| 95 | +} |
| 96 | + |
| 97 | +var obj = { |
| 98 | + 'a': 1, |
| 99 | + 'b': 2, |
| 100 | + 'c': 3, |
| 101 | + 'd': 4 |
| 102 | +}; |
| 103 | + |
| 104 | +var context = { |
| 105 | + 'sum': 0, |
| 106 | + 'count': 0 |
| 107 | +}; |
| 108 | + |
| 109 | +var bool = noneInBy( obj, sum, context ); |
| 110 | +// returns true |
| 111 | + |
| 112 | +var mean = context.sum / context.count; |
| 113 | +// returns 2.5 |
| 114 | +``` |
| 115 | + |
| 116 | +</section> |
| 117 | + |
| 118 | +<!-- /.usage --> |
| 119 | + |
| 120 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 121 | + |
| 122 | +<section class="notes"> |
| 123 | + |
| 124 | +## Notes |
| 125 | + |
| 126 | +- If the 1st argument is not an object or the second argument is not a fuction , the |
| 127 | + function throws a Type Error. |
| 128 | + |
| 129 | +- If provided an empty object, the function returns `true`. |
| 130 | + |
| 131 | + ```javascript |
| 132 | + function truthy() { |
| 133 | + return true; |
| 134 | + } |
| 135 | + var bool = noneInBy( {}, truthy ); |
| 136 | + // returns true |
| 137 | + ``` |
| 138 | + |
| 139 | +- The function does **not** skip `undefined` elements. |
| 140 | + |
| 141 | + <!-- eslint-disable no-sparse-arrays, stdlib/doctest-marker --> |
| 142 | + |
| 143 | + ```javascript |
| 144 | + function log( value, index ) { |
| 145 | + console.log( '%s: %s', index, value ); |
| 146 | + return false; |
| 147 | + } |
| 148 | + |
| 149 | + var obj = { |
| 150 | + 'a': 1, |
| 151 | + 'b': NaN, |
| 152 | + 'c': NaN, |
| 153 | + 'd': 4 |
| 154 | + }; |
| 155 | + |
| 156 | + var bool = noneInBy( arr, log ); |
| 157 | + /* => |
| 158 | + 0: 1 |
| 159 | + 1: undefined |
| 160 | + 2: undefined |
| 161 | + 3: 4 |
| 162 | + */ |
| 163 | + ``` |
| 164 | + |
| 165 | +</section> |
| 166 | + |
| 167 | +<!-- /.notes --> |
| 168 | + |
| 169 | +<!-- Package usage examples. --> |
| 170 | + |
| 171 | +<section class="examples"> |
| 172 | + |
| 173 | +## Examples |
| 174 | + |
| 175 | +<!-- eslint no-undef: "error" --> |
| 176 | + |
| 177 | +```javascript |
| 178 | +var noneInBy = require( '@stdlib/object/none-in-by' ); |
| 179 | +
|
| 180 | +function isUnderage( age ) { |
| 181 | + return age < 18; |
| 182 | +} |
| 183 | +
|
| 184 | +var obj = { |
| 185 | + 'a': 26, |
| 186 | + 'b': 20, |
| 187 | + 'c': 25 |
| 188 | +}; |
| 189 | +
|
| 190 | +var bool = noneInBy( obj, isUnderage ); |
| 191 | +// returns true |
| 192 | +``` |
| 193 | + |
| 194 | +</section> |
| 195 | + |
| 196 | +<!-- /.examples --> |
| 197 | + |
| 198 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 199 | + |
| 200 | +<section class="references"> |
| 201 | + |
| 202 | +</section> |
| 203 | + |
| 204 | +<!-- /.references --> |
| 205 | + |
| 206 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 207 | + |
| 208 | +<section class="related"> |
| 209 | + |
| 210 | +* * * |
| 211 | + |
| 212 | +## See Also |
| 213 | + |
| 214 | +- <span class="package-name">[`@stdlib/utils/any-in-by`][@stdlib/utils/any-in-by]</span><span class="delimiter">: </span><span class="description">test whether at least one property in an object passes a test implemented by a predicate function.</span> |
| 215 | +- <span class="package-name">[`@stdlib/object/every-in-by`][@stdlib/object/every-in-by]</span><span class="delimiter">: </span><span class="description">test whether all properties (own and inherited) of an object pass a test implemented by a predicate function.</span> |
| 216 | +- <span class="package-name">[`@stdlib/utils/for-in`][@stdlib/utils/for-in]</span><span class="delimiter">: </span><span class="description">invoke a function for each own and inherited enumerable property of an object.</span> |
| 217 | +- <span class="package-name">[`@stdlib/utils/none-by`][@stdlib/utils/none-by]</span><span class="delimiter">: </span><span class="description">test whether all elements in a collection fail a test implemented by a predicate function.</span> |
| 218 | +- <span class="package-name">[`@stdlib/utils/some-in-by`][@stdlib/utils/some-in-by]</span><span class="delimiter">: </span><span class="description">test whether an object contains at least n properties (own and inherited) which pass a test implemented by a predicate function.</span> |
| 219 | + |
| 220 | +</section> |
| 221 | + |
| 222 | +<!-- /.related --> |
| 223 | + |
| 224 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 225 | + |
| 226 | +<section class="links"> |
| 227 | + |
| 228 | +<!-- <related-links> --> |
| 229 | + |
| 230 | +[@stdlib/utils/any-in-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/any-in-by |
| 231 | + |
| 232 | +[@stdlib/object/every-in-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/every-in-by |
| 233 | + |
| 234 | +[@stdlib/utils/for-in]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/for-in |
| 235 | + |
| 236 | +[@stdlib/utils/none-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/none-by |
| 237 | + |
| 238 | +[@stdlib/utils/some-in-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/some-in-by |
| 239 | + |
| 240 | +<!-- </related-links> --> |
| 241 | + |
| 242 | +</section> |
| 243 | + |
| 244 | +<!-- /.links --> |
0 commit comments