@orderly.network/utils 0.0.57 → 0.0.59

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/dist/index.d.mts CHANGED
@@ -12,8 +12,8 @@ declare const getPrecisionByNumber: (num: number | string) => number;
12
12
  * const number1 = 12345;
13
13
  * const number2 = 987654321;
14
14
  *
15
- * console.log(numberToHumanStyle(number1)); // Output: "12.35K"
16
- * console.log(numberToHumanStyle(number2)); // Output: "987.65M"
15
+ *
16
+ *
17
17
  */
18
18
  declare function numberToHumanStyle(number: number, decimalPlaces?: number): string;
19
19
 
package/dist/index.d.ts CHANGED
@@ -12,8 +12,8 @@ declare const getPrecisionByNumber: (num: number | string) => number;
12
12
  * const number1 = 12345;
13
13
  * const number2 = 987654321;
14
14
  *
15
- * console.log(numberToHumanStyle(number1)); // Output: "12.35K"
16
- * console.log(numberToHumanStyle(number2)); // Output: "987.65M"
15
+ *
16
+ *
17
17
  */
18
18
  declare function numberToHumanStyle(number: number, decimalPlaces?: number): string;
19
19
 
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/decimal.ts","../src/dateTime.ts","../src/chain.ts"],"sourcesContent":["export { default as dayjs } from \"dayjs\";\n\nexport { default as Decimal } from \"./decimal\";\nexport * from \"./decimal\";\nexport * from \"./dateTime\";\nexport * from \"./chain\";\n","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\n/**\n *\n * @example\n * const number1 = 12345;\n * const number2 = 987654321;\n *\n * console.log(numberToHumanStyle(number1)); // Output: \"12.35K\"\n * console.log(numberToHumanStyle(number2)); // Output: \"987.65M\"\n */\nexport function numberToHumanStyle(\n number: number,\n decimalPlaces: number = 2\n): string {\n const abbreviations = [\"\", \"K\", \"M\", \"B\", \"T\"];\n\n let index = 0;\n while (number >= 1000 && index < abbreviations.length - 1) {\n number /= 1000;\n index++;\n }\n\n const roundedNumber = number.toFixed(decimalPlaces);\n\n return `${roundedNumber}${abbreviations[index]}`;\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","export const hex2int = (chainId: string): number => parseInt(chainId);\nexport const int2hex = (chainId: number): string => `0x${chainId.toString(16)}`;\nexport const praseChainId = (chainId: string | number): number => {\n if (typeof chainId === \"string\") return hex2int(chainId);\n return chainId;\n};\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,YAAAC,EAAA,cAAAC,EAAA,6CAAAC,EAAA,YAAAC,EAAA,YAAAC,EAAA,uBAAAC,EAAA,iBAAAC,EAAA,sBAAAC,EAAA,SAAAC,IAAA,eAAAC,EAAAZ,GAAA,IAAAa,EAAiC,oBCAjC,IAAAC,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,EAWO,SAASK,EACdC,EACAC,EAAwB,EAChB,CACR,IAAMC,EAAgB,CAAC,GAAI,IAAK,IAAK,IAAK,GAAG,EAEzCC,EAAQ,EACZ,KAAOH,GAAU,KAAQG,EAAQD,EAAc,OAAS,GACtDF,GAAU,IACVG,IAKF,MAAO,GAFeH,EAAO,QAAQC,CAAa,CAE3B,GAAGC,EAAcC,CAAK,CAAC,EAChD,CCpDO,IAAMC,EAAqBC,GAA2B,CAC3DA,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,CACjB,ECPO,IAAMC,EAAWC,GAA4B,SAASA,CAAO,EACvDC,EAAWD,GAA4B,KAAKA,EAAQ,SAAS,EAAE,CAAC,GAChEE,EAAgBF,GACvB,OAAOA,GAAY,SAAiBD,EAAQC,CAAO,EAChDA","names":["src_exports","__export","decimal_default","commify","cutNumber","getPrecisionByNumber","hex2int","int2hex","numberToHumanStyle","praseChainId","timeConvertString","zero","__toCommonJS","import_dayjs","import_decimal","Decimal","decimal_default","cutNumber","num","lenght","zero","commify","parts","numberPart","decimalPart","thousands","getPrecisionByNumber","numberToHumanStyle","number","decimalPlaces","abbreviations","index","timeConvertString","time","h","m","s","hex2int","chainId","int2hex","praseChainId"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/decimal.ts","../src/dateTime.ts","../src/chain.ts"],"sourcesContent":["export { default as dayjs } from \"dayjs\";\n\nexport { default as Decimal } from \"./decimal\";\nexport * from \"./decimal\";\nexport * from \"./dateTime\";\nexport * from \"./chain\";\n","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\n/**\n *\n * @example\n * const number1 = 12345;\n * const number2 = 987654321;\n *\n *\n *\n */\nexport function numberToHumanStyle(\n number: number,\n decimalPlaces: number = 2\n): string {\n const abbreviations = [\"\", \"K\", \"M\", \"B\", \"T\"];\n\n let index = 0;\n while (number >= 1000 && index < abbreviations.length - 1) {\n number /= 1000;\n index++;\n }\n\n const roundedNumber = number.toFixed(decimalPlaces);\n\n return `${roundedNumber}${abbreviations[index]}`;\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","export const hex2int = (chainId: string): number => parseInt(chainId);\nexport const int2hex = (chainId: number): string => `0x${chainId.toString(16)}`;\nexport const praseChainId = (chainId: string | number): number => {\n if (typeof chainId === \"string\") return hex2int(chainId);\n return chainId;\n};\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,YAAAC,EAAA,cAAAC,EAAA,6CAAAC,EAAA,YAAAC,EAAA,YAAAC,EAA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vB,OAAOA,GAAY,SAAiBD,EAAQC,CAAO,EAChDA","names":["src_exports","__export","decimal_default","commify","cutNumber","getPrecisionByNumber","hex2int","int2hex","numberToHumanStyle","praseChainId","timeConvertString","zero","__toCommonJS","import_dayjs","import_decimal","Decimal","decimal_default","cutNumber","num","lenght","zero","commify","parts","numberPart","decimalPart","thousands","getPrecisionByNumber","numberToHumanStyle","number","decimalPlaces","abbreviations","index","timeConvertString","time","h","m","s","hex2int","chainId","int2hex","praseChainId"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/decimal.ts","../src/dateTime.ts","../src/chain.ts"],"sourcesContent":["export { default as dayjs } from \"dayjs\";\n\nexport { default as Decimal } from \"./decimal\";\nexport * from \"./decimal\";\nexport * from \"./dateTime\";\nexport * from \"./chain\";\n","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\n/**\n *\n * @example\n * const number1 = 12345;\n * const number2 = 987654321;\n *\n * console.log(numberToHumanStyle(number1)); // Output: \"12.35K\"\n * console.log(numberToHumanStyle(number2)); // Output: \"987.65M\"\n */\nexport function numberToHumanStyle(\n number: number,\n decimalPlaces: number = 2\n): string {\n const abbreviations = [\"\", \"K\", \"M\", \"B\", \"T\"];\n\n let index = 0;\n while (number >= 1000 && index < abbreviations.length - 1) {\n number /= 1000;\n index++;\n }\n\n const roundedNumber = number.toFixed(decimalPlaces);\n\n return `${roundedNumber}${abbreviations[index]}`;\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","export const hex2int = (chainId: string): number => parseInt(chainId);\nexport const int2hex = (chainId: number): string => `0x${chainId.toString(16)}`;\nexport const praseChainId = (chainId: string | number): number => {\n if (typeof chainId === \"string\") return hex2int(chainId);\n return chainId;\n};\n"],"mappings":"AAAA,OAAoB,WAAXA,MAAwB,QCAjC,OAAOC,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,EAWO,SAASK,EACdC,EACAC,EAAwB,EAChB,CACR,IAAMC,EAAgB,CAAC,GAAI,IAAK,IAAK,IAAK,GAAG,EAEzCC,EAAQ,EACZ,KAAOH,GAAU,KAAQG,EAAQD,EAAc,OAAS,GACtDF,GAAU,IACVG,IAKF,MAAO,GAFeH,EAAO,QAAQC,CAAa,CAE3B,GAAGC,EAAcC,CAAK,CAAC,EAChD,CCpDO,IAAMC,EAAqBC,GAA2B,CAC3DA,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,CACjB,ECPO,IAAMC,EAAWC,GAA4B,SAASA,CAAO,EACvDC,EAAWD,GAA4B,KAAKA,EAAQ,SAAS,EAAE,CAAC,GAChEE,EAAgBF,GACvB,OAAOA,GAAY,SAAiBD,EAAQC,CAAO,EAChDA","names":["default","Decimal","decimal_default","cutNumber","num","lenght","zero","commify","parts","numberPart","decimalPart","thousands","getPrecisionByNumber","numberToHumanStyle","number","decimalPlaces","abbreviations","index","timeConvertString","time","h","m","s","hex2int","chainId","int2hex","praseChainId"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/decimal.ts","../src/dateTime.ts","../src/chain.ts"],"sourcesContent":["export { default as dayjs } from \"dayjs\";\n\nexport { default as Decimal } from \"./decimal\";\nexport * from \"./decimal\";\nexport * from \"./dateTime\";\nexport * from \"./chain\";\n","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\n/**\n *\n * @example\n * const number1 = 12345;\n * const number2 = 987654321;\n *\n *\n *\n */\nexport function numberToHumanStyle(\n number: number,\n decimalPlaces: number = 2\n): string {\n const abbreviations = [\"\", \"K\", \"M\", \"B\", \"T\"];\n\n let index = 0;\n while (number >= 1000 && index < abbreviations.length - 1) {\n number /= 1000;\n index++;\n }\n\n const roundedNumber = number.toFixed(decimalPlaces);\n\n return `${roundedNumber}${abbreviations[index]}`;\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","export const hex2int = (chainId: string): number => parseInt(chainId);\nexport const int2hex = (chainId: number): string => `0x${chainId.toString(16)}`;\nexport const praseChainId = (chainId: string | number): number => {\n if (typeof chainId === \"string\") return hex2int(chainId);\n return chainId;\n};\n"],"mappings":"AAAA,OAAoB,WAAXA,MAAwB,QCAjC,OAAOC,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,EAWO,SAASK,EACdC,EACAC,EAAwB,EAChB,CACR,IAAMC,EAAgB,CAAC,GAAI,IAAK,IAAK,IAAK,GAAG,EAEzCC,EAAQ,EACZ,KAAOH,GAAU,KAAQG,EAAQD,EAAc,OAAS,GACtDF,GAAU,IACVG,IAKF,MAAO,GAFeH,EAAO,QAAQC,CAAa,CAE3B,GAAGC,EAAcC,CAAK,CAAC,EAChD,CCpDO,IAAMC,EAAqBC,GAA2B,CAC3DA,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,CACjB,ECPO,IAAMC,EAAWC,GAA4B,SAASA,CAAO,EACvDC,EAAWD,GAA4B,KAAKA,EAAQ,SAAS,EAAE,CAAC,GAChEE,EAAgBF,GACvB,OAAOA,GAAY,SAAiBD,EAAQC,CAAO,EAChDA","names":["default","Decimal","decimal_default","cutNumber","num","lenght","zero","commify","parts","numberPart","decimalPart","thousands","getPrecisionByNumber","numberToHumanStyle","number","decimalPlaces","abbreviations","index","timeConvertString","time","h","m","s","hex2int","chainId","int2hex","praseChainId"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orderly.network/utils",
3
- "version": "0.0.57",
3
+ "version": "0.0.59",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -18,7 +18,7 @@
18
18
  "jest": "^29.6.1",
19
19
  "tsup": "^7.1.0",
20
20
  "typescript": "^5.1.6",
21
- "tsconfig": "0.0.64"
21
+ "tsconfig": "0.0.66"
22
22
  },
23
23
  "dependencies": {
24
24
  "dayjs": "^1.11.9",