當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript numbro.format函數代碼示例

本文整理匯總了TypeScript中numbro.format函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript format函數的具體用法?TypeScript format怎麽用?TypeScript format使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了format函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: __guard__

  string = string.replace(/(^|[^@])@(?:(\$?\w+)|{([^{}]+)})(?:{([^{}]+)})?/g, (_match, prefix, name, long_name, format) => {
    name = (long_name != null) ? long_name : name;

    const value =
      name[0] === "$" ?
        special_vars[name.substring(1)]
      :

        __guard__(data_source.get_column(name), x => x[i]);

    let replacement = null;
    if ((value == null)) {
      replacement = "???";

    } else {
      // 'safe' format, just return the value as is
      if (format === 'safe') {
        return `${prefix}${value}`;

      } else if (format != null) {

        // see if the field has an entry in the formatters dict
        if ((formatters != null) && name in formatters) {
          if (formatters[name] === "numeral") {
            replacement = Numbro.format(value, format);
          } else if (formatters[name] === "datetime") {
            replacement = tz(value, format);
          } else if (formatters[name] === "printf") {
            replacement = sprintf(format, value);
          } else {
            throw new Error(`Unknown tooltip field formatter type '${ formatters[name] }'`);
          }

        // if not assume the format string is Numbro
        } else {
          replacement = Numbro.format(value, format);
        }

      // no format supplied, just use a basic default numeric format
      } else {
        replacement = _format_number(value);
      }
    }

    return replacement = `${prefix}${escape(replacement)}`;
  });
開發者ID:FourtekIT-incubator,項目名稱:bokeh,代碼行數:46,代碼來源:templating.ts

示例2: if

  str = str.replace(/(^|[^@])@(?:(\$?\w+)|{([^{}]+)})(?:{([^{}]+)})?/g, (_match, prefix, name, long_name, format) => {
    name = long_name != null ? long_name : name

    let value: any
    if (name[0] == "$")
      value = special_vars[name.substring(1)]
    else {
      const column = data_source.get_column(name)
      if (column != null)
        value = column[i]
    }

    let replacement = null
    if (value == null)
      replacement = "???"
    else {
      // 'safe' format, just return the value as is
      if (format == 'safe')
        return `${prefix}${value}`
      else if (format != null) {
        // see if the field has an entry in the formatters dict
        if (formatters != null && name in formatters) {
          const formatter = formatters[name]
          switch (formatter) {
            case "numeral":
              replacement = Numbro.format(value, format)
              break
            case "datetime":
              replacement = tz(value, format)
              break
            case "printf":
              replacement = sprintf(format, value)
              break
            default:
              throw new Error(`Unknown tooltip field formatter type '${formatter}'`)
          }
        // if not assume the format string is Numbro
        } else
          replacement = Numbro.format(value, format)
      // no format supplied, just use a basic default numeric format
      } else
        replacement = _format_number(value)
    }

    return `${prefix}${escape(replacement)}`
  })
開發者ID:Zyell,項目名稱:bokeh,代碼行數:46,代碼來源:templating.ts

示例3: doFormat

 doFormat(row: any, cell: any, value: any, columnDef: any, dataContext: any): string {
   const {format, language} = this
   const rounding = (() => { switch (this.rounding) {
     case "round": case "nearest":   return Math.round
     case "floor": case "rounddown": return Math.floor
     case "ceil":  case "roundup":   return Math.ceil
   } })()
   value = Numbro.format(value, format, language, rounding)
   return super.doFormat(row, cell, value, columnDef, dataContext)
 }
開發者ID:,項目名稱:,代碼行數:10,代碼來源:

示例4: doFormat

 doFormat(row, cell, value, columnDef, dataContext) {
   const { format } = this;
   const { language } = this;
   const rounding = (() => { switch (this.rounding) {
     case "round": case "nearest":   return Math.round;
     case "floor": case "rounddown": return Math.floor;
     case "ceil":  case "roundup":   return Math.ceil;
   } })();
   value = Numbro.format(value, format, language, rounding);
   return super.doFormat(row, cell, value, columnDef, dataContext);
 }
開發者ID:FourtekIT-incubator,項目名稱:bokeh,代碼行數:11,代碼來源:cell_formatters.ts

示例5:

 return ticks.map((tick) => Numbro.format(tick, format, language, _rounding_fn))
開發者ID:Zyell,項目名稱:bokeh,代碼行數:1,代碼來源:numeral_tick_formatter.ts

示例6: function

 "numeral"  : function(value:any, format:string, _special_vars: Vars) { return Numbro.format(value, format) },
開發者ID:,項目名稱:,代碼行數:1,代碼來源:

示例7:

 numeral:  (value: string | number, format: string, _special_vars: Vars) => Numbro.format(value, format),
開發者ID:digitalsatori,項目名稱:Bokeh,代碼行數:1,代碼來源:templating.ts

示例8:

 const labels = (ticks.map((tick) => Numbro.format(tick, format, language, rounding)));
開發者ID:FourtekIT-incubator,項目名稱:bokeh,代碼行數:1,代碼來源:numeral_tick_formatter.ts


注:本文中的numbro.format函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。