• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript lodash.truncate函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript lodash.unescape函数代码示例发布时间:2022-05-25
下一篇:
TypeScript lodash.trimStart函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap