wenay-common 1.0.84 → 1.0.86

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.
@@ -40,9 +40,11 @@ export declare namespace BSearch {
40
40
  var LESS_OR_EQUAL: E_MATCH;
41
41
  var GREAT_OR_EQUAL: E_MATCH;
42
42
  }
43
+ export declare const BSearchAsync: typeof ___BSearchAsync;
43
44
  export declare function BSearchDefault<T extends {
44
45
  valueOf(): number;
45
46
  }>(array: ArrayLike<T>, value: T, match?: SearchMatchMode, mode?: SortMode): number;
47
+ declare function ___BSearchAsync<T>(length: number, compareIndexToValue: (index: number) => Promise<number>, matchMode?: SearchMatchMode, sortMode?: SortMode): Promise<number>;
46
48
  export declare function BSearchNearest(array: ArrayLike<number>, searchValue: number, maxDelta?: number): number;
47
49
  export declare function BSearchNearest<T>(array: ArrayLike<T>, searchValue: number, arrayGetValue: (element: T) => number, maxDelta?: number): number;
48
50
  export declare function _BSearchNearest<T>(array: ArrayLike<T>, searchValue: number, arrayGetValue: (element: T) => number, maxDelta?: number): number;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CCachedValue2 = exports.CCachedValueT = exports.WeakMapExt = exports.MapExt = exports.CObjectID = exports.shallowEqual = exports.deepEqual = exports.copyToClipboard = exports.Mutex = exports.MyTimerInterval = exports.createCancellableTaskWrapper = exports.createCancellableTimer = exports.CancelablePromise = exports.CancelToken = exports.JSON_clone = exports.VirtualItems = exports.ArraySet = exports.ArrayMap = exports.StructSet = exports.StructMap = exports.MyNumMap = exports.MyMap = exports.__MyMap = exports.CreateArrayProxy = exports.ArrayItemHandler = exports.DblToStrAuto = exports.GetDblPrecision = exports.GetDblPrecision2 = exports.MaxCommonDivisorOnArray = exports.MaxCommonDivisor = exports.NormalizeDouble = exports._BSearchNearest = exports.BSearchNearest = exports.BSearchDefault = exports.BSearch = exports.E_MATCH = exports.E_SORTMODE = exports.GetEnumValues = exports.CBase = exports.sleepAsync = exports.readonlyFull = exports.toImmutable = exports.deepCloneObjectMutable = exports.deepCloneObject = exports.deepCloneMutable = exports.deepClone = exports._deepClone = exports.shallowClone = exports.isDate = exports.GetEnumKeys = void 0;
4
- exports.isObjectCastableTo = void 0;
3
+ exports.CCachedValueT = exports.WeakMapExt = exports.MapExt = exports.CObjectID = exports.shallowEqual = exports.deepEqual = exports.copyToClipboard = exports.Mutex = exports.MyTimerInterval = exports.createCancellableTaskWrapper = exports.createCancellableTimer = exports.CancelablePromise = exports.CancelToken = exports.JSON_clone = exports.VirtualItems = exports.ArraySet = exports.ArrayMap = exports.StructSet = exports.StructMap = exports.MyNumMap = exports.MyMap = exports.__MyMap = exports.CreateArrayProxy = exports.ArrayItemHandler = exports.DblToStrAuto = exports.GetDblPrecision = exports.GetDblPrecision2 = exports.MaxCommonDivisorOnArray = exports.MaxCommonDivisor = exports.NormalizeDouble = exports._BSearchNearest = exports.BSearchNearest = exports.BSearchDefault = exports.BSearchAsync = exports.BSearch = exports.E_MATCH = exports.E_SORTMODE = exports.GetEnumValues = exports.CBase = exports.sleepAsync = exports.readonlyFull = exports.toImmutable = exports.deepCloneObjectMutable = exports.deepCloneObject = exports.deepCloneMutable = exports.deepClone = exports._deepClone = exports.shallowClone = exports.isDate = exports.GetEnumKeys = void 0;
4
+ exports.isObjectCastableTo = exports.CCachedValue2 = void 0;
5
5
  function GetEnumKeys(T) { return Object.keys(T).filter(k => isNaN(k)); }
6
6
  exports.GetEnumKeys = GetEnumKeys;
