How to use @elastic/numeral - 10 common examples

To help you get started, we’ve selected a few @elastic/numeral examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elastic / kibana / x-pack / legacy / plugins / ml / common / util / job_utils.js View on Github external
export function validateModelMemoryLimit(job, limits) {
  const messages = [];
  let valid = true;
  // model memory limit
  if (typeof job.analysis_limits !== 'undefined' && typeof job.analysis_limits.model_memory_limit !== 'undefined') {
    if (typeof limits === 'object' && typeof limits.max_model_memory_limit !== 'undefined') {
      const max = limits.max_model_memory_limit.toUpperCase();
      const mml = job.analysis_limits.model_memory_limit.toUpperCase();

      const mmlBytes = numeral(mml).value();
      const maxBytes = numeral(max).value();

      if(mmlBytes > maxBytes) {
        messages.push({ id: 'model_memory_limit_invalid' });
        valid = false;
      } else {
        messages.push({ id: 'model_memory_limit_valid' });
      }
    }
  }
  return {
    valid,
    messages,
    contains: id =>  (messages.some(m => id === m.id)),
    find: id => (messages.find(m => id === m.id)),
  };
}
github elastic / kibana / x-pack / legacy / plugins / ml / common / util / job_utils.js View on Github external
export function validateModelMemoryLimit(job, limits) {
  const messages = [];
  let valid = true;
  // model memory limit
  if (typeof job.analysis_limits !== 'undefined' && typeof job.analysis_limits.model_memory_limit !== 'undefined') {
    if (typeof limits === 'object' && typeof limits.max_model_memory_limit !== 'undefined') {
      const max = limits.max_model_memory_limit.toUpperCase();
      const mml = job.analysis_limits.model_memory_limit.toUpperCase();

      const mmlBytes = numeral(mml).value();
      const maxBytes = numeral(max).value();

      if(mmlBytes > maxBytes) {
        messages.push({ id: 'model_memory_limit_invalid' });
        valid = false;
      } else {
        messages.push({ id: 'model_memory_limit_valid' });
      }
    }
  }
  return {
    valid,
    messages,
    contains: id =>  (messages.some(m => id === m.id)),
    find: id => (messages.find(m => id === m.id)),
  };
github elastic / kibana / x-pack / plugins / ml / public / file_datavisualizer / components / file_datavisualizer_view / file_error_callouts.js View on Github external
export function FileTooLarge({ fileSize, maxFileSize }) {
  const fileSizeFormatted = numeral(fileSize).format(FILE_SIZE_DISPLAY_FORMAT);
  const maxFileSizeFormatted = numeral(maxFileSize).format(FILE_SIZE_DISPLAY_FORMAT);

  // Format the byte values, using the second format if the difference between
  // the file size and the max is so small that the formatted values are identical
  // e.g. 100.01 MB and 100.0 MB
  let errorText;
  if (fileSizeFormatted !== maxFileSizeFormatted) {
    errorText = (
      <p>
        </p>
github elastic / kibana / x-pack / legacy / plugins / infra / public / pages / logs / analysis / sections / log_rate / bar_chart.tsx View on Github external
          tickFormat={value => numeral(value.toPrecision(3)).format('0[.][00]a')} // https://github.com/adamwdraper/Numeral-js/issues/194
        />
github elastic / kibana / src / plugins / data / common / field_formats / converters / numeral.ts View on Github external
* KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

// @ts-ignore
import numeral from '@elastic/numeral';
// @ts-ignore
import numeralLanguages from '@elastic/numeral/languages';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat } from '../field_format';
import { TextContextTypeConvert } from '../types';

const numeralInst = numeral();

numeralLanguages.forEach((numeralLanguage: Record) =&gt; {
  numeral.language(numeralLanguage.id, numeralLanguage.lang);
});

export abstract class NumeralFormat extends FieldFormat {
  static fieldType = KBN_FIELD_TYPES.NUMBER;

  abstract id: string;
  abstract title: string;

  getParamDefaults = () =&gt; ({
    pattern: this.getConfig!(`format:${this.id}:defaultPattern`),
  });

  protected getConvertedValue(val: any): string {
    if (val === -Infinity) return '-∞';
    if (val === +Infinity) return '+∞';
github elastic / kibana / src / legacy / core_plugins / kibana / ui_setting_defaults.js View on Github external
export function getUiSettingDefaults() {
  const weekdays = moment.weekdays().slice();
  const [defaultWeekday] = weekdays;
  // We add the `en` key manually here, since that's not a real numeral locale, but the
  // default fallback in case the locale is not found.
  const numeralLanguageIds = [
    'en',
    ...numeralLanguages.map(function(numeralLanguage) {
      return numeralLanguage.id;
    }),
  ];

  const luceneQueryLanguageLabel = i18n.translate(
    'kbn.advancedSettings.searchQueryLanguageLucene',
    {
      defaultMessage: 'Lucene',
    }
  );

  const queryLanguageSettingName = i18n.translate('kbn.advancedSettings.searchQueryLanguageTitle', {
    defaultMessage: 'Query language',
  });

  const requestPreferenceOptionLabels = {
github elastic / kibana / x-pack / legacy / plugins / siem / public / components / page / overview / overview_network_stats / index.tsx View on Github external
id: 'filebeatSuricata',
  },
  {
    description:
      has('filebeatZeek', data) &amp;&amp; data.filebeatZeek !== null
        ? numeral(data.filebeatZeek).format('0,0')
        : getEmptyTagValue(),
    title: (
      
    ),
    id: 'filebeatZeek',
  },
  {
    description:
      has('packetbeatDNS', data) &amp;&amp; data.packetbeatDNS !== null
        ? numeral(data.packetbeatDNS).format('0,0')
        : getEmptyTagValue(),
    title: (
      
    ),
    id: 'packetbeatDNS',
  },
  {
    description:
      has('packetbeatFlow', data) &amp;&amp; data.packetbeatFlow !== null
        ? numeral(data.packetbeatFlow).format('0,0')
        : getEmptyTagValue(),
    title: (
github elastic / kibana / src / legacy / server / logging / log_format.js View on Github external
data.res = {
        statusCode: event.statusCode,
        responseTime: event.responseTime,
        contentLength: contentLength
      };

      const query = querystring.stringify(event.query);
      if (query) data.req.url += '?' + query;

      data.message = data.req.method.toUpperCase() + ' ';
      data.message += data.req.url;
      data.message += ' ';
      data.message += levelColor(data.res.statusCode);
      data.message += ' ';
      data.message += chalk.gray(data.res.responseTime + 'ms');
      data.message += chalk.gray(' - ' + numeral(contentLength).format('0.0b'));
    }
    else if (data.type === 'ops') {
      _.defaults(data, _.pick(event, [
        'pid',
        'os',
        'proc',
        'load'
      ]));
      data.message  = chalk.gray('memory: ');
      data.message += numeral(get(data, 'proc.mem.heapUsed')).format('0.0b');
      data.message += ' ';
      data.message += chalk.gray('uptime: ');
      data.message += numeral(get(data, 'proc.uptime')).format('00:00:00');
      data.message += ' ';
      data.message += chalk.gray('load: [');
      data.message += get(data, 'os.load', []).map(function (val) {
github elastic / kibana / x-pack / plugins / apm / public / utils / formatters.ts View on Github external
export function asDecimal(value: number) {
  return numeral(value).format('0,0.0');
}
github elastic / kibana / x-pack / legacy / plugins / siem / public / components / page / overview / overview_network_stats / index.tsx View on Github external
description:
      has('filebeatPanw', data) &amp;&amp; data.filebeatPanw !== null
        ? numeral(data.filebeatPanw).format('0,0')
        : getEmptyTagValue(),
    title: (
      
    ),
    id: 'filebeatPanw',
  },
  {
    description:
      has('filebeatSuricata', data) &amp;&amp; data.filebeatSuricata !== null
        ? numeral(data.filebeatSuricata).format('0,0')
        : getEmptyTagValue(),
    title: (
      
    ),
    id: 'filebeatSuricata',
  },
  {
    description:
      has('filebeatZeek', data) &amp;&amp; data.filebeatZeek !== null
        ? numeral(data.filebeatZeek).format('0,0')
        : getEmptyTagValue(),
    title: (

@elastic/numeral

Fork of numeraljs for use in Kibana

MIT
Latest version published 3 years ago

Package Health Score

54 / 100
Full package analysis

Similar packages