Socket
Socket
Sign inDemoInstall

comb

Package Overview
Dependencies
0
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.3 to 0.3.4

8

History.md

@@ -0,1 +1,9 @@

# 0.3.4
* Update `comb.string.format` to handle signing numbers with padding properly
* `comb.string.format('%+07.2d', 10); //"+010.00"`
* `comb.string.format('%+07.2d', -10); //"-010.00"`
* `comb.string.format('%+ 7.2d', 10); //" +10.00"`
* `comb.string.format('%+ 7.2d', -10); //" -10.00"`
# 0.3.3

@@ -2,0 +10,0 @@

47

lib/base/string.js

@@ -7,3 +7,4 @@ var comb = exports, date,

pSlice = Array.prototype.slice,
toStr = Object.prototype.toString;
toStr = Object.prototype.toString,
abs = Math.abs;

@@ -121,3 +122,3 @@ function getDate() {

var FORMAT_REGEX = /%((?:-?\+?.?\d*(?:\.\d+)*)?|(?:\[[^\[|\]]*\]))?([sjdDZ])/g;
var FORMAT_REGEX = /%((?:-?[\+| ]?.?\d*(?:\.\d+)*)?|(?:\[[^\[|\]]*\]))?([sjdDZ])/g;
var INTERP_REGEX = /{(?:\[([^\[|\]]*)\])?(\w+)}/g;

@@ -147,9 +148,9 @@ var STR_FORMAT = /(-?)(\+?)([A-Z|a-z|\W]?)([1-9][0-9]*)?$/;

if (typeof number === "number") {
ret = "" + number;
ret = "" + abs(number);
var match = format.match(NUMBER_FORMAT);
if (match) {
var isLeftJustified = match[1], signed = match[2], padChar = match[3], width = match[4], precision = match[5];
var isLeftJustified = match[1], signed = (number < 0 ? '-' : match[2]), padChar = match[3] || ' ', width = match[4], precision = match[5];
if (precision) {
precision = parseInt(precision.replace(/^\./, ""), 10);
ret = round(number, precision) + "";
ret = round(abs(number), precision) + "";
//check and ensure we have padding zeros

@@ -163,7 +164,11 @@ var split = ret.split(".");

}
if (signed) {
ret = (number > 0 ? signed : "") + ret;
if (padChar === ' ') {
ret = signed + ret;
signed = false;
}
if (width) {
width = parseInt(width, 10);
if (signed) {
width--;
}
if (ret.length < width) {

@@ -175,2 +180,5 @@ ret = pad(ret, width, padChar || " ", isLeftJustified);

}
if (signed) {
ret = signed + ret;
}

@@ -233,9 +241,16 @@ }

* //width
* comb.string.format('% 5d', 10); //" 10"
* comb.string.format('%5d', 10); //" 10"
*
* //width and precision
* comb.string.format('% 6.2d', 10); //" 10.00"
* comb.string.format('%6.2d', 10); //" 10.00"
*
* //signed, width and precision
* comb.string.format('%+ 7.2d', 10); //" +10.00"
* comb.string.format('%+ 7.2d', 10); //" +10.00"
* comb.string.format('%+ 7.2d', -10); //" -10.00"
* comb.string.format('%+07.2d', 10); //"+010.00"
* comb.string.format('%+07.2d', -10); //"-010.00"
* comb.string.format('% 7.2d', 10); //" 10.00"
* comb.string.format('% 7.2d', -10); //" -10.00"
* comb.string.format('% 7.2d', 10); //" 10.00"
* comb.string.format('% 7.2d', -10); //" -10.00"
*

@@ -292,7 +307,7 @@ * //use a 0 as padding

* <ul>
* <li>- : left justified</li>
* <li>+ : signed number</li>
* <li>Char : padding character <b>Excludes d,j,s</b></li>
* <li>Number : width</li>
* <li>.Precision</li>
* <li>`-` : left justified</li>
* <li>`+` or `<space>` : signed number if space is used the number will use a extra `<space>` instead of a `+`</li>
* <li>`<Char>` : padding character <b>Excludes d,j,s</b></li>
* <li>`Number` : width</li>
* <li>`.Number`: specify the precision of the number</li>
* </ul>

@@ -538,2 +553,2 @@ * </li>

escapeHtml: escapeHtml
};
};
{
"name": "comb",
"description": "A framework for node",
"version": "0.3.3",
"version": "0.3.4",
"keywords": ["OO", "Object Oriented", "Collections", "Tree", "HashTable", "Pool", "Logging", "Promise", "Promises", "Proxy"],

@@ -6,0 +6,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc