UNPKG

vtils

Version:

一个面向业务的 JavaScript/TypeScript 实用程序库。

20 lines (19 loc) 539 B
"use strict"; exports.__esModule = true; exports.toSingleLineString = toSingleLineString; var _lodashUni = require("lodash-uni"); /** * 将多行字符串转换为单行字符串。 * * @param value 要转换的字符串 * @returns 返回结果 */ function toSingleLineString(value, truncateOptions) { var res = value.replace(/[\r\n]+/g, ' ').trim(); if (truncateOptions) { res = (0, _lodashUni.truncate)(res, typeof truncateOptions === 'number' ? { length: truncateOptions } : truncateOptions); } return res; }