@orderly.network/utils 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +22 -0
- package/CHANGELOG.md +7 -0
- package/__test__/decimal.test.ts +8 -0
- package/babel.config.js +6 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +33 -0
- package/src/dateTime.ts +8 -0
- package/src/decimal.ts +51 -0
- package/src/index.ts +3 -0
- package/tsconfig.json +13 -0
- package/tsup.config.ts +12 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
> @orderly.network/utils@0.0.1 build /Users/leo/orderly/orderly-web/packages/utils
|
|
3
|
+
> tsup
|
|
4
|
+
|
|
5
|
+
CLI Building entry: src/index.ts
|
|
6
|
+
CLI Using tsconfig: tsconfig.json
|
|
7
|
+
CLI tsup v7.1.0
|
|
8
|
+
CLI Using tsup config: /Users/leo/orderly/orderly-web/packages/utils/tsup.config.ts
|
|
9
|
+
CLI Target: es6
|
|
10
|
+
CLI Cleaning output folder
|
|
11
|
+
CJS Build start
|
|
12
|
+
ESM Build start
|
|
13
|
+
ESM dist/index.mjs 1.39 KB
|
|
14
|
+
ESM dist/index.mjs.map 2.67 KB
|
|
15
|
+
ESM ⚡️ Build success in 29ms
|
|
16
|
+
CJS dist/index.js 3.20 KB
|
|
17
|
+
CJS dist/index.js.map 2.89 KB
|
|
18
|
+
CJS ⚡️ Build success in 31ms
|
|
19
|
+
DTS Build start
|
|
20
|
+
DTS ⚡️ Build success in 792ms
|
|
21
|
+
DTS dist/index.d.ts 504.00 B
|
|
22
|
+
DTS dist/index.d.mts 504.00 B
|
package/CHANGELOG.md
ADDED
package/babel.config.js
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Decimal from 'decimal.js-light';
|
|
2
|
+
export { default as Decimal } from 'decimal.js-light';
|
|
3
|
+
|
|
4
|
+
declare const cutNumber: (num: number | string, lenght: number) => void;
|
|
5
|
+
declare const zero: Decimal;
|
|
6
|
+
declare const commify: (num: number | string) => string;
|
|
7
|
+
declare const getPrecisionByNumber: (num: number | string) => number;
|
|
8
|
+
declare function numberToHumanStyle(number: number): string;
|
|
9
|
+
|
|
10
|
+
declare const timeConvertString: (time: number) => number[];
|
|
11
|
+
|
|
12
|
+
export { commify, cutNumber, getPrecisionByNumber, numberToHumanStyle, timeConvertString, zero };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Decimal from 'decimal.js-light';
|
|
2
|
+
export { default as Decimal } from 'decimal.js-light';
|
|
3
|
+
|
|
4
|
+
declare const cutNumber: (num: number | string, lenght: number) => void;
|
|
5
|
+
declare const zero: Decimal;
|
|
6
|
+
declare const commify: (num: number | string) => string;
|
|
7
|
+
declare const getPrecisionByNumber: (num: number | string) => number;
|
|
8
|
+
declare function numberToHumanStyle(number: number): string;
|
|
9
|
+
|
|
10
|
+
declare const timeConvertString: (time: number) => number[];
|
|
11
|
+
|
|
12
|
+
export { commify, cutNumber, getPrecisionByNumber, numberToHumanStyle, timeConvertString, zero };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var m=Object.create;var i=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var h=(t,o)=>{for(var n in o)i(t,n,{get:o[n],enumerable:!0})},a=(t,o,n,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of p(o))!f.call(t,r)&&r!==n&&i(t,r,{get:()=>o[r],enumerable:!(e=g(o,r))||e.enumerable});return t};var b=(t,o,n)=>(n=t!=null?m(d(t)):{},a(o||!t||!t.__esModule?i(n,"default",{value:t,enumerable:!0}):n,t)),x=t=>a(i({},"__esModule",{value:!0}),t);var v={};h(v,{Decimal:()=>c,commify:()=>D,cutNumber:()=>M,getPrecisionByNumber:()=>N,numberToHumanStyle:()=>y,timeConvertString:()=>P,zero:()=>S});module.exports=x(v);var s=b(require("decimal.js-light"));s.default.set({rounding:s.default.ROUND_DOWN});var c=s.default,M=(t,o)=>{},S=new s.default(0),D=t=>{var o=t.toString().split(".");let n=o[0],e=o[1],r=/\B(?=(\d{3})+(?!\d))/g;return n.replace(r,",")+(e?"."+e:"")},N=t=>{let o=t.toString().split(".");return o[1]?o[1].length:0};function y(t){let o=["","thousand","million","billion","trillion","quadrillion"],n=",";if(t<1e3)return t.toString();let e=Math.sign(t),r=Math.abs(t),u=Math.floor(Math.log10(r)/3),l=(Math.round(r/Math.pow(1e3,u)*10)/10).toLocaleString();return(e<0?"-":"")+l+" "+o[u]}var P=t=>{t/=1e3;let o=Math.floor(t/3600),n=Math.floor(t/60%60),e=Math.floor(t%60);return[o,n,e]};0&&(module.exports={Decimal,commify,cutNumber,getPrecisionByNumber,numberToHumanStyle,timeConvertString,zero});
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/decimal.ts","../src/dateTime.ts"],"sourcesContent":["export {default as Decimal} from './decimal'\nexport * from './decimal'\nexport * from './dateTime'","import Decimal from \"decimal.js-light\";\n\nDecimal.set({\n rounding: Decimal.ROUND_DOWN,\n});\n\nexport default Decimal;\n\nexport const cutNumber = (num: number | string, lenght: number) => {};\n\nexport const zero = new Decimal(0);\n\nexport const commify = (num: number | string): string => {\n var parts = num.toString().split(\".\");\n const numberPart = parts[0];\n const decimalPart = parts[1];\n const thousands = /\\B(?=(\\d{3})+(?!\\d))/g;\n return (\n numberPart.replace(thousands, \",\") + (decimalPart ? \".\" + decimalPart : \"\")\n );\n};\n\nexport const getPrecisionByNumber = (num: number | string): number => {\n // if(Math.floor(num) === num) return 0;\n const parts = num.toString().split(\".\");\n return parts[1] ? parts[1].length : 0;\n};\n\nexport function numberToHumanStyle(number: number): string {\n const units = [\n \"\",\n \"thousand\",\n \"million\",\n \"billion\",\n \"trillion\",\n \"quadrillion\",\n ];\n const delimiter = \",\";\n\n if (number < 1000) {\n return number.toString();\n }\n\n const sign = Math.sign(number);\n const num = Math.abs(number);\n const exp = Math.floor(Math.log10(num) / 3);\n const rounded = Math.round((num / Math.pow(1000, exp)) * 10) / 10;\n const formatted = rounded.toLocaleString();\n\n return (sign < 0 ? \"-\" : \"\") + formatted + \" \" + units[exp];\n}\n","export const timeConvertString = (time: number): number[] => {\n time /= 1000;\n const h = Math.floor(time / 3600);\n const m = Math.floor((time / 60) % 60);\n const s = Math.floor(time % 60);\n // return result = h + \"小时\" + m + \"分钟\" + s + \"秒\";\n return [h, m, s];\n};\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,YAAAC,EAAA,cAAAC,EAAA,yBAAAC,EAAA,uBAAAC,EAAA,sBAAAC,EAAA,SAAAC,IAAA,eAAAC,EAAAT,GCAA,IAAAU,EAAoB,+BAEpB,EAAAC,QAAQ,IAAI,CACV,SAAU,EAAAA,QAAQ,UACpB,CAAC,EAED,IAAOC,EAAQ,EAAAD,QAEFE,EAAY,CAACC,EAAsBC,IAAmB,CAAC,EAEvDC,EAAO,IAAI,EAAAL,QAAQ,CAAC,EAEpBM,EAAWH,GAAiC,CACvD,IAAII,EAAQJ,EAAI,SAAS,EAAE,MAAM,GAAG,EACpC,IAAMK,EAAaD,EAAM,CAAC,EACpBE,EAAcF,EAAM,CAAC,EACrBG,EAAY,wBAClB,OACEF,EAAW,QAAQE,EAAW,GAAG,GAAKD,EAAc,IAAMA,EAAc,GAE5E,EAEaE,EAAwBR,GAAiC,CAEpE,IAAMI,EAAQJ,EAAI,SAAS,EAAE,MAAM,GAAG,EACtC,OAAOI,EAAM,CAAC,EAAIA,EAAM,CAAC,EAAE,OAAS,CACtC,EAEO,SAASK,EAAmBC,EAAwB,CACzD,IAAMC,EAAQ,CACZ,GACA,WACA,UACA,UACA,WACA,aACF,EACMC,EAAY,IAElB,GAAIF,EAAS,IACX,OAAOA,EAAO,SAAS,EAGzB,IAAMG,EAAO,KAAK,KAAKH,CAAM,EACvBV,EAAM,KAAK,IAAIU,CAAM,EACrBI,EAAM,KAAK,MAAM,KAAK,MAAMd,CAAG,EAAI,CAAC,EAEpCe,GADU,KAAK,MAAOf,EAAM,KAAK,IAAI,IAAMc,CAAG,EAAK,EAAE,EAAI,IACrC,eAAe,EAEzC,OAAQD,EAAO,EAAI,IAAM,IAAME,EAAY,IAAMJ,EAAMG,CAAG,CAC5D,CClDO,IAAME,EAAqBC,GAA2B,CACzDA,GAAQ,IACR,IAAMC,EAAI,KAAK,MAAMD,EAAO,IAAI,EAC1BE,EAAI,KAAK,MAAOF,EAAO,GAAM,EAAE,EAC/BG,EAAI,KAAK,MAAMH,EAAO,EAAE,EAE9B,MAAO,CAACC,EAAGC,EAAGC,CAAC,CACnB","names":["src_exports","__export","decimal_default","commify","cutNumber","getPrecisionByNumber","numberToHumanStyle","timeConvertString","zero","__toCommonJS","import_decimal","Decimal","decimal_default","cutNumber","num","lenght","zero","commify","parts","numberPart","decimalPart","thousands","getPrecisionByNumber","numberToHumanStyle","number","units","delimiter","sign","exp","formatted","timeConvertString","time","h","m","s"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import s from"decimal.js-light";s.set({rounding:s.ROUND_DOWN});var a=s,m=(t,o)=>{},g=new s(0),p=t=>{var o=t.toString().split(".");let r=o[0],n=o[1],e=/\B(?=(\d{3})+(?!\d))/g;return r.replace(e,",")+(n?"."+n:"")},d=t=>{let o=t.toString().split(".");return o[1]?o[1].length:0};function f(t){let o=["","thousand","million","billion","trillion","quadrillion"],r=",";if(t<1e3)return t.toString();let n=Math.sign(t),e=Math.abs(t),i=Math.floor(Math.log10(e)/3),u=(Math.round(e/Math.pow(1e3,i)*10)/10).toLocaleString();return(n<0?"-":"")+u+" "+o[i]}var b=t=>{t/=1e3;let o=Math.floor(t/3600),r=Math.floor(t/60%60),n=Math.floor(t%60);return[o,r,n]};export{a as Decimal,p as commify,m as cutNumber,d as getPrecisionByNumber,f as numberToHumanStyle,b as timeConvertString,g as zero};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/decimal.ts","../src/dateTime.ts"],"sourcesContent":["import Decimal from \"decimal.js-light\";\n\nDecimal.set({\n rounding: Decimal.ROUND_DOWN,\n});\n\nexport default Decimal;\n\nexport const cutNumber = (num: number | string, lenght: number) => {};\n\nexport const zero = new Decimal(0);\n\nexport const commify = (num: number | string): string => {\n var parts = num.toString().split(\".\");\n const numberPart = parts[0];\n const decimalPart = parts[1];\n const thousands = /\\B(?=(\\d{3})+(?!\\d))/g;\n return (\n numberPart.replace(thousands, \",\") + (decimalPart ? \".\" + decimalPart : \"\")\n );\n};\n\nexport const getPrecisionByNumber = (num: number | string): number => {\n // if(Math.floor(num) === num) return 0;\n const parts = num.toString().split(\".\");\n return parts[1] ? parts[1].length : 0;\n};\n\nexport function numberToHumanStyle(number: number): string {\n const units = [\n \"\",\n \"thousand\",\n \"million\",\n \"billion\",\n \"trillion\",\n \"quadrillion\",\n ];\n const delimiter = \",\";\n\n if (number < 1000) {\n return number.toString();\n }\n\n const sign = Math.sign(number);\n const num = Math.abs(number);\n const exp = Math.floor(Math.log10(num) / 3);\n const rounded = Math.round((num / Math.pow(1000, exp)) * 10) / 10;\n const formatted = rounded.toLocaleString();\n\n return (sign < 0 ? \"-\" : \"\") + formatted + \" \" + units[exp];\n}\n","export const timeConvertString = (time: number): number[] => {\n time /= 1000;\n const h = Math.floor(time / 3600);\n const m = Math.floor((time / 60) % 60);\n const s = Math.floor(time % 60);\n // return result = h + \"小时\" + m + \"分钟\" + s + \"秒\";\n return [h, m, s];\n};\n"],"mappings":"AAAA,OAAOA,MAAa,mBAEpBA,EAAQ,IAAI,CACV,SAAUA,EAAQ,UACpB,CAAC,EAED,IAAOC,EAAQD,EAEFE,EAAY,CAACC,EAAsBC,IAAmB,CAAC,EAEvDC,EAAO,IAAIL,EAAQ,CAAC,EAEpBM,EAAWH,GAAiC,CACvD,IAAII,EAAQJ,EAAI,SAAS,EAAE,MAAM,GAAG,EACpC,IAAMK,EAAaD,EAAM,CAAC,EACpBE,EAAcF,EAAM,CAAC,EACrBG,EAAY,wBAClB,OACEF,EAAW,QAAQE,EAAW,GAAG,GAAKD,EAAc,IAAMA,EAAc,GAE5E,EAEaE,EAAwBR,GAAiC,CAEpE,IAAMI,EAAQJ,EAAI,SAAS,EAAE,MAAM,GAAG,EACtC,OAAOI,EAAM,CAAC,EAAIA,EAAM,CAAC,EAAE,OAAS,CACtC,EAEO,SAASK,EAAmBC,EAAwB,CACzD,IAAMC,EAAQ,CACZ,GACA,WACA,UACA,UACA,WACA,aACF,EACMC,EAAY,IAElB,GAAIF,EAAS,IACX,OAAOA,EAAO,SAAS,EAGzB,IAAMG,EAAO,KAAK,KAAKH,CAAM,EACvBV,EAAM,KAAK,IAAIU,CAAM,EACrBI,EAAM,KAAK,MAAM,KAAK,MAAMd,CAAG,EAAI,CAAC,EAEpCe,GADU,KAAK,MAAOf,EAAM,KAAK,IAAI,IAAMc,CAAG,EAAK,EAAE,EAAI,IACrC,eAAe,EAEzC,OAAQD,EAAO,EAAI,IAAM,IAAME,EAAY,IAAMJ,EAAMG,CAAG,CAC5D,CClDO,IAAME,EAAqBC,GAA2B,CACzDA,GAAQ,IACR,IAAMC,EAAI,KAAK,MAAMD,EAAO,IAAI,EAC1BE,EAAI,KAAK,MAAOF,EAAO,GAAM,EAAE,EAC/BG,EAAI,KAAK,MAAMH,EAAO,EAAE,EAE9B,MAAO,CAACC,EAAGC,EAAGC,CAAC,CACnB","names":["Decimal","decimal_default","cutNumber","num","lenght","zero","commify","parts","numberPart","decimalPart","thousands","getPrecisionByNumber","numberToHumanStyle","number","units","delimiter","sign","exp","formatted","timeConvertString","time","h","m","s"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orderly.network/utils",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"keywords": [],
|
|
8
|
+
"author": "leo",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@babel/core": "^7.22.9",
|
|
12
|
+
"@babel/preset-env": "^7.22.9",
|
|
13
|
+
"@babel/preset-typescript": "^7.22.5",
|
|
14
|
+
"@types/jest": "^29.5.3",
|
|
15
|
+
"babel-jest": "^29.6.1",
|
|
16
|
+
"jest": "^29.6.1",
|
|
17
|
+
"tsup": "^7.1.0",
|
|
18
|
+
"typescript": "^5.1.6",
|
|
19
|
+
"tsconfig": "0.0.0"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"dayjs": "^1.11.9",
|
|
23
|
+
"decimal.js-light": "^2.5.1"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"dev": "tsup --watch",
|
|
30
|
+
"build": "tsup",
|
|
31
|
+
"test": "jest"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/dateTime.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const timeConvertString = (time: number): number[] => {
|
|
2
|
+
time /= 1000;
|
|
3
|
+
const h = Math.floor(time / 3600);
|
|
4
|
+
const m = Math.floor((time / 60) % 60);
|
|
5
|
+
const s = Math.floor(time % 60);
|
|
6
|
+
// return result = h + "小时" + m + "分钟" + s + "秒";
|
|
7
|
+
return [h, m, s];
|
|
8
|
+
};
|
package/src/decimal.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import Decimal from "decimal.js-light";
|
|
2
|
+
|
|
3
|
+
Decimal.set({
|
|
4
|
+
rounding: Decimal.ROUND_DOWN,
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
export default Decimal;
|
|
8
|
+
|
|
9
|
+
export const cutNumber = (num: number | string, lenght: number) => {};
|
|
10
|
+
|
|
11
|
+
export const zero = new Decimal(0);
|
|
12
|
+
|
|
13
|
+
export const commify = (num: number | string): string => {
|
|
14
|
+
var parts = num.toString().split(".");
|
|
15
|
+
const numberPart = parts[0];
|
|
16
|
+
const decimalPart = parts[1];
|
|
17
|
+
const thousands = /\B(?=(\d{3})+(?!\d))/g;
|
|
18
|
+
return (
|
|
19
|
+
numberPart.replace(thousands, ",") + (decimalPart ? "." + decimalPart : "")
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getPrecisionByNumber = (num: number | string): number => {
|
|
24
|
+
// if(Math.floor(num) === num) return 0;
|
|
25
|
+
const parts = num.toString().split(".");
|
|
26
|
+
return parts[1] ? parts[1].length : 0;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function numberToHumanStyle(number: number): string {
|
|
30
|
+
const units = [
|
|
31
|
+
"",
|
|
32
|
+
"thousand",
|
|
33
|
+
"million",
|
|
34
|
+
"billion",
|
|
35
|
+
"trillion",
|
|
36
|
+
"quadrillion",
|
|
37
|
+
];
|
|
38
|
+
const delimiter = ",";
|
|
39
|
+
|
|
40
|
+
if (number < 1000) {
|
|
41
|
+
return number.toString();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const sign = Math.sign(number);
|
|
45
|
+
const num = Math.abs(number);
|
|
46
|
+
const exp = Math.floor(Math.log10(num) / 3);
|
|
47
|
+
const rounded = Math.round((num / Math.pow(1000, exp)) * 10) / 10;
|
|
48
|
+
const formatted = rounded.toLocaleString();
|
|
49
|
+
|
|
50
|
+
return (sign < 0 ? "-" : "") + formatted + " " + units[exp];
|
|
51
|
+
}
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig((options) => ({
|
|
4
|
+
entry: ["src/index.ts"],
|
|
5
|
+
splitting: false,
|
|
6
|
+
minify: !options.watch,
|
|
7
|
+
format: ["cjs", "esm"],
|
|
8
|
+
target: "es6",
|
|
9
|
+
sourcemap: true,
|
|
10
|
+
clean: true,
|
|
11
|
+
dts: true,
|
|
12
|
+
}));
|