@sswroom/sswr 1.6.0 → 1.6.1

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/Changelog CHANGED
@@ -1,3 +1,13 @@
1
+ 1.6.1
2
+ -Fixed parser: parseJpg and parseWebp problem
3
+ -Modified data.Timestamp.fromStr to return null if error
4
+ -Added data.LocalDate.fromStr
5
+ -Added data.LocalDate.today
6
+ -Added text.toUTF32Length
7
+ -Added text.isUInteger
8
+ -Added text.isEmailAddress, isHKID
9
+ -Added text.charIsAlphaNumeric, text.charIsDigit, text.charIsUpperCase, text.charIsLowerCase
10
+
1
11
  1.6.0
2
12
  -Added data.ByteReader.readInt24/readUInt24
3
13
  -Added data.ByteReader.readUTF16
package/data.d.ts CHANGED
@@ -97,6 +97,8 @@ export class LocalDate
97
97
  toString(pattern: string | null): string;
98
98
  compareTo(obj: Date): number;
99
99
  isNull(): boolean;
100
+ static today(): LocalDate;
101
+ static fromStr(s: string): LocalDate | null;
100
102
  }
101
103
 
102
104
  export class TimeInstant
@@ -133,7 +135,7 @@ export class TimeInstant
133
135
  export class Timestamp {
134
136
  constructor(inst: TimeInstant, tzQhr?: number);
135
137
  static fromTicks(ticks: number | number, tzQhr?: number): Timestamp;
136
- static fromStr(str: string, defTzQhr?: number): Timestamp;
138
+ static fromStr(str: string, defTzQhr?: number): Timestamp | null;
137
139
  static now(): Timestamp;
138
140
  static utcNow(): Timestamp;
139
141
  static fromVariTime(variTime: any): Timestamp;
package/data.js CHANGED
@@ -1784,6 +1784,22 @@ export class LocalDate
1784
1784
  {
1785
1785
  return this.dateVal == LocalDate.DATE_NULL;
1786
1786
  }
1787
+
1788
+ static today()
1789
+ {
1790
+ let d = new Date();
1791
+ return new LocalDate(d.getFullYear(), d.getMonth() + 1, d.getDate());
1792
+ }
1793
+
1794
+ static fromStr(s)
1795
+ {
1796
+ let timeVal = DateTimeUtil.string2TimeValue(s, 0);
1797
+ if (timeVal)
1798
+ {
1799
+ return new LocalDate(timeVal.year, timeVal.month, timeVal.day);
1800
+ }
1801
+ return null;
1802
+ }
1787
1803
  }
1788
1804
 
1789
1805
  export class TimeInstant
@@ -1979,9 +1995,9 @@ export class Timestamp
1979
1995
  static fromStr(str, defTzQhr)
1980
1996
  {
1981
1997
  let tval = DateTimeUtil.string2TimeValue(str, defTzQhr);
1982
- if (tval == 0)
1998
+ if (tval == null)
1983
1999
  {
1984
- return new Timestamp(new TimeInstant(0, 0), defTzQhr);
2000
+ return null;
1985
2001
  }
1986
2002
  else
1987
2003
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sswroom/sswr",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "Libraries made by sswroom",
5
5
  "main": "sswr.js",
6
6
  "scripts": {
package/parser.js CHANGED
@@ -795,7 +795,7 @@ function parseKMLNode(kmlNode, doc)
795
795
  }
796
796
  }
797
797
 
798
- async function parseJpg(reader)
798
+ async function parseJpg(reader, sourceName)
799
799
  {
800
800
  if (!(reader instanceof data.ByteReader))
801
801
  return null;
@@ -933,7 +933,7 @@ async function parseJpg(reader)
933
933
  return null;
934
934
  }
935
935
 
