nv-facutil-slct-ta 1.1.4 → 1.1.5

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.
Files changed (2) hide show
  1. package/index.js +47 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -261,12 +261,13 @@ function get_ta_cls_with_max_cnt(cnt,using_u64_when_gt_safe_f64_int=false) {
261
261
  function get_byt_from_cls(Cls) {
262
262
  return CLS2BYT.get(Cls)
263
263
  }
264
+ function get_cls_from_byt(byt) {
265
+ return DUMP_ONE_BYTE_TYPE_MP[byt]??Float64Array
266
+ }
264
267
  function get_fst_byte_for_dump(Cls) { //旧代码兼容
265
268
  return CLS2BYT.get(Cls)
266
269
  }
267
-
268
-
269
- function get_cls_from_dump_fst_byte(byt) {
270
+ function get_cls_from_dump_fst_byte(byt) { //旧代码兼容
270
271
  return DUMP_ONE_BYTE_TYPE_MP[byt]??Float64Array
271
272
  }
272
273
 
@@ -552,6 +553,46 @@ const write_dv_with_cls = (dv, Cls, offset, value, little_endian = true) => {
552
553
  };
553
554
 
554
555
 
556
+ const fmt_underlying = (underlying)=>{
557
+ if(underlying === null || underlying === undefined) {
558
+ return {
559
+ src:null,
560
+ offset:0
561
+ }
562
+ } else if(is_ablike(underlying)) {
563
+ return {
564
+ src:underlying,
565
+ offset:0,
566
+ }
567
+ } else {
568
+ return {
569
+ src:underlying.src??null,
570
+ offset:underlying.offset??0
571
+ }
572
+ }
573
+ }
574
+
575
+ //inline 为true 时,会自动忽略 .ptr 此时ptr自动计算
576
+ const fmt_data = (data)=>{
577
+ if(data === null || data === true || data === undefined || Boolean(data?.inline) === true) {
578
+ return {
579
+ ptr: undefined, //自动计算
580
+ inline:true,
581
+ }
582
+ } else if(typeof(data) === "number" || typeof(data)==="bigint") { //只填写 ptr 后视作非inline
583
+ return {
584
+ ptr: parseInt(Number(data)),
585
+ inline:false,
586
+ }
587
+ } else {
588
+ return {
589
+ ptr: parseInt(Number(data.ptr??0)),
590
+ inline: Boolean(data.inline)
591
+ }
592
+ }
593
+ }
594
+
595
+
555
596
  module.exports = {
556
597
  tcate, is_signed_int_cls , is_unsigned_int_cls,
557
598
  ////
@@ -561,6 +602,7 @@ module.exports = {
561
602
  calc_max_incr_cnt,
562
603
  get_ta_cls_with_max_cnt,
563
604
  get_byt_from_cls,
605
+ get_cls_from_byt,
564
606
  get_cls_from_dump_fst_byte,
565
607
  get_fst_byte_for_dump,
566
608
  set_fst_byte_for_dump,
@@ -608,4 +650,6 @@ module.exports = {
608
650
  read_dv_with_cls,
609
651
  write_dv_with_cls,
610
652
  ////
653
+ fmt_underlying,
654
+ fmt_data,
611
655
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nv-facutil-slct-ta",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"