# All files props.ts

90.94% Statements 221/243
77.69% Branches 202/260
90% Functions 27/30
92.51% Lines 210/227

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    9105x
    5x
    5x
    5x

    5x
    5x

    5x
    3x
    3x

    3x
    1x

    3x

    5x

    14x

    14x

    5x

    4x

    4x
    3x
    2x

    1x

    1x

    5x
    5x
    5x
    5x
    5x
    5x

    5x

    2x

    5x
    7x

    22x
    3x
    19x
    2x
    17x
    2x
    22x
    22x

    5x

    13x
    13x
    13x
    13x

    4x

    4x

    2x

    4x

    13x

    7x

    7x
    5x

    2x

    7x

    7x
    7x

    13x

    5x

    5x

    5x
    1x
    4x
    4x

    3x

    4x
    1x

    3x

    3x
    3x

    4x

    1x

    5x

    5x
    5x

    13x

    5x

    3x

    3x

    3x

    3x
    3x

    3x
    3x

    5x
    7x
    7x

    5x
    5x
    5x
    5x
    5x
    2x
    2x

    3x

    2x

    1x

    5x

    5x

    7x

    2x
    2x
    2x
    2x

    2x

    1x

    2x

    2x

    7x

    5x

    1x

    1x

    1x
    1x

    1x
    1x

    1x
    1x

    1x
    1x

    5x

    11x

    11x
    11x
    11x

    6x
    6x
    11x
    11x
    10x
    10x

    10x

    2x
    2x

    2x
    2x

    2x

    2x

    2x
    2x

    2x

    2x

    8x
    3x
    1x
    1x

    2x
    2x

    5x
    2x

    3x
    2x

    1x

    1x
    1x
    1x

    1x

    5x

    2x
    2x
    2x

    2x
    2x
    4x

    4x

    2x

    5x

    1x
    1x

    1x
    1x

    1x

    1x

    1x

    1x
    1x

    1x

    1x

    5x

    88x
    88x
    88x

    87x
    87x

    87x

    87x

    87x

    87x

    87x

    87x
    1x

    1x

    1x

    87x

    87x

    87x

    87x

    87x

    87x

    87x

    87x
    2x
    2x
    2x

    87x
    87x

    4x
    4x

    1x
    1x

     import React from "react";
    import { getRenderedJSON } from "./index";
    import * as utilities from "./utils";
    import {
      getComponentFromMap,
      getReactFunctionComponent,
      getReactClassComponent,
      makeFunctionComponent,
    } from "./components";
    // if (typeof window === 'undefined') {
    //   var window = window || {};
    // }
    import * as defs from "./types/jsonx/index";
    declare global {
      interface window {
        [index: string]: any;
      }
      namespace NodeJS {
        interface Global {
          document: Document;
          window: Window;
          navigator: Navigator;
        }
      }
    }

    //https://stackoverflow.com/questions/1007981/how-to-get-function-parameter-names-values-dynamically
    export const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
    export const ARGUMENT_NAMES = /([^\s,]+)/g;
    /**
     * returns the names of parameters from a function declaration
     * @example
     * const arrowFunctionAdd = (a,b)=>a+b;
     * function regularFunctionAdd(c,d){return c+d;}
     * getParamNames(arrowFunctionAdd) // => ['a','b']
     * getParamNames(regularFunctionAdd) // => ['c','d']
     * @param {Function} func
     * @todo write tests
     */
    export function getParamNames(func: defs.functionParam) {
      var fnStr = func.toString().replace(STRIP_COMMENTS, "");
      var result = fnStr
        .slice(fnStr.indexOf("(") + 1, fnStr.indexOf(")"))
        .match(ARGUMENT_NAMES);
      if (result === null) {
        result = [];
      }
      return result;
    }

    /**
     * It uses traverse on a traverseObject to returns a resolved object on propName. So if you're making an ajax call and want to pass properties into a component, you can assign them using asyncprops and reference object properties by an array of property paths
     * @param {Object} [traverseObject={}] - the object that contains values of propName
     * @param {Object} options
     * @param {Object} options.jsonx - Valid JSONX JSON
     * @param {Object} [options.propName='asyncprops'] - Property on JSONX to resolve values onto, i.e (asyncprops,thisprops,windowprops)
     * @returns {Object} resolved object
     * @example
     const traverseObject = {
      user: {
        name: 'jsonx',
        description: 'react withouth javascript',
      },
      stats: {
        logins: 102,
        comments: 3,
      },
      authentication: 'OAuth2',
    };
    const testJSONX = {
      component: 'div',
      props: {
        id: 'generatedJSONX',
        className:'jsonx',
      },
      asyncprops:{
        auth: [ 'authentication', ],
        username: [ 'user', 'name', ],
      },
      children: [
        {
          component: 'p',
          props: {
            style: {
              color: 'red',
              fontWeight:'bold',
            },
          },
          children:'hello world',
        },
      ],
    };
    const JSONXP = getJSONXProps({ jsonx: testJSONX, traverseObject, });
    // => {
    //   auth: 'OAuth2',
    //   username: 'jsonx'
    // }

    //finally resolves:
    const testJSONX = {
      component: 'div',
      props: {
        id: 'generatedJSONX',
        className:'jsonx',
        auth: 'OAuth2',
        username: 'jsonx',
      },
      children: [
        {
          component: 'p',
          props: {
            style: {
              color: 'red',
              fontWeight:'bold',
            },
          },
          children:'hello world',
        },
      ],
    };
     */
    export function getJSONXProps(options: defs.dynamicFunctionParams = {}) {
      // eslint-disable-next-line
      let { jsonx = {}, propName = "asyncprops", traverseObject = {} } = options;
      // return (jsonx.asyncprops && typeof jsonx.asyncprops === 'object')
      // ? utilities.traverse(jsonx.asyncprops, resources)
      // : {};
      return jsonx[propName] && typeof jsonx[propName] === "object"
        ? utilities.traverse(jsonx[propName], traverseObject)
        : {};
    }

    /**
     * returns children jsonx components defined on __spreadComponent spread over an array on props.__spread
     * @param {*} options
     */
    export function getChildrenComponents(
      this: defs.Context,
      options: { allProps?: any; jsonx?: defs.jsonx } = {}
    ) {
      const { allProps = {}, jsonx = {} } = options;
      // const asyncprops = getJSONXProps({ jsonx, propName: 'spreadprops', traverseObject: allProps, });
      if (Array.isArray(allProps.__spread) === false) {
        if ((this && this.debug) || jsonx.debug) {
          return {
            children: new Error(
              "Using __spreadComponent requires an array prop '__spread'"
            ).toString()
          };
        } else {
          return { children: undefined };
        }
      } else {
        return {
          _children: allProps.__spread.map((__item: any, __idx: string) => {
            const clonedChild = Object.assign({}, jsonx.__spreadComponent);
            const clonedChildProps = Object.assign({}, clonedChild.props);
            clonedChildProps.__item = __item;
            clonedChildProps.__idx = __idx;
            clonedChild.props = clonedChildProps;
            return clonedChild;
          })
        };
      }
    }

    /**
     * registers an input to a reactHookForm register function
     * @param {*} options
     * @returns {object} - returns name, ref, onBlur, onChange
     */
    export function useFormRegisterHandler(
      this:{
        reactHookForm:{
          register:(ref:string)=>{
            name:string;
            ref:HTMLElement;
            onBlur:()=>void;
            onChange:()=>void
          }
        }
      },
      options: { jsonx?: defs.jsonx } = {}
    ){
      return this.reactHookForm.register(options?.jsonx?.props?.name)
    }

    /**
     * returns a reducer function that returns values ot bind to an eval function. This function is used when values need to be passed from a hook function to a prop that is a function
     * @param {object} this
     * @param {object} jsonx
     * @returns {function}
     */
    export function boundArgsReducer(this: defs.Context, jsonx: defs.jsonx = {}) {
      return (args: any, arg: string) => {
        let val;
        if (this && this.state && typeof this.state[arg] !== "undefined")
          val = this.state[arg];
        else if (this && this.props && typeof this.props[arg] !== "undefined")
          val = this.props[arg];
        else if (jsonx.props && typeof jsonx.props[arg] !== "undefined")
          val = jsonx.props[arg];
        if (typeof val !== "undefined") args.push(val);
        return args.filter((a: any) => typeof a !== "undefined");
      };
    }

    /**
     * Used to evalute javascript and set those variables as props. getEvalProps evaluates __dangerouslyEvalProps and __dangerouslyBindEvalProps properties with eval, this is used when component properties are functions, __dangerouslyBindEvalProps is used when those functions require that this is bound to the function. For __dangerouslyBindEvalProps it must resolve an expression, so functions should be wrapped in (). I.e. (function f(x){ return this.minimum+x;})
     * @param {Object} options
     * @param {Object} options.jsonx - Valid JSONX JSON
     * @returns {Object} returns resolved object with evaluated javascript
     * @example
     const testVals = {
        auth: 'true',
        username: '(user={})=>user.name',
      };
      const testJSONX = Object.assign({}, sampleJSONX, {
        __dangerouslyEvalProps: testVals, __dangerouslyBindEvalProps: {
          email: '(function getUser(user={}){ return this.testBound(); })',
        },
      });
      const JSONXP = getEvalProps.call({ testBound: () => 'bounded', }, { jsonx: testJSONX, });
      const evalutedComputedFunc = JSONXP.username({ name: 'bob', });
      const evalutedComputedBoundFunc = JSONXP.email({ email:'test@email.domain', });
      // expect(JSONXP.auth).to.be.true;
      // expect(evalutedComputedFunc).to.eql('bob');
      // expect(evalutedComputedBoundFunc).to.eql('bounded');
     */
    export function getEvalProps(
      this: defs.Context,
      options: { jsonx: defs.jsonx } = { jsonx: {} }
    ) {
      const { jsonx } = options;
      const scopedEval = eval; //https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval
      let evAllProps = {};
      if (jsonx.__dangerouslyEvalAllProps) {
        let evVal;
        try {
          // eslint-disable-next-line
          evVal =
            typeof evVal === "function"
              ? jsonx.__dangerouslyEvalAllProps
              : scopedEval(jsonx.__dangerouslyEvalAllProps as string);
        } catch (e) {
          if (this.debug || jsonx.debug) evVal = function(){return {error:e}};
        }
        evAllProps = typeof evVal === "function"
          ? evVal.call(this, { jsonx })
          : evVal;
      }
      const evProps = Object.keys(jsonx.__dangerouslyEvalProps || {}).reduce(
        (eprops, epropName) => {
          let evVal;
          let evValString;
          try {
            // eslint-disable-next-line
            //@ts-ignore
            evVal = scopedEval(jsonx.__dangerouslyEvalProps[epropName]);
            evValString = evVal.toString();
          } catch (e) {
            if (this.debug || jsonx.debug) evVal = e;
          }
          //@ts-ignore
          eprops[epropName] =
            typeof evVal === "function" ? evVal.call(this, { jsonx }) : evVal;
          //@ts-ignore
          if (this.exposeEval) eprops[`__eval_${epropName}`] = evValString;
          return eprops;
        },
        {}
      );
      const evBindProps = Object.keys(
        jsonx.__dangerouslyBindEvalProps || {}
      ).reduce((eprops, epropName) => {
        let evVal;
        let evValString;

        try {
          let args;
          //@ts-ignore
          const functionBody = jsonx.__dangerouslyBindEvalProps[epropName];
          // InlineFunction = Function.prototype.constructor.apply({}, args);
          let functionDefinition;
          if (typeof functionBody === "function") {
            functionDefinition = functionBody;
          } else if (jsonx.__dangerouslyBindEvalProps) {
            functionDefinition = scopedEval(
              jsonx.__dangerouslyBindEvalProps[epropName] as string
            );
            evValString = functionDefinition.toString();
          } // eslint-disable-next-line
          if (jsonx.__functionargs && jsonx.__functionargs[epropName]) {
            args = [this].concat(
              jsonx.__functionargs[epropName].reduce(
                boundArgsReducer.call(this, jsonx),
                []
              )
            );
          } else Iif (jsonx.__functionparams === false) {
            args = [this];
          } else {
            const functionDefArgs = getParamNames(functionDefinition);
            args = [this].concat(
              functionDefArgs.reduce(boundArgsReducer.call(this, jsonx), [])
            );
          }
          // eslint-disable-next-line
          evVal = functionDefinition.bind(...args);
        } catch (e) {
          if (this.debug || jsonx.debug) evVal = e;
        }
        // eslint-disable-next-line
        //@ts-ignore
        eprops[epropName] = evVal;
        //@ts-ignore
        if (this.exposeEval) eprops[`__eval_${epropName}`] = evValString;
        return eprops;
      }, {});

      return Object.assign({}, evProps, evBindProps, evAllProps);
    }

    /**
     * Resolves jsonx.__dangerouslyInsertComponents into an object that turns each value into a React components. This is typically used in a library like Recharts where you pass custom components for chart ticks or plot points.
     * @param {Object} options
     * @param {Object} options.jsonx - Valid JSONX JSON
     * @param {Object} [options.resources={}] - object to use for resourceprops(asyncprops), usually a result of an asynchronous call
     * @returns {Object} resolved object of React Components
     */
    export function getComponentProps(
      this: defs.Context,
      options: defs.Config = { jsonx: {} }
    ) {
      const { jsonx, resources } = options;
      //@ts-ignore
      return Object.keys(jsonx.__dangerouslyInsertComponents).reduce(
        (cprops: defs.jsonxResourceProps, cpropName: string) => {
          let componentVal;
          try {
            // eslint-disable-next-line
            if (jsonx.__dangerouslyInsertComponents) {
              componentVal = getRenderedJSON.call(
                this,
                jsonx.__dangerouslyInsertComponents[cpropName],
                resources
              );
            }
          } catch (e) {
            Iif (this.debug || jsonx.debug) componentVal = e;
          }
          cprops[cpropName] = componentVal;
          return cprops;
        },
        {}
      );
    }

    /**
     * Used to create components from jsonx as props
     * @param this
     * @param options
     */
    export function getReactComponents(this: defs.Context, options: defs.Config) {
      const { jsonx, resources } = options;
      const functionComponents = !jsonx.__dangerouslyInsertFunctionComponents
        ? {}
        : Object.keys(jsonx.__dangerouslyInsertFunctionComponents).reduce(
            (cprops: defs.jsonxResourceProps, cpropName) => {
              let componentVal;
              try {
                const args = jsonx.__dangerouslyInsertFunctionComponents && jsonx.__dangerouslyInsertFunctionComponents[cpropName] as defs.createFunctionComponentArgs;
                if (args) {
                  args.options = Object.assign({}, args.options, { resources });
                if(args.function){
                  const newComponent = makeFunctionComponent.call(this,args.function,args.options);
                  componentVal = args?.invoke
                    ? newComponent(jsonx.props)
                    : newComponent;
                } else {
                  const newComponent = getReactFunctionComponent.call(
                    this,
                    args.reactComponent,
                    args.functionBody,
                    args.options
                  );
                  componentVal = args?.invoke
                    ? newComponent(jsonx.props)
                    : newComponent;
                  }
                }
              } catch (e) {
                if (this.debug || jsonx.debug) componentVal = e;
              }
              cprops[cpropName] =
                cpropName === "_children" ? [componentVal] : componentVal;
              return cprops;
            },
            {}
          );
      const classComponents = !jsonx.__dangerouslyInsertClassComponents
        ? {}
        : Object.keys(jsonx.__dangerouslyInsertClassComponents).reduce(
            (cprops: defs.jsonxResourceProps, cpropName) => {
              let componentVal;
              try {
                const args = jsonx.__dangerouslyInsertClassComponents && jsonx.__dangerouslyInsertClassComponents[cpropName];
                if (args) {
                  args.options = Object.assign({}, args.options, { resources });
                  // eslint-disable-next-line
                  componentVal = getReactClassComponent.call(
                    this,
                    args.reactComponent,
                    args.options
                  );
                }
              } catch (e) {
                if (this.debug || jsonx.debug) componentVal = e;
              }
              cprops[cpropName] =
                cpropName === "_children" ? [componentVal] : componentVal;
              return cprops;
            },
            {}
          );
      return Object.assign({}, functionComponents, classComponents);
    }

    /**
     * Resolves jsonx.__dangerouslyInsertReactComponents into an object that turns each value into a React components. This is typically used in a library like Recharts where you pass custom components for chart ticks or plot points.
     * @param {Object} options
     * @param {Object} options.jsonx - Valid JSONX JSON
    //  * @param {Object} [options.resources={}] - object to use for asyncprops, usually a result of an asynchronous call
     * @returns {Object} resolved object of React Components
     */
    export function getReactComponentProps(
      this: defs.Context,
      options: { jsonx: defs.jsonx } = { jsonx: {} }
    ) {
      const { jsonx } = options;
      const customComponents =
        this && this.reactComponents ? this.reactComponents : {};
      const customLibraries =
        this && this.componentLibraries ? this.componentLibraries : {};
      Iif (
        jsonx.__dangerouslyInsertJSONXComponents &&
        Object.keys(jsonx.__dangerouslyInsertJSONXComponents).length
      ) {
        return Object.keys(jsonx.__dangerouslyInsertJSONXComponents).reduce(
          (cprops: defs.jsonxResourceProps, cpropName) => {
            let componentVal;
            try {
              componentVal = getComponentFromMap({
                jsonx: jsonx.__dangerouslyInsertJSONXComponents && jsonx.__dangerouslyInsertJSONXComponents[cpropName],
                reactComponents: customComponents,
                componentLibraries: customLibraries
              });
            } catch (e) {
              Iif (this.debug || jsonx.debug) componentVal = e;
            }
            // eslint-disable-next-line
            cprops[cpropName] = componentVal;
            return cprops;
          },
          {}
        );
      } else if(jsonx.__dangerouslyInsertReactComponents && Object.keys(jsonx.__dangerouslyInsertReactComponents).length){
        return Object.keys(jsonx.__dangerouslyInsertReactComponents).reduce(
          (cprops: defs.jsonxResourceProps, cpropName: string) => {
            let componentVal;
            try {
              componentVal = getComponentFromMap({
                jsonx: {
                  component: jsonx.__dangerouslyInsertReactComponents && jsonx.__dangerouslyInsertReactComponents[cpropName],
                  props: jsonx.__dangerouslyInsertComponentProps
                    ? jsonx.__dangerouslyInsertComponentProps[cpropName]
                    : {}
                },
                reactComponents: customComponents,
                componentLibraries: customLibraries
              });
            } catch (e) {
              Iif (this.debug || jsonx.debug) componentVal = e;
            }
            // eslint-disable-next-line
            cprops[cpropName] = componentVal;
            return cprops;
          },
          {}
        );
      }
    }

    /**
     * Takes a function string and returns a function on either this.props or window. The function can only be 2 levels deep
     * @param {Object} options
     * @param {String} [options.propFunc='func:'] - function string, like func:window.LocalStorage.getItem or func:this.props.onClick  or func:inline.myInlineFunction
     * @param {Object} [options.allProps={}] - merged computed props, Object.assign({ key: renderIndex, }, thisprops, jsonx.props, resourceprops, asyncprops, windowprops, evalProps, insertedComponents);
     * @returns {Function} returns a function from this.props or window functions
     * @example
     * getFunctionFromProps({ propFunc='func:this.props.onClick', }) // => this.props.onClick
     * @deprecated
     */
    export function getFunctionFromProps(
      this: defs.Context,
      options: {
        propFunc?: string;
        propBody: string;
        jsonx: defs.jsonx;
        functionProperty?: string;
      } = { jsonx: {}, propBody: "" }
    ) {
      const {
        propFunc = "func:",
        propBody,
        jsonx,
        functionProperty = ""
      } = options;
      // eslint-disable-next-line
      const { logError = console.error, debug } = this;
      let windowObject: any = {};
      if (this.window) windowObject = this.window;
      //@ts-ignore
      else if (typeof global !== "undefined" && global.window)
        windowObject = global.window;
      try {
        const functionNameString = propFunc.split(":")[1] || "";
        const functionNameArray = functionNameString.split(".");
        const functionName = functionNameArray.length
          ? functionNameArray[functionNameArray.length - 1]
          : "";

        if (propFunc.includes("func:inline")) {
          // eslint-disable-next-line
          let InlineFunction;
          if (jsonx.__functionargs) {
            const args: string[] = [].concat(
              jsonx.__functionargs[functionProperty]
            );
            args.push(propBody);
            InlineFunction = Function.prototype.constructor.apply({}, args);
          } else E{
            InlineFunction = Function(
              "param1",
              "param2",
              '"use strict";' + propBody
            );
          }
          const [propFuncName, funcName] = propFunc.split(".");

          Object.defineProperty(InlineFunction, "name", {
            value: funcName
          });
          if (jsonx.__functionargs) {
            const boundArgs = [this].concat(
              jsonx.__functionargs[functionProperty].map(
                (arg: string) => jsonx.props[arg]
              )
            );
            return InlineFunction.bind(...boundArgs);
          } else E{
            return InlineFunction.bind(this);
          }
        } else if (propFunc.indexOf("func:window") !== -1) {
          if (functionNameArray.length === 3) {
            try {
              return windowObject[functionNameArray[1]][functionName].bind(this);
            } catch (e) {
              Iif (debug) {
                logError(e);
              }
              return windowObject[functionNameArray[1]][functionName];
            }
          } else {
            try {
              return windowObject[functionName].bind(this);
            } catch (e) {
              Iif (debug) {
                logError(e);
              }
              return windowObject[functionName];
            }
          }
        } else if (functionNameArray.length === 4) {
          return this.props
            ? this.props[functionNameArray[2]][functionName]
            : jsonx.props[functionNameArray[2]][functionName];
        } else if (functionNameArray.length === 3) {
          return this.props
            ? this.props[functionName].bind(this)
            : jsonx.props[functionName].bind(this);
        } else {
          return function() {};
        }
      } catch (e) {
        if (this.debug) {
          logError(e);
          Iif (jsonx && jsonx.debug) return e;
        }
        return function() {};
      }
    }

    /**
     * Returns a resolved object from function strings that has functions pulled from jsonx.__functionProps
     * @param {Object} options
     * @param {Object} options.jsonx - Valid JSONX JSON
     * @param {Object} [options.allProps={}] - merged computed props, Object.assign({ key: renderIndex, }, thisprops, jsonx.props, asyncprops, windowprops, evalProps, insertedComponents);
     * @returns {Object} resolved object of functions from function strings
     */
    export function getFunctionProps(
      this: defs.Context,
      options: { allProps?: any; jsonx: defs.jsonx } = { jsonx: {} }
    ) {
      const { allProps = {}, jsonx = {} } = options;
      const getFunction = getFunctionFromProps.bind(this);
      const funcProps = jsonx.__functionProps;
      //Allowing for window functions
      if (funcProps) {
        Object.keys(funcProps).forEach(key => {
          if (
            typeof funcProps[key] === "string" &&
            funcProps[key].indexOf("func:") !== -1
          ) {
            allProps[key] = getFunction({
              propFunc: funcProps[key],
              propBody: jsonx.__inline ? jsonx.__inline[key] : "",
              jsonx,
              functionProperty: key
            });
          }
        });
      }
      return allProps;
    }

    /**
     * Returns a resolved object that has React Components pulled from window.__jsonx_custom_elements
     * @param {Object} options
     * @param {Object} options.jsonx - Valid JSONX JSON
     * @param {Object} [options.allProps={}] - merged computed props, Object.assign({ key: renderIndex, }, thisprops, jsonx.props, asyncprops, windowprops, evalProps, insertedComponents);
     * @returns {Object} resolved object of with React Components from a window property window.__jsonx_custom_elements
     */
    export function getWindowComponents(
      this: defs.Context,
      options: { allProps?: any; jsonx: defs.jsonx } = { jsonx: {} }
    ) {
      const { allProps, jsonx } = options;
      const windowComponents = jsonx.__windowComponents;
      //@ts-ignore
      const window = this.window || global.window || {};
      const windowFuncPrefix = "func:window.__jsonx_custom_elements";
      // if (jsonx.hasWindowComponent && window.__jsonx_custom_elements) {
      Object.keys(windowComponents).forEach(key => {
        const windowKEY =
          typeof windowComponents[key] === "string"
            ? windowComponents[key].replace(`${windowFuncPrefix}.`, "")
            : "";
        if (
          typeof windowComponents[key] === "string" &&
          windowComponents[key].indexOf(windowFuncPrefix) !== -1 &&
          typeof window.__jsonx_custom_elements[windowKEY] === "function"
        ) {
          const windowComponentElement = window.__jsonx_custom_elements[windowKEY];
          const windowComponentProps = allProps["__windowComponentProps"]
            ? allProps["__windowComponentProps"]
            : this.props;
          allProps[key] = React.createElement(
            windowComponentElement,
            windowComponentProps,
            null
          );
        }
      });
      return allProps;
    }

    /**
     * Returns computed properties for React Components and any property that's prefixed with __ is a computedProperty
     * @param {Object} options
     * @param {Object} options.jsonx - Valid JSONX JSON
     * @param {Object} [options.resources={}] - object to use for asyncprops, usually a result of an asynchronous call
     * @param {Number} options.renderIndex - number used for React key prop
     * @param {function} [options.logError=console.error] - error logging function
     * @param {Object} [options.componentLibraries] - react components to render with JSONX
     * @param {Boolean} [options.useReduxState=true] - use redux props in this.props
     * @param {Boolean} [options.ignoreReduxPropsInComponentLibraries=true] - ignore redux props in this.props for component libraries, this is helpful incase these properties collide with component library element properties
     * @param {boolean} [options.debug=false] - use debug messages
     * @example
    const testJSONX = { component: 'div',
      props: { id: 'generatedJSONX', className: 'jsonx' },
      children: [ [Object] ],
      asyncprops: { auth: [Array], username: [Array] },
      __dangerouslyEvalProps: { getUsername: '(user={})=>user.name' },
      __dangerouslyInsertComponents: { myComponent: [Object] }
    const resources = {
      user: {
        name: 'jsonx',
        description: 'react withouth javascript',
      },
      stats: {
        logins: 102,
        comments: 3,
      },
      authentication: 'OAuth2',
    };
    const renderIndex = 1;
    getComputedProps.call({}, {
            jsonx: testJSONX,
            resources,
            renderIndex,
          });
    computedProps = { key: 1,
         id: 'generatedJSONX',
         className: 'jsonx',
         auth: 'OAuth2',
         username: 'jsonx',
         getUsername: [Function],
         myComponent:
          { '$$typeof': Symbol(react.element),
            type: 'p',
            key: '8',
            ref: null,
            props: [Object],
            _owner: null,
            _store: {} } } }
     *
     */
    export function getComputedProps(
      this: defs.Context,
      options: {
        jsonx?: defs.jsonx;
        resources?: defs.jsonxResourceProps;
        renderIndex?: number;
        logError?: any;
        useReduxState?: boolean;
        ignoreReduxPropsInComponentLibraries?: boolean;
        disableRenderIndexKey?: boolean;
        debug?: boolean;
        componentLibraries?: defs.jsonxLibrary;
      } = {}
    ) {
      // eslint-disable-next-line
      const {
        jsonx = {},
        resources = {},
        renderIndex,
        logError = console.error,
        useReduxState = true,
        ignoreReduxPropsInComponentLibraries = true,
        disableRenderIndexKey = true,
        debug,
        componentLibraries = {}
      } = options;
      try {
        const componentThisProp = jsonx.thisprops
          ? Object.assign(
              {
                __jsonx: {
                  _component: jsonx,
                  _resources: resources
                }
              },
              this.props,
              jsonx.props,
              //@ts-ignore
              useReduxState &&
                !jsonx.ignoreReduxProps &&
                ignoreReduxPropsInComponentLibraries &&
                jsonx.component &&
                !componentLibraries[jsonx.component]
                ? this.props && this.props.getState
                  ? this.props.getState()
                  : {}
                : {}
            )
          : undefined;

        const windowTraverse = typeof window !== "undefined" ? window : {};
        const asyncprops = jsonx.asyncprops
          ? getJSONXProps({
              jsonx,
              propName: "asyncprops",
              traverseObject: resources
            })
          : {};
        const resourceprops = jsonx.resourceprops
          ? getJSONXProps({
              jsonx,
              propName: "resourceprops",
              traverseObject: resources
            })
          : {};
        const windowprops = jsonx.windowprops
          ? getJSONXProps({
              jsonx,
              propName: "windowprops",
              traverseObject: windowTraverse
            })
          : {};
        const thisprops = jsonx.thisprops
          ? getJSONXProps({
              jsonx,
              propName: "thisprops",
              traverseObject: componentThisProp
            })
          : {};
        const thisstate = jsonx.thisstate
          ? getJSONXProps({
              jsonx,
              propName: "thisstate",
              traverseObject: this.state
            })
          : {};
        let thiscontext = jsonx.thiscontext
          ? getJSONXProps({
              jsonx,
              propName: "thiscontext",
              traverseObject: this || {}
            })
          : {};
        if(jsonx.useformregister){
          const evalJSONX = {
            ...jsonx,
            __dangerouslyEvalAllProps:useFormRegisterHandler
          }
          const contextProps = getEvalProps.call(this,{
            jsonx: evalJSONX
          })
          thiscontext = {
            ...thiscontext,
            ...contextProps
          };
        }

        //allowing javascript injections
        const evalProps =
          jsonx.__dangerouslyEvalProps || jsonx.__dangerouslyBindEvalProps
            ? getEvalProps.call(this, { jsonx })
            : {};
        const insertedComponents = jsonx.__dangerouslyInsertComponents
          ? getComponentProps.call(this, { jsonx, resources, debug })
          : {};
        const insertedReactComponents =
          jsonx.__dangerouslyInsertReactComponents ||
          jsonx.__dangerouslyInsertJSONXComponents
            ? getReactComponentProps.call(this, { jsonx, debug })
            : {};
        const insertedComputedComponents =
          jsonx.__dangerouslyInsertFunctionComponents ||
          jsonx.__dangerouslyInsertClassComponents
            ? getReactComponents.call(this, { jsonx, debug })
            : {};

        const evalAllProps = jsonx.__dangerouslyEvalAllProps
          ? getEvalProps.call(this, { jsonx })
          : {};
        const allProps = Object.assign(
          {},
          this.disableRenderIndexKey || disableRenderIndexKey
            ? {}
            : { key: renderIndex },
          jsonx.props,
          thisprops,
          thisstate,
          thiscontext,
          resourceprops,
          asyncprops,
          windowprops,
          evalProps,
          insertedComponents,
          insertedReactComponents,
          insertedComputedComponents
        );
        const computedProps = Object.assign(
          {},
          allProps,
          jsonx.__functionProps
            ? getFunctionProps.call(this, { allProps, jsonx })
            : {},
          jsonx.__windowComponents
            ? getWindowComponents.call(this, { allProps, jsonx })
            : {},
          jsonx.__spreadComponent
            ? getChildrenComponents.call(this, { allProps, jsonx })
            : {},
          evalAllProps
        );
        if (jsonx.useremoveprops && Array.isArray(jsonx.useremoveprops)) {
          for (const prop of jsonx.useremoveprops) {
            computedProps[prop] = undefined;
            delete computedProps[prop];
          }
        }
        Iif (jsonx.debug) console.debug({ jsonx, computedProps });
        return (jsonx.useincludeprops && Array.isArray(jsonx.useincludeprops))
          ? jsonx.useincludeprops.concat( ['key'],
            Object.keys(thisprops as {[index:string]: any}),
            Object.keys(thisstate), Object.keys(thiscontext), Object.keys(resourceprops), Object.keys(asyncprops), Object.keys(windowprops), Object.keys(evalProps), Object.keys(insertedComponents), Object.keys(insertedReactComponents as {[index:string]: any}), Object.keys(insertedComputedComponents),
            ).reduce((includedProps:any,prop:string)=>{
              includedProps[prop] = computedProps[prop]
              return includedProps
            },{})
          : computedProps;
      } catch (e) {
        debug && logError(e, (e as Error).stack ? (e as Error).stack : "no stack");
        return null;
      }
    }