936
- async function parseWebp(reader)
936
+ async function parseWebp(reader, sourceName)
937
937
  {
938
938
  if (!(reader instanceof data.ByteReader))
939
939
  return null;
package/text.d.ts CHANGED
@@ -14,6 +14,7 @@ export enum LineBreakType
14
14
 
15
15
  export function zeroPad(val: string | number, ndigits: number): string;
16
16
  export function isInteger(s: string): boolean;
17
+ export function isUInteger(s: string): boolean;
17
18
  export function toJSText(s: string): string;
18
19
  export function toXMLText(s: string): string;
19
20
  export function toAttrText(s: string): string;
@@ -25,6 +26,13 @@ export function toHex16(v: number): string;
25
26
  export function toHex32(v: number): string;
26
27
  export function u8Arr2Hex(buff: Uint8Array, byteSep: string, rowSep: string): string;
27
28
  export function splitLines(txt: string): string[];
29
+ export function isEmailAddress(s: string): boolean;
30
+ export function toUTF32Length(s: string): number;
31
+ export function isHKID(s: string): boolean;
32
+ export function charIsAlphaNumeric(s: string, index: number): boolean;
33
+ export function charIsDigit(s: string, index: number): boolean;
34
+ export function charIsUpperCase(s: string, index: number): boolean;
35
+ export function charIsLowerCase(s: string, index: number): boolean;
28
36
  export function getEncList(): TextBinEnc[];
29
37
 
30
38
  export class TextBinEnc
package/text.js CHANGED
@@ -42,6 +42,25 @@ export function isInteger(s)
42
42
  return true;
43
43
  }
44
44
 
45
+ export function isUInteger(s)
46
+ {
47
+ if (s === null)
48
+ return false;
49
+ let j = s.length;
50
+ if (j == 0)
51
+ return false;
52
+ let i = 0;
53
+ let c;
54
+ while (i < j)
55
+ {
56
+ c = s.charCodeAt(i);
57
+ if (c < 0x30 || c > 0x39)
58
+ return false;
59
+ i++;
60
+ }
61
+ return true;
62
+ }
63
+
45
64
  export function toJSText(s)
46
65
  {
47
66
  let out = "\"";
@@ -288,6 +307,228 @@ export function splitLines(txt)
288
307
  return lines;
289
308
  }
290
309
 
