imdone-core 2.1.0 → 2.1.2

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.
@@ -6,5 +6,33 @@ export async function getCardData({ path, line }) {
6
6
 
7
7
  const file = project.getFile(path)
8
8
  const card = file.getTaskAtLine(line)
9
- return {...card.data };
9
+ const data = { ...project.data, ...card.data };
10
+ // flatten the data arrays and objects and exclude functions and return the result
11
+ const flattenedData = Object.fromEntries(
12
+ Object.entries(data).flatMap(([key, value]) => {
13
+ if (Array.isArray(value)) {
14
+ const arrayEntry = [[key, JSON.stringify(value)]];
15
+ if (value.length === 1) {
16
+ return [...arrayEntry, [`${key}.0`, value[0]]];
17
+ }
18
+ return [...arrayEntry, ...value.map((item, index) => [`${key}.${index}`, item])];
19
+ }
20
+ if (typeof value === 'object' && value !== null) {
21
+ const objectEntry = [[key, JSON.stringify(value)]];
22
+ const flattenedEntries = Object.entries(value).flatMap(([subKey, subValue]) => {
23
+ if (Array.isArray(subValue)) {
24
+ const arrayEntry = [[`${key}.${subKey}`, JSON.stringify(subValue)]];
25
+ if (subValue.length === 1) {
26
+ return [...arrayEntry, [`${key}.${subKey}.0`, subValue[0]]];
27
+ }
28
+ return [...arrayEntry, ...subValue.map((item, index) => [`${key}.${subKey}.${index}`, item])];
29
+ }
30
+ return [[`${key}.${subKey}`, subValue]];
31
+ });
32
+ return [...objectEntry, ...flattenedEntries];
33
+ }
34
+ return [[key, value]];
35
+ })
36
+ );
37
+ return Object.fromEntries(Object.entries(flattenedData).filter(([key, value]) => typeof value !== 'function'));
10
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imdone-core",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "imdone-core",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,4 +1,6 @@
1
1
  export function getCardData({ path, line }: {
2
2
  path: any;
3
3
  line: any;
4
- }): Promise<any>;
4
+ }): Promise<{
5
+ [k: string]: any;
6
+ }>;