@augment-vir/common 31.61.0 → 31.63.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.
@@ -0,0 +1,15 @@
1
+ import { type AnyObject, type UnknownObject } from '@augment-vir/core';
2
+ /**
3
+ * Flattens a nested object into a single-level object.
4
+ *
5
+ * @category Package : @augment-vir/common
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import {flattenObject} from '@augment-vir/common';
10
+ *
11
+ * flattenObject({a: 'hello', b: {c: 42, d: {e: true, a: 'bye'}}});
12
+ * // {a: 'bye', 'c': 42, 'e': true}
13
+ * ```
14
+ */
15
+ export declare function flattenObject(originalObject: Readonly<AnyObject>): UnknownObject;
@@ -0,0 +1,32 @@
1
+ import { check } from '@augment-vir/assert';
2
+ /**
3
+ * Flattens a nested object into a single-level object.
4
+ *
5
+ * @category Package : @augment-vir/common
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import {flattenObject} from '@augment-vir/common';
10
+ *
11
+ * flattenObject({a: 'hello', b: {c: 42, d: {e: true, a: 'bye'}}});
12
+ * // {a: 'bye', 'c': 42, 'e': true}
13
+ * ```
14
+ */
15
+ export function flattenObject(originalObject) {
16
+ return Object.fromEntries(flattenObjectToEntries(originalObject));
17
+ }
18
+ function flattenObjectToEntries(originalObject) {
19
+ return Object.entries(originalObject).flatMap(([key, value,]) => {
20
+ if (check.isObject(value)) {
21
+ return flattenObjectToEntries(value);
22
+ }
23
+ else {
24
+ return [
25
+ [
26
+ key,
27
+ value,
28
+ ],
29
+ ];
30
+ }
31
+ });
32
+ }
package/dist/index.d.ts CHANGED
@@ -48,6 +48,7 @@ export * from './augments/object/deep-copy.js';
48
48
  export * from './augments/object/deep-value.js';
49
49
  export * from './augments/object/diff.js';
50
50
  export * from './augments/object/empty.js';
51
+ export * from './augments/object/flatten-object.js';
51
52
  export * from './augments/object/get-or-set.js';
52
53
  export * from './augments/object/key-count.js';
53
54
  export * from './augments/object/map-entries.js';
package/dist/index.js CHANGED
@@ -48,6 +48,7 @@ export * from './augments/object/deep-copy.js';
48
48
  export * from './augments/object/deep-value.js';
49
49
  export * from './augments/object/diff.js';
50
50
  export * from './augments/object/empty.js';
51
+ export * from './augments/object/flatten-object.js';
51
52
  export * from './augments/object/get-or-set.js';
52
53
  export * from './augments/object/key-count.js';
53
54
  export * from './augments/object/map-entries.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "31.61.0",
3
+ "version": "31.63.0",
4
4
  "description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
5
5
  "keywords": [
6
6
  "augment",
@@ -40,8 +40,8 @@
40
40
  "test:web": "virmator --no-deps test web"
41
41
  },
42
42
  "dependencies": {
43
- "@augment-vir/assert": "^31.61.0",
44
- "@augment-vir/core": "^31.61.0",
43
+ "@augment-vir/assert": "^31.63.0",
44
+ "@augment-vir/core": "^31.63.0",
45
45
  "@date-vir/duration": "^8.1.0",
46
46
  "ansi-styles": "^6.2.3",
47
47
  "deepcopy-esm": "^2.1.1",