本文整理汇总了TypeScript中lodash.get.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript get.default方法的具体用法?TypeScript get.default怎么用?TypeScript get.default使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lodash.get
的用法示例。
在下文中一共展示了get.default方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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)
};
}
示例2: 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),
//.........这里部分代码省略.........
示例3:
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;
});
示例4: visit
visit(ast, 'heading', (node: any) => {
const slug = get(node, 'data.id')
const depth = get(node, 'depth')
headings.push({
depth,
slug,
value: humanize(slug),
})
})
示例5: get
fieldsToValidate.forEach((field) => {
const vmFieldValue = get(vm, field, undefined);
if (vmFieldValue !== undefined) {
const fieldValidationResultsPromise = validationFn(vm, field, vmFieldValue);
fieldValidationResultsPromises.push(fieldValidationResultsPromise);
}
});
示例6: return
return (method, ...args) => {
if (plugins && plugins.length > 0) {
for (const plugin of plugins) {
const fn = get(plugin, method)
isFn(fn) && fn(...args)
}
}
}
示例7: get
const getParsedData = (ast: any) => {
const node = find(ast, (node: any) => is('yaml', node))
return get(node, `data.parsedValue`)
}
示例8: get
return [...(plugins || [])].reduce((obj: any, plugin) => {
const fn = get(plugin, method)
return fn && isFn(fn) ? fn(obj) : obj
}, initial)
示例9: objPath
return string.replace(/\{\{(.+?)\}\}/g, function () {
return objPath(data, arguments[1], '');
});