assign-gingerly 0.0.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -0
  3. package/package.json +20 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Bruce B. Anderson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # assign-gingerly
2
+
3
+ This package provides a utility function for carefully merging one object into another.
4
+
5
+ It builds on Object.assign. It adds support for:
6
+
7
+ 1. Carefully merging in nested properties.
8
+ 2. Dependency injection based on a mapping protocol.
9
+
10
+ ## Example 1 - assignGingerly is mostly a "superset" of Object.assign:
11
+
12
+ ```TypeScript
13
+ const sourceObj = {hello: 'world'};
14
+ assignGingerly(sourceObj, {hello: 'Venus', foo: 'bar'});
15
+ // Because none of the keys of the second parameter start with "?.",
16
+ // assign gingerly produces identical results as Object.assign:
17
+ console.log(sourceObj);
18
+ //{hello: 'Venus', foo: 'bar'}
19
+ ```
20
+
21
+ ## Example 2 Merging into an existing sub object
22
+
23
+ ```html
24
+ <body>
25
+ <input id=myInput>
26
+ </body>
27
+ ```
28
+
29
+ ```TypeScript
30
+ const oInput = document.querySelector('#myInput');
31
+ assignGingerly(oInput, {'?.style?.height': '15px'});
32
+ console.log(oInput.style.height);
33
+ // 15px
34
+ ```
35
+
36
+ This can go many levels deep.
37
+
38
+ ## Example 3 Deeply nested
39
+
40
+ ```TypeScript
41
+ const obj = {};
42
+ assignGingerly(obj, {
43
+ '?.style?.height': '15px',
44
+ '?.a?.b?.c': {
45
+ d: 'hello',
46
+ e: 'world'
47
+ }
48
+ });
49
+ console.log(obj);
50
+ // {
51
+ // a: {b: c: {d: 'hello', e: 'world'}},
52
+ // style: {height: '15px'}
53
+ // }
54
+ ```
55
+
56
+ When the right hand side of an expression is an object, assignGingerly is recursively applied (passing the third argument in if applicable, which will be discussed below)
57
+
58
+ ## Dependency injection based on a registry object
59
+
60
+ ```Typescript
61
+
62
+ ```
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "assign-gingerly",
3
+ "version": "0.0.0",
4
+ "description": "This package provides a utility function for carefully merging one object into another.",
5
+ "homepage": "https://github.com/bahrus/assign-gingerly#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/bahrus/assign-gingerly/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/bahrus/assign-gingerly.git"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Bruce B. Anderson <andeson.bruce.b@gmail.com>",
15
+ "type": "module",
16
+ "main": "index.js",
17
+ "scripts": {
18
+ "test": "playwright test"
19
+ }
20
+ }