mol_wire_lib 1.0.745 → 1.0.746

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/node.mjs CHANGED
@@ -834,6 +834,8 @@ var $;
834
834
  result = compare_pojo(left, right);
835
835
  else if (!Reflect.getPrototypeOf(left_proto))
836
836
  result = compare_pojo(left, right);
837
+ else if (Symbol.toPrimitive in left)
838
+ result = compare_primitive(left, right);
837
839
  else if (Array.isArray(left))
838
840
  result = compare_array(left, right);
839
841
  else if (left instanceof Set)
@@ -844,8 +846,6 @@ var $;
844
846
  result = compare_buffer(left, right);
845
847
  else if (Symbol.iterator in left)
846
848
  result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
847
- else if (Symbol.toPrimitive in left)
848
- result = compare_primitive(left, right);
849
849
  else
850
850
  result = false;
851
851
  }
package/node.test.js CHANGED
@@ -826,6 +826,8 @@ var $;
826
826
  result = compare_pojo(left, right);
827
827
  else if (!Reflect.getPrototypeOf(left_proto))
828
828
  result = compare_pojo(left, right);
829
+ else if (Symbol.toPrimitive in left)
830
+ result = compare_primitive(left, right);
829
831
  else if (Array.isArray(left))
830
832
  result = compare_array(left, right);
831
833
  else if (left instanceof Set)
@@ -836,8 +838,6 @@ var $;
836
838
  result = compare_buffer(left, right);
837
839
  else if (Symbol.iterator in left)
838
840
  result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
839
- else if (Symbol.toPrimitive in left)
840
- result = compare_primitive(left, right);
841
841
  else
842
842
  result = false;
843
843
  }
@@ -2872,6 +2872,283 @@ var $;
2872
2872
  ;
2873
2873
  "use strict";
2874
2874
  var $;
