11
22//POLYFILL because no window object
3+ globalThis . window = globalThis ;
34let window = globalThis ;
5+ globalThis . global = globalThis ;
46//END POLYFILL
57
68const getProps = ( obj ) => {
@@ -12,15 +14,18 @@ const getProps = (obj) => {
1214 return [ ...properties . keys ( ) ] ; //.filter(item => typeof obj[item] === 'function')
1315}
1416
17+ window . getProps = getProps ;
18+
1519const keyToDesc = ( obj , key ) => {
16- return key + " : " + typeof ( obj [ key ] ) ;
20+ return key + " : " + typeof ( obj [ key ] ) ;
1721}
1822
1923export class EvalComplete {
2024 constructor ( ) {
2125 this . lastObj = undefined ;
2226 this . potentialObj = undefined ;
2327 this . prop = undefined ;
28+ /**@type {Array<String> } */
2429 this . lastKeys = undefined ;
2530
2631 this . completeStrings = new Array ( ) ;
@@ -33,9 +38,7 @@ export class EvalComplete {
3338 * @returns {boolean } successful iteration or not (not necessarily fail when false)
3439 */
3540 complete ( str , allPropsOfStr = false ) {
36- if ( str . includes ( " " ) ) {
37- str = str . split ( " " ) . pop ( ) ;
38- }
41+ if ( str [ str . length - 1 ] == "." ) allPropsOfStr = true ;
3942 if ( allPropsOfStr ) {
4043 str = str . substring ( 0 , str . length - 1 ) ;
4144 try {
@@ -47,7 +50,7 @@ export class EvalComplete {
4750 this . lastObj = this . potentialObj ;
4851 //Set complete strings to all keys of object
4952 this . completeStrings = getProps ( this . lastObj ) ;
50- this . completeStrings . forEach ( ( v ) => {
53+ this . completeStrings . forEach ( ( v ) => {
5154 return keyToDesc ( this . lastObj , v ) ;
5255 } ) ;
5356 }
@@ -61,34 +64,36 @@ export class EvalComplete {
6164 this . prop = str . split ( "." ) . pop ( ) ;
6265
6366 //If we completed the word property return it by itself
64- if ( this . lastObj && this . lastObj [ this . prop ] ) {
65- this . completeStrings . length = 1 ;
66- this . completeStrings [ 0 ] = keyToDesc ( this . lastObj , this . prop ) ;
67- } else { //Else, try to complete the property be seeing if we have a part of it
68- if ( this . lastObj === undefined ) {
69- //If we don't have a last object and we're not referencing subobjects
70- if ( ! str . includes ( "." ) ) {
71- //Use global window object as reference for autocomplete on global
72- this . lastObj = window ;
73- }
67+ // if (this.lastObj && this.lastObj[this.prop]) {
68+ // this.completeStrings.length = 1;
69+ // this.completeStrings[0] = keyToDesc(this.lastObj, this.prop);
70+ // } else { //Else, try to complete the property be seeing if we have a part of it
71+ if ( this . lastObj === undefined ) {
72+ //If we don't have a last object and we're not referencing subobjects
73+ if ( ! str . includes ( "." ) ) {
74+ //Use global window object as reference for autocomplete on global
75+ this . lastObj = window ;
7476 }
75- //If our last object reference is actually an object
76- if ( this . lastObj instanceof Object ) {
77- //Get its keys
78- this . lastKeys = getProps ( this . lastObj ) ; //Object.keys(this.lastObj);
79- //Clear our returned strings
80- this . completeStrings . length = 0 ;
81- //Loop through keys to see if we can match them with our search prop
82- for ( let key of this . lastKeys ) {
83- //if (key.startsWith(this.prop)) {
84- if ( key . includes ( this . prop ) ) {
85- key = keyToDesc ( this . lastObj , key ) ;
86- this . completeStrings . push ( key ) ;
87- }
77+ }
78+ //If our last object reference is actually an object
79+ if ( this . lastObj instanceof Object ) {
80+ //Get its keys
81+ this . lastKeys = getProps ( this . lastObj ) ; //Object.keys(this.lastObj);
82+ //Clear our returned strings
83+ this . completeStrings . length = 0 ;
84+ //Loop through keys to see if we can match them with our search prop
85+ let matchkey ;
86+ for ( let key of this . lastKeys ) {
87+ matchkey = key . toLowerCase ( ) ; //More matching!
88+ //if (key.startsWith(this.prop)) {
89+ if ( matchkey . includes ( this . prop . toLowerCase ( ) ) ) {
90+ key = keyToDesc ( this . lastObj , key ) ;
91+ this . completeStrings . push ( key ) ;
8892 }
8993 }
9094 }
9195 //}
96+ //}
9297 }
9398 }
9499}
0 commit comments