@helpers4/object 2.0.0-alpha.9 → 2.0.0-beta.3

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.
@@ -0,0 +1,6 @@
1
+ {
2
+ "category": "object",
3
+ "label": "Object",
4
+ "smallDescription": "Object manipulation utilities",
5
+ "description": "Utilities for working with objects including property removal, filtering, and object transformation"
6
+ }
@@ -1,6 +1,21 @@
1
1
  {
2
2
  "category": "object",
3
3
  "functions": [
4
+ {
5
+ "name": "compact",
6
+ "examples": [
7
+ {
8
+ "title": "Remove falsy values from object",
9
+ "description": "Removes all entries with falsy values (false, null, undefined, 0, \"\", NaN).",
10
+ "code": "compact({ a: 1, b: null, c: '', d: 0, e: 'hello' })\n// => { a: 1, e: 'hello' }"
11
+ },
12
+ {
13
+ "title": "Clean up API response",
14
+ "description": "Useful to strip empty or missing fields before sending data.",
15
+ "code": "compact({ name: 'Alice', email: '', age: 0, role: 'admin' })\n// => { name: 'Alice', role: 'admin' }"
16
+ }
17
+ ]
18
+ },
4
19
  {
5
20
  "name": "deepClone",
6
21
  "examples": [
@@ -12,27 +27,52 @@
12
27
  ]
13
28
  },
14
29
  {
15
- "name": "deepCompare",
30
+ "name": "deepMerge",
31
+ "examples": [
32
+ {
33
+ "title": "Merge two objects deeply",
34
+ "description": "Recursively merges source properties into the target object.",
35
+ "code": "deepMerge({ a: 1, b: { c: 2 } }, { b: { d: 3 }, e: 4 })\n// => { a: 1, b: { c: 2, d: 3 }, e: 4 }"
36
+ }
37
+ ]
38
+ },
39
+ {
40
+ "name": "diff",
16
41
  "examples": [
17
42
  {
18
43
  "title": "Compare nested objects",
19
44
  "description": "Deeply compares two objects, returning true when they are structurally equal.",
20
- "code": "deepCompare({ a: { b: 1 } }, { a: { b: 1 } })\n// => true"
45
+ "code": "diff({ a: { b: 1 } }, { a: { b: 1 } })\n// => true"
21
46
  },
22
47
  {
23
48
  "title": "Detect deep differences",
24
49
  "description": "Returns a detailed diff object when nested values differ.",
25
- "code": "deepCompare({ a: { b: 1 } }, { a: { b: 2 } })\n// => { a: { b: false } }"
50
+ "code": "diff({ a: { b: 1 } }, { a: { b: 2 } })\n// => { a: { b: false } }"
26
51
  }
27
52
  ]
28
53
  },
29
54
  {
30
- "name": "deepMerge",
55
+ "name": "equalsDeep",
31
56
  "examples": [
32
57
  {
33
- "title": "Merge two objects deeply",
34
- "description": "Recursively merges source properties into the target object.",
35
- "code": "deepMerge({ a: 1, b: { c: 2 } }, { b: { d: 3 }, e: 4 })\n// => { a: 1, b: { c: 2, d: 3 }, e: 4 }"
58
+ "title": "Compare nested objects",
59
+ "description": "Recursive structural equality. Returns true when the two values are deeply equal.",
60
+ "code": "equalsDeep({ a: { b: 1 } }, { a: { b: 1 } })\n// => true"
61
+ },
62
+ {
63
+ "title": "Detect deep differences",
64
+ "description": "Returns false when nested values differ.",
65
+ "code": "equalsDeep({ a: { b: 1 } }, { a: { b: 2 } })\n// => false"
66
+ }
67
+ ]
68
+ },
69
+ {
70
+ "name": "equalsShallow",
71
+ "examples": [
72
+ {
73
+ "title": "Compare two equal objects",
74
+ "description": "Uses JSON.stringify for a fast comparison.",
75
+ "code": "equalsShallow({ a: 1, b: 2 }, { a: 1, b: 2 })\n// => true"
36
76
  }
37
77
  ]
38
78
  },
@@ -52,12 +92,82 @@
52
92
  ]
53
93
  },
