anthelpers 0.1.0 → 0.1.2
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/.idea/workspace.xml +24 -25
- package/Random.js +1 -1
- package/index.js +104 -3
- package/index.ts +100 -4
- package/package.json +1 -1
- package/tests.js +22 -16
package/.idea/workspace.xml
CHANGED
|
@@ -4,21 +4,7 @@
|
|
|
4
4
|
<option name="autoReloadType" value="SELECTIVE" />
|
|
5
5
|
</component>
|
|
6
6
|
<component name="ChangeListManager">
|
|
7
|
-
<list default="true" id="cbb82d94-0dbd-445b-8adb-15f10cc25fd5" name="Changes" comment="
|
|
8
|
-
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
|
9
|
-
<change afterPath="$PROJECT_DIR$/Random.js" afterDir="false" />
|
|
10
|
-
<change afterPath="$PROJECT_DIR$/Random.ts" afterDir="false" />
|
|
11
|
-
<change afterPath="$PROJECT_DIR$/deepEquals.js" afterDir="false" />
|
|
12
|
-
<change afterPath="$PROJECT_DIR$/deepEquals.ts" afterDir="false" />
|
|
13
|
-
<change afterPath="$PROJECT_DIR$/parseBigInt.js" afterDir="false" />
|
|
14
|
-
<change afterPath="$PROJECT_DIR$/parseBigInt.ts" afterDir="false" />
|
|
15
|
-
<change afterPath="$PROJECT_DIR$/promise.d.ts" afterDir="false" />
|
|
16
|
-
<change afterPath="$PROJECT_DIR$/tests.js" afterDir="false" />
|
|
17
|
-
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
|
18
|
-
<change beforePath="$PROJECT_DIR$/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/index.js" afterDir="false" />
|
|
19
|
-
<change beforePath="$PROJECT_DIR$/index.ts" beforeDir="false" afterPath="$PROJECT_DIR$/index.ts" afterDir="false" />
|
|
20
|
-
<change beforePath="$PROJECT_DIR$/tsconfig.json" beforeDir="false" afterPath="$PROJECT_DIR$/tsconfig.json" afterDir="false" />
|
|
21
|
-
</list>
|
|
7
|
+
<list default="true" id="cbb82d94-0dbd-445b-8adb-15f10cc25fd5" name="Changes" comment="0.1.1" />
|
|
22
8
|
<option name="SHOW_DIALOG" value="false" />
|
|
23
9
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
24
10
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
@@ -103,6 +89,16 @@
|
|
|
103
89
|
<workItem from="1760055007271" duration="99000" />
|
|
104
90
|
<workItem from="1760360991867" duration="6060000" />
|
|
105
91
|
<workItem from="1760367500301" duration="5155000" />
|
|
92
|
+
<workItem from="1760381450117" duration="82000" />
|
|
93
|
+
<workItem from="1760450025283" duration="307000" />
|
|
94
|
+
<workItem from="1760465405349" duration="25000" />
|
|
95
|
+
<workItem from="1760624359056" duration="387000" />
|
|
96
|
+
<workItem from="1760624846255" duration="78000" />
|
|
97
|
+
<workItem from="1760692756231" duration="1357000" />
|
|
98
|
+
<workItem from="1760711965130" duration="19000" />
|
|
99
|
+
<workItem from="1760790608185" duration="2527000" />
|
|
100
|
+
<workItem from="1760804107961" duration="81000" />
|
|
101
|
+
<workItem from="1760988620869" duration="190000" />
|
|
106
102
|
</task>
|
|
107
103
|
<task id="LOCAL-00001" summary="git add ,">
|
|
108
104
|
<option name="closed" value="true" />
|
|
@@ -112,28 +108,31 @@
|
|
|
112
108
|
<option name="project" value="LOCAL" />
|
|
113
109
|
<updated>1750701889682</updated>
|
|
114
110
|
</task>
|
|
115
|
-
<
|
|
111
|
+
<task id="LOCAL-00002" summary="0.1.1">
|
|
112
|
+
<option name="closed" value="true" />
|
|
113
|
+
<created>1760988802704</created>
|
|
114
|
+
<option name="number" value="00002" />
|
|
115
|
+
<option name="presentableId" value="LOCAL-00002" />
|
|
116
|
+
<option name="project" value="LOCAL" />
|
|
117
|
+
<updated>1760988802704</updated>
|
|
118
|
+
</task>
|
|
119
|
+
<option name="localTasksCounter" value="3" />
|
|
116
120
|
<servers />
|
|
117
121
|
</component>
|
|
118
122
|
<component name="TypeScriptGeneratedFilesManager">
|
|
119
123
|
<option name="version" value="3" />
|
|
120
124
|
<option name="exactExcludedFiles">
|
|
121
125
|
<list>
|
|
122
|
-
<option value="$PROJECT_DIR$/index.js" />
|
|
123
|
-
<option value="$PROJECT_DIR$/WebWorkers/PromisedWorker.js" />
|
|
124
|
-
<option value="$PROJECT_DIR$/WebWorkers/PromisedWorkerInside.js" />
|
|
125
|
-
<option value="$PROJECT_DIR$/WebWorkers/FetchedWorker.js" />
|
|
126
|
-
<option value="$PROJECT_DIR$/WebWorkers/CustomError.js" />
|
|
127
|
-
<option value="$PROJECT_DIR$/WebWorkers/FetchedWorkerWithin.js" />
|
|
128
126
|
<option value="$PROJECT_DIR$/parseBigInt.js" />
|
|
129
|
-
<option value="$PROJECT_DIR$/deepEquals.js" />
|
|
130
|
-
<option value="$PROJECT_DIR$/WebWorkers/FWClass.js" />
|
|
131
127
|
<option value="$PROJECT_DIR$/Random.js" />
|
|
128
|
+
<option value="$PROJECT_DIR$/deepEquals.js" />
|
|
129
|
+
<option value="$PROJECT_DIR$/index.js" />
|
|
132
130
|
</list>
|
|
133
131
|
</option>
|
|
134
132
|
</component>
|
|
135
133
|
<component name="VcsManagerConfiguration">
|
|
136
134
|
<MESSAGE value="git add ," />
|
|
137
|
-
<
|
|
135
|
+
<MESSAGE value="0.1.1" />
|
|
136
|
+
<option name="LAST_COMMIT_MESSAGE" value="0.1.1" />
|
|
138
137
|
</component>
|
|
139
138
|
</project>
|
package/Random.js
CHANGED
package/index.js
CHANGED
|
@@ -94,16 +94,16 @@ export const EXMAScript = Object.freeze({
|
|
|
94
94
|
}
|
|
95
95
|
throw new TypeError('could not convert to Primitive');
|
|
96
96
|
}, toPrimitive(value, hint) {
|
|
97
|
-
if (!["string", "number"].includes(hint))
|
|
97
|
+
if (!["string", "number", "default"].includes(hint))
|
|
98
98
|
throw new TypeError('incorrect hint');
|
|
99
99
|
let primitive;
|
|
100
100
|
if (value === null)
|
|
101
101
|
return "null";
|
|
102
102
|
if (typeof value === "object" || typeof value === "function") {
|
|
103
103
|
if (Symbol.toPrimitive in value && typeof value[Symbol.toPrimitive] === "function") {
|
|
104
|
-
primitive = value[Symbol.toPrimitive](
|
|
104
|
+
primitive = value[Symbol.toPrimitive](hint);
|
|
105
105
|
if (isObject(primitive))
|
|
106
|
-
throw new TypeError;
|
|
106
|
+
throw new TypeError('could not convert to primitive');
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
109
109
|
primitive = EXMAScript.OrdinaryToPrimitive(value, "string");
|
|
@@ -201,6 +201,9 @@ export const EXMAScript = Object.freeze({
|
|
|
201
201
|
export function ResolveSecondsAfterNow(s = 0) {
|
|
202
202
|
return new Date((new Date).setMilliseconds(0) + (+s) * 1000);
|
|
203
203
|
}
|
|
204
|
+
export function ResolveSecondsAfter(s = 0, now) {
|
|
205
|
+
return new Date((new Date(now ?? Date.now())).setMilliseconds(0) + (+s) * 1000);
|
|
206
|
+
}
|
|
204
207
|
/*
|
|
205
208
|
function ResolveSecondsAfterNow(s=0){return new Date((new Date).setMilliseconds(0)+(+s)*1000)}
|
|
206
209
|
*/
|
|
@@ -335,3 +338,101 @@ export class CounterItems {
|
|
|
335
338
|
return this;
|
|
336
339
|
}
|
|
337
340
|
}
|
|
341
|
+
export function printLn(varaibles) {
|
|
342
|
+
const result = [];
|
|
343
|
+
for (const [keuy, value] of Object.entries(varaibles)) {
|
|
344
|
+
let variable = String(keuy) + '=';
|
|
345
|
+
if (value === null) {
|
|
346
|
+
result.push(`${variable}null`);
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
switch (typeof value) {
|
|
350
|
+
case "string":
|
|
351
|
+
case "symbol":
|
|
352
|
+
variable += JSON.stringify(String(value));
|
|
353
|
+
break;
|
|
354
|
+
case "number":
|
|
355
|
+
variable += JSON.stringify(value);
|
|
356
|
+
break;
|
|
357
|
+
case "bigint":
|
|
358
|
+
variable += String(value) + 'n';
|
|
359
|
+
break;
|
|
360
|
+
case "boolean":
|
|
361
|
+
variable += JSON.stringify(value);
|
|
362
|
+
break;
|
|
363
|
+
case "undefined":
|
|
364
|
+
variable += "undefined";
|
|
365
|
+
break;
|
|
366
|
+
case "object":
|
|
367
|
+
variable += JSON.stringify(value);
|
|
368
|
+
break;
|
|
369
|
+
case "function":
|
|
370
|
+
variable += JSON.stringify(String(value));
|
|
371
|
+
break;
|
|
372
|
+
default:
|
|
373
|
+
throw new TypeError(`typeof value is not recognized (${typeof value})`);
|
|
374
|
+
}
|
|
375
|
+
result.push(variable);
|
|
376
|
+
}
|
|
377
|
+
return result.join('; ');
|
|
378
|
+
}
|
|
379
|
+
function sliceOut_String(string, start, end, strict = false) {
|
|
380
|
+
Object.prototype.valueOf.call(string);
|
|
381
|
+
string = `${string}`;
|
|
382
|
+
const len = string.length;
|
|
383
|
+
const intStart = EXMAScript.toIntegerOrInfinity(start);
|
|
384
|
+
let from;
|
|
385
|
+
if (strict) {
|
|
386
|
+
from = intStart;
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
if (intStart === -Infinity) {
|
|
390
|
+
from = 0;
|
|
391
|
+
}
|
|
392
|
+
else if (intStart < 0) {
|
|
393
|
+
from = Math.max(len + intStart, 0);
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
from = Math.min(intStart, len);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
let intEnd;
|
|
400
|
+
if (end === undefined) {
|
|
401
|
+
intEnd = len;
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
intEnd = EXMAScript.toIntegerOrInfinity(end);
|
|
405
|
+
}
|
|
406
|
+
let to;
|
|
407
|
+
if (strict) {
|
|
408
|
+
to = intEnd;
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
if (intEnd === -Infinity) {
|
|
412
|
+
to = 0;
|
|
413
|
+
}
|
|
414
|
+
else if (intEnd < 0) {
|
|
415
|
+
to = Math.max(len + intEnd, 0);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
to = Math.min(intEnd, len);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (from >= to) {
|
|
422
|
+
if (strict) {
|
|
423
|
+
throw new RangeError(`the normalized value of start (${from}) is greater than the normalized value of end (${to}) in sliceOut_String\'s strict mode`);
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
return "";
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (strict) {
|
|
430
|
+
if (from < 0) {
|
|
431
|
+
throw new RangeError(`start is less than 0 in sliceOut_String\'s strict mode (got ${from})`);
|
|
432
|
+
}
|
|
433
|
+
if (to > len) {
|
|
434
|
+
throw new RangeError(`end is greater than ${len} in sliceOut_String\'s strict mode (got ${to})`);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return (string.slice(0, from) + string.slice(to));
|
|
438
|
+
}
|
package/index.ts
CHANGED
|
@@ -100,15 +100,15 @@ export const EXMAScript = Object.freeze({
|
|
|
100
100
|
}
|
|
101
101
|
throw new TypeError('could not convert to Primitive');
|
|
102
102
|
}, toPrimitive(value: any, hint: "string" | "number" | "default"): EXMAScript_primitive {
|
|
103
|
-
if (!["string", "number"].includes(hint)) throw new TypeError('incorrect hint');
|
|
103
|
+
if (!["string", "number", "default"].includes(hint)) throw new TypeError('incorrect hint');
|
|
104
104
|
let primitive;
|
|
105
105
|
if (value === null) return "null";
|
|
106
106
|
if (typeof value === "object" || typeof value === "function") {
|
|
107
107
|
if (Symbol.toPrimitive in value && typeof value[Symbol.toPrimitive] === "function") {
|
|
108
|
-
primitive = value[Symbol.toPrimitive](
|
|
109
|
-
if (isObject(primitive)) throw new TypeError;
|
|
108
|
+
primitive = value[Symbol.toPrimitive](hint);
|
|
109
|
+
if (isObject(primitive)) throw new TypeError('could not convert to primitive');
|
|
110
110
|
} else {
|
|
111
|
-
primitive = EXMAScript.OrdinaryToPrimitive(value, "
|
|
111
|
+
primitive = EXMAScript.OrdinaryToPrimitive(value, "number");
|
|
112
112
|
}
|
|
113
113
|
} else primitive = value;
|
|
114
114
|
return primitive;
|
|
@@ -210,6 +210,10 @@ export function ResolveSecondsAfterNow(s: number = 0): Date {
|
|
|
210
210
|
return new Date((new Date).setMilliseconds(0) + (+s) * 1000);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
export function ResolveSecondsAfter(s: number = 0, now?: Date | string | number): Date {
|
|
214
|
+
return new Date((new Date(now ?? Date.now())).setMilliseconds(0) + (+s) * 1000);
|
|
215
|
+
}
|
|
216
|
+
|
|
213
217
|
/*
|
|
214
218
|
function ResolveSecondsAfterNow(s=0){return new Date((new Date).setMilliseconds(0)+(+s)*1000)}
|
|
215
219
|
*/
|
|
@@ -352,3 +356,95 @@ export class CounterItems<T> {
|
|
|
352
356
|
return this;
|
|
353
357
|
}
|
|
354
358
|
}
|
|
359
|
+
|
|
360
|
+
export function printLn(varaibles: any) {
|
|
361
|
+
const result = [];
|
|
362
|
+
for (const [keuy, value] of Object.entries(varaibles)) {
|
|
363
|
+
let variable = String(keuy) + '=';
|
|
364
|
+
if (value === null) {
|
|
365
|
+
result.push(`${variable}null`);
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
switch (typeof value) {
|
|
369
|
+
case "string":
|
|
370
|
+
case "symbol":
|
|
371
|
+
variable += JSON.stringify(String(value));
|
|
372
|
+
break;
|
|
373
|
+
case "number":
|
|
374
|
+
variable += JSON.stringify(value);
|
|
375
|
+
break;
|
|
376
|
+
case "bigint":
|
|
377
|
+
variable += String(value) + 'n';
|
|
378
|
+
break;
|
|
379
|
+
case "boolean":
|
|
380
|
+
variable += JSON.stringify(value);
|
|
381
|
+
break;
|
|
382
|
+
case "undefined":
|
|
383
|
+
variable += "undefined";
|
|
384
|
+
break;
|
|
385
|
+
case "object":
|
|
386
|
+
variable += JSON.stringify(value);
|
|
387
|
+
break;
|
|
388
|
+
case "function":
|
|
389
|
+
variable += JSON.stringify(String(value));
|
|
390
|
+
break;
|
|
391
|
+
default:
|
|
392
|
+
throw new TypeError(`typeof value is not recognized (${typeof value})`);
|
|
393
|
+
}
|
|
394
|
+
result.push(variable);
|
|
395
|
+
}
|
|
396
|
+
return result.join('; ');
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function sliceOut_String(string: string, start?: number, end?: number, strict: boolean = false) {
|
|
400
|
+
Object.prototype.valueOf.call(string);
|
|
401
|
+
string = `${string}`;
|
|
402
|
+
const len = string.length;
|
|
403
|
+
const intStart = EXMAScript.toIntegerOrInfinity(start);
|
|
404
|
+
let from;
|
|
405
|
+
if (strict) {
|
|
406
|
+
from = intStart;
|
|
407
|
+
} else {
|
|
408
|
+
if (intStart === -Infinity) {
|
|
409
|
+
from = 0;
|
|
410
|
+
} else if (intStart < 0) {
|
|
411
|
+
from = Math.max(len + intStart, 0);
|
|
412
|
+
} else {
|
|
413
|
+
from = Math.min(intStart, len);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
let intEnd;
|
|
417
|
+
if (end === undefined) {
|
|
418
|
+
intEnd = len;
|
|
419
|
+
} else {
|
|
420
|
+
intEnd = EXMAScript.toIntegerOrInfinity(end);
|
|
421
|
+
}
|
|
422
|
+
let to;
|
|
423
|
+
if (strict) {
|
|
424
|
+
to = intEnd;
|
|
425
|
+
} else {
|
|
426
|
+
if (intEnd === -Infinity) {
|
|
427
|
+
to = 0;
|
|
428
|
+
} else if (intEnd < 0) {
|
|
429
|
+
to = Math.max(len + intEnd, 0);
|
|
430
|
+
} else {
|
|
431
|
+
to = Math.min(intEnd, len);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
if (from >= to) {
|
|
435
|
+
if (strict) {
|
|
436
|
+
throw new RangeError(`the normalized value of start (${from}) is greater than the normalized value of end (${to}) in sliceOut_String\'s strict mode`);
|
|
437
|
+
} else {
|
|
438
|
+
return "";
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (strict) {
|
|
442
|
+
if (from < 0) {
|
|
443
|
+
throw new RangeError(`start is less than 0 in sliceOut_String\'s strict mode (got ${from})`);
|
|
444
|
+
}
|
|
445
|
+
if (to > len) {
|
|
446
|
+
throw new RangeError(`end is greater than ${len} in sliceOut_String\'s strict mode (got ${to})`);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return (string.slice(0, from) + string.slice(to));
|
|
450
|
+
}
|
package/package.json
CHANGED
package/tests.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {jsonEncode, CounterItems} from "./index.js";
|
|
1
|
+
import {parseColorString} from "./index.js";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
// import {WeightedRandomRarity} from "./Random.js";
|
|
4
|
+
// import {jsonEncode, CounterItems} from "./index.js";
|
|
5
|
+
//
|
|
6
|
+
// const random = new WeightedRandomRarity({
|
|
7
|
+
// 'Common': 55,
|
|
8
|
+
// 'Uncommon': 24,
|
|
9
|
+
// 'Rare': 15,
|
|
10
|
+
// 'Ultra-Rare': 5,
|
|
11
|
+
// 'Legendary': 1,
|
|
12
|
+
// }), odds = random.getOdds().asPercents;
|
|
13
|
+
// const itemCounter = new CounterItems();
|
|
14
|
+
// itemCounter.set0('Common').set0('Uncommon').set0('Rare').set0('Ultra-Rare').set0('Legendary');
|
|
15
|
+
// let last = 'unknown';
|
|
16
|
+
// for (let i = 0; i < 100; i++) {
|
|
17
|
+
// itemCounter.add(last = random.next());
|
|
18
|
+
// }
|
|
19
|
+
//
|
|
20
|
+
// console.log(jsonEncode({itemCounter, odds, last}, true));
|
|
17
21
|
|
|
18
|
-
console.log(
|
|
22
|
+
console.log(parseColorString("#00a8f3; #8cfffa;#fff100;#ff4500;#fea700;#fee1b9;#00ff00;#00a8f3;#0073a6;#00587f;#004665;#002d40;#ff4500;#a62c00;#7e2100;#651a00;#401100;#fff100;#a68300;#7e6400;#655000;#403c00;#00ff00;#00a600;#007e00;#006500;#004000;#ff00ff;#a600a6;#7e007e;#650065;#400040;#00ffff;#00a6a6;#007e7e;#006565;#004040;#fea700;#a66d00;#7e5300;#654200;#aeef0f;#7aa60a;#5d7f08;#4a6506;#2f4004;#40bf55;#38a648;#2b7f37;#22652c;#15401c;#8e46db;#6a35a6;#51297f;#402065;#291440;#758eb1;#fefefe;#272727;#fdf5d9;#00bf00;#009500;#0f0f0f;#000000;#fce5bb;#c77f08;#1f1f1f;#151515;#005100;#004000;#ffffff;#f5749d;#f30083;#fee1b9;#0072f3;#004fa9;#616161;#00f331;#ff4500;#87ceeb;#99ffff;#cbffff;#191970;#fe57e8;#35cf38;#5bcffb;#3c8aa6;#2e697f;#255465;#173540;#f5abb9;#a6747d;#7f5960;#65464c;#402d30;#fe8125;#ad0512;#fa5511;").map(String))
|
|
23
|
+
|
|
24
|
+
console.log(parseColorString("#00a8f3;#8cfffa#ad0512;#fa5511;").map(String))
|