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


TypeScript lodash.truncate函数代码示例

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


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

示例1: peertubeTruncate

// Consistent with .length, lodash truncate function is not
function peertubeTruncate (str: string, maxLength: number) {
  const options = {
    length: maxLength
  }
  const truncatedStr = truncate(str, options)

  // The truncated string is okay, we can return it
  if (truncatedStr.length <= maxLength) return truncatedStr

  // Lodash takes into account all UTF characters, whereas String.prototype.length does not: some characters have a length of 2
  // We always use the .length so we need to truncate more if needed
  options.length -= truncatedStr.length - maxLength
  return truncate(str, options)
}
开发者ID:jiang263,项目名称:PeerTube,代码行数:15,代码来源:core-utils.ts

示例2: writeSettings

  app.patch('/system', (req, res) => {
    if(req.body.application) {
      req.body.application.taxRate = +req.body.application.taxRate;
      req.body.application.businessName = _.truncate(req.body.application.businessName, { length: 50, omission: '' });
      req.body.application.locationName = +req.body.application.locationName;
      req.body.application.customBusinessCurrency = _.truncate(req.body.application.customBusinessCurrency, { length: 25, omission: '' });
    }

    if(req.body.printer) {
      req.body.printer.characterWidth = +req.body.printer.characterWidth;
    }

    writeSettings(req.body, () => {
      recordAuditMessage(req, MESSAGE_CATEGORIES.SYSTEM, `System settings were updated.`, { settings: req.body });
      res.json({ flash: 'Settings updated successfully.', data: req.body });
    });
  });
开发者ID:Linko91,项目名称:posys,代码行数:17,代码来源:system.ts

示例3: truncate

 return function truncate(string:string, maxChars:number = 50, doTruncate:boolean = true):string {
     if (!doTruncate) {
         return string;
     }
     return _.truncate(string, {
         length: maxChars,
         separator: /,? +/,
         omission: `&hellip;`
     });
 }
开发者ID:swordman1205,项目名称:angular-typescript-material,代码行数:10,代码来源:string.ts

示例4: changeMOTD

  changeMOTD(player, motd: string) {
    const guild: Guild = player.guild;
    if(!guild.isMod(player)) return 'You do not have enough privileges to do this!';

    motd = motd.trim();
    if(!motd) return 'Please be nice, give them a message to look at.';
    if(motd.length > 500) motd = _.truncate(motd, { length: 500 });

    guild.changeMOTD(motd);
  }
开发者ID:IdleLands,项目名称:IdleLands,代码行数:10,代码来源:guilds.ts

示例5:

export const recordErrorMessage = (req, module, message, stack, foundAt = 'Server') => {

  message = _.truncate(message, { length: 500, omission: '' });

  const insertRecord: any = { module, message, stack, foundAt };
  insertRecord.locationId = +req.header('X-Location');
  insertRecord.terminalId = req.header('X-Terminal');

  if(_.isNaN(insertRecord.locationId)) {
    return;
  }

  ErrorMessage
    .forge(insertRecord)
    .save();
};
开发者ID:Linko91,项目名称:posys,代码行数:16,代码来源:_logging.ts

示例6: normalizeActor

function normalizeActor (actor: any) {
  if (!actor || !actor.url) return

  if (typeof actor.url !== 'string') {
    actor.url = actor.url.href || actor.url.url
  }

  if (actor.summary && typeof actor.summary === 'string') {
    actor.summary = truncate(actor.summary, { length: CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max })

    if (actor.summary.length < CONSTRAINTS_FIELDS.USERS.DESCRIPTION.min) {
      actor.summary = null
    }
  }

  return
}
开发者ID:jiang263,项目名称:PeerTube,代码行数:17,代码来源:actor.ts

示例7: switch

export const formatColumnValue = (
  column: string,
  value: string,
  charLimit: number
): string => {
  switch (column) {
    case 'timestamp':
      return moment(+value / 1000000).format(DEFAULT_TIME_FORMAT)
    case 'procid':
    case 'host':
    case 'appname':
      return truncateText(value, column)
    case 'message':
      value = (value || 'No Message Provided').replace('\\n', '')
      if (value.indexOf(' ') > charLimit - 5) {
        value = _.truncate(value, {length: charLimit - 5})
      }
      return value
  }
  return value
}
开发者ID:viccom,项目名称:influxdb,代码行数:21,代码来源:table.ts

示例8: parseSpelExpressions

export const evaluateExpression = (context: object, value: string): IExpressionChange => {
  if (!value) {
    return { value, spelError: null, spelPreview: '' };
  }

  const stringify = (obj: any): string => {
    return obj === null ? 'null' : obj === undefined ? 'undefined' : JSON.stringify(obj, null, 2);
  };

  try {
    const exprs = parseSpelExpressions(value);
    const results = exprs.map(expr => expr.eval(context));
    return { value, spelError: null, spelPreview: results.join('') };
  } catch (err) {
    const spelError: ISpelError = {
      message: null,
      context: null,
      contextTruncated: null,
    };

    if (err.name && err.message) {
      if (err.name === 'NullPointerException' && err.state && err.state.activeContext) {
        spelError.context = stringify(err.state.activeContext.peek());
        spelError.contextTruncated = truncate(spelError.context, { length: 200 });
      }
      spelError.message = `${err.name}: ${err.message}`;
    } else {
      try {
        spelError.message = JSON.stringify(err);
      } catch (ignored) {
        spelError.message = err.toString();
      }
    }

    return { value, spelError, spelPreview: null };
  }
};
开发者ID:emjburns,项目名称:deck,代码行数:37,代码来源:evaluateExpression.ts

示例9: saveProject

 saveProject(formValue) {
   this.projectData.update({ visibility: formValue.visibility });
   this.projectData.update({ name: truncate(formValue.name, { length: 20 }) });
 }
开发者ID:seiyria,项目名称:deck.zone,代码行数:4,代码来源:create-settings.component.ts

示例10:

 const cleanName = (printName, length = 22) => {
   return _.truncate(printName, { length, omission: '' });
 };
开发者ID:Linko91,项目名称:posys,代码行数:3,代码来源:invoice.ts


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