@@ -46,33 +46,62 @@ export default (
4646 /* Расчетные свойства для работы с древовидным объектом */
4747 /* -------------------------------------------------------------------------- */
4848
49- const properties : PropertyDescriptorMap = {
49+ const properties = {
5050 [ keyBranch ] : {
51- get ( this : unObject ) {
51+ /**
52+ * A computed property that returns an array containing the current object
53+ * and all its parent objects by traversing up the parent chain using the
54+ * keyParent property.
55+ *
56+ * @returns {unObject[] } An array of objects starting from the topmost
57+ * parent to the current object.
58+ */
59+ get ( this : unObject ) : unObject [ ] {
5260 const ret = [ this ] ;
5361 while ( ret [ 0 ] ?. [ keyParent ] ) ret . unshift ( ret [ 0 ] [ keyParent ] as unObject ) ;
5462 return ret ;
5563 } ,
5664 } ,
57- [ keyIndex ] : {
58- get ( this : unObject ) {
59- return ( this [ keySiblings ] as unObject [ ] ) . findIndex (
60- ( sibling ) => this [ keyId ] === sibling [ keyId ] ,
61- ) ;
65+ [ keyPrev ] : {
66+ /**
67+ * A computed property that returns the previous sibling of the current
68+ * object.
69+ *
70+ * @returns {unObject | undefined } The previous sibling object or
71+ * undefined if there is no previous sibling.
72+ */
73+ get ( this : unObject ) : undefined | unObject {
74+ return ( this [ keySiblings ] as unObject [ ] ) [
75+ ( this [ keyIndex ] as number ) - 1
76+ ] ;
6277 } ,
6378 } ,
6479 [ keyNext ] : {
65- get ( this : unObject ) {
80+ /**
81+ * A computed property that returns the next sibling of the current
82+ * object.
83+ *
84+ * @returns {unObject | undefined } The next sibling object or undefined if
85+ * there is no next sibling.
86+ */
87+ get ( this : unObject ) : undefined | unObject {
6688 return ( this [ keySiblings ] as unObject [ ] ) [
6789 ( this [ keyIndex ] as number ) + 1
6890 ] ;
6991 } ,
7092 } ,
71- [ keyPrev ] : {
72- get ( this : unObject ) {
73- return ( this [ keySiblings ] as unObject [ ] ) [
74- ( this [ keyIndex ] as number ) - 1
75- ] ;
93+ [ keyIndex ] : {
94+ /**
95+ * A computed property that finds the index of the current object in its
96+ * siblings array.
97+ *
98+ * @returns {number } The index of the current object in its siblings
99+ * array.
100+ */
101+ get ( this : unObject ) : number {
102+ return ( this [ keySiblings ] as unObject [ ] ) . findIndex (
103+ ( sibling ) => this [ keyId ] === sibling [ keyId ] ,
104+ ) ;
76105 } ,
77106 } ,
78107 } ;
@@ -81,6 +110,14 @@ export default (
81110 /* Формирование массива элементов дерева простого и ассоциативного */
82111 /* -------------------------------------------------------------------------- */
83112
113+ /**
114+ * A generator function that traverses a tree-like structure of nodes and
115+ * yields each node after setting up its relationships and properties
116+ *
117+ * @param {unObject[] } nodes - Array of nodes to be processed
118+ * @yields {unObject} Each node in the tree, with its relationships and
119+ * properties
120+ */
84121 const getNodes = function * ( nodes : unObject [ ] ) {
85122 const stack = getItems ( nodes ) ;
86123 while ( stack . length ) {
0 commit comments