54
94
  {
55
- "name": "quickCompare",
95
+ "name": "groupBy",
56
96
  "examples": [
57
97
  {
58
- "title": "Compare two equal objects",
59
- "description": "Uses JSON.stringify for a fast comparison.",
60
- "code": "quickCompare({ a: 1, b: 2 }, { a: 1, b: 2 })\n// => true"
98
+ "title": "Group numbers by parity",
99
+ "description": "Groups elements by the string key returned by the callback.",
100
+ "code": "groupBy([1, 2, 3, 4], n => n % 2 === 0 ? 'even' : 'odd')\n// => { odd: [1, 3], even: [2, 4] }"
101
+ },
102
+ {
103
+ "title": "Group objects by a property",
104
+ "description": "Use a property accessor as the grouping key.",
105
+ "code": "const users = [\n { name: 'Alice', role: 'admin' },\n { name: 'Bob', role: 'user' },\n { name: 'Carol', role: 'admin' },\n];\ngroupBy(users, u => u.role)\n// => { admin: [{...Alice}, {...Carol}], user: [{...Bob}] }"
106
+ }
107
+ ]
108
+ },
109
+ {
110
+ "name": "invert",
111
+ "examples": [
112
+ {
113
+ "title": "Swap keys and values",
114
+ "description": "Returns a new object with keys and values swapped.",
115
+ "code": "invert({ a: 'x', b: 'y', c: 'z' })\n// => { x: 'a', y: 'b', z: 'c' }"
116
+ },
117
+ {
118
+ "title": "Build a reverse lookup map",
119
+ "description": "Useful when you have a code-to-label map and need label-to-code.",
120
+ "code": "const STATUS_LABELS = { 200: 'OK', 404: 'Not Found', 500: 'Internal Server Error' };\nconst LABEL_TO_CODE = invert(STATUS_LABELS);\n\nLABEL_TO_CODE['OK']; // => '200'"
121
+ }
122
+ ]
123
+ },
124
+ {
125
+ "name": "map",
126
+ "examples": [
127
+ {
128
+ "title": "Transform values",
129
+ "description": "Maps each value of an object through a transform function.",
130
+ "code": "map({ a: 1, b: 2 }, v => v * 10)\n// => { a: 10, b: 20 }"
131
+ },
132
+ {
133
+ "title": "Transform keys",
134
+ "description": "Maps each key of an object through a transform function.",
135
+ "code": "map({ a: 1, b: 2 }, undefined, k => k.toUpperCase())\n// => { A: 1, B: 2 }"
136
+ },
137
+ {
138
+ "title": "Transform both keys and values in a single pass",
139
+ "description": "Provide both a value mapper and a key mapper to rewrite the whole object.",
140
+ "code": "map(\n { price: 100, discount: 20 },\n v => v / 100,\n k => `${k}Ratio`\n)\n// => { priceRatio: 1, discountRatio: 0.2 }"
141
+ }
142
+ ]
143
+ },
144
+ {
145
+ "name": "omit",
146
+ "examples": [
147
+ {
148
+ "title": "Omit specific keys",
149
+ "description": "Creates a new object without the specified keys.",
150
+ "code": "omit({ a: 1, b: 2, c: 3 }, ['b'])\n// => { a: 1, c: 3 }"
151
+ },
152
+ {
153
+ "title": "Remove sensitive fields",
154
+ "description": "Useful to strip sensitive data before sending to client.",
155
+ "code": "const user = { id: 1, name: 'Alice', password: 'secret', token: 'abc123' };\nomit(user, ['password', 'token'])\n// => { id: 1, name: 'Alice' }"
156
+ }
157
+ ]
158
+ },
159
+ {
160
+ "name": "pick",
161
+ "examples": [
162
+ {
163
+ "title": "Pick specific keys",
164
+ "description": "Creates a new object with only the specified keys.",
165
+ "code": "pick({ a: 1, b: 2, c: 3 }, ['a', 'c'])\n// => { a: 1, c: 3 }"
166
+ },
167
+ {
168
+ "title": "Extract user fields",
169
+ "description": "Useful to select only the fields you need from an object.",
170
+ "code": "const user = { id: 1, name: 'Alice', email: 'alice@example.com', password: 'secret' };\npick(user, ['id', 'name', 'email'])\n// => { id: 1, name: 'Alice', email: 'alice@example.com' }"
61
171
  }
62
172
  ]
63
173
  },
@@ -71,6 +181,26 @@
71
181
  }
72
182
  ]
73
183
  },
