How to use numeral - 10 common examples

To help you get started, we’ve selected a few 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 graphsense / graphsense-dashboard / src / index.js View on Github external
import 'numeral/locales'

Logger.setLogLevel(IS_DEV ? Logger.LogLevels.DEBUG : Logger.LogLevels.ERROR) // eslint-disable-line no-undef

const getNavigatorLanguage = () => {
  if (navigator.languages && navigator.languages.length) {
    return navigator.languages[0]
  } else {
    return navigator.userLanguage || navigator.language || navigator.browserLanguage || 'en'
  }
}

const locale = getNavigatorLanguage().split('-')[0]
numeral.locale(locale)
try {
  numeral.localeData(locale)
} catch (e) {
  console.warn(`Couldn't find locale '${locale}', falling back to 'en'`)
  numeral.locale('en')
}

if (locale === 'de') {
  // overwrite locale format
  let de = numeral.localeData(locale)
  de.delimiters.thousands = '.'
}
moment.locale(locale)

const timezone = jstz.determine().name()
moment.tz.setDefault(timezone)

let model = new Start(locale)
github graphsense / graphsense-dashboard / src / index.js View on Github external
return navigator.userLanguage || navigator.language || navigator.browserLanguage || 'en'
  }
}

const locale = getNavigatorLanguage().split('-')[0]
numeral.locale(locale)
try {
  numeral.localeData(locale)
} catch (e) {
  console.warn(`Couldn't find locale '${locale}', falling back to 'en'`)
  numeral.locale('en')
}

if (locale === 'de') {
  // overwrite locale format
  let de = numeral.localeData(locale)
  de.delimiters.thousands = '.'
}
moment.locale(locale)

const timezone = jstz.determine().name()
moment.tz.setDefault(timezone)

let model = new Start(locale)
model.render(document.body)
github wikimedia / analytics-wikistats2 / src / App.vue View on Github external
setUpNumeralLocale() {
            //locale recognition, rudimentary, from navigator.language if defined
            // webpack does not have locale support out of the box
            // but numeral locales are 8k compressed thus importing them all
            if (navigator.language){

                var locale = navigator.language.toLowerCase();

                numeral.locale(locale);

                // it might not exist as instead of "en-us"
                // numeral defines "en", live with this for now
                // change later to use navigators convention http://www.ietf.org/rfc/bcp/bcp47.txt
                if (!numeral.localeData()){
                    // try again with an abbreviated version
                    numeral.locale(locale.split( '-' )[0]);
                }

                if (!numeral.localeData()){
                    // set to english, browser might be set
                    // to a locale numeral does not have
                    numeral.locale("en-gb")
                }
            }
        },
