to-percent-js
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -5,7 +5,11 @@ "use strict"; | ||
exports.toNum = exports.toInt = exports.round = exports.percent = exports.getNum = exports["default"] = void 0; | ||
var _reshowConstant = require("reshow-constant"); | ||
// @ts-check | ||
var numTypes = "|" + _reshowConstant.NUMBER + "|" + _reshowConstant.STRING + "|"; | ||
/** | ||
* @param {any} num | ||
* @returns {string} | ||
*/ | ||
var toPercent = function toPercent(num) { | ||
@@ -15,2 +19,6 @@ return percent(num) + "%"; | ||
/** | ||
* @param {any} num | ||
* @returns {string} | ||
*/ | ||
var percent = function percent(num) { | ||
@@ -20,11 +28,18 @@ return round(toNum(num) * 100); | ||
/** | ||
* @param {number} f | ||
* @param {number} [precision] | ||
* @returns {string} | ||
*/ | ||
exports.percent = percent; | ||
var round = function round(f, precision) { | ||
return toNum(f).toFixed(precision !== null && precision !== void 0 ? precision : 2); | ||
}; | ||
exports.round = round; | ||
var ERROR_INFO = "Get number fail."; | ||
/** | ||
* @param {any} num | ||
* @returns {number} | ||
*/ | ||
var toNum = function toNum(num) { | ||
@@ -40,3 +55,2 @@ if (_reshowConstant.UNDEFINED === typeof num) { | ||
var maybeInt = parseInt(maybeString, 10); | ||
if (maybeFloat === maybeInt && (maybeInt + "" === maybeString || 0 === maybeInt)) { | ||
@@ -50,3 +64,2 @@ return maybeInt; | ||
var willNum = 0; | ||
if (-1 !== maybeString.indexOf(".")) { | ||
@@ -59,3 +72,2 @@ return maybeFloat; | ||
} | ||
console.warn(ERROR_INFO, { | ||
@@ -72,11 +84,17 @@ willNum: willNum, | ||
/** | ||
* @param {any} num | ||
* @returns {number} | ||
*/ | ||
exports.toNum = toNum; | ||
var toInt = function toInt(num) { | ||
return toNum(round(num, 0)); | ||
}; | ||
exports.toInt = toInt; | ||
var numReg = /(\-)?(\d+)(\.)?(\d+)?/g; | ||
/** | ||
* @param {any} s | ||
* @returns {number} | ||
*/ | ||
var getNum = function getNum(s) { | ||
@@ -86,5 +104,3 @@ if (_reshowConstant.STRING !== typeof s) { | ||
} | ||
var match = s.replace(",", "").match(numReg); | ||
if (!match) { | ||
@@ -97,5 +113,4 @@ console.warn(ERROR_INFO, s); | ||
}; | ||
exports.getNum = getNum; | ||
var _default = toPercent; | ||
exports["default"] = _default; |
{ | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"name": "to-percent-js", | ||
@@ -29,12 +29,16 @@ "repository": { | ||
"scripts": { | ||
"clean": "find ./build -name '*.*' | xargs rm -rf", | ||
"clean": "find ./build ./types -name '*.*' | xargs rm -rf", | ||
"build:cjs": "BABEL_ENV=cjs babel src -d build/cjs/src --ignore /**/__tests__ --root-mode upward", | ||
"build:es": "BABEL_ENV=es babel src -d build/es/src --out-file-extension .mjs --root-mode upward", | ||
"build": "npm run clean && npm run build:cjs && npm run build:es", | ||
"build:type": "npx -p typescript tsc src/*.js --declaration --allowJs --emitDeclarationOnly --skipLibCheck --declarationDir types", | ||
"build": "npm run clean && npm run build:cjs && npm run build:es && npm run build:type", | ||
"mochaFor": "mocha", | ||
"mocha": "npm run mochaFor -- 'build/es/**/__tests__/*.mjs'", | ||
"test:report": "npm run build && npm run mochaFor -- --reporter mocha-junit-reporter --reporter-options mochaFile=./test_output/mocha.xml 'build/es/**/__tests__/*.mjs'", | ||
"test": "npm run build && npm run mocha", | ||
"prepublishOnly": "npm run test" | ||
}, | ||
"types": "./types/index.d.ts", | ||
"files": [ | ||
"types", | ||
"build", | ||
@@ -41,0 +45,0 @@ "package.json", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10860
6
342
0