Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'numbro' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
const numberValue = stringValue ? Number(numbro.unformat(stringValue)) : 0;
// default to 0 if defaultValue is NaN
if (is.number(numberValue) && !is.empty(stringValue)) {
let newValue = numberValue;
if (key === 'ArrowDown') {
newValue = Number(numbro(numberValue).subtract(props.step).format({ mantissa: countDecimals(props.step) }));
if (greaterThanMin(newValue) && lessThanMax(newValue)) {
const updateError = displayErrorMessage(!is.empty(stringValue) ? newValue : '');
context.updateState({ value: toCurrency(newValue, countDecimals(props.step)), ...updateError }, () => {
if (is.fn(props.onChange)) {
props.onChange(newValue, props.id, type, key);
}
});
}
} else if (key === 'ArrowUp') {
newValue = Number(numbro(numberValue).add(props.step).format({ mantissa: countDecimals(props.step) }));
if (greaterThanMin(newValue) && lessThanMax(newValue)) {
const updateError = displayErrorMessage(!is.empty(stringValue) ? newValue : '');
context.updateState({ value: toCurrency(newValue, countDecimals(props.step)), ...updateError }, () => {
if (is.fn(props.onChange)) {
props.onChange(newValue, props.id, type, key);
}
});
}
}
}
};
.value()
// prettier-ignore
const deposit = this.conf.deposit
// @ts-ignore
? Math.max(0, n(this.conf.deposit).subtract(this.s.asset_capital))
: this.balance.currency // zero on negative
this.balance.deposit = n(deposit < this.balance.currency ? deposit : this.balance.currency).value()
if (!this.s.start_capital) {
this.s.start_price = n(quote.ask).value()
this.s.start_capital = n(this.balance.deposit)
.add(this.s.asset_capital)
.value()
this.s.real_capital = n(this.balance.currency)
.add(this.s.asset_capital)
.value()
this.s.net_currency = this.balance.deposit
if (this.conf.mode !== 'sim') {
this.pushMessage(
'Balance ' + this.exchange.name.toUpperCase(),
'sync balance ' + this.s.real_capital + ' ' + this.selector.currency + '\n'
)
}
} else {
this.s.net_currency = n(this.s.net_currency)
.add(postCurrency)
.value()
}
dump(statsonly: boolean = false, dumpOnly: boolean = true) {
const tmp_balance = n(this.s.net_currency)
.add(n(this.s.period.close).multiply(this.s.balance.asset))
.format('0.00000000')
const profit = this.s.start_capital
? n(tmp_balance)
.subtract(this.s.start_capital)
.divide(this.s.start_capital)
: n(0)
const buy_hold = this.s.start_price
? n(this.s.period.close).multiply(n(this.s.start_capital).divide(this.s.start_price))
: n(tmp_balance)
const buy_hold_profit = this.s.start_capital
? n(buy_hold)
.subtract(this.s.start_capital)
.divide(this.s.start_capital)
: n(0)
const output_lines = []
// prettier-ignore
output_lines.push('last balance: ' + n(tmp_balance).format('0.00000000').yellow + ' (' + profit.format('0.00%') + ')')
// prettier-ignore
output_lines.push('buy hold: ' + buy_hold.format('0.00000000').yellow + ' (' + n(buy_hold_profit).format('0.00%') + ')')
// prettier-ignore
output_lines.push('vs. buy hold: ' + n(tmp_balance).subtract(buy_hold).divide(buy_hold).format('0.00%').yellow)
cmd = require('commander'),
columnify = require('columnify');
/* eslint no-useless-escape:0 */
let start = new Date().getTime();
let conf = require('./conf').conf;
let Iconv = require('iconv').Iconv;
let iconv = new Iconv('GBK', 'UTF-8//TRANSLIT//IGNORE');
let request = require('request');
let Common = require('./common').Common;
let from = null;
let to = null;
let ft = conf.fmt;
numbro.culture('zh-CN', conf.numbro);
// switch between languages
numbro.culture('zh-CN');
numbro.zeroFormat('N/A');
numbro.defaultFormat(ft.common);
/**
* 各类提示信息
* @type {Object}
*/
const MSG = {
NO_TRADING : '在当前时间范围内无董监高交易记录!',
PARAM_ERROR : '参数输入错误,请检查后重试!',
INPUT_ERROR : '输入错误,当前只支持通过单只证券代码查询,请重新输入!',
REQUEST_ERROR : '数据请求错误,请重试!错误信息:\n',
SYSTEM_BUSY : '系统正忙,请稍后再试!\n',
SHOW_DETAIL_TIP : ' 具体交易记录省略,可通过 "--show-detail" 参数查看详情...',
// This is necessary because if only one option field is passed, the other becomes undefined
// Feels like there must be a better way to pass options
options.precision = (options.precision === undefined) ? 2 : options.precision;
options.compact = (typeof options.compact === 'boolean') ? options.compact : true;
let lang = 'en-US';
switch (currency) {
case 'EUR': lang = 'fr-FR';
break;
case 'SEK': lang = 'sv-SE';
break;
case 'GBP': lang = 'en-GB';
break;
}
Numbro.culture(lang);
// remove the negative sign from the value
const number = Numbro(value/100);
let formatted = (options.precision === 0) ? number.format('$0,0') : number.format('$0,0.00');
if (!options.compact) {
formatted = `${currency} ${formatted}`;
}
return formatted;
};
/* eslint no-useless-escape:0 */
let start = new Date().getTime();
let conf = require('./conf').conf;
let Iconv = require('iconv').Iconv;
let iconv = new Iconv('GBK', 'UTF-8//TRANSLIT//IGNORE');
let request = require('request');
let Common = require('./common').Common;
let from = null;
let to = null;
let ft = conf.fmt;
numbro.culture('zh-CN', conf.numbro);
// switch between languages
numbro.culture('zh-CN');
numbro.zeroFormat('N/A');
numbro.defaultFormat(ft.common);
/**
* 各类提示信息
* @type {Object}
*/
const MSG = {
NO_TRADING : '在当前时间范围内无董监高交易记录!',
PARAM_ERROR : '参数输入错误,请检查后重试!',
INPUT_ERROR : '输入错误,当前只支持通过单只证券代码查询,请重新输入!',
REQUEST_ERROR : '数据请求错误,请重试!错误信息:\n',
SYSTEM_BUSY : '系统正忙,请稍后再试!\n',
SHOW_DETAIL_TIP : ' 具体交易记录省略,可通过 "--show-detail" 参数查看详情...',
};
const handleKeyDown = (e) => {
const { type, key } = e;
const stringValue = ref.current.value;
const numberValue = stringValue ? Number(numbro.unformat(stringValue)) : 0;
// default to 0 if defaultValue is NaN
if (is.number(numberValue) && !is.empty(stringValue)) {
let newValue = numberValue;
if (key === 'ArrowDown') {
newValue = Number(numbro(numberValue).subtract(props.step).format({ mantissa: countDecimals(props.step) }));
if (greaterThanMin(newValue) && lessThanMax(newValue)) {
const updateError = displayErrorMessage(!is.empty(stringValue) ? newValue : '');
context.updateState({ value: toCurrency(newValue, countDecimals(props.step)), ...updateError }, () => {
if (is.fn(props.onChange)) {
props.onChange(newValue, props.id, type, key);
}
});
}
} else if (key === 'ArrowUp') {
newValue = Number(numbro(numberValue).add(props.step).format({ mantissa: countDecimals(props.step) }));
if (greaterThanMin(newValue) && lessThanMax(newValue)) {
let start = new Date().getTime();
let conf = require('./conf').conf;
let Iconv = require('iconv').Iconv;
let iconv = new Iconv('GBK', 'UTF-8//TRANSLIT//IGNORE');
let request = require('request');
let Common = require('./common').Common;
let from = null;
let to = null;
let ft = conf.fmt;
numbro.culture('zh-CN', conf.numbro);
// switch between languages
numbro.culture('zh-CN');
numbro.zeroFormat('N/A');
numbro.defaultFormat(ft.common);
/**
* 各类提示信息
* @type {Object}
*/
const MSG = {
NO_TRADING : '在当前时间范围内无董监高交易记录!',
PARAM_ERROR : '参数输入错误,请检查后重试!',
INPUT_ERROR : '输入错误,当前只支持通过单只证券代码查询,请重新输入!',
REQUEST_ERROR : '数据请求错误,请重试!错误信息:\n',
SYSTEM_BUSY : '系统正忙,请稍后再试!\n',
SHOW_DETAIL_TIP : ' 具体交易记录省略,可通过 "--show-detail" 参数查看详情...',
};
const MISC_QUERY_KEY = 'uzfin.com';
/* eslint no-useless-escape:0 */
let start = new Date().getTime();
let conf = require('./conf').conf;
let Iconv = require('iconv').Iconv;
let iconv = new Iconv('GBK', 'UTF-8//TRANSLIT//IGNORE');
let request = require('request');
let Common = require('./common').Common;
let from = null;
let to = null;
let ft = conf.fmt;
numbro.culture('zh-CN', conf.numbro);
// switch between languages
numbro.culture('zh-CN');
numbro.zeroFormat('N/A');
numbro.defaultFormat(ft.common);
/**
* 各类提示信息
* @type {Object}
*/
const MSG = {
NO_TRADING : '在当前时间范围内无董监高交易记录!',
PARAM_ERROR : '参数输入错误,请检查后重试!',
INPUT_ERROR : '输入错误,当前只支持通过单只证券代码查询,请重新输入!',
REQUEST_ERROR : '数据请求错误,请重试!错误信息:\n',
SYSTEM_BUSY : '系统正忙,请稍后再试!\n',
SHOW_DETAIL_TIP : ' 具体交易记录省略,可通过 "--show-detail" 参数查看详情...',
};
const MISC_QUERY_KEY = 'uzfin.com';
function numericRenderer(instance, TD, row, col, prop, value, cellProperties) {
let newValue = value;
if (isNumeric(newValue)) {
const numericFormat = cellProperties.numericFormat;
const cellCulture = numericFormat && numericFormat.culture || '-';
const cellFormatPattern = numericFormat && numericFormat.pattern;
const className = cellProperties.className || '';
const classArr = className.length ? className.split(' ') : [];
if (typeof cellCulture !== 'undefined' && !numbro.languages()[cellCulture]) {
const shortTag = cellCulture.replace('-', '');
const langData = numbro.allLanguages ? numbro.allLanguages[cellCulture] : numbro[shortTag];
if (langData) {
numbro.registerLanguage(langData);
}
}
numbro.setLanguage(cellCulture);
newValue = numbro(newValue).format(cellFormatPattern || '0');
if (classArr.indexOf('htLeft') < 0 && classArr.indexOf('htCenter') < 0 &&
classArr.indexOf('htRight') < 0 && classArr.indexOf('htJustify') < 0) {
classArr.push('htRight');
}
if (classArr.indexOf('htNumeric') < 0) {
classArr.push('htNumeric');
}