7
7
  function isDate(value) {
@@ -103,6 +103,8 @@ function BSearch(array, arg2, arg3, ...args) {
103
103
  BSearchDefault(array, arg2, arg3, ...args);
104
104
  }
105
105
  exports.BSearch = BSearch;
106
+ const BSearchAsync = (...a) => ___BSearchAsync(...a);
107
+ exports.BSearchAsync = BSearchAsync;
106
108
  function BSearchDefault(array, value, match, mode) {
107
109
  return __BSearch(array, value, (a, b) => Math.sign(a.valueOf() - b.valueOf()), match, mode);
108
110
  }
@@ -110,6 +112,44 @@ exports.BSearchDefault = BSearchDefault;
110
112
  function __BSearch(array, value, comparer, matchMode, sortMode) {
111
113
  return ___BSearch(array, (item) => comparer(item, value), matchMode, sortMode);
112
114
  }
115
+ async function ___BSearchAsync(length, compareIndexToValue, matchMode, sortMode) {
116
+ if (sortMode == undefined)
117
+ sortMode = E_SORTMODE.ASCEND;
118
+ let k = (sortMode === E_SORTMODE.DESCEND || sortMode == "descend" ? -1 : sortMode === E_SORTMODE.ASCEND || sortMode == "ascend" ? 1 : (() => { throw "wrong sortMode: " + JSON.stringify(sortMode); })());
119
+ let match = typeof matchMode != "string" ? matchMode : matchMode == "equal" ? E_MATCH.EQUAL : matchMode == "lessOrEqual" ? E_MATCH.LESS_OR_EQUAL : matchMode == "greatOrEqual" ? E_MATCH.GREAT_OR_EQUAL : (() => { throw ("wrong matchMode!"); })();
120
+ let start = 0;
121
+ let count = length;
122
+ let end = start + count - 1;
123
+ let left = start;
124
+ let right = end;
125
+ let i = left;
126
+ while (left <= right) {
127
+ i = (left + right) >> 1;
128
+ let cmp = await compareIndexToValue(i) * k;
129
+ if (cmp > 0) {
130
+ right = i - 1;
131
+ continue;
132
+ }
133
+ if (cmp < 0) {
134
+ left = i + 1;
135
+ continue;
136
+ }
137
+ return i;
138
+ }
139
+ if (match == E_MATCH.LESS_OR_EQUAL) {
140
+ i = right;
141
+ if (i < start)
142
+ i = -1;
143
+ }
144
+ else if (match == E_MATCH.GREAT_OR_EQUAL) {
145
+ i = left;
146
+ if (i > end)
147
+ i = -1;
148
+ }
149
+ else
150
+ i = -1;
151
+ return i;
152
+ }
113
153
  function ___BSearch(array, compareItemToValue, matchMode, sortMode) {
114
154
  if (sortMode == undefined)
115
155
  sortMode = E_SORTMODE.ASCEND;
package/package.json CHANGED
@@ -1,20 +1,14 @@
1
1
  {
2
2
  "name": "wenay-common",
3
- "version": "1.0.84",
3
+ "version": "1.0.86",
4
4
  "description": "math math math",
5
5
  "strict": true,
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
8
- "scripts": {
9
- "build": "tsc",
10
- "test": "",
11
- "prepare": "npm run build",
12
- "prepublishOnly": "npm test"
13
- },
14
8
  "files": [
15
9
  "lib/**/*"
16
10
  ],
17
- "author": "wenay",
11
+ "author": "perfectoff",
18
12
  "license": "ISC",
19
13
  "type": "commonjs",
20
14
  "engines": {
@@ -28,19 +22,8 @@
28
22
  "axios": "^1.4.0",
29
23
  "create-hmac": "^1.1.7",
30
24
  "node-fetch": "^3.3.1",
31
- "npm": "^9.6.7",
32
- "ts-node": "^10.9.1",
33
- "wenay-common": "^1.0.69",
34
25
  "xmlhttprequest": "^1.8.0"
35
26
  },
36
- "devDependencies": {
37
- "@types/create-hmac": "^1.1.0",
38
- "@types/dotenv": "^8.2.0",
39
- "@types/node": "^18.7.14",
40
- "@types/validator": "^13.1.0",
41
- "dotenv": "^8.2.0",
42
- "typescript": "^5.1.3"
43
- },
44
27
  "optionalDependencies": {
45
28
  "utf-8-validate": "^6.0.3"
46
29
  },