mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-20 00:04:22 +02:00
DOCUMENTATION: Add link to NS API documentation (#1460)
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { Settings } from "../Settings/Settings";
|
||||
import { CONSTANTS } from "../Constants";
|
||||
|
||||
/*
|
||||
Converts a date representing time in milliseconds to a string with the format H hours M minutes and S seconds
|
||||
e.g. 10000 -> "10 seconds"
|
||||
120000 -> "2 minutes and 0 seconds"
|
||||
*/
|
||||
function convertTimeMsToTimeElapsedString(time: number, showMilli = false): string {
|
||||
export function convertTimeMsToTimeElapsedString(time: number, showMilli = false): string {
|
||||
const negFlag = time < 0;
|
||||
time = Math.abs(Math.floor(time));
|
||||
const millisecondsPerSecond = 1000;
|
||||
@@ -51,7 +52,7 @@ function convertTimeMsToTimeElapsedString(time: number, showMilli = false): stri
|
||||
}
|
||||
|
||||
// Finds the longest common starting substring in a set of strings
|
||||
function longestCommonStart(strings: string[]): string {
|
||||
export function longestCommonStart(strings: string[]): string {
|
||||
if (!containsAllStrings(strings)) {
|
||||
return "";
|
||||
}
|
||||
@@ -72,12 +73,12 @@ function longestCommonStart(strings: string[]): string {
|
||||
}
|
||||
|
||||
// Returns whether an array contains entirely of string objects
|
||||
function containsAllStrings(arr: string[]): boolean {
|
||||
export function containsAllStrings(arr: string[]): boolean {
|
||||
return arr.every((value) => typeof value === "string");
|
||||
}
|
||||
|
||||
// Generates a random alphanumeric string with N characters
|
||||
function generateRandomString(n: number): string {
|
||||
export function generateRandomString(n: number): string {
|
||||
let str = "";
|
||||
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
@@ -95,7 +96,7 @@ function generateRandomString(n: number): string {
|
||||
* @param seed A seed to randomize the result
|
||||
* @returns An hexadecimal string representation of the hashed input
|
||||
*/
|
||||
function cyrb53(str: string, seed = 0): string {
|
||||
export function cyrb53(str: string, seed = 0): string {
|
||||
let h1 = 0xdeadbeef ^ seed;
|
||||
let h2 = 0x41c6ce57 ^ seed;
|
||||
for (let i = 0, ch; i < str.length; i++) {
|
||||
@@ -108,23 +109,19 @@ function cyrb53(str: string, seed = 0): string {
|
||||
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(16);
|
||||
}
|
||||
|
||||
function capitalizeFirstLetter(s: string): string {
|
||||
export function capitalizeFirstLetter(s: string): string {
|
||||
return s.charAt(0).toUpperCase() + s.slice(1);
|
||||
}
|
||||
|
||||
function capitalizeEachWord(s: string): string {
|
||||
export function capitalizeEachWord(s: string): string {
|
||||
return s
|
||||
.split(" ")
|
||||
.map((word) => capitalizeFirstLetter(word))
|
||||
.join(" ");
|
||||
}
|
||||
|
||||
export {
|
||||
convertTimeMsToTimeElapsedString,
|
||||
longestCommonStart,
|
||||
containsAllStrings,
|
||||
generateRandomString,
|
||||
cyrb53,
|
||||
capitalizeFirstLetter,
|
||||
capitalizeEachWord,
|
||||
};
|
||||
export function getNsApiDocumentationUrl(isDevBranch = CONSTANTS.isDevBranch): string {
|
||||
return `https://github.com/bitburner-official/bitburner-src/blob/${
|
||||
isDevBranch ? "dev" : "stable"
|
||||
}/markdown/bitburner.ns.md`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user