@7365admin1/layer-common 4.15.3-staging.326 → 4.15.3-staging.327
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.
|
@@ -292,8 +292,11 @@ import {
|
|
|
292
292
|
BULK_SHEET_DEFAULT_SIZE,
|
|
293
293
|
BULK_SHEET_SIZES,
|
|
294
294
|
DEFAULT_DIAL_CODE,
|
|
295
|
+
bulkAlphaNumeric,
|
|
296
|
+
bulkIdNumber,
|
|
295
297
|
bulkPhoneToStore,
|
|
296
298
|
bulkRowCounts,
|
|
299
|
+
splitPhoneEntry,
|
|
297
300
|
bulkSubmitBatches,
|
|
298
301
|
emptyBulkRow,
|
|
299
302
|
isBulkRowEmpty,
|
|
@@ -684,11 +687,33 @@ function commitAndMoveRight() {
|
|
|
684
687
|
|
|
685
688
|
function setCell(row: BulkVehicleRow, key: ColumnKey, value: string) {
|
|
686
689
|
if (isLocked(row)) return;
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
690
|
+
|
|
691
|
+
if (key === "plateNumber") {
|
|
692
|
+
// Letters and digits, in capitals - the same rule the one-vehicle form's
|
|
693
|
+
// Vehicle Number field applies as you type, so a plate typed "sba 1234 x"
|
|
694
|
+
// here and "SBA1234X" there are one plate, not two.
|
|
695
|
+
row.plateNumber = bulkAlphaNumeric(value);
|
|
696
|
+
} else if (key === "nric") {
|
|
697
|
+
// Capitals, keeping the separators an ID can carry (a dash, a slash) and
|
|
698
|
+
// losing only the spacing people write it with. Dropping a dash would
|
|
699
|
+
// store a number that is not the person's.
|
|
700
|
+
row.nric = bulkIdNumber(value);
|
|
701
|
+
} else if (key === "dialCode") {
|
|
702
|
+
// A row without a dial code would store a number under nobody's country,
|
|
703
|
+
// so emptying the cell puts the default back rather than leaving it blank.
|
|
704
|
+
row.dialCode = value.trim() || DEFAULT_DIAL_CODE;
|
|
705
|
+
} else if (key === "phone") {
|
|
706
|
+
// The cell keeps digits only - the country belongs to the Code column. A
|
|
707
|
+
// number that arrives carrying its own code (+60…, 0060…) moves the Code
|
|
708
|
+
// with it rather than being stored under the wrong country.
|
|
709
|
+
const entry = splitPhoneEntry(value, DIAL_CODE_VALUES);
|
|
710
|
+
if (entry.dialCode) row.dialCode = entry.dialCode;
|
|
711
|
+
row.phone = entry.phone;
|
|
712
|
+
if (entry.dialCode) row.invalid = row.invalid.filter((f) => f !== "dialCode");
|
|
713
|
+
} else {
|
|
714
|
+
row[key] = value;
|
|
715
|
+
}
|
|
716
|
+
|
|
692
717
|
row.invalid = row.invalid.filter((field) => field !== key);
|
|
693
718
|
|
|
694
719
|
// Emptied of everything again: whatever happened to it last time no longer
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "4.15.3-staging.
|
|
5
|
+
"version": "4.15.3-staging.327",
|
|
6
6
|
"author": "7365admin1",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
8
8
|
"//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
|
|
@@ -79,16 +79,46 @@ export function isBulkRowEmpty(row: BulkVehicleRow): boolean {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
* A phone number
|
|
83
|
-
*
|
|
84
|
-
*
|
|
82
|
+
* A phone number as the sheet holds one: DIGITS, and nothing else. The country
|
|
83
|
+
* is the Code column's business, so a cell keeps only the number itself - what
|
|
84
|
+
* a person would dial locally. Blank is fine; it is not a required column.
|
|
85
85
|
*/
|
|
86
86
|
export function isValidBulkPhone(value: unknown): boolean {
|
|
87
87
|
const text = String(value ?? "").trim();
|
|
88
88
|
if (!text) return true;
|
|
89
|
-
|
|
89
|
+
return /^\d{7,15}$/.test(text);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Everything but the digits, gone: what a phone cell stores. */
|
|
93
|
+
export function bulkPhoneDigits(value: unknown): string {
|
|
94
|
+
return String(value ?? "").replace(/\D/g, "");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Split what somebody typed or pasted into a phone cell into the country it
|
|
99
|
+
* names and the number itself.
|
|
100
|
+
*
|
|
101
|
+
* "+60 12-345 6789" and "006012 3456789" both carry their own country, so the
|
|
102
|
+
* Code column follows the number rather than contradicting it. A plain local
|
|
103
|
+
* number names no country and leaves the Code alone.
|
|
104
|
+
*/
|
|
105
|
+
export function splitPhoneEntry(
|
|
106
|
+
value: unknown,
|
|
107
|
+
codes: string[],
|
|
108
|
+
): { dialCode: string; phone: string } {
|
|
109
|
+
const text = String(value ?? "").trim().replace(/[\s()\-.]/g, "");
|
|
110
|
+
const carriesCode = text.startsWith("+") || text.startsWith("00");
|
|
90
111
|
const digits = text.replace(/\D/g, "");
|
|
91
|
-
|
|
112
|
+
|
|
113
|
+
if (!carriesCode || !digits) return { dialCode: "", phone: digits };
|
|
114
|
+
|
|
115
|
+
const body = text.startsWith("00") ? digits.slice(2) : digits;
|
|
116
|
+
const match = [...codes]
|
|
117
|
+
.sort((a, b) => b.length - a.length)
|
|
118
|
+
.find((code) => body.startsWith(code.replace(/\D/g, "")));
|
|
119
|
+
|
|
120
|
+
if (!match) return { dialCode: "", phone: body };
|
|
121
|
+
return { dialCode: match, phone: body.slice(match.replace(/\D/g, "").length) };
|
|
92
122
|
}
|
|
93
123
|
|
|
94
124
|
/** What the one-vehicle form puts in front of a number with no country code. */
|
|
@@ -104,22 +134,18 @@ export const DEFAULT_DIAL_CODE = "+65";
|
|
|
104
134
|
* together. A number already written with a country code keeps its own.
|
|
105
135
|
*/
|
|
106
136
|
export function bulkPhoneToStore(value: unknown, dialCode?: string): string {
|
|
107
|
-
const
|
|
108
|
-
if (!
|
|
137
|
+
const digits = bulkPhoneDigits(value);
|
|
138
|
+
if (!digits) return "";
|
|
109
139
|
|
|
110
140
|
const code = String(dialCode ?? "").trim() || DEFAULT_DIAL_CODE;
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
// A number that already carries a country code keeps the one it carries.
|
|
114
|
-
if (compact.startsWith("+")) return compact;
|
|
115
|
-
if (compact.startsWith("00")) return `+${compact.slice(2)}`;
|
|
141
|
+
const codeDigits = code.replace(/\D/g, "");
|
|
116
142
|
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
return `+${
|
|
143
|
+
// A number that already carries its country's digits is not given them twice.
|
|
144
|
+
if (codeDigits && digits.startsWith(codeDigits) && digits.length > codeDigits.length) {
|
|
145
|
+
return `+${digits}`;
|
|
120
146
|
}
|
|
121
147
|
|
|
122
|
-
return
|
|
148
|
+
return `+${codeDigits}${digits}`;
|
|
123
149
|
}
|
|
124
150
|
|
|
125
151
|
/** Each dial code's number patterns, e.g. { "+65": ["^\\+65\\d{8}$"] }. */
|
|
@@ -175,10 +201,34 @@ export function isValidBulkNumber(
|
|
|
175
201
|
return patterns.some((pattern) => matches(pattern, stored));
|
|
176
202
|
}
|
|
177
203
|
|
|
178
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* An NRIC or a plate as the system keeps them: letters and digits, in capitals.
|
|
206
|
+
*
|
|
207
|
+
* The one-vehicle form's own NRIC and Vehicle Number fields strip everything
|
|
208
|
+
* else as you type, so "sba 1234 x" and "SBA1234X" cannot both be stored for
|
|
209
|
+
* one car. The sheet applies the same rule, wherever a value came from.
|
|
210
|
+
*/
|
|
211
|
+
export function bulkAlphaNumeric(value: unknown): string {
|
|
212
|
+
return String(value ?? "").replace(/[^A-Za-z0-9]/g, "").toUpperCase();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* An identity number as the sheet keeps one: capitals, and the separators an
|
|
217
|
+
* ID can really carry.
|
|
218
|
+
*
|
|
219
|
+
* Not every ID is eight letters and digits - a Malaysian IC is written
|
|
220
|
+
* 900101-14-5678, a permit can carry a slash - so a symbol is kept rather than
|
|
221
|
+
* silently dropped. What goes is only what nobody's ID contains: spaces,
|
|
222
|
+
* commas and full stops, which are how people space a number out when they
|
|
223
|
+
* write it down.
|
|
224
|
+
*/
|
|
225
|
+
export function bulkIdNumber(value: unknown): string {
|
|
226
|
+
return String(value ?? "").replace(/[\s,.]/g, "").toUpperCase();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** A plate number: letters and digits, and nothing else. */
|
|
179
230
|
export function isValidBulkPlate(value: unknown): boolean {
|
|
180
|
-
|
|
181
|
-
return /^[A-Za-z0-9][A-Za-z0-9 -]{0,14}$/.test(text);
|
|
231
|
+
return /^[A-Za-z0-9]{1,15}$/.test(String(value ?? "").trim());
|
|
182
232
|
}
|
|
183
233
|
|
|
184
234
|
/** Plates written the same way once spacing and case are ignored. */
|
|
@@ -184,6 +184,32 @@ function decodeXml(text: string): string {
|
|
|
184
184
|
});
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
/**
|
|
188
|
+
* A number as the sheet showed it, not as the file stored it.
|
|
189
|
+
*
|
|
190
|
+
* A workbook may keep 98695434 as `9.8695434E7` - which is the same number,
|
|
191
|
+
* and nobody's phone. The digits are shifted by hand rather than through
|
|
192
|
+
* `Number`, so a long one cannot lose its last digit to a float.
|
|
193
|
+
*/
|
|
194
|
+
export function plainNumberText(raw: string): string {
|
|
195
|
+
const match = /^([-+]?)(\d+)(?:\.(\d+))?[eE]([-+]?\d+)$/.exec(String(raw ?? "").trim());
|
|
196
|
+
if (!match) return String(raw ?? "");
|
|
197
|
+
|
|
198
|
+
const [, sign, whole, fraction = "", exponent] = match;
|
|
199
|
+
const digits = `${whole}${fraction}`;
|
|
200
|
+
const point = whole.length + Number(exponent);
|
|
201
|
+
|
|
202
|
+
let text: string;
|
|
203
|
+
if (point <= 0) text = `0.${"0".repeat(-point)}${digits}`;
|
|
204
|
+
else if (point >= digits.length) text = digits + "0".repeat(point - digits.length);
|
|
205
|
+
else text = `${digits.slice(0, point)}.${digits.slice(point)}`;
|
|
206
|
+
|
|
207
|
+
// 98695434.000 and 98695434 are the same number; the sheet shows the shorter.
|
|
208
|
+
if (text.includes(".")) text = text.replace(/\.?0+$/, "");
|
|
209
|
+
|
|
210
|
+
return `${sign === "-" ? "-" : ""}${text}`;
|
|
211
|
+
}
|
|
212
|
+
|
|
187
213
|
/** A1 -> 0, B1 -> 1, AA1 -> 26. */
|
|
188
214
|
export function columnFromRef(ref: string): number {
|
|
189
215
|
const letters = String(ref ?? "").match(/^[A-Z]+/)?.[0] ?? "";
|
|
@@ -309,7 +335,7 @@ function sheetToGrid(xml: string, strings: string[]): string[][] {
|
|
|
309
335
|
value =
|
|
310
336
|
type === "s"
|
|
311
337
|
? (strings[Number(decodeXml(raw))] ?? "")
|
|
312
|
-
: decodeXml(raw);
|
|
338
|
+
: plainNumberText(decodeXml(raw));
|
|
313
339
|
}
|
|
314
340
|
}
|
|
315
341
|
|