@stdlib/utils
Version:
Standard utilities.
165 lines (103 loc) • 3.34 kB
Markdown
<!--
@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.
-->
# noneOwnBy
> Tests whether every own property of an object fails a test implemented by a predicate function.
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
<section class="intro">
</section>
<!-- /.intro -->
<!-- Package usage documentation. -->
<section class="usage">
## Usage
```javascript
var noneOwnBy = require( '@stdlib/utils/none-own-by' );
```
#### noneOwnBy( object, predicate\[, thisArg ] )
Tests whether every `own` property of an object fails a test implemented by a `predicate` function.
```javascript
function isUnderage( age ) {
return ( age < 18 );
}
var obj = {
'a': 28,
'b': 22,
'c': 25
};
var bool = noneOwnBy( obj, isUnderage );
// returns true
```
If a `predicate` function returns a truthy value, the function **immediately** returns `false`.
```javascript
function isUnderage( age ) {
return ( age < 18 );
}
var obj = {
'a': 12,
'b': 22,
'c': 25
};
var bool = noneOwnBy( obj, isUnderage );
// returns false
```
</section>
<!-- /.usage -->
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
<section class="notes">
## Notes
- If the 1st argument is not an object or the second argument is not a fuction , the function throws a Type Error.
- If provided an empty object, the function returns `true`.
```javascript
function truthy() {
return true;
}
var bool = noneOwnBy( {}, truthy );
// returns true
```
</section>
<!-- /.notes -->
<!-- Package usage examples. -->
<section class="examples">
## Examples
<!-- eslint no-undef: "error" -->
```javascript
var noneOwnBy = require( '@stdlib/utils/none-own-by' );
function isUnderage( age ) {
return age < 18;
}
var obj = {
'a': 26,
'b': 20,
'c': 25
};
var bool = noneOwnBy( obj, isUnderage );
// returns true
```
</section>
<!-- /.examples -->
<!-- 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. -->
<section class="references">
</section>
<!-- /.references -->
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
<section class="related">
* * *
## See Also
</section>
<!-- /.related -->
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
<section class="links">
<!-- <related-links> -->
<!-- </related-links> -->
</section>
<!-- /.links -->