|
925 | 925 | ], |
926 | 926 | "name": "asyncMap" |
927 | 927 | }, |
| 928 | + { |
| 929 | + "kind": "Function", |
| 930 | + "canonicalReference": "sculp-js!buildTree:function(1)", |
| 931 | + "docComment": "/**\n * 根据 idProp 与 parentIdProp 从对象数组中构建对应的树 当 A[parentIdProp] === B[idProp] 时,对象A会被移动到对象B的children。 当一个对象的 parentIdProp 不与其他对象的 idProp 字段相等时,该对象被作为树的顶层节点\n *\n * @param idProp - 元素ID\n *\n * @param parentIdProp - 父元素ID\n *\n * @param items - 一维数组\n *\n * @returns {WithChildren<T>[]} 树\n *\n * @example\n *\n * const array = [ { id: 'node-1', parent: 'root' }, { id: 'node-2', parent: 'root' }, { id: 'node-3', parent: 'node-2' }, { id: 'node-4', parent: 'node-2' }, { id: 'node-5', parent: 'node-4' }, ] const tree = buildTree('id', 'parent', array) expect(tree).toEqual([ { id: 'node-1', parent: 'root' }, { id: 'node-2', parent: 'root', children: [ { id: 'node-3', parent: 'node-2' }, { id: 'node-4', parent: 'node-2', children: [{ id: 'node-5', parent: 'node-4' }], }, ], }, ])\n */\n", |
| 932 | + "excerptTokens": [ |
| 933 | + { |
| 934 | + "kind": "Content", |
| 935 | + "text": "declare function buildTree<ID extends " |
| 936 | + }, |
| 937 | + { |
| 938 | + "kind": "Content", |
| 939 | + "text": "string" |
| 940 | + }, |
| 941 | + { |
| 942 | + "kind": "Content", |
| 943 | + "text": ", PID extends " |
| 944 | + }, |
| 945 | + { |
| 946 | + "kind": "Content", |
| 947 | + "text": "string" |
| 948 | + }, |
| 949 | + { |
| 950 | + "kind": "Content", |
| 951 | + "text": ", T extends " |
| 952 | + }, |
| 953 | + { |
| 954 | + "kind": "Content", |
| 955 | + "text": "{\n [key in ID | PID]: string;\n}" |
| 956 | + }, |
| 957 | + { |
| 958 | + "kind": "Content", |
| 959 | + "text": ">(idProp: " |
| 960 | + }, |
| 961 | + { |
| 962 | + "kind": "Content", |
| 963 | + "text": "ID" |
| 964 | + }, |
| 965 | + { |
| 966 | + "kind": "Content", |
| 967 | + "text": ", parentIdProp: " |
| 968 | + }, |
| 969 | + { |
| 970 | + "kind": "Content", |
| 971 | + "text": "PID" |
| 972 | + }, |
| 973 | + { |
| 974 | + "kind": "Content", |
| 975 | + "text": ", items: " |
| 976 | + }, |
| 977 | + { |
| 978 | + "kind": "Content", |
| 979 | + "text": "T[]" |
| 980 | + }, |
| 981 | + { |
| 982 | + "kind": "Content", |
| 983 | + "text": "): " |
| 984 | + }, |
| 985 | + { |
| 986 | + "kind": "Reference", |
| 987 | + "text": "WithChildren", |
| 988 | + "canonicalReference": "sculp-js!WithChildren:type" |
| 989 | + }, |
| 990 | + { |
| 991 | + "kind": "Content", |
| 992 | + "text": "<T>[]" |
| 993 | + }, |
| 994 | + { |
| 995 | + "kind": "Content", |
| 996 | + "text": ";" |
| 997 | + } |
| 998 | + ], |
| 999 | + "fileUrlPath": "lib/index.d.ts", |
| 1000 | + "returnTypeTokenRange": { |
| 1001 | + "startIndex": 13, |
| 1002 | + "endIndex": 15 |
| 1003 | + }, |
| 1004 | + "releaseTag": "Public", |
| 1005 | + "overloadIndex": 1, |
| 1006 | + "parameters": [ |
| 1007 | + { |
| 1008 | + "parameterName": "idProp", |
| 1009 | + "parameterTypeTokenRange": { |
| 1010 | + "startIndex": 7, |
| 1011 | + "endIndex": 8 |
| 1012 | + }, |
| 1013 | + "isOptional": false |
| 1014 | + }, |
| 1015 | + { |
| 1016 | + "parameterName": "parentIdProp", |
| 1017 | + "parameterTypeTokenRange": { |
| 1018 | + "startIndex": 9, |
| 1019 | + "endIndex": 10 |
| 1020 | + }, |
| 1021 | + "isOptional": false |
| 1022 | + }, |
| 1023 | + { |
| 1024 | + "parameterName": "items", |
| 1025 | + "parameterTypeTokenRange": { |
| 1026 | + "startIndex": 11, |
| 1027 | + "endIndex": 12 |
| 1028 | + }, |
| 1029 | + "isOptional": false |
| 1030 | + } |
| 1031 | + ], |
| 1032 | + "typeParameters": [ |
| 1033 | + { |
| 1034 | + "typeParameterName": "ID", |
| 1035 | + "constraintTokenRange": { |
| 1036 | + "startIndex": 1, |
| 1037 | + "endIndex": 2 |
| 1038 | + }, |
| 1039 | + "defaultTypeTokenRange": { |
| 1040 | + "startIndex": 0, |
| 1041 | + "endIndex": 0 |
| 1042 | + } |
| 1043 | + }, |
| 1044 | + { |
| 1045 | + "typeParameterName": "PID", |
| 1046 | + "constraintTokenRange": { |
| 1047 | + "startIndex": 3, |
| 1048 | + "endIndex": 4 |
| 1049 | + }, |
| 1050 | + "defaultTypeTokenRange": { |
| 1051 | + "startIndex": 0, |
| 1052 | + "endIndex": 0 |
| 1053 | + } |
| 1054 | + }, |
| 1055 | + { |
| 1056 | + "typeParameterName": "T", |
| 1057 | + "constraintTokenRange": { |
| 1058 | + "startIndex": 5, |
| 1059 | + "endIndex": 6 |
| 1060 | + }, |
| 1061 | + "defaultTypeTokenRange": { |
| 1062 | + "startIndex": 0, |
| 1063 | + "endIndex": 0 |
| 1064 | + } |
| 1065 | + } |
| 1066 | + ], |
| 1067 | + "name": "buildTree" |
| 1068 | + }, |
928 | 1069 | { |
929 | 1070 | "kind": "Function", |
930 | 1071 | "canonicalReference": "sculp-js!calculateDate:function(1)", |
|
7846 | 7987 | } |
7847 | 7988 | ], |
7848 | 7989 | "name": "wait" |
| 7990 | + }, |
| 7991 | + { |
| 7992 | + "kind": "TypeAlias", |
| 7993 | + "canonicalReference": "sculp-js!WithChildren:type", |
| 7994 | + "docComment": "", |
| 7995 | + "excerptTokens": [ |
| 7996 | + { |
| 7997 | + "kind": "Content", |
| 7998 | + "text": "type WithChildren<T> = " |
| 7999 | + }, |
| 8000 | + { |
| 8001 | + "kind": "Content", |
| 8002 | + "text": "T & {\n children?: " |
| 8003 | + }, |
| 8004 | + { |
| 8005 | + "kind": "Reference", |
| 8006 | + "text": "WithChildren", |
| 8007 | + "canonicalReference": "sculp-js!WithChildren:type" |
| 8008 | + }, |
| 8009 | + { |
| 8010 | + "kind": "Content", |
| 8011 | + "text": "<T>[];\n}" |
| 8012 | + }, |
| 8013 | + { |
| 8014 | + "kind": "Content", |
| 8015 | + "text": ";" |
| 8016 | + } |
| 8017 | + ], |
| 8018 | + "fileUrlPath": "lib/index.d.ts", |
| 8019 | + "releaseTag": "Public", |
| 8020 | + "name": "WithChildren", |
| 8021 | + "typeParameters": [ |
| 8022 | + { |
| 8023 | + "typeParameterName": "T", |
| 8024 | + "constraintTokenRange": { |
| 8025 | + "startIndex": 0, |
| 8026 | + "endIndex": 0 |
| 8027 | + }, |
| 8028 | + "defaultTypeTokenRange": { |
| 8029 | + "startIndex": 0, |
| 8030 | + "endIndex": 0 |
| 8031 | + } |
| 8032 | + } |
| 8033 | + ], |
| 8034 | + "typeTokenRange": { |
| 8035 | + "startIndex": 1, |
| 8036 | + "endIndex": 4 |
| 8037 | + } |
7849 | 8038 | } |
7850 | 8039 | ] |
7851 | 8040 | } |
|
0 commit comments