2875
+ (function ($) {
2876
+ function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
2877
+ return new Proxy(new $mol_range2_array(), {
2878
+ get(target, field) {
2879
+ if (typeof field === 'string') {
2880
+ if (field === 'length')
2881
+ return size();
2882
+ const index = Number(field);
2883
+ if (index < 0)
2884
+ return undefined;
2885
+ if (index >= size())
2886
+ return undefined;
2887
+ if (index === Math.trunc(index))
2888
+ return item(index);
2889
+ }
2890
+ return target[field];
2891
+ },
2892
+ set(target, field) {
2893
+ return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
2894
+ },
2895
+ ownKeys(target) {
2896
+ return [...Array(size())].map((v, i) => String(i)).concat('length');
2897
+ },
2898
+ getOwnPropertyDescriptor(target, field) {
2899
+ if (field === "length")
2900
+ return {
2901
+ value: size(),
2902
+ writable: true,
2903
+ enumerable: false,
2904
+ configurable: false,
2905
+ };
2906
+ const index = Number(field);
2907
+ if (index === Math.trunc(index))
2908
+ return {
2909
+ get: () => this.get(target, field, this),
2910
+ enumerable: true,
2911
+ configurable: true,
2912
+ };
2913
+ return Object.getOwnPropertyDescriptor(target, field);
2914
+ }
2915
+ });
2916
+ }
2917
+ $.$mol_range2 = $mol_range2;
2918
+ class $mol_range2_array extends Array {
2919
+ concat(...tail) {
2920
+ if (tail.length === 0)
2921
+ return this;
2922
+ if (tail.length > 1) {
2923
+ let list = this;
2924
+ for (let item of tail)
2925
+ list = list.concat(item);
2926
+ return list;
2927
+ }
2928
+ return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
2929
+ }
2930
+ filter(check, context) {
2931
+ const filtered = new $mol_range2_array();
2932
+ for (let index = 0; index < this.length; ++index) {
2933
+ const item = this[index];
2934
+ if (check.call(context, item, index, this))
2935
+ filtered.push(item);
2936
+ }
2937
+ return filtered;
2938
+ }
2939
+ forEach(proceed, context) {
2940
+ for (let [key, value] of this.entries())
2941
+ proceed.call(context, value, key, this);
2942
+ }
2943
+ map(proceed, context) {
2944
+ return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
2945
+ }
2946
+ reduce(merge, result) {
2947
+ let index = 0;
2948
+ if (arguments.length === 1) {
2949
+ result = this[index++];
2950
+ }
2951
+ for (; index < this.length; ++index) {
2952
+ result = merge(result, this[index], index, this);
2953
+ }
2954
+ return result;
2955
+ }
2956
+ toReversed() {
2957
+ return $mol_range2(index => this[this.length - 1 - index], () => this.length);
2958
+ }
2959
+ slice(from = 0, to = this.length) {
2960
+ return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
2961
+ }
2962
+ some(check, context) {
2963
+ for (let index = 0; index < this.length; ++index) {
2964
+ if (check.call(context, this[index], index, this))
2965
+ return true;
2966
+ }
2967
+ return false;
2968
+ }
2969
+ every(check, context) {
2970
+ for (let index = 0; index < this.length; ++index) {
2971
+ if (!check.call(context, this[index], index, this))
2972
+ return false;
2973
+ }
2974
+ return true;
2975
+ }
2976
+ reverse() {
2977
+ return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
2978
+ }
2979
+ sort() {
2980
+ return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
2981
+ }
2982
+ [Symbol.toPrimitive]() {
2983
+ return $mol_guid();
2984
+ }
2985
+ }
2986
+ $.$mol_range2_array = $mol_range2_array;
2987
+ })($ || ($ = {}));
2988
+ //mol/range2/range2.ts
2989
+ ;
2990
+ "use strict";
2991
+ var $;
2992
+ (function ($) {
2993
+ $mol_test({
2994
+ 'lazy calls'() {
2995
+ let calls = 0;
2996
+ const list = $mol_range2(index => (++calls, index), () => 10);
2997
+ $mol_assert_ok(list instanceof Array);
2998
+ $mol_assert_equal(list.length, 10);
2999
+ $mol_assert_equal(list[-1], undefined);
3000
+ $mol_assert_equal(list[0], 0);
3001
+ $mol_assert_equal(list[9], 9);
3002
+ $mol_assert_equal(list[9.5], undefined);
3003
+ $mol_assert_equal(list[10], undefined);
3004
+ $mol_assert_equal(calls, 2);
3005
+ },
3006
+ 'infinity list'() {
3007
+ let calls = 0;
3008
+ const list = $mol_range2(index => (++calls, index));
3009
+ $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
3010
+ $mol_assert_equal(list[0], 0);
3011
+ $mol_assert_equal(list[4], 4);
3012
+ $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
3013
+ $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
3014
+ $mol_assert_equal(calls, 3);
3015
+ },
3016
+ 'stringify'() {
3017
+ const list = $mol_range2(i => i, () => 5);
3018
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
3019
+ $mol_assert_equal(list.join(';'), '0;1;2;3;4');
3020
+ },
3021
+ 'for-of'() {
3022
+ let log = '';
3023
+ for (let i of $mol_range2(i => i + 1, () => 5)) {
3024
+ log += i;
3025
+ }
3026
+ $mol_assert_equal(log, '12345');
3027
+ },
3028
+ 'for-in'() {
3029
+ let log = '';
3030
+ for (let i in $mol_range2(i => i, () => 5)) {
3031
+ log += i;
3032
+ }
3033
+ $mol_assert_equal(log, '01234');
3034
+ },
3035
+ 'forEach'() {
3036
+ let log = '';
3037
+ $mol_range2(i => i, () => 5).forEach(i => log += i);
3038
+ $mol_assert_equal(log, '01234');
3039
+ },
3040
+ 'lazy concat'() {
3041
+ let calls1 = 0;
3042
+ let calls2 = 0;
3043
+ const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
3044
+ $mol_assert_ok(list instanceof Array);
3045
+ $mol_assert_equal(list.length, 15);
3046
+ $mol_assert_equal(list[0], 0);
3047
+ $mol_assert_equal(list[4], 4);
3048
+ $mol_assert_equal(list[5], 0);
3049
+ $mol_assert_equal(list[9], 4);
3050
+ $mol_assert_equal(list[10], 0);
3051
+ $mol_assert_equal(list[14], 4);
3052
+ $mol_assert_equal(list[15], undefined);
3053
+ $mol_assert_equal(calls1, 2);
3054
+ $mol_assert_equal(calls2, 2);
3055
+ },
3056
+ 'filter'() {
3057
+ let calls = 0;
3058
+ const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
3059
+ $mol_assert_ok(list instanceof Array);
3060
+ $mol_assert_equal(list.length, 3);
3061
+ $mol_assert_equal(list[0], 1);
3062
+ $mol_assert_equal(list[2], 5);
3063
+ $mol_assert_equal(list[3], undefined);
3064
+ $mol_assert_equal(calls, 10);
3065
+ },
3066
+ 'reverse'() {
3067
+ let calls = 0;
3068
+ const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
3069
+ $mol_assert_ok(list instanceof Array);
3070
+ $mol_assert_equal(list.length, 3);
3071
+ $mol_assert_equal(list[0], 9);
3072
+ $mol_assert_equal(list[2], 7);
3073
+ $mol_assert_equal(list[3], undefined);
3074
+ $mol_assert_equal(calls, 2);
3075
+ },
3076
+ 'reduce'() {
3077
+ let calls = 0;
3078
+ const list = $mol_range2().slice(1, 6);
3079
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
3080
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
3081
+ },
3082
+ 'lazy map'() {
3083
+ let calls1 = 0;
3084
+ let calls2 = 0;
3085
+ const source = $mol_range2(index => (++calls1, index), () => 5);
3086
+ const target = source.map((item, index, self) => {
3087
+ ++calls2;
3088
+ $mol_assert_equal(source, self);
3089
+ return index + 10;
3090
+ }, () => 5);
3091
+ $mol_assert_ok(target instanceof Array);
3092
+ $mol_assert_equal(target.length, 5);
3093
+ $mol_assert_equal(target[0], 10);
3094
+ $mol_assert_equal(target[4], 14);
3095
+ $mol_assert_equal(target[5], undefined);
3096
+ $mol_assert_equal(calls1, 2);
3097
+ $mol_assert_equal(calls2, 2);
3098
+ },
3099
+ 'lazy slice'() {
3100
+ let calls = 0;
3101
+ const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
3102
+ $mol_assert_ok(list instanceof Array);
3103
+ $mol_assert_equal(list.length, 4);
3104
+ $mol_assert_equal(list[0], 3);
3105
+ $mol_assert_equal(list[3], 6);
3106
+ $mol_assert_equal(list[4], undefined);
3107
+ $mol_assert_equal(calls, 2);
3108
+ },
3109
+ 'lazy some'() {
3110
+ let calls = 0;
3111
+ $mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
3112
+ $mol_assert_equal(calls, 3);
3113
+ $mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
3114
+ $mol_assert_ok($mol_range2(i => i).some(v => v > 5));
3115
+ },
3116
+ 'lazy every'() {
3117
+ let calls = 0;
3118
+ $mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
3119
+ $mol_assert_equal(calls, 3);
3120
+ $mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
3121
+ $mol_assert_not($mol_range2(i => i).every(v => v < 5));
3122
+ },
3123
+ 'lazyfy'() {
3124
+ let calls = 0;
3125
+ const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
3126
+ $mol_assert_ok(list instanceof Array);
3127
+ $mol_assert_equal(list.length, 4);
3128
+ $mol_assert_equal(calls, 0);
3129
+ $mol_assert_equal(list[0], 12);
3130
+ $mol_assert_equal(list[3], 15);
3131
+ $mol_assert_equal(list[4], undefined);
3132
+ $mol_assert_equal(calls, 2);
3133
+ },
3134
+ 'prevent modification'() {
3135
+ const list = $mol_range2(i => i, () => 5);
3136
+ $mol_assert_fail(() => list.push(4), TypeError);
3137
+ $mol_assert_fail(() => list.pop(), TypeError);
3138
+ $mol_assert_fail(() => list.unshift(4), TypeError);
3139
+ $mol_assert_fail(() => list.shift(), TypeError);
3140
+ $mol_assert_fail(() => list.splice(1, 2), TypeError);
3141
+ $mol_assert_fail(() => list[1] = 2, TypeError);
3142
+ $mol_assert_fail(() => list.reverse(), TypeError);
3143
+ $mol_assert_fail(() => list.sort(), TypeError);
3144
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
3145
+ }
3146
+ });
3147
+ })($ || ($ = {}));
3148
+ //mol/range2/range2.test.ts
3149
+ ;
3150
+ "use strict";
3151
+ var $;
2875
3152
  (function ($) {
2876
3153
  $mol_test({
2877
3154
  'nulls & undefineds'() {
@@ -2901,6 +3178,8 @@ var $;
2901
3178
  $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
2902
3179
  $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
2903
3180
  $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
3181
+ $mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
3182
+ $mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
2904
3183
  },
2905
3184
  'Non POJO are different'() {
2906
3185
  class Thing extends Object {