@rickard.antonsson/ts-utility 1.0.0 → 1.0.1

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 (2) hide show
  1. package/README.md +46 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -61,3 +61,49 @@ const result = groupBy(itemsWithSpecificGroups, item => item.group);
61
61
  // result now contains the grouped arrays.
62
62
  // typescript error occurs if you try to access result.noneexisting since its not in the group names
63
63
  ```
64
+
65
+ ## Other
66
+
67
+ ### Deep Partial Set
68
+
69
+ As the name implies, sets an objects and subobjects properties.
70
+ Optionally use a function to modify current value.
71
+
72
+ ```typescript
73
+ it('should add 10 gold, 10 silver and 10 copper to persons pouch', () => {
74
+ const person = {
75
+ personal: {
76
+ firstName: 'Test',
77
+ lastName: 'Testsson',
78
+ },
79
+ items: {
80
+ pouch: {color: 'blue', contents: {gold: 10, silver: 20, copper: 30}},
81
+ },
82
+ };
83
+
84
+ const result = deepPartialSet(person, {
85
+ items: {
86
+ pouch: {
87
+ contents: {
88
+ gold: i => i + 10,
89
+ silver: i => i + 10,
90
+ copper: i => i + 10,
91
+ },
92
+ },
93
+ },
94
+ });
95
+
96
+ expect(result.items.pouch.contents).toEqual({
97
+ gold: 20,
98
+ silver: 30,
99
+ copper: 40,
100
+ });
101
+ // Keep unchanged objects
102
+ expect(result.personal).toBe(person.personal);
103
+ // New objects for the complete tree where a child has a change
104
+ expect(result).not.toBe(person);
105
+ expect(result.items).not.toBe(person.items);
106
+ expect(result.items.pouch).not.toBe(person.items.pouch);
107
+ expect(result.items.pouch.contents).not.toBe(person.items.pouch.contents);
108
+ });
109
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickard.antonsson/ts-utility",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",