310
+ export function isEmailAddress(s)
311
+ {
312
+ let atPos = -1;
313
+ let dotIndex = -1;
314
+ let c;
315
+ let i = 0;
316
+ let j = s.length;
317
+ while (i < j)
318
+ {
319
+ c = s.charAt(i);
320
+ if (charIsAlphaNumeric(s, i) || c == '-')
321
+ {
322
+
323
+ }
324
+ else if (c == '.')
325
+ {
326
+ if (atPos != -1)
327
+ {
328
+ dotIndex = i;
329
+ }
330
+ }
331
+ else if (c == '@')
332
+ {
333
+ if (atPos != -1)
334
+ {
335
+ return false;
336
+ }
337
+ atPos = i;
338
+ dotIndex = -1;
339
+ }
340
+ else
341
+ {
342
+ return false;
343
+ }
344
+ i++;
345
+ }
346
+ if (atPos == -1 || atPos == 0 || dotIndex == -1 || (j - dotIndex) < 2)
347
+ {
348
+ return false;
349
+ }
350
+ return true;
351
+ }
352
+
353
+ export function toUTF32Length(s)
354
+ {
355
+ let i = 0;
356
+ let j = s.length;
357
+ let ret = 0;
358
+ while (i < j)
359
+ {
360
+ if (i + 1 < j)
361
+ {
362
+ let c1 = s.charCodeAt(i);
363
+ let c2 = s.charCodeAt(i + 1);
364
+ if (c1 >= 0xd800 && c1 < 0xdc00 && c2 >= 0xdc00 && c2 < 0xe000)
365
+ {
366
+ i += 2;
367
+ }
368
+ else
369
+ {
370
+ i++;
371
+ }
372
+ }
373
+ else
374
+ {
375
+ i++;
376
+ }
377
+ ret++;
378
+ }
379
+ return ret;
380
+ }
381
+
382
+ export function isHKID(s)
383
+ {
384
+ let hkid;
385
+ let chk;
386
+ let ichk;
387
+ if (s.endsWith(')'))
388
+ {
389
+ if (s.length == 10)
390
+ {
391
+ if (s.charAt(7) == '(')
392
+ {
393
+ hkid = s.substring(0, 7);
394
+ chk = s.charAt(8);
395
+ }
396
+ else
397
+ {
398
+ return false;
399
+ }
400
+ }
401
+ else if (s.length == 11)
402
+ {
403
+ if (s.charAt(8) == '(')
404
+ {
405
+ hkid = s.substring(0, 8);
406
+ chk = s.charAt(9);
407
+ }
408
+ else
409
+ {
410
+ return false;
411
+ }
412
+ }
413
+ else
414
+ {
415
+ return false;
416
+ }
417
+ }
418
+ else
419
+ {
420
+ if (s.length == 8)
421
+ {
422
+ hkid = s.substring(0, 7);
423
+ chk = s.charAt(7);
424
+ }
425
+ else if (s.length == 9)
426
+ {
427
+ hkid = s.substring(0, 8);
428
+ chk = s.charAt(8);
429
+ }
430
+ else
431
+ {
432
+ return false;
433
+ }
434
+ }
435
+
436
+ if (charIsDigit(chk, 0))
437
+ ichk = Number.parseInt(chk);
438
+ else if (chk == 'A')
439
+ ichk = 10;
440
+ else
441
+ {
442
+ return false;
443
+ }
444
+
445
+ let thisChk;
446
+ if (hkid.length == 8)
447
+ {
448
+ if (!charIsUpperCase(hkid, 0) ||
449
+ !charIsUpperCase(hkid, 1) ||
450
+ !charIsDigit(hkid, 2) ||
451
+ !charIsDigit(hkid, 3) ||
452
+ !charIsDigit(hkid, 4) ||
453
+ !charIsDigit(hkid, 5) ||
454
+ !charIsDigit(hkid, 6) ||
455
+ !charIsDigit(hkid, 7))
456
+ return false;
457
+
458
+ thisChk = 0;
459
+ thisChk += (hkid.charCodeAt(0) - 0x41 + 10) * 9;
460
+ thisChk += (hkid.charCodeAt(1) - 0x41 + 10) * 8;
461
+ thisChk += (hkid.charCodeAt(2) - 0x30) * 7;
462
+ thisChk += (hkid.charCodeAt(3) - 0x30) * 6;
463
+ thisChk += (hkid.charCodeAt(4) - 0x30) * 5;
464
+ thisChk += (hkid.charCodeAt(5) - 0x30) * 4;
465
+ thisChk += (hkid.charCodeAt(6) - 0x30) * 3;
466
+ thisChk += (hkid.charCodeAt(7) - 0x30) * 2;
467
+ if (ichk != (thisChk % 11))
468
+ return false;
469
+ return true;
470
+ }
471
+ else
472
+ {
473
+ if (!charIsUpperCase(hkid, 0) ||
474
+ !charIsDigit(hkid, 1) ||
475
+ !charIsDigit(hkid, 2) ||
476
+ !charIsDigit(hkid, 3) ||
477
+ !charIsDigit(hkid, 4) ||
478
+ !charIsDigit(hkid, 5) ||
479
+ !charIsDigit(hkid, 6))
480
+ return false;
481
+
482
+ thisChk = 36 * 9;
483
+ thisChk += (hkid.charCodeAt(0) - 0x41 + 10) * 8;
484
+ thisChk += (hkid.charCodeAt(1) - 0x30) * 7;
485
+ thisChk += (hkid.charCodeAt(2) - 0x30) * 6;
486
+ thisChk += (hkid.charCodeAt(3) - 0x30) * 5;
487
+ thisChk += (hkid.charCodeAt(4) - 0x30) * 4;
488
+ thisChk += (hkid.charCodeAt(5) - 0x30) * 3;
489
+ thisChk += (hkid.charCodeAt(6) - 0x30) * 2;
490
+ if (ichk != (thisChk % 11))
491
+ return false;
492
+ return true;
493
+ }
494
+ }
495
+
496
+ export function charIsAlphaNumeric(s, index)
497
+ {
498
+ let c = s.charCodeAt(index);
499
+ if (c >= 0x30 && c <= 0x39)
500
+ return true;
501
+ if (c >= 0x41 && c <= 0x5A)
502
+ return true;
503
+ if (c >= 0x61 && c <= 0x7A)
504
+ return true;
505
+ return false;
506
+ }
507
+
508
+ export function charIsDigit(s, index)
509
+ {
510
+ let c = s.charCodeAt(index);
511
+ if (c >= 0x30 && c <= 0x39)
512
+ return true;
513
+ return false;
514
+ }
515
+
516
+ export function charIsUpperCase(s, index)
517
+ {
518
+ let c = s.charCodeAt(index);
519
+ if (c >= 0x41 && c <= 0x5A)
520
+ return true;
521
+ return false;
522
+ }
523
+
524
+ export function charIsLowerCase(s, index)
525
+ {
526
+ let c = s.charCodeAt(index);
527
+ if (c >= 0x61 && c <= 0x7A)
528
+ return true;
529
+ return false;
530
+ }
531
+
291
532
  export function getEncList()
292
533
  {
293
534
  let ret = [];