-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce376f3
commit d6e941a
Showing
10 changed files
with
780 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
<!-- | ||
@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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* @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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pkg = require( './../package.json' ).name; | ||
var noneOwnBy = require( './../lib' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var bool; | ||
var obj; | ||
var i; | ||
|
||
function predicate( v ) { | ||
return isnan( v ); | ||
} | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
obj = { | ||
'a': i, | ||
'b': i+1, | ||
'c': i+2, | ||
'd': i+3 | ||
}; | ||
bool = noneOwnBy( obj, predicate ); | ||
if ( typeof bool !== 'boolean' ) { | ||
b.fail( 'should return a boolean' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( !isBoolean( bool ) ) { | ||
b.fail( 'should return a boolean' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
{{alias}}( object, predicate[, thisArg ] ) | ||
Tests whether every own property of an object fails a test implemented | ||
by a predicate function. | ||
|
||
The predicate function is provided three arguments: | ||
|
||
- `value`: property value | ||
- `index`: property key | ||
- `object`: the input object | ||
|
||
The function immediately returns upon encountering a truthy return value. | ||
|
||
If provided an empty object, the function returns `true`. | ||
|
||
Parameters | ||
---------- | ||
object: Object | ||
Input object. | ||
|
||
predicate: Function | ||
Test function. | ||
|
||
thisArg: any (optional) | ||
Execution context. | ||
|
||
Returns | ||
------- | ||
bool: boolean | ||
The function returns `true` if the predicate function returns a falsy | ||
value for all own properties; otherwise, the function returns `false`. | ||
|
||
Examples | ||
-------- | ||
> function isUnderage( v ) { return ( v < 18 ); }; | ||
> var obj = { 'a': 11, 'b': 12, 'c': 22 }; | ||
> var bool = {{alias}}( obj, isUnderage ) | ||
false | ||
|
||
See Also | ||
-------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* @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. | ||
*/ | ||
|
||
// TypeScript Version: 4.1 | ||
|
||
/// <reference types="@stdlib/types"/> | ||
|
||
|
||
/** | ||
* Checks whether an own property of the object passes the test. | ||
* | ||
* @returns boolean indicating whether an own property of the object passes the test | ||
*/ | ||
type Nullary<U> = ( this: U ) => boolean; | ||
|
||
/** | ||
* Checks whether an own property of the object passes the test. | ||
* | ||
* @param value - property value | ||
* @returns boolean indicating whether an own property of the object passes the test | ||
*/ | ||
type Unary<T, U> = ( this: U, value: T ) => boolean; | ||
|
||
/** | ||
* Checks whether an own property of the object passes the test. | ||
* | ||
* @param value - property value | ||
* @param key - property key | ||
* @returns boolean indicating whether an own property of the object passes the test | ||
*/ | ||
type Binary<T, U> = ( this: U, value: T, key: number ) => boolean; | ||
|
||
/** | ||
* Checks whether an own property of the object passes the test. | ||
* | ||
* @param value - property value | ||
* @param key - property key | ||
* @param object - input object | ||
* @returns boolean indicating whether an own property of the object passes the test | ||
*/ | ||
type Ternary<T, U> = ( this: U, value: T, key: number, object: Object ) => boolean; | ||
|
||
/** | ||
* Checks whether an own property of the object passes the test. | ||
* | ||
* @param value - object value | ||
* @param key - object key | ||
* @param object - input object | ||
* @returns boolean indicating whether an own property of the object passes the test | ||
*/ | ||
type Predicate<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U>; | ||
|
||
/** | ||
* Tests whether every property of an object fails a test implemented by a predicate function. | ||
* | ||
* ## Notes | ||
* | ||
* - The predicate function is provided three arguments: | ||
* | ||
* - `value`: property value | ||
* - `key`: property key | ||
* - `object`: the input object | ||
* | ||
* - The function immediately returns upon encountering a truthy return value. | ||
* - If provided an empty object, the function returns `true`. | ||
* | ||
* @param object - input object | ||
* @param predicate - test function | ||
* @param thisArg - execution context | ||
* @returns boolean indicating whether every property fails a test | ||
* | ||
* @example | ||
* function isUnderage( v ) { | ||
* return ( v < 18 ); | ||
* } | ||
* | ||
* var obj = { 'a': 20, 'b': 22, 'c': 25 }; | ||
* | ||
* var bool = noneOwnBy( obj, isUnderage ); | ||
* // returns true | ||
*/ | ||
declare function noneOwnBy<T = unknown, U = unknown>( object: Record<string, unknown>, predicate: Predicate<T, U>, thisArg?: ThisParameterType<Predicate<T, U>> ): boolean; | ||
|
||
|
||
// EXPORTS // | ||
|
||
export = noneOwnBy; |
Oops, something went wrong.