184
+ {
185
+ "name": "safeJsonParse",
186
+ "examples": [
187
+ {
188
+ "title": "Parse valid JSON",
189
+ "description": "Returns the parsed value when the input is valid JSON.",
190
+ "code": "safeJsonParse<{ a: number }>('{\"a\":1}')\n// => { a: 1 }"
191
+ },
192
+ {
193
+ "title": "Return null on invalid input",
194
+ "description": "Returns null instead of throwing when JSON is malformed.",
195
+ "code": "safeJsonParse('invalid')\n// => null"
196
+ },
197
+ {
198
+ "title": "Use a fallback value",
199
+ "description": "Returns the provided fallback when parsing fails.",
200
+ "code": "safeJsonParse('invalid', [])\n// => []"
201
+ }
202
+ ]
203
+ },
74
204
  {
75
205
  "name": "set",
76
206
  "examples": [
@@ -1,11 +1,4 @@
1
1
  {
2
2
  "category": "object",
3
- "dependencies": [
4
- {
5
- "name": "radashi",
6
- "license": "MIT",
7
- "homepage": "https://radashi.js.org",
8
- "repository": "https://github.com/radashi-org/radashi"
9
- }
10
- ]
3
+ "dependencies": []
11
4
  }
@@ -0,0 +1,50 @@
1
+ {
2
+ "category": "object",
3
+ "functions": [
4
+ {
5
+ "name": "keys / values",
6
+ "libraries": [
7
+ "lodash",
8
+ "radashi",
9
+ "ramda"
10
+ ],
11
+ "native": "Object.keys() / Object.values()",
12
+ "since": "ES2017",
13
+ "example": "Object.keys(obj)\nObject.values(obj)",
14
+ "notes": "TypeScript types keys as string[]"
15
+ },
16
+ {
17
+ "name": "toPairs / fromPairs",
18
+ "libraries": [
19
+ "lodash",
20
+ "ramda"
21
+ ],
22
+ "native": "Object.entries() / Object.fromEntries()",
23
+ "since": "ES2019",
24
+ "example": "Object.entries(obj)\nObject.fromEntries(entries)"
25
+ },
26
+ {
27
+ "name": "has",
28
+ "libraries": [
29
+ "lodash",
30
+ "ramda"
31
+ ],
32
+ "native": "Object.hasOwn(obj, key)",
33
+ "since": "ES2022",
34
+ "example": "Object.hasOwn(obj, 'key')",
35
+ "notes": "Replaces obj.hasOwnProperty(key)"
36
+ },
37
+ {
38
+ "name": "merge (shallow)",
39
+ "libraries": [
40
+ "lodash",
41
+ "radashi",
42
+ "ramda"
43
+ ],
44
+ "native": "{ ...a, ...b } or Object.assign({}, a, b)",
45
+ "since": "ES2015",
46
+ "example": "const merged = { ...defaults, ...options }",
47
+ "notes": "For deep merge, use deepMerge from helpers4"
48
+ }
49
+ ]
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helpers4/object",
3
- "version": "2.0.0-alpha.9",
3
+ "version": "2.0.0-beta.3",
4
4
  "description": "A set of helpers in TS/JS, compatible with tree-shaking, for object.",
5
5
  "author": "baxyz <baxy@etik.com>",
6
6
  "license": "LGPL-3.0",
@@ -21,17 +21,26 @@
21
21
  "./meta/api.json": "./meta/api.json",
22
22
  "./meta/examples.json": "./meta/examples.json",
23
23
  "./meta/licenses.json": "./meta/licenses.json",
24
+ "./llms.txt": "./llms.txt",
24
25
  "./package.json": "./package.json"
25
26
  },
26
27
  "keywords": [
27
28
  "helpers",
28
29
  "object",
30
+ "compact",
29
31
  "deepClone",
30
- "deepCompare",
31
32
  "deepMerge",
33
+ "diff",
34
+ "equalsDeep",
35
+ "equalsShallow",
32
36
  "get",
33
- "quickCompare",
37
+ "groupBy",
38
+ "invert",
39
+ "map",
40
+ "omit",
41
+ "pick",
34
42
  "removeUndefinedNull",
43
+ "safeJsonParse",
35
44
  "set"
36
45
  ],
37
46
  "files": [
@@ -39,14 +48,12 @@
39
48
  "lib/index.d.ts",
40
49
  "lib/index.js.map",
41
50
  "meta/",
51
+ "llms.txt",
42
52
  "LICENSE.md",
43
53
  "package.json",
44
54
  "README.md"
45
55
  ],
46
56
  "engines": {
47
57
  "node": ">=18.0.0"
48
- },
49
- "peerDependencies": {
50
- "radashi": "^12.7.2"
51
58
  }
52
59
  }