@shwfed/nuxt 0.1.63 → 0.1.64

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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
3
  "configKey": "shwfed",
4
- "version": "0.1.63",
4
+ "version": "0.1.64",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -2,7 +2,58 @@ import { Environment, EvaluationError, Optional } from "@marcbachmann/cel-js";
2
2
  import { startOfDay, startOfWeek, startOfYear, startOfMonth, endOfDay, endOfWeek, endOfYear, endOfMonth, addYears, addMonths, addDays, addWeeks, setDate, setMonth, setYear, formatDate, isBefore, isAfter, isEqual } from "date-fns";
3
3
  import { TZDate } from "@date-fns/tz";
4
4
  import { BigNumber } from "bignumber.js";
5
- import Nzh from "nzh";
5
+ const DIGITS = "\u96F6\u58F9\u8D30\u53C1\u8086\u4F0D\u9646\u67D2\u634C\u7396";
6
+ const SMALL_UNITS = ["", "\u62FE", "\u4F70", "\u4EDF"];
7
+ const BIG_UNITS = ["", "\u4E07", "\u4EBF", "\u4E07\u4EBF"];
8
+ function encodeSimplifiedChineseUppercaseInteger(s) {
9
+ if (s === "0") return DIGITS.charAt(0);
10
+ const padded = s.padStart(Math.ceil(s.length / 4) * 4, "0");
11
+ const groups = [];
12
+ for (let i = 0; i < padded.length; i += 4) groups.push(padded.slice(i, i + 4));
13
+ let out = "";
14
+ let needZero = false;
15
+ for (let gi = 0; gi < groups.length; gi++) {
16
+ const g = groups[gi];
17
+ if (g === void 0) continue;
18
+ const bigUnitIdx = groups.length - 1 - gi;
19
+ const bigUnit = BIG_UNITS[bigUnitIdx] ?? "";
20
+ let block = "";
21
+ let blockNeedZero = false;
22
+ for (let i = 0; i < 4; i++) {
23
+ const d = g.charAt(i);
24
+ const digit = d === "0" ? -1 : Number.parseInt(d, 10);
25
+ const smallUnit = SMALL_UNITS[4 - 1 - i] ?? "";
26
+ let hasNonZeroAfter = false;
27
+ for (let j = i + 1; j < 4; j++) {
28
+ if (g.charAt(j) !== "0") {
29
+ hasNonZeroAfter = true;
30
+ break;
31
+ }
32
+ }
33
+ if (digit === -1) {
34
+ blockNeedZero = true;
35
+ } else {
36
+ if (blockNeedZero && (block !== "" || hasNonZeroAfter && smallUnit !== "\u62FE")) {
37
+ block += DIGITS.charAt(0);
38
+ blockNeedZero = false;
39
+ }
40
+ if (digit === 1 && smallUnit === "\u62FE") block += smallUnit;
41
+ else if (digit > 0) block += DIGITS.charAt(digit) + smallUnit;
42
+ if (digit > 0) blockNeedZero = false;
43
+ }
44
+ }
45
+ if (block !== "") {
46
+ if (needZero) {
47
+ out += DIGITS.charAt(0);
48
+ needZero = false;
49
+ }
50
+ out += block + bigUnit;
51
+ } else {
52
+ needZero = true;
53
+ }
54
+ }
55
+ return out;
56
+ }
6
57
  export function createEnvironment() {
7
58
  const env = new Environment({
8
59
  enableOptionalTypes: true,
@@ -96,9 +147,17 @@ export function createEnvironment() {
96
147
  }).registerFunction("int.toLocaleString(dyn): string", (number, options) => {
97
148
  return number.toLocaleString(navigator.language, options);
98
149
  }).registerFunction("double.encodeSimplifiedChineseUppercase(): string", (number) => {
99
- return Nzh.cn.encodeB(number);
150
+ if (!Number.isFinite(number) || number < 0) throw new EvaluationError("Number must be finite and non-negative");
151
+ const intPart = Math.floor(number);
152
+ const decPart = Math.round((number - intPart) * 100);
153
+ const intStr = encodeSimplifiedChineseUppercaseInteger(String(intPart));
154
+ if (decPart === 0) return intStr;
155
+ const jiao = Math.floor(decPart / 10);
156
+ const fen = decPart % 10;
157
+ return intStr + "\u5706" + DIGITS.charAt(jiao) + "\u89D2" + DIGITS.charAt(fen) + "\u5206";
100
158
  }).registerFunction("int.encodeSimplifiedChineseUppercase(): string", (number) => {
101
- return Nzh.cn.encodeB(number.toString());
159
+ if (number < 0n) throw new EvaluationError("Number must be non-negative");
160
+ return encodeSimplifiedChineseUppercaseInteger(number.toString());
102
161
  }).registerFunction("parseJSON(string): dyn", (string) => {
103
162
  return JSON.parse(string);
104
163
  }).registerFunction("string.slice(int): string", (s, start) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
- "version": "0.1.63",
3
+ "version": "0.1.64",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -54,7 +54,6 @@
54
54
  "effect": "^3.19.15",
55
55
  "markdown-it": "^14.1.0",
56
56
  "mutative": "^1.3.0",
57
- "nzh": "^1.0.14",
58
57
  "reka-ui": "^2.7.0",
59
58
  "tailwind-merge": "^3.4.0",
60
59
  "vue": "^3.5.27",