@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
package/for-in/README.md
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2018 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
|
+
# forIn
|
|
22
|
+
|
|
23
|
+
> Invoke a function for each own and inherited enumerable property of an object.
|
|
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 forIn = require( '@stdlib/object/for-in' );
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### forIn( obj, fcn\[, thisArg ] )
|
|
44
|
+
|
|
45
|
+
Invokes a `function` for each own and inherited enumerable property of an `object`.
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
function log( value, key ) {
|
|
49
|
+
console.log( '%s: %d', key, value );
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function Foo() {
|
|
53
|
+
this.a = 1;
|
|
54
|
+
this.b = 2;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Foo.prototype.c = 3;
|
|
59
|
+
Foo.prototype.d = 4;
|
|
60
|
+
|
|
61
|
+
var obj = new Foo();
|
|
62
|
+
|
|
63
|
+
forIn( obj, log );
|
|
64
|
+
/* e.g., =>
|
|
65
|
+
a: 1
|
|
66
|
+
b: 2
|
|
67
|
+
c: 3
|
|
68
|
+
d: 4
|
|
69
|
+
*/
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The invoked `function` is provided three arguments:
|
|
73
|
+
|
|
74
|
+
- **value**: object property value.
|
|
75
|
+
- **key**: object property.
|
|
76
|
+
- **obj**: the input object.
|
|
77
|
+
|
|
78
|
+
To terminate iteration before visiting all properties, the provided function must explicitly return `false`.
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
function log( value, key ) {
|
|
82
|
+
console.log( '%s: %d', key, value );
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var obj = {
|
|
87
|
+
'a': 1,
|
|
88
|
+
'b': 2,
|
|
89
|
+
'c': 3,
|
|
90
|
+
'd': 4
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
forIn( obj, log );
|
|
94
|
+
// e.g., => a: 1
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
To set the function execution context, provide a `thisArg`.
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
function sum( value ) {
|
|
101
|
+
this.sum += value;
|
|
102
|
+
this.count += 1;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
var obj = {
|
|
106
|
+
'a': 1,
|
|
107
|
+
'b': 2,
|
|
108
|
+
'c': 3,
|
|
109
|
+
'd': 4
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
var context = {
|
|
113
|
+
'sum': 0,
|
|
114
|
+
'count': 0
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
forIn( obj, sum, context );
|
|
118
|
+
|
|
119
|
+
var mean = context.sum / context.count;
|
|
120
|
+
// returns 2.5
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
</section>
|
|
124
|
+
|
|
125
|
+
<!-- /.usage -->
|
|
126
|
+
|
|
127
|
+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
128
|
+
|
|
129
|
+
<section class="notes">
|
|
130
|
+
|
|
131
|
+
## Notes
|
|
132
|
+
|
|
133
|
+
- The function returns the input `object`.
|
|
134
|
+
- Property iteration order is **not** guaranteed.
|
|
135
|
+
|
|
136
|
+
</section>
|
|
137
|
+
|
|
138
|
+
<!-- /.notes -->
|
|
139
|
+
|
|
140
|
+
<!-- Package usage examples. -->
|
|
141
|
+
|
|
142
|
+
<section class="examples">
|
|
143
|
+
|
|
144
|
+
## Examples
|
|
145
|
+
|
|
146
|
+
<!-- eslint no-undef: "error" -->
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
var fromCodePoint = require( '@stdlib/string/from-code-point' );
|
|
150
|
+
var forIn = require( '@stdlib/object/for-in' );
|
|
151
|
+
|
|
152
|
+
function update( value, key, obj ) {
|
|
153
|
+
console.log( '%s: %d', key, value );
|
|
154
|
+
obj[ key ] *= value;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function Foo() {
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
Foo.prototype.beep = 3.14;
|
|
162
|
+
|
|
163
|
+
var obj;
|
|
164
|
+
var key;
|
|
165
|
+
var i;
|
|
166
|
+
|
|
167
|
+
obj = new Foo();
|
|
168
|
+
for ( i = 0; i < 26; i++ ) {
|
|
169
|
+
key = fromCodePoint( 97 + i );
|
|
170
|
+
obj[ key ] = i;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
forIn( obj, update );
|
|
174
|
+
console.log( obj );
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
</section>
|
|
178
|
+
|
|
179
|
+
<!-- /.examples -->
|
|
180
|
+
|
|
181
|
+
<!-- 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. -->
|
|
182
|
+
|
|
183
|
+
<section class="references">
|
|
184
|
+
|
|
185
|
+
</section>
|
|
186
|
+
|
|
187
|
+
<!-- /.references -->
|
|
188
|
+
|
|
189
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
190
|
+
|
|
191
|
+
<section class="related">
|
|
192
|
+
|
|
193
|
+
* * *
|
|
194
|
+
|
|
195
|
+
## See Also
|
|
196
|
+
|
|
197
|
+
- <span class="package-name">[`@stdlib/utils/for-each`][@stdlib/utils/for-each]</span><span class="delimiter">: </span><span class="description">invoke a function for each element in a collection.</span>
|
|
198
|
+
- <span class="package-name">[`@stdlib/object/for-own`][@stdlib/object/for-own]</span><span class="delimiter">: </span><span class="description">invoke a function for each own enumerable property of an object.</span>
|
|
199
|
+
|
|
200
|
+
</section>
|
|
201
|
+
|
|
202
|
+
<!-- /.related -->
|
|
203
|
+
|
|
204
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
205
|
+
|
|
206
|
+
<section class="links">
|
|
207
|
+
|
|
208
|
+
<!-- <related-links> -->
|
|
209
|
+
|
|
210
|
+
[@stdlib/utils/for-each]: https://www.npmjs.com/package/@stdlib/utils-for-each
|
|
211
|
+
|
|
212
|
+
[@stdlib/object/for-own]: https://github.com/stdlib-js/object/tree/main/for-own
|
|
213
|
+
|
|
214
|
+
<!-- </related-links> -->
|
|
215
|
+
|
|
216
|
+
</section>
|
|
217
|
+
|
|
218
|
+
<!-- /.links -->
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( obj, fcn[, thisArg] )
|
|
3
|
+
Invokes a function for each own and inherited enumerable property of an
|
|
4
|
+
object.
|
|
5
|
+
|
|
6
|
+
When invoked, the function is provided three arguments:
|
|
7
|
+
|
|
8
|
+
- value: object property value.
|
|
9
|
+
- key: object property.
|
|
10
|
+
- obj: the input object.
|
|
11
|
+
|
|
12
|
+
To terminate iteration before visiting all properties, the provided function
|
|
13
|
+
must explicitly return `false`.
|
|
14
|
+
|
|
15
|
+
Property iteration order is *not* guaranteed.
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
obj: Object
|
|
20
|
+
Input object, including arrays, typed arrays, and other collections.
|
|
21
|
+
|
|
22
|
+
fcn: Function
|
|
23
|
+
The function to invoke for each own enumerable property.
|
|
24
|
+
|
|
25
|
+
thisArg: any (optional)
|
|
26
|
+
Execution context.
|
|
27
|
+
|
|
28
|
+
Returns
|
|
29
|
+
-------
|
|
30
|
+
out: Object
|
|
31
|
+
Input object.
|
|
32
|
+
|
|
33
|
+
Examples
|
|
34
|
+
--------
|
|
35
|
+
> function logger( v, k ) { console.log( '%s: %d', k, v ); };
|
|
36
|
+
> function Foo() { return this; };
|
|
37
|
+
> Foo.prototype.beep = 'boop';
|
|
38
|
+
> var obj = new Foo();
|
|
39
|
+
> {{alias}}( obj, logger )
|
|
40
|
+
beep: boop
|
|
41
|
+
|
|
42
|
+
See Also
|
|
43
|
+
--------
|
|
44
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 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: 4.1
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Invokes a function once for each own and inherited enumerable property of an object.
|
|
23
|
+
*
|
|
24
|
+
* ## Notes
|
|
25
|
+
*
|
|
26
|
+
* - When invoked, the function is provided three arguments:
|
|
27
|
+
*
|
|
28
|
+
* - `value`: object property value
|
|
29
|
+
* - `key`: object property
|
|
30
|
+
* - `obj`: the input object
|
|
31
|
+
*
|
|
32
|
+
* - To terminate iteration before visiting all properties, the provided function must explicitly return `false`.
|
|
33
|
+
*
|
|
34
|
+
* - Iteration order is **not** guaranteed.
|
|
35
|
+
*
|
|
36
|
+
*
|
|
37
|
+
* @param obj - input object
|
|
38
|
+
* @param fcn - function to invoke
|
|
39
|
+
* @param thisArg - execution context
|
|
40
|
+
* @returns obj - input object
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* function log( v, key ) {
|
|
44
|
+
* console.log( '%s: %d', key, v );
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* function Foo() {
|
|
48
|
+
* this.a = 1;
|
|
49
|
+
* this.b = 2;
|
|
50
|
+
* return this;
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* Foo.prototype.c = 3;
|
|
54
|
+
* Foo.prototype.d = 4;
|
|
55
|
+
*
|
|
56
|
+
* var obj = new Foo();
|
|
57
|
+
*
|
|
58
|
+
* forIn( obj, log );
|
|
59
|
+
*/
|
|
60
|
+
declare function forIn( obj: any, fcn: Function, thisArg?: any ): any;
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
// EXPORTS //
|
|
64
|
+
|
|
65
|
+
export = forIn;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 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
|
+
/* eslint-disable no-new-wrappers */
|
|
20
|
+
|
|
21
|
+
import forIn = require( './index' );
|
|
22
|
+
|
|
23
|
+
const log = ( v: any, key: string ): string => {
|
|
24
|
+
return `${key}: ${v}`;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// TESTS //
|
|
28
|
+
|
|
29
|
+
// The function returns an object...
|
|
30
|
+
{
|
|
31
|
+
forIn( new String( 'abc' ), log ); // $ExpectType any
|
|
32
|
+
forIn( new String( 'abc' ), log, {} ); // $ExpectType any
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The compiler throws an error if the function is provided a second argument which is not a function...
|
|
36
|
+
{
|
|
37
|
+
forIn( new String( 'abc' ), 2 ); // $ExpectError
|
|
38
|
+
forIn( new String( 'abc' ), false ); // $ExpectError
|
|
39
|
+
forIn( new String( 'abc' ), true ); // $ExpectError
|
|
40
|
+
forIn( new String( 'abc' ), 'abc' ); // $ExpectError
|
|
41
|
+
forIn( new String( 'abc' ), {} ); // $ExpectError
|
|
42
|
+
forIn( new String( 'abc' ), [] ); // $ExpectError
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The compiler throws an error if the function is provided an invalid number of arguments...
|
|
46
|
+
{
|
|
47
|
+
forIn(); // $ExpectError
|
|
48
|
+
forIn( new String( 'abc' ) ); // $ExpectError
|
|
49
|
+
forIn( new String( 'abc' ), log, {}, 3 ); // $ExpectError
|
|
50
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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
|
+
* Invoke a function once for each own and inherited enumerable property of an object.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/object/for-in
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var forIn = require( '@ohos-ports/stdlib-object/for-in' );
|
|
28
|
+
*
|
|
29
|
+
* function log( v, key ) {
|
|
30
|
+
* console.log( '%s: %d', key, v );
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* function Foo() {
|
|
34
|
+
* this.a = 1;
|
|
35
|
+
* this.b = 2;
|
|
36
|
+
* return this;
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* Foo.prototype.c = 3;
|
|
40
|
+
* Foo.prototype.d = 4;
|
|
41
|
+
*
|
|
42
|
+
* var obj = new Foo();
|
|
43
|
+
*
|
|
44
|
+
* forIn( obj, log );
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
// MODULES //
|
|
48
|
+
|
|
49
|
+
var main = require( './main.js' );
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// EXPORTS //
|
|
53
|
+
|
|
54
|
+
module.exports = main;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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
|
+
* Invokes a function once for each own and inherited enumerable property of an object.
|
|
31
|
+
*
|
|
32
|
+
* ## Notes
|
|
33
|
+
*
|
|
34
|
+
* - Iteration order is **not** guaranteed.
|
|
35
|
+
*
|
|
36
|
+
* @param {Object} obj - input object
|
|
37
|
+
* @param {Function} fcn - function to invoke
|
|
38
|
+
* @param {*} [thisArg] - execution context
|
|
39
|
+
* @throws {TypeError} first argument must be an object
|
|
40
|
+
* @throws {TypeError} second argument must be a function
|
|
41
|
+
* @returns {Object} obj - input object
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* function log( v, key ) {
|
|
45
|
+
* console.log( '%s: %d', key, v );
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* function Foo() {
|
|
49
|
+
* this.a = 1;
|
|
50
|
+
* this.b = 2;
|
|
51
|
+
* return this;
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* Foo.prototype.c = 3;
|
|
55
|
+
* Foo.prototype.d = 4;
|
|
56
|
+
*
|
|
57
|
+
* var obj = new Foo();
|
|
58
|
+
*
|
|
59
|
+
* forIn( obj, log );
|
|
60
|
+
*/
|
|
61
|
+
function forIn( obj, fcn, thisArg ) {
|
|
62
|
+
var bool;
|
|
63
|
+
var key;
|
|
64
|
+
if ( typeof obj !== 'object' || obj === null ) {
|
|
65
|
+
throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );
|
|
66
|
+
}
|
|
67
|
+
if ( !isFunction( fcn ) ) {
|
|
68
|
+
throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );
|
|
69
|
+
}
|
|
70
|
+
for ( key in obj ) { // eslint-disable-line guard-for-in
|
|
71
|
+
bool = fcn.call( thisArg, obj[ key ], key, obj );
|
|
72
|
+
if ( bool === false ) {
|
|
73
|
+
return obj;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return obj;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
// EXPORTS //
|
|
81
|
+
|
|
82
|
+
module.exports = forIn;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/object/for-in",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Invoke a function for each own and inherited enumerable property of an object.",
|
|
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
|
+
"for",
|
|
60
|
+
"in",
|
|
61
|
+
"forin",
|
|
62
|
+
"object.keys",
|
|
63
|
+
"keys",
|
|
64
|
+
"properties",
|
|
65
|
+
"props",
|
|
66
|
+
"enumerable",
|
|
67
|
+
"inherited",
|
|
68
|
+
"inheritance",
|
|
69
|
+
"prototype",
|
|
70
|
+
"iterate",
|
|
71
|
+
"object",
|
|
72
|
+
"obj"
|
|
73
|
+
]
|
|
74
|
+
}
|