当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.result函数代码示例

本文整理汇总了TypeScript中lodash.result函数的典型用法代码示例。如果您正苦于以下问题:TypeScript result函数的具体用法?TypeScript result怎么用?TypeScript result使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了result函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: explainTransaction

  /**
   * Explain/parse transaction
   * @param params
   * - txBase64: transaction encoded as base64 string
   * @returns {{displayOrder: [string,string,string,string,string], id: *, outputs: Array, changeOutputs: Array}}
   */
  explainTransaction(params) {
    const { txBase64 } = params;
    let tx;

    try {
      tx = new stellar.Transaction(txBase64);
    } catch (e) {
      throw new Error('txBase64 needs to be a valid tx encoded as base64 string');
    }
    const id = tx.hash().toString('hex');
    const explanation: any = {
      displayOrder: ['id', 'outputAmount', 'changeAmount', 'outputs', 'changeOutputs', 'fee', 'memo'],
      id,
      outputs: [],
      changeOutputs: [],
      memo: {}
    };

    // In a Stellar tx, the _memo property is an object with the methods:
    // value() and arm() that provide memo value and type, respectively.
    if (_.result(tx, '_memo.value') && _.result(tx, '_memo.arm')) {
      explanation.memo = {
        value: _.result(tx, '_memo.value').toString(),
        type: _.result(tx, '_memo.arm')
      };
    }

    let spendAmount = new BigNumber(0);
    // Process only operations of the native asset (XLM)
    const operations = _.filter(tx.operations, operation => !operation.asset || operation.asset.getCode() === 'XLM');
    if (_.isEmpty(operations)) {
      throw new Error('missing operations');
    }
    explanation.outputs = _.map(operations, operation => {
      // Get memo to attach to address, if type is 'id'
      const memoId = (_.get(explanation, 'memo.type') === 'id' && ! _.get(explanation, 'memo.value') ? `?memoId=${explanation.memo.value}` : '');
      const output = {
        amount: this.bigUnitsToBaseUnits(operation.startingBalance || operation.amount),
        address: operation.destination + memoId
      };
      spendAmount = spendAmount.plus(output.amount);
      return output;
    });

    explanation.outputAmount = spendAmount.toFixed(0);
    explanation.changeAmount = '0';

    explanation.fee = {
      fee: tx.fee.toFixed(0),
      feeRate: null,
      size: null
    };
    return explanation;
  }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:60,代码来源:xlm.ts

示例2: handleError

  static handleError(err, res, config: Config) {
    var error = new Error(get(res, 'body.description') || get(err, 'response.statusText') || 'No error details available')

    if (res) {
      error['headers']    = res.headers
      error['object']     = res.body
      error['statusCode'] = res.statusCode
      error['statusText'] = res.statusText
      error['url']        = res.req.url
      error['method']     = res.req.method
      error['stack']      = err.stack
    }
    else {
      const errMsg = result(err, 'toString')
      error['statusCode'] = 500
      error['statusText'] = errMsg || 'Unknown error'
    }

    // session timed out, reset cookies and caches
    if (error['statusCode'] === 419) {
      Cache.instance.clear()
      config.clear()
    }

    if (config.settings.errorInterceptor) {
      if (config.settings.errorInterceptor(error)) return [true, error]
    }

    return [false, error]
  }
开发者ID:mediapeers,项目名称:chinchilla,代码行数:30,代码来源:tools.ts

示例3:

            .reduce(function(colorActions: ILineColorAction[], astNode: ILambdaScriptAstNode) {
                const color = colorMap[astNode.type];

                if (color) {
                    const colorFn = chalk[color].bind(chalk),
                        locKey = alternateLocMap[astNode.type] || 'loc',

                        // I'm just using _.result to avoid TS7017
                        loc: ILoc = _.result(astNode, locKey);

                    /**
                     * Originally, I just colored as soon as I found a node. However, this does not work,
                     * because other coloring may have occurred on the line already, which will offset our
                     * column indices. And it is not sufficient just to drop all color from the line and
                     * see what the length difference is, because some of that color could be *after* our
                     * column indices and thus irrelevant. To solve this, we will gather all the colorings
                     * we want to do, and then apply them in sorted order. This makes the offset caclulation trivial.
                     */
                    return colorActions.concat({
                        // I don't know why but jison does not 0-index the line number.
                        lineIndex: loc.first_line - 1,
                        colStart: loc.first_column,
                        colEnd: loc.last_column,
                        colorFn: colorFn
                    });
                }

                return colorActions;
            }, []),
开发者ID:NickHeiner,项目名称:lambdascript,代码行数:29,代码来源:get-highlighted-code.ts

示例4: handlePolling

export function handlePolling(url: string, settings: any, sendRequest: (url: string, settings: any) => any)
: Promise<ApiResponse> {
    const pollingDelay: number = result(settings, 'pollDelay');

    return new Promise((resolve, reject) => {
        setTimeout(() => {
            sendRequest(url, settings).then(resolve, reject);
        }, pollingDelay);
    });
}
开发者ID:gooddata,项目名称:gooddata-js,代码行数:10,代码来源:xhr.ts

示例5: it

	it('hashmap pode ter funçþes como propriedades', () => {
		let hash: any = {
			a: 'algum valor',
			b(): number {
				return 10;
			}
		}

		expect(hash.b()).to.equal(10);
		expect(_.result(hash, 'b')).to.equal(10);
	});
开发者ID:feliperohdee,项目名称:node-meetup-cheatsheet,代码行数:11,代码来源:hashmap.ts

示例6: constructor

 constructor(public appState: AppState) {
   this.currentLang = _.result(appState, "get('lang')", 'en_US');
 }
开发者ID:karnex47,项目名称:iaa,代码行数:3,代码来源:change-lang.component.ts

示例7: return

export const renderWhenTrue = (Component: JSX.Element | (() => JSX.Element)) => (trueStatement) => {
	return (trueStatement ? result({ Component }, 'Component') : null) as JSX.Element | JSX.Element[];
};
开发者ID:3drepo,项目名称:3drepo.io,代码行数:3,代码来源:rendering.ts


注:本文中的lodash.result函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。