🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@fnmain/number

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fnmain/number - npm Package Compare versions

Comparing version

to
1.7.0

5

dist/index.d.ts
type Options = {
fixed?: number;
wanFixed?: number;
yiFixed?: number;
wanYiFixed?: number;
trimEndZeros?: boolean;

@@ -10,3 +13,3 @@ space?: string;

export declare function toWanYi(value: number, { fixed, trimEndZeros, space }?: Options): string;
export declare function toAuto(value: number, { fixed, trimEndZeros, space }?: Options): string;
export declare function toAuto(value: number, { fixed, wanFixed, yiFixed, wanYiFixed, trimEndZeros, space }?: Options): string;
export declare function toPercent(value: number, { fixed, trimEndZeros, space }?: Options): string;

@@ -13,0 +16,0 @@ export declare function parseNumber(input: any): number;

@@ -32,3 +32,3 @@ "use strict";

exports.toWanYi = toWanYi;
function toAuto(value, { fixed = 0, trimEndZeros = false, space = "" } = {}) {
function toAuto(value, { fixed = 0, wanFixed, yiFixed, wanYiFixed, trimEndZeros = false, space = "" } = {}) {
const abs = Math.abs(value);

@@ -41,7 +41,10 @@ if (abs < 10000) {

if (abs < 100000000) {
fixed = (isNumber(wanFixed) && wanFixed) || fixed;
return toWan(value, { fixed, trimEndZeros, space });
}
if (abs < 1000000000000) {
fixed = (isNumber(yiFixed) && yiFixed) || fixed;
return toYi(value, { fixed, trimEndZeros, space });
}
fixed = (isNumber(wanYiFixed) && wanYiFixed) || fixed;
return toWanYi(value, { fixed, trimEndZeros, space });

@@ -48,0 +51,0 @@ }

24

dist/test.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("./index");
console.log((0, index_1.toAuto)(1234));
console.log((0, index_1.toAuto)(12345));
console.log((0, index_1.toAuto)(123456789));
console.log((0, index_1.toAuto)(1234, { fixed: 1 }));
console.log((0, index_1.toAuto)(12345, { fixed: 1 }));
console.log((0, index_1.toAuto)(123456789, { fixed: 2, space: " " }));
console.log((0, index_1.toAuto)(12.3 * 10000 * 10000 * 10000, { fixed: 1, space: " " }));
console.log((0, index_1.toAuto)(1.00002, { fixed: 1, trimEndZeros: true }));
console.log((0, index_1.toPercent)(0.1234, { fixed: 1, space: " " }));
console.log((0, index_1.toPercent)(1.23456, { trimEndZeros: true }));
console.log((0, index_1.toPercent)(1.9, { fixed: 4, trimEndZeros: true }));
console.log((0, index_1.toAuto)(1234)); // 1234
console.log((0, index_1.toAuto)(12345)); // 1万
console.log((0, index_1.toAuto)(123456789)); // 1亿
console.log((0, index_1.toAuto)(1234, { fixed: 1 })); // 1234.0
console.log((0, index_1.toAuto)(12345, { fixed: 1 })); // 1.2万
console.log((0, index_1.toAuto)(12345, { wanFixed: 2 })); // 1.23万
console.log((0, index_1.toAuto)(123456789, { fixed: 2, space: " " })); // 1.23 亿
console.log((0, index_1.toAuto)(123456789, { yiFixed: 3, space: " " })); // 1.235 亿
console.log((0, index_1.toAuto)(12.3 * 10000 * 10000 * 10000, { fixed: 1, space: " " })); // 12.3 万亿
console.log((0, index_1.toAuto)(1.00002, { fixed: 1, trimEndZeros: true })); // 1
console.log((0, index_1.toPercent)(0.1234, { fixed: 1, space: " " })); // 12.3 %
console.log((0, index_1.toPercent)(1.23456, { trimEndZeros: true })); // 123%
console.log((0, index_1.toPercent)(1.9, { fixed: 4, trimEndZeros: true })); // 190%
// Example usage

@@ -16,0 +18,0 @@ console.log((0, index_1.parseNumber)("50%")); // 0.5

{
"name": "@fnmain/number",
"version": "1.6.1",
"version": "1.7.0",
"description": "number utils",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

type Options = {
fixed?: number;
wanFixed?: number;
yiFixed?: number;
wanYiFixed?: number;
trimEndZeros?: boolean;

@@ -46,3 +49,3 @@ space?: string;

value: number,
{ fixed = 0, trimEndZeros = false, space = "" }: Options = {}
{ fixed = 0, wanFixed, yiFixed, wanYiFixed, trimEndZeros = false, space = "" }: Options = {}
): string {

@@ -56,7 +59,10 @@ const abs = Math.abs(value);

if (abs < 100000000) {
fixed = (isNumber(wanFixed) && wanFixed) || fixed;
return toWan(value, { fixed, trimEndZeros, space });
}
if (abs < 1000000000000) {
fixed = (isNumber(yiFixed) && yiFixed) || fixed;
return toYi(value, { fixed, trimEndZeros, space });
}
fixed = (isNumber(wanYiFixed) && wanYiFixed) || fixed;
return toWanYi(value, { fixed, trimEndZeros, space });

@@ -63,0 +69,0 @@ }

import { formatWithCommas, isNotNumber, isNumber, parseNumber, toAuto, toPercent } from "./index";
console.log(toAuto(1234));
console.log(toAuto(12345));
console.log(toAuto(123456789));
console.log(toAuto(1234)); // 1234
console.log(toAuto(12345)); // 1万
console.log(toAuto(123456789)); // 1亿
console.log(toAuto(1234, { fixed: 1 }));
console.log(toAuto(12345, { fixed: 1 }));
console.log(toAuto(123456789, { fixed: 2, space: " " }));
console.log(toAuto(12.3 * 10000 * 10000 * 10000, { fixed: 1, space: " " }));
console.log(toAuto(1.00002, { fixed: 1, trimEndZeros: true }));
console.log(toAuto(1234, { fixed: 1 })); // 1234.0
console.log(toAuto(12345, { fixed: 1 })); // 1.2万
console.log(toAuto(12345, { wanFixed: 2 })); // 1.23万
console.log(toAuto(123456789, { fixed: 2, space: " " })); // 1.23 亿
console.log(toAuto(123456789, { yiFixed: 3, space: " " })); // 1.235 亿
console.log(toAuto(12.3 * 10000 * 10000 * 10000, { fixed: 1, space: " " })); // 12.3 万亿
console.log(toAuto(1.00002, { fixed: 1, trimEndZeros: true })); // 1
console.log(toPercent(0.1234, { fixed: 1, space: " " }));
console.log(toPercent(1.23456, { trimEndZeros: true }));
console.log(toPercent(1.9, { fixed: 4, trimEndZeros: true }));
console.log(toPercent(0.1234, { fixed: 1, space: " " })); // 12.3 %
console.log(toPercent(1.23456, { trimEndZeros: true })); // 123%
console.log(toPercent(1.9, { fixed: 4, trimEndZeros: true })); // 190%

@@ -17,0 +19,0 @@ // Example usage

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet