@ohos-ports/stdlib-object 0.0.0-stage → 0.4.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +262 -2
- package/SECURITY.md +5 -0
- package/any-in-by/README.md +217 -0
- package/any-in-by/docs/repl.txt +41 -0
- package/any-in-by/docs/types/index.d.ts +102 -0
- package/any-in-by/docs/types/test.ts +53 -0
- package/any-in-by/lib/index.js +50 -0
- package/any-in-by/lib/main.js +75 -0
- package/any-in-by/package.json +66 -0
- package/any-own-by/README.md +221 -0
- package/any-own-by/docs/repl.txt +43 -0
- package/any-own-by/docs/types/index.d.ts +101 -0
- package/any-own-by/docs/types/test.ts +63 -0
- package/any-own-by/lib/index.js +46 -0
- package/any-own-by/lib/main.js +77 -0
- package/any-own-by/package.json +70 -0
- package/assign/README.md +139 -0
- package/assign/docs/repl.txt +34 -0
- package/assign/docs/types/index.d.ts +113 -0
- package/assign/docs/types/test.ts +47 -0
- package/assign/lib/builtin.js +55 -0
- package/assign/lib/has_object_assign.js +33 -0
- package/assign/lib/index.js +52 -0
- package/assign/lib/polyfill.js +86 -0
- package/assign/package.json +64 -0
- package/assign-in/README.md +145 -0
- package/assign-in/docs/repl.txt +34 -0
- package/assign-in/docs/types/index.d.ts +175 -0
- package/assign-in/docs/types/test.ts +44 -0
- package/assign-in/lib/index.js +54 -0
- package/assign-in/lib/main.js +92 -0
- package/assign-in/package.json +60 -0
- package/bifurcate-in/README.md +298 -0
- package/bifurcate-in/docs/repl.txt +68 -0
- package/bifurcate-in/docs/types/index.d.ts +189 -0
- package/bifurcate-in/docs/types/test.ts +97 -0
- package/bifurcate-in/lib/index.js +106 -0
- package/bifurcate-in/lib/main.js +148 -0
- package/bifurcate-in/lib/return_keys.js +81 -0
- package/bifurcate-in/lib/return_pairs.js +87 -0
- package/bifurcate-in/lib/return_values.js +87 -0
- package/bifurcate-in/lib/validate.js +76 -0
- package/bifurcate-in/package.json +72 -0
- package/bifurcate-own/README.md +255 -0
- package/bifurcate-own/docs/repl.txt +63 -0
- package/bifurcate-own/docs/types/index.d.ts +183 -0
- package/bifurcate-own/docs/types/test.ts +97 -0
- package/bifurcate-own/lib/index.js +87 -0
- package/bifurcate-own/lib/main.js +127 -0
- package/bifurcate-own/lib/return_keys.js +81 -0
- package/bifurcate-own/lib/return_pairs.js +87 -0
- package/bifurcate-own/lib/return_values.js +87 -0
- package/bifurcate-own/lib/validate.js +76 -0
- package/bifurcate-own/package.json +71 -0
- package/capitalize-keys/README.md +139 -0
- package/capitalize-keys/docs/repl.txt +28 -0
- package/capitalize-keys/docs/types/index.d.ts +46 -0
- package/capitalize-keys/docs/types/test.ts +33 -0
- package/capitalize-keys/lib/index.js +45 -0
- package/capitalize-keys/lib/main.js +69 -0
- package/capitalize-keys/package.json +76 -0
- package/common-keys/README.md +125 -0
- package/common-keys/docs/repl.txt +29 -0
- package/common-keys/docs/types/index.d.ts +70 -0
- package/common-keys/docs/types/test.ts +33 -0
- package/common-keys/lib/index.js +51 -0
- package/common-keys/lib/main.js +106 -0
- package/common-keys/package.json +70 -0
- package/common-keys-in/README.md +125 -0
- package/common-keys-in/docs/repl.txt +29 -0
- package/common-keys-in/docs/types/index.d.ts +70 -0
- package/common-keys-in/docs/types/test.ts +33 -0
- package/common-keys-in/lib/index.js +51 -0
- package/common-keys-in/lib/main.js +106 -0
- package/common-keys-in/package.json +72 -0
- package/ctor/README.md +536 -0
- package/ctor/docs/repl.txt +592 -0
- package/ctor/docs/types/index.d.ts +56 -0
- package/ctor/docs/types/test.ts +33 -0
- package/ctor/lib/index.js +54 -0
- package/ctor/lib/main.js +58 -0
- package/ctor/package.json +58 -0
- package/deep-get/README.md +181 -0
- package/deep-get/docs/repl.txt +63 -0
- package/deep-get/docs/types/index.d.ts +125 -0
- package/deep-get/docs/types/test.ts +109 -0
- package/deep-get/lib/defaults.js +38 -0
- package/deep-get/lib/dget.js +57 -0
- package/deep-get/lib/factory.js +94 -0
- package/deep-get/lib/index.js +58 -0
- package/deep-get/lib/main.js +101 -0
- package/deep-get/lib/validate.js +66 -0
- package/deep-get/package.json +68 -0
- package/deep-set/README.md +273 -0
- package/deep-set/docs/repl.txt +87 -0
- package/deep-set/docs/types/index.d.ts +180 -0
- package/deep-set/docs/types/test.ts +134 -0
- package/deep-set/lib/defaults.js +39 -0
- package/deep-set/lib/dset.js +80 -0
- package/deep-set/lib/factory.js +99 -0
- package/deep-set/lib/index.js +58 -0
- package/deep-set/lib/main.js +120 -0
- package/deep-set/lib/validate.js +74 -0
- package/deep-set/package.json +69 -0
- package/docs/types/index.d.ts +964 -0
- package/every-in-by/README.md +156 -0
- package/every-in-by/docs/repl.txt +43 -0
- package/every-in-by/docs/types/index.d.ts +83 -0
- package/every-in-by/docs/types/test.ts +60 -0
- package/every-in-by/lib/index.js +51 -0
- package/every-in-by/lib/main.js +70 -0
- package/every-in-by/package.json +67 -0
- package/every-own-by/README.md +223 -0
- package/every-own-by/docs/repl.txt +43 -0
- package/every-own-by/docs/types/index.d.ts +102 -0
- package/every-own-by/docs/types/test.ts +62 -0
- package/every-own-by/lib/index.js +46 -0
- package/every-own-by/lib/main.js +77 -0
- package/every-own-by/package.json +68 -0
- package/for-in/README.md +218 -0
- package/for-in/docs/repl.txt +44 -0
- package/for-in/docs/types/index.d.ts +65 -0
- package/for-in/docs/types/test.ts +50 -0
- package/for-in/lib/index.js +54 -0
- package/for-in/lib/main.js +82 -0
- package/for-in/package.json +74 -0
- package/for-own/README.md +209 -0
- package/for-own/docs/repl.txt +49 -0
- package/for-own/docs/types/index.d.ts +63 -0
- package/for-own/docs/types/test.ts +50 -0
- package/for-own/lib/index.js +50 -0
- package/for-own/lib/main.js +85 -0
- package/for-own/package.json +71 -0
- package/inverse/README.md +163 -0
- package/inverse/docs/repl.txt +53 -0
- package/inverse/docs/types/index.d.ts +66 -0
- package/inverse/docs/types/test.ts +60 -0
- package/inverse/lib/index.js +59 -0
- package/inverse/lib/main.js +123 -0
- package/inverse/package.json +69 -0
- package/inverse-by/README.md +205 -0
- package/inverse-by/docs/repl.txt +67 -0
- package/inverse-by/docs/types/index.d.ts +160 -0
- package/inverse-by/docs/types/test.ts +81 -0
- package/inverse-by/lib/index.js +78 -0
- package/inverse-by/lib/main.js +148 -0
- package/inverse-by/package.json +75 -0
- package/lib/index.js +276 -0
- package/lowercase-keys/README.md +139 -0
- package/lowercase-keys/docs/repl.txt +28 -0
- package/lowercase-keys/docs/types/index.d.ts +46 -0
- package/lowercase-keys/docs/types/test.ts +33 -0
- package/lowercase-keys/lib/index.js +45 -0
- package/lowercase-keys/lib/main.js +63 -0
- package/lowercase-keys/package.json +74 -0
- package/move-property/README.md +144 -0
- package/move-property/docs/repl.txt +38 -0
- package/move-property/docs/types/index.d.ts +53 -0
- package/move-property/docs/types/test.ts +46 -0
- package/move-property/lib/index.js +46 -0
- package/move-property/lib/main.js +74 -0
- package/move-property/package.json +69 -0
- package/none-in-by/README.md +241 -0
- package/none-in-by/docs/repl.txt +42 -0
- package/none-in-by/docs/types/index.d.ts +101 -0
- package/none-in-by/docs/types/test.ts +61 -0
- package/none-in-by/lib/index.js +46 -0
- package/none-in-by/lib/main.js +71 -0
- package/none-in-by/package.json +68 -0
- package/none-own-by/README.md +177 -0
- package/none-own-by/docs/repl.txt +42 -0
- package/none-own-by/docs/types/index.d.ts +102 -0
- package/none-own-by/docs/types/test.ts +61 -0
- package/none-own-by/lib/index.js +50 -0
- package/none-own-by/lib/main.js +75 -0
- package/none-own-by/package.json +68 -0
- package/package.json +66 -4
- package/some-in-by/README.md +232 -0
- package/some-in-by/docs/repl.txt +45 -0
- package/some-in-by/docs/types/index.d.ts +104 -0
- package/some-in-by/docs/types/test.ts +66 -0
- package/some-in-by/lib/index.js +46 -0
- package/some-in-by/lib/main.js +87 -0
- package/some-in-by/package.json +75 -0
- package/some-own-by/README.md +251 -0
- package/some-own-by/docs/repl.txt +45 -0
- package/some-own-by/docs/types/index.d.ts +103 -0
- package/some-own-by/docs/types/test.ts +66 -0
- package/some-own-by/lib/index.js +46 -0
- package/some-own-by/lib/main.js +85 -0
- package/some-own-by/package.json +72 -0
- package/uncapitalize-keys/README.md +139 -0
- package/uncapitalize-keys/docs/repl.txt +28 -0
- package/uncapitalize-keys/docs/types/index.d.ts +46 -0
- package/uncapitalize-keys/docs/types/test.ts +33 -0
- package/uncapitalize-keys/lib/index.js +45 -0
- package/uncapitalize-keys/lib/main.js +69 -0
- package/uncapitalize-keys/package.json +76 -0
- package/uppercase-keys/README.md +139 -0
- package/uppercase-keys/docs/repl.txt +28 -0
- package/uppercase-keys/docs/types/index.d.ts +46 -0
- package/uppercase-keys/docs/types/test.ts +33 -0
- package/uppercase-keys/lib/index.js +45 -0
- package/uppercase-keys/lib/main.js +63 -0
- package/uppercase-keys/package.json +74 -0
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
# everyInBy
|
|
22
|
+
|
|
23
|
+
> Test whether all properties (own and inherited) of an object pass 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 everyInBy = require( '@stdlib/object/every-in-by' );
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### everyInBy( object, predicate\[, thisArg ] )
|
|
44
|
+
|
|
45
|
+
Tests whether all properties (own and inherited) of an `object` pass a test implemented by a `predicate` function.
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
var o;
|
|
49
|
+
var bool;
|
|
50
|
+
|
|
51
|
+
function isPositive( v ) {
|
|
52
|
+
return ( v > 0 );
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
o = {
|
|
56
|
+
'a': 1,
|
|
57
|
+
'b': 2,
|
|
58
|
+
'c': 3
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
bool = everyInBy( o, isPositive );
|
|
62
|
+
// returns true
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
If provided an empty `object`, the function returns `true`.
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
function isPositive( v ) {
|
|
69
|
+
return ( v > 0 );
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
var bool = everyInBy( {}, isPositive );
|
|
73
|
+
// returns true
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
</section>
|
|
77
|
+
|
|
78
|
+
<!-- /.usage -->
|
|
79
|
+
|
|
80
|
+
<!-- Package usage examples. -->
|
|
81
|
+
|
|
82
|
+
<section class="examples">
|
|
83
|
+
|
|
84
|
+
## Examples
|
|
85
|
+
|
|
86
|
+
<!-- eslint no-undef: "error" -->
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
var randu = require( '@stdlib/random/base/randu' );
|
|
90
|
+
var everyInBy = require( '@stdlib/object/every-in-by' );
|
|
91
|
+
|
|
92
|
+
var bool;
|
|
93
|
+
var o;
|
|
94
|
+
var i;
|
|
95
|
+
|
|
96
|
+
function isPositive( v ) {
|
|
97
|
+
return ( v > 0 );
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
o = {};
|
|
101
|
+
for ( i = 0; i < 100; i++ ) {
|
|
102
|
+
o[ i ] = ( randu() < 0.95 );
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
bool = everyInBy( o, isPositive );
|
|
106
|
+
// returns <boolean>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
</section>
|
|
110
|
+
|
|
111
|
+
<!-- /.examples -->
|
|
112
|
+
|
|
113
|
+
<!-- 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. -->
|
|
114
|
+
|
|
115
|
+
<section class="references">
|
|
116
|
+
|
|
117
|
+
</section>
|
|
118
|
+
|
|
119
|
+
<!-- /.references -->
|
|
120
|
+
|
|
121
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
122
|
+
|
|
123
|
+
<section class="related">
|
|
124
|
+
|
|
125
|
+
* * *
|
|
126
|
+
|
|
127
|
+
## See Also
|
|
128
|
+
|
|
129
|
+
- <span class="package-name">[`@stdlib/object/any-in-by`][@stdlib/object/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>
|
|
130
|
+
- <span class="package-name">[`@stdlib/object/none-in-by`][@stdlib/object/none-in-by]</span><span class="delimiter">: </span><span class="description">test whether every property in an object fails a test implemented by a predicate function.</span>
|
|
131
|
+
- <span class="package-name">[`@stdlib/object/some-in-by`][@stdlib/object/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>
|
|
132
|
+
- <span class="package-name">[`@stdlib/object/every-own-by`][@stdlib/object/every-own-by]</span><span class="delimiter">: </span><span class="description">test whether all own properties of an object pass a test implemented by a predicate function.</span>
|
|
133
|
+
|
|
134
|
+
</section>
|
|
135
|
+
|
|
136
|
+
<!-- /.related -->
|
|
137
|
+
|
|
138
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
139
|
+
|
|
140
|
+
<section class="links">
|
|
141
|
+
|
|
142
|
+
<!-- <related-links> -->
|
|
143
|
+
|
|
144
|
+
[@stdlib/object/any-in-by]: https://github.com/stdlib-js/object/tree/main/any-in-by
|
|
145
|
+
|
|
146
|
+
[@stdlib/object/none-in-by]: https://github.com/stdlib-js/object/tree/main/none-in-by
|
|
147
|
+
|
|
148
|
+
[@stdlib/object/some-in-by]: https://github.com/stdlib-js/object/tree/main/some-in-by
|
|
149
|
+
|
|
150
|
+
[@stdlib/object/every-own-by]: https://github.com/stdlib-js/object/tree/main/every-own-by
|
|
151
|
+
|
|
152
|
+
<!-- </related-links> -->
|
|
153
|
+
|
|
154
|
+
</section>
|
|
155
|
+
|
|
156
|
+
<!-- /.links -->
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( object, predicate[, thisArg ] )
|
|
3
|
+
Test whether all properties (own and inherited) of an object pass a
|
|
4
|
+
test implemented by a predicate function.
|
|
5
|
+
|
|
6
|
+
The predicate function is provided three arguments:
|
|
7
|
+
|
|
8
|
+
- value: object value.
|
|
9
|
+
- key: object key.
|
|
10
|
+
- object: the input object.
|
|
11
|
+
|
|
12
|
+
The function immediately returns upon encountering a non-truthy return
|
|
13
|
+
value.
|
|
14
|
+
|
|
15
|
+
If provided an empty object, the function returns `true`.
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
object: Object
|
|
20
|
+
Input object over which to iterate.
|
|
21
|
+
|
|
22
|
+
predicate: Function
|
|
23
|
+
Test function.
|
|
24
|
+
|
|
25
|
+
thisArg: any (optional)
|
|
26
|
+
Execution context.
|
|
27
|
+
|
|
28
|
+
Returns
|
|
29
|
+
-------
|
|
30
|
+
bool: boolean
|
|
31
|
+
The function returns `true` if the predicate function returns a truthy
|
|
32
|
+
value for all elements; otherwise, the function returns `false`.
|
|
33
|
+
|
|
34
|
+
Examples
|
|
35
|
+
--------
|
|
36
|
+
> function positive( v ) { return ( v > 0 ); };
|
|
37
|
+
> var o = {a: 1, b: 2, c: 3};
|
|
38
|
+
> var bool = {{alias}}( o, positive )
|
|
39
|
+
true
|
|
40
|
+
|
|
41
|
+
See Also
|
|
42
|
+
--------
|
|
43
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
import { Collection } from '@stdlib/types/array';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Checks whether an element in a collection passes a test.
|
|
23
|
+
*
|
|
24
|
+
* @returns boolean indicating whether an element in a collection passes a test
|
|
25
|
+
*/
|
|
26
|
+
type Nullary<U> = ( this: U ) => boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Checks whether an element in a collection passes a test.
|
|
30
|
+
*
|
|
31
|
+
* @param value - collection value
|
|
32
|
+
* @returns boolean indicating whether an element in a collection passes a test
|
|
33
|
+
*/
|
|
34
|
+
type Unary<T, U> = ( this: U, value: T ) => boolean;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Checks whether an element in a collection passes a test.
|
|
38
|
+
*
|
|
39
|
+
* @param value - collection value
|
|
40
|
+
* @param index - collection index
|
|
41
|
+
* @returns boolean indicating whether an element in a collection passes a test
|
|
42
|
+
*/
|
|
43
|
+
type Binary<T, U> = ( this: U, value: T, index: number ) => boolean;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Checks whether an element in a collection passes a test.
|
|
47
|
+
*
|
|
48
|
+
* @param value - collection value
|
|
49
|
+
* @param index - collection index
|
|
50
|
+
* @param collection - input collection
|
|
51
|
+
* @returns boolean indicating whether an element in a collection passes a test
|
|
52
|
+
*/
|
|
53
|
+
type Ternary<T, U> = ( this: U, value: T, index: number, collection: Collection<T> ) => boolean;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Checks whether an element in a collection passes a test.
|
|
57
|
+
*
|
|
58
|
+
* @param value - collection value
|
|
59
|
+
* @param index - collection index
|
|
60
|
+
* @param collection - input collection
|
|
61
|
+
* @returns boolean indicating whether an element in a collection passes a test
|
|
62
|
+
*/
|
|
63
|
+
type Predicate<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Checks whether all own and inherited properties in an object pass a test implemented by a predicate function.
|
|
67
|
+
*
|
|
68
|
+
* @param obj - object to iterate over
|
|
69
|
+
* @param predicate - test function to apply to each property
|
|
70
|
+
* @param thisArg - optional execution context for the predicate function
|
|
71
|
+
* @throws if `obj` is not an object or if `predicate` is not a function
|
|
72
|
+
* @returns boolean indicating whether all properties pass the test
|
|
73
|
+
*/
|
|
74
|
+
declare function everyInBy<T, U>(
|
|
75
|
+
obj: object,
|
|
76
|
+
predicate: Predicate<T, U>,
|
|
77
|
+
thisArg?: ThisParameterType<Predicate<T, U>>
|
|
78
|
+
): boolean;
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
// EXPORTS //
|
|
82
|
+
|
|
83
|
+
export = everyInBy;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
import everyInBy = require( './index' );
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// TESTS //
|
|
23
|
+
|
|
24
|
+
function isPositive( v: number ): boolean {
|
|
25
|
+
if ( typeof v !== 'object' || v === null ) {
|
|
26
|
+
throw new TypeError( 'Expected an object' );
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return v > 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The function returns a boolean...
|
|
33
|
+
{
|
|
34
|
+
everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, isPositive ); // $ExpectType boolean
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// The compiler throws an error if the function is provided a first argument which is not a object...
|
|
38
|
+
{
|
|
39
|
+
everyInBy( 2 ); // $ExpectError
|
|
40
|
+
everyInBy( false ); // $ExpectError
|
|
41
|
+
everyInBy( true ); // $ExpectError
|
|
42
|
+
everyInBy( [1, 2, 3, 4] ); // $ExpectError
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The compiler throws an error if the function is provided a second argument which is not a function...
|
|
46
|
+
{
|
|
47
|
+
everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, 2 ); // $ExpectError
|
|
48
|
+
everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, false ); // $ExpectError
|
|
49
|
+
everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, true ); // $ExpectError
|
|
50
|
+
everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, 'abc' ); // $ExpectError
|
|
51
|
+
everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, {} ); // $ExpectError
|
|
52
|
+
everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, [] ); // $ExpectError
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The compiler throws an error if the function is provided an invalid number of arguments...
|
|
56
|
+
{
|
|
57
|
+
everyInBy(); // $ExpectError
|
|
58
|
+
everyInBy( { 'a': 1, 'b': 2, 'c': 3} ); // $ExpectError
|
|
59
|
+
everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, {}, 3 ); // $ExpectError
|
|
60
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Test whether all elements in an object pass a test implemented by a predicate function.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/object/every-in-by
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var everyInBy = require( '@ohos-ports/stdlib-object/every-in-by' );
|
|
28
|
+
*
|
|
29
|
+
* function isPositive( v ) {
|
|
30
|
+
* return ( v > 0 );
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* var o = { a: 1, b: 2, c: 3 }
|
|
34
|
+
*
|
|
35
|
+
* var bool = everyInBy( o, isPositive )
|
|
36
|
+
* // returns true
|
|
37
|
+
*
|
|
38
|
+
* o.a = -1
|
|
39
|
+
*
|
|
40
|
+
* bool = everyInBy( o, isPositive )
|
|
41
|
+
* // returns false
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
// MODULES //
|
|
45
|
+
|
|
46
|
+
var main = require( './main.js' );
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// EXPORTS //
|
|
50
|
+
|
|
51
|
+
module.exports = main;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var isFunction = require( '@ohos-ports/stdlib-assert/is-function' );
|
|
24
|
+
var format = require( '@ohos-ports/stdlib-string/format' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Tests whether all properties (own and inherited) of an object pass a test implemented by a predicate function.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} obj - input object
|
|
33
|
+
* @param {Function} predicate - test function
|
|
34
|
+
* @param {*} [thisArg] - execution context
|
|
35
|
+
* @throws {TypeError} first argument must be an object
|
|
36
|
+
* @throws {TypeError} second argument must be a function
|
|
37
|
+
* @returns {boolean} boolean indicating whether all elements pass a test
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* function isPositive( v ) {
|
|
41
|
+
* return ( v > 0 );
|
|
42
|
+
* }
|
|
43
|
+
*
|
|
44
|
+
* var o = { a: 1, b: 2, c: 3 };
|
|
45
|
+
*
|
|
46
|
+
* var bool = everyInBy( o, isPositive );
|
|
47
|
+
* // returns true
|
|
48
|
+
*/
|
|
49
|
+
function everyInBy( obj, predicate, thisArg ) {
|
|
50
|
+
var key;
|
|
51
|
+
if ( typeof obj !== 'object' || obj === null ) {
|
|
52
|
+
throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );
|
|
53
|
+
}
|
|
54
|
+
if ( !isFunction( predicate ) ) {
|
|
55
|
+
throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', predicate ) );
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
for ( key in obj ) {
|
|
59
|
+
if ( !predicate.call( thisArg, obj[ key ], key, obj ) ) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
// EXPORTS //
|
|
69
|
+
|
|
70
|
+
module.exports = everyInBy;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/object/every-in-by",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Test whether all properties (own and inherited) of an object pass a test implemented by a predicate function.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"benchmark": "./benchmark",
|
|
19
|
+
"doc": "./docs",
|
|
20
|
+
"example": "./examples",
|
|
21
|
+
"lib": "./lib",
|
|
22
|
+
"test": "./test"
|
|
23
|
+
},
|
|
24
|
+
"types": "./docs/types",
|
|
25
|
+
"scripts": {},
|
|
26
|
+
"homepage": "https://github.com/stdlib-js/stdlib",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git://github.com/stdlib-js/stdlib.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {},
|
|
35
|
+
"devDependencies": {},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=0.10.0",
|
|
38
|
+
"npm": ">2.7.0"
|
|
39
|
+
},
|
|
40
|
+
"os": [
|
|
41
|
+
"aix",
|
|
42
|
+
"darwin",
|
|
43
|
+
"freebsd",
|
|
44
|
+
"linux",
|
|
45
|
+
"macos",
|
|
46
|
+
"openbsd",
|
|
47
|
+
"sunos",
|
|
48
|
+
"win32",
|
|
49
|
+
"windows"
|
|
50
|
+
],
|
|
51
|
+
"keywords": [
|
|
52
|
+
"stdlib",
|
|
53
|
+
"stdutils",
|
|
54
|
+
"stdutil",
|
|
55
|
+
"utilities",
|
|
56
|
+
"utility",
|
|
57
|
+
"utils",
|
|
58
|
+
"util",
|
|
59
|
+
"test",
|
|
60
|
+
"predicate",
|
|
61
|
+
"every",
|
|
62
|
+
"all",
|
|
63
|
+
"object",
|
|
64
|
+
"iterate",
|
|
65
|
+
"validate"
|
|
66
|
+
]
|
|
67
|
+
}
|