@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,101 @@
|
|
|
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
|
+
// TypeScript Version: 4.1
|
|
20
|
+
|
|
21
|
+
/// <reference types="@stdlib/types"/>
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Checks whether an own property of the object passes the test.
|
|
25
|
+
*
|
|
26
|
+
* @returns boolean indicating whether an own property of the object passes the test
|
|
27
|
+
*/
|
|
28
|
+
type Nullary<U> = ( this: U ) => boolean;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Checks whether an own property of the object passes the test.
|
|
32
|
+
*
|
|
33
|
+
* @param value - collection value
|
|
34
|
+
* @returns boolean indicating whether an own property of the object passes the test
|
|
35
|
+
*/
|
|
36
|
+
type Unary<T, U> = ( this: U, value: T ) => boolean;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Checks whether an own property of the object passes the test.
|
|
40
|
+
*
|
|
41
|
+
* @param value - property value
|
|
42
|
+
* @param key - property key
|
|
43
|
+
* @returns boolean indicating whether an own property of the object passes the test
|
|
44
|
+
*/
|
|
45
|
+
type Binary<T, U> = ( this: U, value: T, key: number ) => boolean;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Checks whether an own property of the object passes the test.
|
|
49
|
+
*
|
|
50
|
+
* @param value - property value
|
|
51
|
+
* @param key - property key
|
|
52
|
+
* @param object - input object
|
|
53
|
+
* @returns boolean indicating whether an own property of the object passes the test
|
|
54
|
+
*/
|
|
55
|
+
type Ternary<T, U> = ( this: U, value: T, key: number, object: Object ) => boolean;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Checks whether an own property of the object passes the test.
|
|
59
|
+
*
|
|
60
|
+
* @param value - property value
|
|
61
|
+
* @param key - property key
|
|
62
|
+
* @param object - input object
|
|
63
|
+
* @returns boolean indicating whether an own property of the object passes the tests
|
|
64
|
+
*/
|
|
65
|
+
type Predicate<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Tests whether any property of an object passes a test implemented by a predicate function.
|
|
69
|
+
*
|
|
70
|
+
* ## Notes
|
|
71
|
+
*
|
|
72
|
+
* - The predicate function is provided three arguments:
|
|
73
|
+
*
|
|
74
|
+
* - `value`: property value
|
|
75
|
+
* - `key`: property key
|
|
76
|
+
* - `object`: the input object
|
|
77
|
+
*
|
|
78
|
+
* - The function immediately returns upon encountering a truthy return value.
|
|
79
|
+
* - If provided an empty object, the function returns `false`.
|
|
80
|
+
*
|
|
81
|
+
* @param object - input object
|
|
82
|
+
* @param predicate - test function
|
|
83
|
+
* @param thisArg - execution context
|
|
84
|
+
* @returns boolean indicating whether any own property pass a test
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* function isPositive( v ) {
|
|
88
|
+
* return ( v > 0 );
|
|
89
|
+
* }
|
|
90
|
+
*
|
|
91
|
+
* var obj = { 'a': -1, 'b': 2, 'c': -3 };
|
|
92
|
+
*
|
|
93
|
+
* var bool = anyOwnBy( obj, isPositive );
|
|
94
|
+
* // returns true
|
|
95
|
+
*/
|
|
96
|
+
declare function anyOwnBy<T = unknown, U = unknown>( object: Record<string, unknown>, predicate: Predicate<T, U>, thisArg?: ThisParameterType<Predicate<T, U>> ): boolean;
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
// EXPORTS //
|
|
100
|
+
|
|
101
|
+
export = anyOwnBy;
|
|
@@ -0,0 +1,63 @@
|
|
|
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 anyOwnBy = require( './index' );
|
|
20
|
+
|
|
21
|
+
const isPositive = ( v: number ): boolean => {
|
|
22
|
+
return ( v > 0 );
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const obj = {
|
|
26
|
+
'a':-1,
|
|
27
|
+
'b':2,
|
|
28
|
+
'c':-3
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// TESTS //
|
|
32
|
+
|
|
33
|
+
// The function returns a boolean...
|
|
34
|
+
{
|
|
35
|
+
anyOwnBy( obj, isPositive ); // $ExpectType boolean
|
|
36
|
+
anyOwnBy( obj, isPositive ); // $ExpectType boolean
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// The compiler throws an error if the function is provided a first argument which is not an object...
|
|
40
|
+
{
|
|
41
|
+
anyOwnBy( 2, isPositive ); // $ExpectError
|
|
42
|
+
anyOwnBy( false, isPositive ); // $ExpectError
|
|
43
|
+
anyOwnBy( true, isPositive ); // $ExpectError
|
|
44
|
+
anyOwnBy( [ 1, 2 ], isPositive ); // $ExpectError
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The compiler throws an error if the function is provided a second argument which is not a function...
|
|
48
|
+
{
|
|
49
|
+
anyOwnBy( obj , 2 ); // $ExpectError
|
|
50
|
+
anyOwnBy( obj , false ); // $ExpectError
|
|
51
|
+
anyOwnBy( obj , true ); // $ExpectError
|
|
52
|
+
anyOwnBy( obj , 'abc' ); // $ExpectError
|
|
53
|
+
anyOwnBy( obj , {} ); // $ExpectError
|
|
54
|
+
anyOwnBy( obj , [] ); // $ExpectError
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// The compiler throws an error if the function is provided an invalid number of arguments...
|
|
58
|
+
{
|
|
59
|
+
anyOwnBy(); // $ExpectError
|
|
60
|
+
anyOwnBy( [ 1, 2, 3 ] ); // $ExpectError
|
|
61
|
+
anyOwnBy( [ 1, 2, 3 ], isPositive, {}, 3 ); // $ExpectError
|
|
62
|
+
}
|
|
63
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
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 any 'own' property of a provided object satisfies a predicate function.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/object/any-own-by
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var anyOwnBy = require( '@ohos-ports/stdlib-object/any-own-by' );
|
|
28
|
+
*
|
|
29
|
+
* function isPositive( v ) {
|
|
30
|
+
* return ( v > 0 );
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* var obj = { 'a': -1, 'b': 2, 'c': -3 };
|
|
34
|
+
*
|
|
35
|
+
* var bool = anyOwnBy( obj, isPositive );
|
|
36
|
+
* // returns true
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
// MODULES //
|
|
40
|
+
|
|
41
|
+
var main = require( './main.js' );
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// EXPORTS //
|
|
45
|
+
|
|
46
|
+
module.exports = main;
|
|
@@ -0,0 +1,77 @@
|
|
|
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 isObject = require( '@ohos-ports/stdlib-assert/is-object' );
|
|
24
|
+
var isFunction = require( '@ohos-ports/stdlib-assert/is-function' );
|
|
25
|
+
var hasOwnProp = require( '@ohos-ports/stdlib-assert/has-own-property' );
|
|
26
|
+
var format = require( '@ohos-ports/stdlib-string/format' );
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// MAIN //
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Tests whether any 'own' property of a provided object satisfies a predicate function.
|
|
33
|
+
*
|
|
34
|
+
* @param {Object} obj - input object
|
|
35
|
+
* @param {Function} predicate - test function
|
|
36
|
+
* @param {*} [thisArg] - execution context
|
|
37
|
+
* @throws {TypeError} first argument must be an object
|
|
38
|
+
* @throws {TypeError} second argument must be a function
|
|
39
|
+
* @returns {boolean} boolean returned indicating whether any own property of an object pass a test
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var anyOwnBy = require( '@ohos-ports/stdlib-object/any-own-by' );
|
|
43
|
+
*
|
|
44
|
+
* function isPositive( v ) {
|
|
45
|
+
* return ( v > 0 );
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* var obj = { 'a': -1, 'b': 2, 'c': -3 };
|
|
49
|
+
*
|
|
50
|
+
* var bool = anyOwnBy( obj, isPositive );
|
|
51
|
+
* // returns true
|
|
52
|
+
*/
|
|
53
|
+
function anyOwnBy( obj, predicate, thisArg ) {
|
|
54
|
+
var result;
|
|
55
|
+
var key;
|
|
56
|
+
if ( !isObject( obj ) ) {
|
|
57
|
+
throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );
|
|
58
|
+
}
|
|
59
|
+
if ( !isFunction( predicate ) ) {
|
|
60
|
+
throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', predicate ) );
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
for ( key in obj ) {
|
|
64
|
+
if ( hasOwnProp( obj, key ) ) {
|
|
65
|
+
result = predicate.call( thisArg, obj[ key ], key, obj );
|
|
66
|
+
if ( result ) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
// EXPORTS //
|
|
76
|
+
|
|
77
|
+
module.exports = anyOwnBy;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/object/any-own-by",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Test whether whether any 'own' property of a provided object satisfies 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
|
+
"doc": "./docs",
|
|
19
|
+
"example": "./examples",
|
|
20
|
+
"lib": "./lib",
|
|
21
|
+
"test": "./test"
|
|
22
|
+
},
|
|
23
|
+
"types": "./docs/types",
|
|
24
|
+
"scripts": {},
|
|
25
|
+
"homepage": "https://github.com/stdlib-js/stdlib",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git://github.com/stdlib-js/stdlib.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {},
|
|
34
|
+
"devDependencies": {},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=0.10.0",
|
|
37
|
+
"npm": ">2.7.0"
|
|
38
|
+
},
|
|
39
|
+
"os": [
|
|
40
|
+
"aix",
|
|
41
|
+
"darwin",
|
|
42
|
+
"freebsd",
|
|
43
|
+
"linux",
|
|
44
|
+
"macos",
|
|
45
|
+
"openbsd",
|
|
46
|
+
"sunos",
|
|
47
|
+
"win32",
|
|
48
|
+
"windows"
|
|
49
|
+
],
|
|
50
|
+
"keywords": [
|
|
51
|
+
"stdlib",
|
|
52
|
+
"stdutils",
|
|
53
|
+
"stdutil",
|
|
54
|
+
"utilities",
|
|
55
|
+
"utility",
|
|
56
|
+
"utils",
|
|
57
|
+
"util",
|
|
58
|
+
"test",
|
|
59
|
+
"predicate",
|
|
60
|
+
"any",
|
|
61
|
+
"iterate",
|
|
62
|
+
"object",
|
|
63
|
+
"property",
|
|
64
|
+
"properties",
|
|
65
|
+
"props",
|
|
66
|
+
"keys",
|
|
67
|
+
"obj",
|
|
68
|
+
"validate"
|
|
69
|
+
]
|
|
70
|
+
}
|
package/assign/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2023 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
|
+
# assign
|
|
22
|
+
|
|
23
|
+
> Copy enumerable own properties from one or more source objects to a target 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 assign = require( '@stdlib/object/assign' );
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### assign( target, source1\[, source2\[,...,sourceN]] )
|
|
44
|
+
|
|
45
|
+
Copies enumerable own properties from one or more source objects to a target object.
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
var x = {
|
|
49
|
+
'a': 'beep'
|
|
50
|
+
};
|
|
51
|
+
var y = {
|
|
52
|
+
'b': 'boop'
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
var z = assign( x, y );
|
|
56
|
+
|
|
57
|
+
var v = z.b;
|
|
58
|
+
// returns 'boop'
|
|
59
|
+
|
|
60
|
+
var bool = ( z === x );
|
|
61
|
+
// returns true
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
</section>
|
|
65
|
+
|
|
66
|
+
<!-- /.usage -->
|
|
67
|
+
|
|
68
|
+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
69
|
+
|
|
70
|
+
<section class="notes">
|
|
71
|
+
|
|
72
|
+
## Notes
|
|
73
|
+
|
|
74
|
+
- If a property key is present in multiple sources, the property from the last source that defines the key prevails.
|
|
75
|
+
- The target object is mutated.
|
|
76
|
+
- Both string and symbol properties are copied.
|
|
77
|
+
|
|
78
|
+
</section>
|
|
79
|
+
|
|
80
|
+
<!-- /.notes -->
|
|
81
|
+
|
|
82
|
+
<!-- Package usage examples. -->
|
|
83
|
+
|
|
84
|
+
<section class="examples">
|
|
85
|
+
|
|
86
|
+
## Examples
|
|
87
|
+
|
|
88
|
+
<!-- eslint no-undef: "error" -->
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
var assign = require( '@stdlib/object/assign' );
|
|
92
|
+
|
|
93
|
+
var obj1 = {
|
|
94
|
+
'name': 'Jane',
|
|
95
|
+
'age': 29
|
|
96
|
+
};
|
|
97
|
+
var obj2 = {
|
|
98
|
+
'country': 'US',
|
|
99
|
+
'city': 'San Francisco'
|
|
100
|
+
};
|
|
101
|
+
var obj3 = {
|
|
102
|
+
'hobby': 'Reading'
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
var result = assign( obj1, obj2, obj3 );
|
|
106
|
+
// returns { 'name': 'Jane', 'age': 29, 'country': 'US', 'city': 'San Francisco', 'hobby': 'Reading' }
|
|
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
|
+
</section>
|
|
126
|
+
|
|
127
|
+
<!-- /.related -->
|
|
128
|
+
|
|
129
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
130
|
+
|
|
131
|
+
<section class="links">
|
|
132
|
+
|
|
133
|
+
<!-- <related-links> -->
|
|
134
|
+
|
|
135
|
+
<!-- </related-links> -->
|
|
136
|
+
|
|
137
|
+
</section>
|
|
138
|
+
|
|
139
|
+
<!-- /.links -->
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( target, ...source )
|
|
3
|
+
Copies own enumerable properties from one or more source objects to a target
|
|
4
|
+
object.
|
|
5
|
+
|
|
6
|
+
If a property key is present in multiple sources, the property from the last
|
|
7
|
+
source that defines the key prevails.
|
|
8
|
+
|
|
9
|
+
Both string and symbol properties are copied.
|
|
10
|
+
|
|
11
|
+
The target object is mutated.
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
target: Object
|
|
16
|
+
Target object.
|
|
17
|
+
|
|
18
|
+
source: ...Object
|
|
19
|
+
Source object(s).
|
|
20
|
+
|
|
21
|
+
Returns
|
|
22
|
+
-------
|
|
23
|
+
out: Object
|
|
24
|
+
Target object.
|
|
25
|
+
|
|
26
|
+
Examples
|
|
27
|
+
--------
|
|
28
|
+
> var obj1 = { 'name': 'John', 'age': 30 };
|
|
29
|
+
> var obj2 = { 'country': 'US', 'city': 'San Francisco' };
|
|
30
|
+
> var result = {{alias}}( obj1, obj2 )
|
|
31
|
+
{ 'name': 'John', 'age': 30, 'country': 'US', 'city': 'San Francisco' }
|
|
32
|
+
|
|
33
|
+
See Also
|
|
34
|
+
--------
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2023 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
|
+
* Copies own enumerable properties from one or more source objects to a target object.
|
|
23
|
+
*
|
|
24
|
+
* ## Notes
|
|
25
|
+
*
|
|
26
|
+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
|
|
27
|
+
* - The target object is mutated.
|
|
28
|
+
* - Both string and symbol properties are copied.
|
|
29
|
+
*
|
|
30
|
+
* @param target - target object
|
|
31
|
+
* @param source - source object
|
|
32
|
+
* @throws first argument must not be null or undefined
|
|
33
|
+
* @returns target object
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* var obj1 = {
|
|
37
|
+
* 'a': 'beep'
|
|
38
|
+
* };
|
|
39
|
+
* var obj2 = {
|
|
40
|
+
* 'b': 'boop'
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* var out = assign( obj1, obj2 );
|
|
44
|
+
* // returns { 'a': 'beep', 'b': 'boop' }
|
|
45
|
+
*/
|
|
46
|
+
declare function assign<T extends object, U>( target: T, source: U ): T & U;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Copies own enumerable properties from one or more source objects to a target object.
|
|
50
|
+
*
|
|
51
|
+
* ## Notes
|
|
52
|
+
*
|
|
53
|
+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
|
|
54
|
+
* - The target object is mutated.
|
|
55
|
+
* - Both string and symbol properties are copied.
|
|
56
|
+
*
|
|
57
|
+
* @param target - target object
|
|
58
|
+
* @param source1 - first source object
|
|
59
|
+
* @param source2 - second source object
|
|
60
|
+
* @throws first argument must not be null or undefined
|
|
61
|
+
* @returns target object
|
|
62
|
+
*/
|
|
63
|
+
declare function assign<T extends object, U, V>( target: T, source1: U, source2: V ): T & U & V;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Copies own enumerable properties from one or more source objects to a target object.
|
|
67
|
+
*
|
|
68
|
+
* ## Notes
|
|
69
|
+
*
|
|
70
|
+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
|
|
71
|
+
* - The target object is mutated.
|
|
72
|
+
* - Both string and symbol properties are copied.
|
|
73
|
+
*
|
|
74
|
+
* @param target - target object
|
|
75
|
+
* @param source1 - first source object
|
|
76
|
+
* @param source2 - second source object
|
|
77
|
+
* @param source3 - third source object
|
|
78
|
+
* @throws first argument must not be null or undefined
|
|
79
|
+
* @returns target object
|
|
80
|
+
*/
|
|
81
|
+
declare function assign<T extends object, U, V, W>( target: T, source1: U, source2: V, source3: W ): T & U & V & W;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Copies own enumerable properties from one or more source objects to a target object.
|
|
85
|
+
*
|
|
86
|
+
* ## Notes
|
|
87
|
+
*
|
|
88
|
+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
|
|
89
|
+
* - The target object is mutated.
|
|
90
|
+
* - Both string and symbol properties are copied.
|
|
91
|
+
*
|
|
92
|
+
* @param target - target object
|
|
93
|
+
* @param source - source object(s)
|
|
94
|
+
* @throws first argument must not be null or undefined
|
|
95
|
+
* @returns target object
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* var obj1 = {
|
|
99
|
+
* 'a': 'beep'
|
|
100
|
+
* };
|
|
101
|
+
* var obj2 = {
|
|
102
|
+
* 'b': 'boop'
|
|
103
|
+
* };
|
|
104
|
+
*
|
|
105
|
+
* var out = assign( obj1, obj2 );
|
|
106
|
+
* // returns { 'a': 'beep', 'b': 'boop' }
|
|
107
|
+
*/
|
|
108
|
+
declare function assign( target: object, ...source: Array<any> ): object;
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
// EXPORTS //
|
|
112
|
+
|
|
113
|
+
export = assign;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2023 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 assign = require( './index' );
|
|
20
|
+
|
|
21
|
+
// TESTS //
|
|
22
|
+
|
|
23
|
+
// The function returns an object...
|
|
24
|
+
{
|
|
25
|
+
const obj1 = { 'name': 'John' };
|
|
26
|
+
assign( obj1 ); // $ExpectType object
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The function returns an object after copying properties...
|
|
30
|
+
{
|
|
31
|
+
const obj1 = { 'name': 'John' };
|
|
32
|
+
const obj2 = { 'country': 'US' };
|
|
33
|
+
assign( obj1, obj2 ); // $ExpectType { name: string; } & { country: string; }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// The compiler throws an error if the function is provided a first argument which is not an object...
|
|
37
|
+
{
|
|
38
|
+
assign( 'abc' ); // $ExpectError
|
|
39
|
+
assign( false ); // $ExpectError
|
|
40
|
+
assign( true ); // $ExpectError
|
|
41
|
+
assign( null ); // $ExpectError
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// The compiler throws an error if the function is provided an insufficient number of arguments...
|
|
45
|
+
{
|
|
46
|
+
assign(); // $ExpectError
|
|
47
|
+
}
|