Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
format-number-with-string
Advanced tools
Readme
Expects a valid number in 'computer' format and a format string (eg '-£#,###,##0.000 /m', '(## years)') which is used to format the number.
Basically a wrapper that uses deconstruct-format-string to deconstruct the format and then passes the results to format-number to do the formatting
Can be a number or a string of a number
.
or ,
as decimal point.
or ,
as thousand separators.
or ,
as thousanths separators#
, 9
or 0
as number place holders
If the format string is undefined or an empty string then defaults are used (see format-number)var format = require('format-number-with-string');
var overrideOptions = {noUnits: true, noSeparator: true};
var output1 = format(3345.23, '-£#,###,###.00');
var output2 = format(3345.23, '-£#,###,###.00', overrideOptions);
A 0
will pad to that position
92332.42,'## ##0.##0 ##'
returns '92 332.420''.42','## ##0.##0 ##'
returns '0.420'33, '00000'
returns '00033'A 0
or 9
in the last decimal space will cause rounding to that number of places
'92332.42467','## ##0.##0'
returns '92 332.425'WARNING - omitting a negative from the format string will return the absolute value
'-332.42','(###.###)'
returns '(332.42)''-332.42','- ###.###'
returns '- 332.42''-332.42','###.###-'
returns '332.42-''-332.42','###.###'
returns '332.42'If a format ends in a . or , then this will be taken as the decimal character UNLESS the same character is used elsewhere so:
'923324234','#,###.'
returns '923,324,234''923324234','#.###,'
returns '923.324.234'If a format only has one of ',' or '.' and the character only appears once it is taken as the decimal point
'2332.42','#,###'
returns '2332,42''2332.42','#.###'
returns '2332.42'If the character appears twice in the format string it is a separator
'923324234','#,###,###'
returns '923,324,234'When in doubt '.' in the format string is the decimal point, so
'234.45645','#.###,#'
returns '234.456,45'
To create a similar structure with decimalChar as ',', just add a '.' at start or end or extend expression eg.#.###,#
#.###,#.
#.###.###,#
Units can be before or after negative symbols.
Prefix text cannot contain number placeholder characters
'-233278', '($# ###.### # per year)'
returns '($233 278 per year)'
'-233278', '$# ##0.00# #- per year'
returns '$233 278- per year';
'-456.23', '-$# ##0.00# # per year'
returns '-$456.23 per year';
As used in format-number
noUnits
boolean: if true will override and leave out prefix and suffix; default= falsenoSeparator
- boolean: if true will override both integer and decimals separator and leave them outFAQs
Format a number based on a format string '-£#,##0.##0'
The npm package format-number-with-string receives a total of 43,465 weekly downloads. As such, format-number-with-string popularity was classified as popular.
We found that format-number-with-string demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.