@grey-ts/types 1.4.0 → 1.5.0
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/dist/index.d.ts +161 -17
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -206,6 +206,12 @@ declare namespace GreyHack {
|
|
|
206
206
|
* If the provided path cannot be resolved, meaning that no file or folder exists, this method will return null.
|
|
207
207
|
*
|
|
208
208
|
* Providing an empty string for the path will result in an error, interrupting the script execution.
|
|
209
|
+
* @example
|
|
210
|
+
* const computer = getShell().hostComputer;
|
|
211
|
+
* const passwd = computer.file("/etc/passwd");
|
|
212
|
+
* if (passwd) {
|
|
213
|
+
* print(`Content of passwd file\n${passwd.getContent()}`)
|
|
214
|
+
* }
|
|
209
215
|
*/
|
|
210
216
|
file: (path: string) => FileType | null;
|
|
211
217
|
}
|
|
@@ -318,21 +324,17 @@ declare namespace GreyHack {
|
|
|
318
324
|
*
|
|
319
325
|
* Certain limitations apply to file creation: the file name must be alphanumeric and below 128 characters. Creation will fail if there is already a file in place or if permissions are lacking. Additionally, there is a file limit of about 250 in each folder and 3125 files in the computer overall.
|
|
320
326
|
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
327
|
* Using this method in an SSH encryption process will cause an error to be thrown, preventing any further script execution.
|
|
324
328
|
*/
|
|
325
329
|
touch: (destFolder: string, fileName: string) => true | string;
|
|
326
330
|
/**
|
|
327
|
-
* Returns
|
|
331
|
+
* Returns an array of the Wi-Fi networks that are available for the provided interface.
|
|
328
332
|
*
|
|
329
|
-
* Each item in the
|
|
333
|
+
* Each item in the array is a string containing information on the BSSID, PWR, and ESSID.
|
|
330
334
|
*
|
|
331
335
|
* If the active network card is not a Wi-Fi card, an error will be thrown, preventing any further script execution.
|
|
332
336
|
*
|
|
333
|
-
* @returns
|
|
334
|
-
* @returns string with details on failure
|
|
335
|
-
* @returns null if no matching netDevice can be found
|
|
337
|
+
* @returns null if no matching netDevice can be found, otherwise the available networks
|
|
336
338
|
*/
|
|
337
339
|
wifiNetworks: (netDevice: netDevice) => string[] | null;
|
|
338
340
|
}
|
|
@@ -761,12 +763,18 @@ declare namespace GreyHack {
|
|
|
761
763
|
* }
|
|
762
764
|
*/
|
|
763
765
|
function isType<T extends keyof GameTypeMap>(value: any, type: T): value is GameTypeMap[T];
|
|
764
|
-
/**
|
|
766
|
+
/**
|
|
767
|
+
* FOR TRANSPILER ONLY
|
|
765
768
|
*
|
|
766
769
|
* Includes the given source to this position. If the file was already transpiled then this does nothing
|
|
767
770
|
*
|
|
768
771
|
* Can be a folder if you want to include all the files inside
|
|
769
|
-
*
|
|
772
|
+
*
|
|
773
|
+
* @param file The absolute or relative path of the file
|
|
774
|
+
*
|
|
775
|
+
* @example
|
|
776
|
+
* include("./commands");
|
|
777
|
+
*/
|
|
770
778
|
function include(file: string): void;
|
|
771
779
|
type LibTypes = {
|
|
772
780
|
"aptclient.so": GreyHack.AptClient;
|
|
@@ -1064,7 +1072,25 @@ declare namespace GreyHack {
|
|
|
1064
1072
|
*
|
|
1065
1073
|
* So in case a password does not exist in the game world, the decryption will fail.
|
|
1066
1074
|
*
|
|
1067
|
-
* On failure, this method will return null. Using this method in an SSH encryption process will cause an error to be thrown, aborting further script execution.
|
|
1075
|
+
* On failure, this method will return null. Using this method in an SSH encryption process will cause an error to be thrown, aborting further script execution.
|
|
1076
|
+
* @example
|
|
1077
|
+
* const crypto = includeLib("/lib/crypto.so");
|
|
1078
|
+
* if (!isType(crypto, "cryptoLib")) exit("Failed to load crypto.so");
|
|
1079
|
+
*
|
|
1080
|
+
* const computer = getShell().hostComputer;
|
|
1081
|
+
* const passwdFile = computer.file("/etc/passwd");
|
|
1082
|
+
* if (!passwdFile) exit("Failed to get passwd file");
|
|
1083
|
+
*
|
|
1084
|
+
* const lines = passwdFile.getContent()!.split(char(10));
|
|
1085
|
+
* for (const line of lines) {
|
|
1086
|
+
* const parsed = line.split(":");
|
|
1087
|
+
* const username = parsed[0];
|
|
1088
|
+
* const passwordhash = parsed[1];
|
|
1089
|
+
*
|
|
1090
|
+
* const password = crypto.decipher(passwordhash);
|
|
1091
|
+
* print(`Password for user '${username}' is: ${password}`);
|
|
1092
|
+
* }
|
|
1093
|
+
*/
|
|
1068
1094
|
decipher(hash: string): string | null;
|
|
1069
1095
|
/** Decrypts the specified file using the provided key.
|
|
1070
1096
|
*
|
|
@@ -1205,22 +1231,43 @@ declare namespace GreyHack {
|
|
|
1205
1231
|
}
|
|
1206
1232
|
}
|
|
1207
1233
|
interface Math {
|
|
1234
|
+
/** Returns the value of pi to the precision of 6 */
|
|
1208
1235
|
readonly PI: number;
|
|
1236
|
+
/** Returns the absolute value of number. */
|
|
1209
1237
|
readonly abs: (value: number) => number;
|
|
1238
|
+
/** Returns the inverse cosine (in radians) of a number. */
|
|
1210
1239
|
readonly acos: (value: number) => number;
|
|
1240
|
+
/** Returns the inverse sine (in radians) of a number. */
|
|
1211
1241
|
readonly asin: (value: number) => number;
|
|
1242
|
+
/** Returns the inverse tangent (in radians) of a number. */
|
|
1212
1243
|
readonly atan: (y: number, x?: number | undefined) => number;
|
|
1244
|
+
/** Returns number rounded up to the integer value of the provided number. */
|
|
1213
1245
|
readonly ceil: (value: number) => number;
|
|
1246
|
+
/** Returns number rounded down to the integer value of the provided number. */
|
|
1214
1247
|
readonly floor: (value: number) => number;
|
|
1248
|
+
/** Returns the cosine of a number in radians. */
|
|
1215
1249
|
readonly cos: (value: number) => number;
|
|
1250
|
+
/** Returns the sine of a number in radians. */
|
|
1216
1251
|
readonly sin: (value: number) => number;
|
|
1252
|
+
/** Returns the tangent of a number in radians. */
|
|
1217
1253
|
readonly tan: (value: number) => number;
|
|
1254
|
+
/** Returns the square root of a number. */
|
|
1218
1255
|
readonly sqrt: (value: number) => number;
|
|
1219
|
-
|
|
1256
|
+
/** Returns 1 or -1 indicating the sign of the value passed or 0 if the value is 0 */
|
|
1257
|
+
readonly sign: (value: number) => -1 | 0 | 1;
|
|
1258
|
+
/** Returns number rounded to the integer value of the provided number. */
|
|
1220
1259
|
readonly round: (value: number, fixed?: number | undefined) => number;
|
|
1260
|
+
/** Returns a random number between 0 and 1. Optionally a seed number can be provided. */
|
|
1221
1261
|
readonly random: (seed?: number | undefined) => number;
|
|
1262
|
+
/**
|
|
1263
|
+
* Returns the natural logarithm of a number.
|
|
1264
|
+
*
|
|
1265
|
+
* By default, the base is 10. Optionally the base can be changed.
|
|
1266
|
+
*/
|
|
1222
1267
|
readonly log: (value: number, base?: number | undefined) => number;
|
|
1268
|
+
/** Returns the smallest number of the given values */
|
|
1223
1269
|
readonly min: (...values: number[]) => number;
|
|
1270
|
+
/** Returns the largest number of the given values */
|
|
1224
1271
|
readonly max: (...values: number[]) => number;
|
|
1225
1272
|
}
|
|
1226
1273
|
declare var Math: Math;
|
|
@@ -1430,17 +1477,69 @@ interface String {
|
|
|
1430
1477
|
indexOf(value: string, offset?: number): number | null;
|
|
1431
1478
|
indexes(): number[];
|
|
1432
1479
|
insert(index: number, value: string): string;
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1480
|
+
/**
|
|
1481
|
+
* Uses regular expression to check if a string matches a certain pattern.
|
|
1482
|
+
*
|
|
1483
|
+
* If the pattern is empty, the provided {@link https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-options|regexOptions} are invalid, or if the regular expression times out, an error will be thrown, preventing further script execution.
|
|
1484
|
+
*/
|
|
1485
|
+
isMatch(pattern: string | RegExp, regexOptions?: string): boolean;
|
|
1486
|
+
/** Returns the last occurrence of a substring in the string. */
|
|
1487
|
+
lastIndexOf(searchString: string): number;
|
|
1488
|
+
/** Converts all the alphabetic characters in a string to lowercase. */
|
|
1489
|
+
toLowerCase(): string;
|
|
1490
|
+
/** Converts all the alphabetic characters in a string to uppercase. */
|
|
1491
|
+
toUpperCase(): string;
|
|
1492
|
+
/**
|
|
1493
|
+
* Returns an object with all search results for the provided regular expression.
|
|
1494
|
+
*
|
|
1495
|
+
* Each key contains the index and the value contains the matching string.
|
|
1496
|
+
*
|
|
1497
|
+
* If the pattern is empty, the provided {@link https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-options|regexOptions} are invalid, or if the regular expression times out, an error will be thrown, preventing further script execution.
|
|
1498
|
+
*/
|
|
1436
1499
|
matches(pattern: string | RegExp, regexOptions?: string): Record<number, string>;
|
|
1500
|
+
/**
|
|
1501
|
+
* Returns a new string with the provided value removed
|
|
1502
|
+
* @example
|
|
1503
|
+
* const myString = "I will not eat an ice cream!";
|
|
1504
|
+
* const newString = myString.remove("not ");
|
|
1505
|
+
* print(newString); // Prints "I will eat an ice cream!"
|
|
1506
|
+
*/
|
|
1437
1507
|
remove(value: string): string;
|
|
1508
|
+
/**
|
|
1509
|
+
* Returns a string with the replaced content by using regular expressions.
|
|
1510
|
+
*
|
|
1511
|
+
* If the pattern is empty, the provided {@link https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-options|regexOptions} are invalid or if the regular expression times out, an error will be thrown, preventing further script execution.
|
|
1512
|
+
*
|
|
1513
|
+
* @example
|
|
1514
|
+
* const myString = "I am now online";
|
|
1515
|
+
* const newString = myString.replace("online", "offline");
|
|
1516
|
+
* print(newString); // Prints "I am now offline"
|
|
1517
|
+
*/
|
|
1438
1518
|
replace(pattern: string | RegExp, newValue: string, regexOptions?: string): string;
|
|
1519
|
+
/**
|
|
1520
|
+
* Returns an array where each item is a segment of the string, separated by the provided separator string.
|
|
1521
|
+
*
|
|
1522
|
+
* This method uses regular expressions for matching, so remember to escape special characters such as dots.
|
|
1523
|
+
*
|
|
1524
|
+
* In case the pattern is empty, the provided {@link https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-options|regexOptions} are invalid, or the regular expression times out, an error will be thrown, preventing further script execution.
|
|
1525
|
+
*
|
|
1526
|
+
* @example
|
|
1527
|
+
* const csvString = "cat,turtle,dog,mouse";
|
|
1528
|
+
* const animals = csvString.split(",");
|
|
1529
|
+
* print(animals); // Prints ["cat", "turtle", "dog", "mouse"]
|
|
1530
|
+
*/
|
|
1439
1531
|
split(pattern: string | RegExp, regexOptions?: string): string[];
|
|
1532
|
+
/**
|
|
1533
|
+
* Returns a number which is parsed from the string as an integer.
|
|
1534
|
+
*
|
|
1535
|
+
* In case the string is not numeric it will return the original string.
|
|
1536
|
+
*/
|
|
1440
1537
|
toInt(): string | number;
|
|
1538
|
+
/** Removes the leading and trailing white space and line terminator characters from a string. */
|
|
1441
1539
|
trim(): string;
|
|
1442
|
-
|
|
1540
|
+
/** Returns a number which is parsed from the string. In case the string is not numeric it will return a zero. */
|
|
1443
1541
|
val(): number;
|
|
1542
|
+
/** Returns an array where each item is a string representing all available characters in the string. Could be compared to using {@link String.split|split} but with empty separator. */
|
|
1444
1543
|
values(): string[];
|
|
1445
1544
|
/** Returns true if this string starts with the searchString. Otherwise returns false. */
|
|
1446
1545
|
startsWith(searchString: string, position?: number): boolean;
|
|
@@ -1458,9 +1557,13 @@ interface String {
|
|
|
1458
1557
|
* @param end The index to the end of the specified portion of string. The substring includes the characters up to, but not including, the character indicated by end. If this value is not specified, the substring continues to the end of string.
|
|
1459
1558
|
*/
|
|
1460
1559
|
slice(start?: number, end?: number): string;
|
|
1560
|
+
/** Returns a string representation of a string. */
|
|
1561
|
+
toString(): string;
|
|
1461
1562
|
readonly [index: number]: string;
|
|
1462
1563
|
}
|
|
1463
1564
|
interface Number {
|
|
1565
|
+
/** Returns a string representation of a number. */
|
|
1566
|
+
toString(): string;
|
|
1464
1567
|
}
|
|
1465
1568
|
type PropertyKey = number | string | symbol;
|
|
1466
1569
|
interface Object {
|
|
@@ -1477,10 +1580,13 @@ interface Object {
|
|
|
1477
1580
|
shuffle(): null;
|
|
1478
1581
|
sum(): number;
|
|
1479
1582
|
values(): any[];
|
|
1583
|
+
/** Returns a string representation of an object. */
|
|
1584
|
+
toString(): string;
|
|
1480
1585
|
}
|
|
1481
1586
|
interface ObjectConstructor {
|
|
1482
1587
|
new (value?: any): Object;
|
|
1483
1588
|
readonly prototype: Object;
|
|
1589
|
+
/** Determines whether an object has a property with the specified name. */
|
|
1484
1590
|
hasOwn<T extends PropertyKey, U = object>(o: U, key: T): o is (T extends keyof U ? U : U & {
|
|
1485
1591
|
[K in T]: unknown;
|
|
1486
1592
|
});
|
|
@@ -1489,14 +1595,26 @@ interface ObjectConstructor {
|
|
|
1489
1595
|
assign<T extends {}, U, V>(target: T, source: U, source2: V): T & U & V;
|
|
1490
1596
|
assign<T extends {}, U, V, W>(target: T, source: U, source2: V, source3: W): T & U & V & W;
|
|
1491
1597
|
assign(target: object, ...sources: any[]): any;
|
|
1598
|
+
/** Returns an array of keys of the object */
|
|
1492
1599
|
keys<T extends Record<any, any>>(o: T): (Exclude<keyof T, symbol>)[];
|
|
1600
|
+
/** Returns an array of values of the object */
|
|
1601
|
+
values<T extends Record<any, any>>(o: T): (T[keyof T])[];
|
|
1493
1602
|
}
|
|
1494
1603
|
interface Array<T> {
|
|
1495
1604
|
readonly length: number;
|
|
1605
|
+
/** Returns a boolean indicating if the provided index exists in the array */
|
|
1496
1606
|
hasIndex(index: number): boolean;
|
|
1607
|
+
/** Returns the index of the first occurrence of a value in an array, or null if it is not present. */
|
|
1497
1608
|
indexOf(value: T, offset?: number): number | null;
|
|
1609
|
+
/** Returns an array containing the indexes of the array */
|
|
1498
1610
|
indexes(): number[];
|
|
1611
|
+
/** Inserts a value into the array at the provided index. This method mutates the array and returns a reference to the same array. */
|
|
1499
1612
|
insert(index: number, value: T): T[];
|
|
1613
|
+
/**
|
|
1614
|
+
* Returns a concatenated string containing all stringified values inside the list. These values will be separated via the provided separator.
|
|
1615
|
+
*
|
|
1616
|
+
* In case the list exceeds `16777215L` items or the delimiter exceeds 128 characters, this method will throw an error, interrupting further script execution.
|
|
1617
|
+
*/
|
|
1500
1618
|
join(delimiter: string): string;
|
|
1501
1619
|
/** Removes the first element from an array and returns it. If the array is empty, null is returned. */
|
|
1502
1620
|
shift(): T | null;
|
|
@@ -1506,11 +1624,33 @@ interface Array<T> {
|
|
|
1506
1624
|
pop(): T | null;
|
|
1507
1625
|
/** Appends new elements to the end of an array, and returns the new length of the array. */
|
|
1508
1626
|
push(...items: T[]): number;
|
|
1627
|
+
/**
|
|
1628
|
+
* Removes an item from the list with the provided index. Due to the removal the list will get mutated.
|
|
1629
|
+
*/
|
|
1509
1630
|
remove(index: number): null;
|
|
1631
|
+
/**
|
|
1632
|
+
* Changes every value of the array that matches `oldValue` into `newValue`
|
|
1633
|
+
*
|
|
1634
|
+
* This method mutates the array and returns a reference to the same array.
|
|
1635
|
+
*/
|
|
1510
1636
|
replace(oldValue: T, newValue: T, maxCount?: number): T[];
|
|
1511
|
-
|
|
1637
|
+
/** Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array. */
|
|
1638
|
+
reverse(): T;
|
|
1639
|
+
/** Shuffles all values in the array. This method mutates the array. */
|
|
1512
1640
|
shuffle(): null;
|
|
1513
|
-
|
|
1641
|
+
/**
|
|
1642
|
+
* Sorts the values of an array alphanumerically.
|
|
1643
|
+
*
|
|
1644
|
+
* This operation mutates the original array. Optionally, a key can be provided, which is used if the items are objects or arrays. Finally, this method returns the updated array.
|
|
1645
|
+
* @example
|
|
1646
|
+
* const myArray = [{ key: 123 }, { key: 5 }, { key: 17 }];
|
|
1647
|
+
* myArray.sort("key");
|
|
1648
|
+
*
|
|
1649
|
+
* const numbers = [1,2,3,4,5];
|
|
1650
|
+
* numbers.sort()
|
|
1651
|
+
*/
|
|
1652
|
+
sort(key?: PropertyKey | null, ascending?: boolean): T[];
|
|
1653
|
+
/** Returns a sum of all values inside the array. Any non-numeric values will be considered a zero. */
|
|
1514
1654
|
sum(): number;
|
|
1515
1655
|
values(): T[];
|
|
1516
1656
|
/** Combines two or more arrays. This method returns a new array without modifying any existing arrays.
|
|
@@ -1534,9 +1674,13 @@ interface Array<T> {
|
|
|
1534
1674
|
* @param end The end index of the specified portion of the array. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the array.
|
|
1535
1675
|
* */
|
|
1536
1676
|
slice(start?: number, end?: number): T[];
|
|
1677
|
+
/** Returns a string representation of an array. */
|
|
1678
|
+
toString(): string;
|
|
1537
1679
|
[n: number]: T;
|
|
1538
1680
|
}
|
|
1539
1681
|
interface Function {
|
|
1682
|
+
/** Returns a string representation of a function. */
|
|
1683
|
+
toString(): string;
|
|
1540
1684
|
}
|
|
1541
1685
|
declare var String: {
|
|
1542
1686
|
new (value?: any): String;
|