當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript lodash.get類代碼示例

本文整理匯總了TypeScript中lodash.get的典型用法代碼示例。如果您正苦於以下問題:TypeScript get類的具體用法?TypeScript get怎麽用?TypeScript get使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了get類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

 return Array.from(input).sort((a: Object, b: Object) => {
   if (get(a, field) < get(b, field)) {
     return desc ? 1 : -1;
   }
   if (get(a, field) > get(b, field)) {
     return desc ? -1 : 1;
   }
   return 0;
 });
開發者ID:SirajAtDPS,項目名稱:angular2-tv-tracker,代碼行數:9,代碼來源:orderBy.ts

示例2: visit

  visit(ast, 'heading', (node: any) => {
    const slug = get(node, 'data.id')
    const depth = get(node, 'depth')

    headings.push({
      depth,
      slug,
      value: humanize(slug),
    })
  })
開發者ID:leslieSie,項目名稱:docz,代碼行數:10,代碼來源:Entry.ts

示例3: get

 fieldsToValidate.forEach((field) => {
   const vmFieldValue = get(vm, field, undefined);
   if (vmFieldValue !== undefined) {
     const fieldValidationResultsPromise = validationFn(vm, field, vmFieldValue);
     fieldValidationResultsPromises.push(fieldValidationResultsPromise);
   }
 });
開發者ID:Lemoncode,項目名稱:lcFormValidation,代碼行數:7,代碼來源:validationsDispatcher.ts

示例4: return

 return (method, ...args) => {
   if (plugins && plugins.length > 0) {
     for (const plugin of plugins) {
       const fn = get(plugin, method)
       isFn(fn) && fn(...args)
     }
   }
 }
開發者ID:leslieSie,項目名稱:docz,代碼行數:8,代碼來源:Plugin.ts

示例5: fromEditorConfig

export function fromEditorConfig(
	config: editorconfig.knownProps,
	defaults: TextEditorOptions
): TextEditorOptions {
	const resolved: TextEditorOptions = {
		tabSize: (config.indent_style === 'tab'
			? get(config, 'tab_width', config.indent_size)
			: get(config, 'indent_size', config.tab_width)
		)
	};
	if (get(resolved, 'tabSize') === 'tab') {
		resolved.tabSize = config.tab_width;
	}
	return {
		insertSpaces: config.indent_style
			? config.indent_style !== 'tab'
			: defaults.insertSpaces,
		tabSize: get(resolved, 'tabSize', defaults.tabSize)
	};
}
開發者ID:Bigous,項目名稱:editorconfig-vscode,代碼行數:20,代碼來源:Utils.ts

示例6: find

const getParsedData = (ast: any) => {
  const node = find(ast, (node: any) => is('yaml', node))
  return get(node, `data.parsedValue`)
}
開發者ID:leslieSie,項目名稱:docz,代碼行數:4,代碼來源:Entry.ts

示例7: get

 return [...(plugins || [])].reduce((obj: any, plugin) => {
   const fn = get(plugin, method)
   return fn && isFn(fn) ? fn(obj) : obj
 }, initial)
開發者ID:leslieSie,項目名稱:docz,代碼行數:4,代碼來源:Plugin.ts

示例8: require

/**
 * Generates a Unicode table and feeds it into configured printer.
 *
 * Top-level arguments:
 *
 * @arg {Object[]} data - the records to format as a table.
 * @arg {Object} options - configuration for the table.
 *
 * @arg {Object[]} [options.columns] - Options for formatting and finding values for table columns.
 * @arg {function(string)} [options.headerAnsi] - Zero-width formattter for entire header.
 * @arg {string} [options.colSep] - Separator between columns.
 * @arg {function(row, options)} [options.after] - Function called after each row is printed.
 * @arg {function(string)} [options.printLine] - Function responsible for printing to terminal.
 * @arg {function(cells)} [options.printHeader] - Function to print header cells as a row.
 * @arg {function(cells)} [options.printRow] - Function to print cells as a row.
 *
 * @arg {function(row)|string} [options.columns[].key] - Path to the value in the row or function to retrieve the pre-formatted value for the cell.
 * @arg {function(string)} [options.columns[].label] - Header name for column.
 * @arg {function(string, row)} [options.columns[].format] - Formatter function for column value.
 * @arg {function(row)} [options.columns[].get] - Function to return a value to be presented in cell without formatting.
 *
 */
function table<T = { height?: number }>(
  out: Output,
  data: any[],
  options: TableOptions<T> = {},
) {
  const ary = require('lodash.ary')
  const defaults = require('lodash.defaults')
  const get = require('lodash.get')
  const identity = require('lodash.identity')
  const partial = require('lodash.partial')
  const property = require('lodash.property')
  const result = require('lodash.result')

  const defaultOptions = {
    colSep: '  ',
    after: () => {
      // noop
    },
    headerAnsi: identity,
    printLine: s => out.log(s),
    printRow(cells) {
      this.printLine(cells.join(this.colSep).trimRight())
    },
    printHeader(cells) {
      this.printRow(cells.map(ary(this.headerAnsi, 1)))
      this.printRow(cells.map(hdr => hdr.replace(/./g, '─')))
    },
  }

  const colDefaults = {
    format: value => (value ? value.toString() : ''),
    width: 0,
    label() {
      return this.key.toString()
    },

    get(row) {
      const path = result(this, 'key')
      const value = !path ? row : get(row, path)
      return this.format(value, row)
    },
  }

  function calcWidth(cell) {
    const lines = stripAnsi(cell).split(/[\r\n]+/)
    const lineLengths = lines.map(property('length'))
    return Math.max.apply(Math, lineLengths)
  }

  function pad(str: string, length: number) {
    const visibleLength = stripAnsi(str).length
    const diff = length - visibleLength

    return str + ' '.repeat(Math.max(0, diff))
  }

  function render() {
    let columns: Array<TableColumn<T>> =
      options!.columns || (Object.keys((data[0] as any) || {}) as any)

    if (typeof columns[0] === 'string') {
      columns = (columns as any).map(key => ({ key }))
    }

    let defaultsApplied = false
    for (const row of data) {
      row.height = 1
      for (const col of columns) {
        if (!defaultsApplied) {
          defaults(col, colDefaults)
        }

        const cell = col.get(row)

        col.width = Math.max(
          result(col, 'label').length,
          col.width || 0,
          calcWidth(cell),
//.........這裏部分代碼省略.........
開發者ID:dhruvcodeword,項目名稱:prisma,代碼行數:101,代碼來源:table.ts

示例9: objPath

 return string.replace(/\{\{(.+?)\}\}/g, function () {
     return objPath(data, arguments[1], '');
 });
開發者ID:b-cuts,項目名稱:browser-sync-core,代碼行數:3,代碼來源:404.ts


注:本文中的lodash.get類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。