本文整理汇总了TypeScript中lodash.toString函数的典型用法代码示例。如果您正苦于以下问题:TypeScript toString函数的具体用法?TypeScript toString怎么用?TypeScript toString使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了toString函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: csvEscape
export function csvEscape(value: any): string {
const valueStr = toString(value)
if (includes(valueStr, ","))
return `"${value.replace(/\"/g, "\"\"")}"`
else
return value
}
示例2: if
_.forEach(funcDef.params, rawParam => {
const param = {
name: rawParam.name,
type: 'string',
optional: !rawParam.required,
multiple: !!rawParam.multiple,
options: undefined,
};
if (rawParam.default !== undefined) {
func.defaultParams.push(_.toString(rawParam.default));
} else if (rawParam.suggestions) {
func.defaultParams.push(_.toString(rawParam.suggestions[0]));
} else {
func.defaultParams.push('');
}
if (rawParam.type === 'boolean') {
param.type = 'boolean';
param.options = ['true', 'false'];
} else if (rawParam.type === 'integer') {
param.type = 'int';
} else if (rawParam.type === 'float') {
param.type = 'float';
} else if (rawParam.type === 'node') {
param.type = 'node';
param.options = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'];
} else if (rawParam.type === 'nodeOrTag') {
param.type = 'node_or_tag';
param.options = ['name', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'];
} else if (rawParam.type === 'intOrInterval') {
param.type = 'int_or_interval';
} else if (rawParam.type === 'seriesList') {
param.type = 'value_or_series';
}
if (rawParam.options) {
param.options = _.map(rawParam.options, _.toString);
} else if (rawParam.suggestions) {
param.options = _.map(rawParam.suggestions, _.toString);
}
func.params.push(param);
});
示例3: indent
static indent(unitIndent: number, numIndent: number, argSource: any, noIndentFirstLine: boolean = false): string {
let result: string = "";
let source: string = _.isString(argSource) ? argSource : _.toString(argSource);
let lines: string[] = source.split(/\n/g);
if (lines[lines.length - 1] == "") lines.pop();
lines.forEach((line: string, index: number) => {
let newLine: string = (index < lines.length - 1) ? "\n" : "";
if (line && (index > 0 || !noIndentFirstLine))
result += _.repeat(" ", unitIndent * numIndent) + line + newLine;
else
result += line + newLine;
});
return result;
}
示例4: getCloneName
private getCloneName(bootEnvironment: BootEnvironment): string {
let commonPrefix = bootEnvironment.id + '-copy-',
usedNames = _.filter((this.bootEnvironments.keySeq().toJS() as string[]), name => _.startsWith(commonPrefix)),
lastUsedIndex = !usedNames.length ?
0 :
_.last(
_.sortBy(
_.map(
usedNames,
name => _.toNumber(name.substring(commonPrefix.length))
)
)
);
return commonPrefix + _.toString(lastUsedIndex + 1);
}
示例5: source
static source(argSource: any): string {
let result: string = "";
let source: string = _.isString(argSource) ? argSource : _.toString(argSource);
let lines: Array<string> = source.toString().split(/\n/g);
if (lines[0] == "") lines.shift();
if (lines[lines.length - 1] == "") lines.pop();
lines.forEach((line: string) => {
if (line.match(/###DeleteLine###/)) return;
if (line.match(/###NoNewLine###/)) {
line = line.replace(/###NoNewLine###/, "");
result = result.replace(/\n$/m, "");
}
result += line + "\n";
});
return result;
}
示例6: return
return (value: any) => {
const { mappings, thresholds, theme } = options;
let color;
let text = _.toString(value);
let numeric = toNumber(value);
let shouldFormat = true;
if (mappings && mappings.length > 0) {
const mappedValue = getMappedValue(mappings, value);
if (mappedValue) {
text = mappedValue.text;
const v = toNumber(text);
if (!isNaN(v)) {
numeric = v;
}
shouldFormat = false;
}
}
if (field.dateFormat) {
const date = toMoment(value, numeric, field.dateFormat);
if (date.isValid()) {
text = date.format(field.dateFormat);
shouldFormat = false;
}
}
if (!isNaN(numeric)) {
if (shouldFormat && !_.isBoolean(value)) {
const { decimals, scaledDecimals } = getDecimalsForValue(value, field.decimals);
text = formatFunc(numeric, decimals, scaledDecimals, options.isUtc);
}
if (thresholds && thresholds.length) {
color = getColorFromThreshold(numeric, thresholds, theme);
}
}
if (!text) {
text = options.noValue ? options.noValue : '';
}
return { text, numeric, color };
};
示例7: function
function(value, index) {
var paramType;
if (index < this.def.params.length) {
paramType = this.def.params[index].type;
} else if (_.get(_.last(this.def.params), 'multiple')) {
paramType = _.get(_.last(this.def.params), 'type');
}
if (paramType === 'value_or_series') {
return value;
}
if (paramType === 'boolean' && _.includes(['true', 'false'], value)) {
return value;
}
if (_.includes(['int', 'float', 'int_or_interval', 'node_or_tag', 'node'], paramType) && _.isFinite(+value)) {
return _.toString(+value);
}
return "'" + value + "'";
}.bind(this)
示例8: if
const parameters = _.map(this.params, (value, index) => {
let paramType;
if (index < this.def.params.length) {
paramType = this.def.params[index].type;
} else if (_.get(_.last(this.def.params), 'multiple')) {
paramType = _.get(_.last(this.def.params), 'type');
}
// param types that should never be quoted
if (_.includes(['value_or_series', 'boolean', 'int', 'float', 'node'], paramType)) {
return value;
}
const valueInterpolated = _.isString(value) ? replaceVariables(value) : value;
// param types that might be quoted
// To quote variables correctly we need to interpolate it to check if it contains a numeric or string value
if (_.includes(['int_or_interval', 'node_or_tag'], paramType) && _.isFinite(+valueInterpolated)) {
return _.toString(value);
}
return "'" + value + "'";
});
示例9:
.map(index => ({
key: _.toString(index),
active: _.eq(index, this.pageIndex),
handler: () => this.setPageIndex(index),
})