github wikimedia / analytics-wikistats2 / src / App.vue View on Github external
var locale = navigator.language.toLowerCase();

                numeral.locale(locale);

                // it might not exist as instead of "en-us"
                // numeral defines "en", live with this for now
                // change later to use navigators convention http://www.ietf.org/rfc/bcp/bcp47.txt
                if (!numeral.localeData()){
                    // try again with an abbreviated version
                    numeral.locale(locale.split( '-' )[0]);
                }

                if (!numeral.localeData()){
                    // set to english, browser might be set
                    // to a locale numeral does not have
                    numeral.locale("en-gb")
                }
            }
        },
        handleResize () {
github wikimedia / analytics-wikistats2 / src / App.vue View on Github external
// but numeral locales are 8k compressed thus importing them all
            if (navigator.language){

                var locale = navigator.language.toLowerCase();

                numeral.locale(locale);

                // it might not exist as instead of "en-us"
                // numeral defines "en", live with this for now
                // change later to use navigators convention http://www.ietf.org/rfc/bcp/bcp47.txt
                if (!numeral.localeData()){
                    // try again with an abbreviated version
                    numeral.locale(locale.split( '-' )[0]);
                }

                if (!numeral.localeData()){
                    // set to english, browser might be set
                    // to a locale numeral does not have
                    numeral.locale("en-gb")
                }
            }
        },
        handleResize () {
github vueblocks / ve-charts / src / utils / formatZhNumber.js View on Github external
import numeral from 'numeral'

numeral.register('format', 'zh-number', {
  regexps: {
    format: /(zh)/,
    unformat: /(zh)/
  },
  format: function (value, format, roundingFunction) {
    // 判断是否有空格
    const space = numeral._.includes(format, ' zh') ? ' ' : ''
    // match 数据格式
    const precision = format.match(/\d.\d+/)
    let digits
    if (precision) {
      // 确定小数点后几位小数
      digits = precision[0].split('.')[1].length
    }
    // check for space before zh
    format = format.replace(/\s?\zh/, '');
github vueblocks / ve-charts / src / utils / formatZhNumber.js View on Github external
format: function (value, format, roundingFunction) {
    // 判断是否有空格
    const space = numeral._.includes(format, ' zh') ? ' ' : ''
    // match 数据格式
    const precision = format.match(/\d.\d+/)
    let digits
    if (precision) {
      // 确定小数点后几位小数
      digits = precision[0].split('.')[1].length
    }
    // check for space before zh
    format = format.replace(/\s?\zh/, '');

    const cnNumberFormat = (val, digits = 0) => {
      if (isNaN(+val)) return val

      let symbolMap = [
        { value: 1E8, symbol: '亿' },
        { value: 1E4, symbol: '万' },
github proxyee-down-org / proxyee-down / front / src / main.js View on Github external
error.response.data.code
      Vue.prototype.$Message.error(i18n.t(i18nKey))
    } else if (error.response.status == 404) {
      Vue.prototype.$Message.error(i18n.t('alert.notFound'))
    } else if (error.response.status == 504) {
      Vue.prototype.$Message.error(i18n.t('alert.timeout'))
    } else {
      Vue.prototype.$Message.error(i18n.t('alert.error'))
    }
    return Promise.reject(error)
  }
)

//去除字节大小格式化后的i字符
const format = numeral.prototype.constructor.fn.format
numeral.prototype.constructor.fn.format = function(fmt) {
  let result = format.call(this, fmt)
  if (/^.*ib$/.test(fmt)) {
    result = result.replace('i', '')
  }
  return result
}
Vue.prototype.$numeral = numeral

Date.prototype.format = function(fmt) {
  var o = {
    'M+': this.getMonth() + 1, // Month
    'd+': this.getDate(), // Day
    'h+': this.getHours(), // Hour
    'm+': this.getMinutes(), // Minute
    's+': this.getSeconds(), // Second
    'q+': Math.floor((this.getMonth() + 3) / 3), // Quarter
github proxyee-down-org / proxyee-down / front / src / main.js View on Github external
'.' +
        error.response.data.code
      Vue.prototype.$Message.error(i18n.t(i18nKey))
    } else if (error.response.status == 404) {
      Vue.prototype.$Message.error(i18n.t('alert.notFound'))
    } else if (error.response.status == 504) {
      Vue.prototype.$Message.error(i18n.t('alert.timeout'))
    } else {
      Vue.prototype.$Message.error(i18n.t('alert.error'))
    }
    return Promise.reject(error)
  }
)

//去除字节大小格式化后的i字符
const format = numeral.prototype.constructor.fn.format
numeral.prototype.constructor.fn.format = function(fmt) {
  let result = format.call(this, fmt)
  if (/^.*ib$/.test(fmt)) {
    result = result.replace('i', '')
  }
  return result
}
Vue.prototype.$numeral = numeral

Date.prototype.format = function(fmt) {
  var o = {
    'M+': this.getMonth() + 1, // Month
    'd+': this.getDate(), // Day
    'h+': this.getHours(), // Hour
    'm+': this.getMinutes(), // Minute
    's+': this.getSeconds(), // Second
github pioneers / PieCentral / dawn / renderer / components / peripherals / Motor.js View on Github external
_.map(param, obj => ( // TODO: Figure out if a ProgressBar is useful
        <div>
          <h4 style="{{">
            {`${obj.param}: ${numeral(obj.float_value).format('+0.00')}`}

          </h4>
          
        </div>
      ))
    }