From f27664657909ceac9b8c18735f7cafe00cfce74b Mon Sep 17 00:00:00 2001 From: G4mingJon4s Date: Fri, 16 Aug 2024 12:39:14 +0200 Subject: [PATCH 1/2] moved formatting functions to interface --- package-lock.json | 9 -- package.json | 1 - src/Netscript/RamCostGenerator.ts | 13 +- src/NetscriptFunctions.ts | 42 +----- src/NetscriptFunctions/Format.ts | 38 +++++ src/ScriptEditor/NetscriptDefinitions.d.ts | 153 ++++++++++----------- 6 files changed, 122 insertions(+), 134 deletions(-) create mode 100644 src/NetscriptFunctions/Format.ts diff --git a/package-lock.json b/package-lock.json index 8ccc7d8cc0..8e76dc20c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,7 +35,6 @@ "material-ui-popup-state": "^1.9.3", "monaco-vim": "^0.3.5", "notistack": "^2.0.8", - "numeral": "^2.0.6", "prop-types": "^15.8.1", "react": "^17.0.2", "react-beautiful-dnd": "^13.1.1", @@ -14656,14 +14655,6 @@ "url": "https://github.com/fb55/nth-check?sponsor=1" } }, - "node_modules/numeral": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/numeral/-/numeral-2.0.6.tgz", - "integrity": "sha512-qaKRmtYPZ5qdw4jWJD6bxEf1FJEqllJrwxCLIm0sQU/A7v2/czigzOb+C2uSiFsa9lBUzeH7M1oK+Q+OLxL3kA==", - "engines": { - "node": "*" - } - }, "node_modules/nwsapi": { "version": "2.2.7", "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.7.tgz", diff --git a/package.json b/package.json index 2225cea017..a125403927 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "material-ui-popup-state": "^1.9.3", "monaco-vim": "^0.3.5", "notistack": "^2.0.8", - "numeral": "^2.0.6", "prop-types": "^15.8.1", "react": "^17.0.2", "react-beautiful-dnd": "^13.1.1", diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index b57979d652..6982e9aa2f 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -222,6 +222,13 @@ const singularity = { getCurrentWork: SF4Cost(0.5), } as const; +const format = { + number: 0, + ram: 0, + percent: 0, + time: 0, +} as const; + // Gang API const gang = { createGang: RamCostConstants.GangApiBase / 4, @@ -473,6 +480,7 @@ export const RamCosts: RamCostTree = { hacknet, stock, singularity, + format, gang, go, bladeburner, @@ -579,11 +587,6 @@ export const RamCosts: RamCostTree = { getScriptExpGain: RamCostConstants.GetScript, getRunningScript: RamCostConstants.GetRunningScript, ramOverride: 0, - formatNumber: 0, - formatRam: 0, - formatPercent: 0, - nFormat: 0, - tFormat: 0, getTimeSinceLastAug: RamCostConstants.GetHackTime, prompt: 0, wget: 0, diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index d44b685205..3ee631ab95 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -60,7 +60,6 @@ import { formatRam, formatSecurity, formatThreads, - formatNumber, } from "./ui/formatNumber"; import { convertTimeMsToTimeElapsedString } from "./utils/StringHelperFunctions"; import { roundToTwo } from "./utils/helpers/roundToTwo"; @@ -97,7 +96,6 @@ import { ScriptDeath } from "./Netscript/ScriptDeath"; import { getBitNodeMultipliers } from "./BitNode/BitNode"; import { assert, arrayAssert, stringAssert, objectAssert } from "./utils/helpers/typeAssertion"; import { escapeRegExp } from "lodash"; -import numeral from "numeral"; import { clearPort, peekPort, portHandle, readPort, tryWritePort, writePort, nextPortWrite } from "./NetscriptPort"; import { FilePath, resolveFilePath } from "./Paths/FilePath"; import { hasScriptExtension } from "./Paths/ScriptFilePath"; @@ -112,6 +110,7 @@ import { assertFunction } from "./Netscript/TypeAssertion"; import { Router } from "./ui/GameRoot"; import { Page } from "./ui/Router"; import { canAccessBitNodeFeature, validBitNodes } from "./BitNode/BitNodeUtils"; +import { NetscriptFormat } from "./NetscriptFunctions/Format"; export const enums: NSEnums = { CityName, @@ -132,6 +131,7 @@ export type NSFull = Readonly = { singularity: NetscriptSingularity(), + format: NetscriptFormat(), gang: NetscriptGang(), go: NetscriptGo(), bladeburner: NetscriptBladeburner(), @@ -1594,44 +1594,6 @@ export const ns: InternalAPI = { } return runningScript.onlineExpGained / runningScript.onlineRunningTime; }, - formatNumber: - (ctx) => - (_n, _fractionalDigits = 3, _suffixStart = 1000, isInteger) => { - const n = helpers.number(ctx, "n", _n); - const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits); - const suffixStart = helpers.number(ctx, "suffixStart", _suffixStart); - return formatNumber(n, fractionalDigits, suffixStart, !!isInteger); - }, - formatRam: - (ctx) => - (_n, _fractionalDigits = 2) => { - const n = helpers.number(ctx, "n", _n); - const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits); - return formatRam(n, fractionalDigits); - }, - formatPercent: - (ctx) => - (_n, _fractionalDigits = 2, _multStart = 1e6) => { - const n = helpers.number(ctx, "n", _n); - const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits); - const multStart = helpers.number(ctx, "multStart", _multStart); - return formatPercent(n, fractionalDigits, multStart); - }, - // Todo: Remove function for real though in 2.4. Until then it just directly wraps numeral. - nFormat: (ctx) => (_n, _format) => { - deprecationWarning( - "ns.nFormat", - "Use ns.formatNumber, formatRam, formatPercent, or js builtins like Intl.NumberFormat instead.", - ); - const n = helpers.number(ctx, "n", _n); - const format = helpers.string(ctx, "format", _format); - return numeral(n).format(format); - }, - tFormat: (ctx) => (_milliseconds, _milliPrecision) => { - const milliseconds = helpers.number(ctx, "milliseconds", _milliseconds); - const milliPrecision = !!_milliPrecision; - return convertTimeMsToTimeElapsedString(milliseconds, milliPrecision); - }, getTimeSinceLastAug: () => () => { deprecationWarning( "ns.getTimeSinceLastAug()", diff --git a/src/NetscriptFunctions/Format.ts b/src/NetscriptFunctions/Format.ts new file mode 100644 index 0000000000..c87a59a7eb --- /dev/null +++ b/src/NetscriptFunctions/Format.ts @@ -0,0 +1,38 @@ +import { Format } from "@nsdefs"; +import { InternalAPI } from "src/Netscript/APIWrapper"; +import { helpers } from "../Netscript/NetscriptHelpers"; +import { formatNumber, formatPercent, formatRam } from "../ui/formatNumber"; +import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions"; + +export function NetscriptFormat(): InternalAPI { + return { + number: + (ctx) => + (_n, _fractionalDigits = 3, _suffixStart = 1000, isInteger) => { + const n = helpers.number(ctx, "n", _n); + const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits); + const suffixStart = helpers.number(ctx, "suffixStart", _suffixStart); + return formatNumber(n, fractionalDigits, suffixStart, !!isInteger); + }, + ram: + (ctx) => + (_n, _fractionalDigits = 2) => { + const n = helpers.number(ctx, "n", _n); + const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits); + return formatRam(n, fractionalDigits); + }, + percent: + (ctx) => + (_n, _fractionalDigits = 2, _multStart = 1e6) => { + const n = helpers.number(ctx, "n", _n); + const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits); + const multStart = helpers.number(ctx, "multStart", _multStart); + return formatPercent(n, fractionalDigits, multStart); + }, + time: (ctx) => (_milliseconds, _milliPrecision) => { + const milliseconds = helpers.number(ctx, "milliseconds", _milliseconds); + const milliPrecision = !!_milliPrecision; + return convertTimeMsToTimeElapsedString(milliseconds, milliPrecision); + }, + }; +} diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index f52f84f9a8..0cafbc5363 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -3681,6 +3681,74 @@ export interface CodingContract { getContractTypes(): string[]; } +/** + * Format API + * @public + */ +export interface Format { + /** + * Format a number. + * @remarks + * RAM cost: 0 GB + * + * Converts a number into a numeric string with the specified format options. + * This is the same function that the game itself uses to display numbers. The format also depends on the Numeric + * Display settings (all options on the "Numeric Display" options page) + * To format ram or percentages, see {@link Format.ram | format.ram} and {@link Format.percent | format.percent} + * + * @param n - Number to format. + * @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 3. + * @param suffixStart - How high a number must be before a suffix will be added. Optional, defaults to 1000. + * @param isInteger - Whether the number represents an integer. Integers do not display fractional digits until a suffix is present. Optional, defaults to false. + * @returns Formatted number. + */ + number(n: number, fractionalDigits?: number, suffixStart?: number, isInteger?: boolean): string; + + /** + * Format a number as an amount of ram. + * @remarks + * RAM cost: 0 GB + * + * Converts a number into a ram string with the specified number of fractional digits. + * This is the same function that the game itself uses to display ram. The format also depends on the Numeric Display + * settings (all options on the "Numeric Display" options page) + * To format plain numbers or percentages, see {@link Format.number | format.number} and {@link Format.percent | format.percent} + * + * @param n - Number to format as an amount of ram, in base units of GB (or GiB if that Numeric Display option is set). + * @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 2. + * @returns Formatted ram amount. + */ + ram(n: number, fractionalDigits?: number): string; + + /** + * Format a number as a percentage. + * @remarks + * RAM cost: 0 GB + * + * Converts a number into a percentage string with the specified number of fractional digits. + * This is the same function that the game itself uses to display percentages. The format also depends on the Numeric + * Display settings (all options on the "Numeric Display" options page) + * To format plain numbers or ram, see {@link Format.number | format.number} and {@link Format.ram | format.ram} + * + * @param n - Number to format as a percentage. + * @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 2. + * @param suffixStart - When to switch the percentage to a multiplier. Default is 1e6 or x1.00m. + * @returns Formatted percentage. + */ + percent(n: number, fractionalDigits?: number, suffixStart?: number): string; + + /** + * Format time to a readable string. + * @remarks + * RAM cost: 0 GB + * + * @param milliseconds - Number of millisecond to format. + * @param milliPrecision - Format time with subsecond precision. Defaults to false. + * @returns The formatted time. + */ + time(milliseconds: number, milliPrecision?: boolean): string; +} + /** * Gang API * @remarks @@ -5437,6 +5505,12 @@ export interface NS { */ readonly codingcontract: CodingContract; + /** + * Namespace for formatting functions. + * @remarks RAM cost: 0 GB + */ + readonly format: Format; + /** * Namespace for gang functions. Contains spoilers. * @remarks RAM cost: 0 GB @@ -7290,85 +7364,6 @@ export interface NS { */ vsprintf(format: string, args: any[]): string; - /** - * Format a number. - * @remarks - * RAM cost: 0 GB - * - * Converts a number into a numeric string with the specified format options. - * This is the same function that the game itself uses to display numbers. The format also depends on the Numeric - * Display settings (all options on the "Numeric Display" options page) - * To format ram or percentages, see {@link NS.formatRam | formatRam} and {@link NS.formatPercent | formatPercent} - * - * @param n - Number to format. - * @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 3. - * @param suffixStart - How high a number must be before a suffix will be added. Optional, defaults to 1000. - * @param isInteger - Whether the number represents an integer. Integers do not display fractional digits until a suffix is present. Optional, defaults to false. - * @returns Formatted number. - */ - formatNumber(n: number, fractionalDigits?: number, suffixStart?: number, isInteger?: boolean): string; - - /** - * Format a number as an amount of ram. - * @remarks - * RAM cost: 0 GB - * - * Converts a number into a ram string with the specified number of fractional digits. - * This is the same function that the game itself uses to display ram. The format also depends on the Numeric Display - * settings (all options on the "Numeric Display" options page) - * To format plain numbers or percentages, see {@link NS.formatNumber | formatNumber} and {@link NS.formatPercent | formatPercent} - * - * @param n - Number to format as an amount of ram, in base units of GB (or GiB if that Numeric Display option is set). - * @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 2. - * @returns Formatted ram amount. - */ - formatRam(n: number, fractionalDigits?: number): string; - - /** - * Format a number as a percentage. - * @remarks - * RAM cost: 0 GB - * - * Converts a number into a percentage string with the specified number of fractional digits. - * This is the same function that the game itself uses to display percentages. The format also depends on the Numeric - * Display settings (all options on the "Numeric Display" options page) - * To format plain numbers or ram, see {@link NS.formatNumber | formatNumber} and {@link NS.formatRam | formatRam} - * - * @param n - Number to format as a percentage. - * @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 2. - * @param suffixStart - When to switch the percentage to a multiplier. Default is 1e6 or x1.00m. - * @returns Formatted percentage. - */ - formatPercent(n: number, fractionalDigits?: number, suffixStart?: number): string; - - /** - * Format a number using the numeral library. This function is deprecated and will be removed in 2.4. - * @deprecated Use ns.formatNumber, formatRam, or formatPercent instead. Will be removed in 2.4. - * @remarks - * RAM cost: 0 GB - * - * Converts a number into a string with the specified format options. - * See http://numeraljs.com/#format for documentation on format strings supported. - * - * This function is deprecated and will be removed in 2.3. - * - * @param n - Number to format. - * @param format - Formatting options. See http://numeraljs.com/#format for valid formats. - * @returns Formatted number. - */ - nFormat(n: number, format: string): string; - - /** - * Format time to a readable string. - * @remarks - * RAM cost: 0 GB - * - * @param milliseconds - Number of millisecond to format. - * @param milliPrecision - Format time with subsecond precision. Defaults to false. - * @returns The formatted time. - */ - tFormat(milliseconds: number, milliPrecision?: boolean): string; - /** * Prompt the player with an input modal. * @remarks From 5d11875874720e1e0aa981ac5898fd57d7b14b51 Mon Sep 17 00:00:00 2001 From: G4mingJon4s Date: Mon, 19 Aug 2024 16:08:58 +0200 Subject: [PATCH 2/2] v3 conversion and doc --- markdown/bitburner.format.md | 23 +++++++++++ ...atnumber.md => bitburner.format.number.md} | 8 ++-- ...percent.md => bitburner.format.percent.md} | 8 ++-- ...s.formatram.md => bitburner.format.ram.md} | 8 ++-- ...ns.tformat.md => bitburner.format.time.md} | 6 +-- markdown/bitburner.md | 1 + markdown/bitburner.ns.format.md | 18 +++++++++ markdown/bitburner.ns.md | 6 +-- markdown/bitburner.ns.nformat.md | 40 ------------------- src/Constants.ts | 2 +- src/SaveObject.ts | 17 ++++++++ src/utils/APIBreaks/3.0.0.ts | 14 +++++++ 12 files changed, 90 insertions(+), 61 deletions(-) create mode 100644 markdown/bitburner.format.md rename markdown/{bitburner.ns.formatnumber.md => bitburner.format.number.md} (72%) rename markdown/{bitburner.ns.formatpercent.md => bitburner.format.percent.md} (69%) rename markdown/{bitburner.ns.formatram.md => bitburner.format.ram.md} (69%) rename markdown/{bitburner.ns.tformat.md => bitburner.format.time.md} (68%) create mode 100644 markdown/bitburner.ns.format.md delete mode 100644 markdown/bitburner.ns.nformat.md create mode 100644 src/utils/APIBreaks/3.0.0.ts diff --git a/markdown/bitburner.format.md b/markdown/bitburner.format.md new file mode 100644 index 0000000000..10feca43df --- /dev/null +++ b/markdown/bitburner.format.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [Format](./bitburner.format.md) + +## Format interface + +Format API + +**Signature:** + +```typescript +export interface Format +``` + +## Methods + +| Method | Description | +| --- | --- | +| [number(n, fractionalDigits, suffixStart, isInteger)](./bitburner.format.number.md) | Format a number. | +| [percent(n, fractionalDigits, suffixStart)](./bitburner.format.percent.md) | Format a number as a percentage. | +| [ram(n, fractionalDigits)](./bitburner.format.ram.md) | Format a number as an amount of ram. | +| [time(milliseconds, milliPrecision)](./bitburner.format.time.md) | Format time to a readable string. | + diff --git a/markdown/bitburner.ns.formatnumber.md b/markdown/bitburner.format.number.md similarity index 72% rename from markdown/bitburner.ns.formatnumber.md rename to markdown/bitburner.format.number.md index 68bfabb263..b7cd5fbf7c 100644 --- a/markdown/bitburner.ns.formatnumber.md +++ b/markdown/bitburner.format.number.md @@ -1,15 +1,15 @@ -[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [formatNumber](./bitburner.ns.formatnumber.md) +[Home](./index.md) > [bitburner](./bitburner.md) > [Format](./bitburner.format.md) > [number](./bitburner.format.number.md) -## NS.formatNumber() method +## Format.number() method Format a number. **Signature:** ```typescript -formatNumber(n: number, fractionalDigits?: number, suffixStart?: number, isInteger?: boolean): string; +number(n: number, fractionalDigits?: number, suffixStart?: number, isInteger?: boolean): string; ``` ## Parameters @@ -31,5 +31,5 @@ Formatted number. RAM cost: 0 GB -Converts a number into a numeric string with the specified format options. This is the same function that the game itself uses to display numbers. The format also depends on the Numeric Display settings (all options on the "Numeric Display" options page) To format ram or percentages, see [formatRam](./bitburner.ns.formatram.md) and [formatPercent](./bitburner.ns.formatpercent.md) +Converts a number into a numeric string with the specified format options. This is the same function that the game itself uses to display numbers. The format also depends on the Numeric Display settings (all options on the "Numeric Display" options page) To format ram or percentages, see [format.ram](./bitburner.format.ram.md) and [format.percent](./bitburner.format.percent.md) diff --git a/markdown/bitburner.ns.formatpercent.md b/markdown/bitburner.format.percent.md similarity index 69% rename from markdown/bitburner.ns.formatpercent.md rename to markdown/bitburner.format.percent.md index 74945f62d8..aa641c5fe1 100644 --- a/markdown/bitburner.ns.formatpercent.md +++ b/markdown/bitburner.format.percent.md @@ -1,15 +1,15 @@ -[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [formatPercent](./bitburner.ns.formatpercent.md) +[Home](./index.md) > [bitburner](./bitburner.md) > [Format](./bitburner.format.md) > [percent](./bitburner.format.percent.md) -## NS.formatPercent() method +## Format.percent() method Format a number as a percentage. **Signature:** ```typescript -formatPercent(n: number, fractionalDigits?: number, suffixStart?: number): string; +percent(n: number, fractionalDigits?: number, suffixStart?: number): string; ``` ## Parameters @@ -30,5 +30,5 @@ Formatted percentage. RAM cost: 0 GB -Converts a number into a percentage string with the specified number of fractional digits. This is the same function that the game itself uses to display percentages. The format also depends on the Numeric Display settings (all options on the "Numeric Display" options page) To format plain numbers or ram, see [formatNumber](./bitburner.ns.formatnumber.md) and [formatRam](./bitburner.ns.formatram.md) +Converts a number into a percentage string with the specified number of fractional digits. This is the same function that the game itself uses to display percentages. The format also depends on the Numeric Display settings (all options on the "Numeric Display" options page) To format plain numbers or ram, see [format.number](./bitburner.format.number.md) and [format.ram](./bitburner.format.ram.md) diff --git a/markdown/bitburner.ns.formatram.md b/markdown/bitburner.format.ram.md similarity index 69% rename from markdown/bitburner.ns.formatram.md rename to markdown/bitburner.format.ram.md index d5b0ae71df..e65cbfed5b 100644 --- a/markdown/bitburner.ns.formatram.md +++ b/markdown/bitburner.format.ram.md @@ -1,15 +1,15 @@ -[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [formatRam](./bitburner.ns.formatram.md) +[Home](./index.md) > [bitburner](./bitburner.md) > [Format](./bitburner.format.md) > [ram](./bitburner.format.ram.md) -## NS.formatRam() method +## Format.ram() method Format a number as an amount of ram. **Signature:** ```typescript -formatRam(n: number, fractionalDigits?: number): string; +ram(n: number, fractionalDigits?: number): string; ``` ## Parameters @@ -29,5 +29,5 @@ Formatted ram amount. RAM cost: 0 GB -Converts a number into a ram string with the specified number of fractional digits. This is the same function that the game itself uses to display ram. The format also depends on the Numeric Display settings (all options on the "Numeric Display" options page) To format plain numbers or percentages, see [formatNumber](./bitburner.ns.formatnumber.md) and [formatPercent](./bitburner.ns.formatpercent.md) +Converts a number into a ram string with the specified number of fractional digits. This is the same function that the game itself uses to display ram. The format also depends on the Numeric Display settings (all options on the "Numeric Display" options page) To format plain numbers or percentages, see [format.number](./bitburner.format.number.md) and [format.percent](./bitburner.format.percent.md) diff --git a/markdown/bitburner.ns.tformat.md b/markdown/bitburner.format.time.md similarity index 68% rename from markdown/bitburner.ns.tformat.md rename to markdown/bitburner.format.time.md index 54b06b02a8..1ceb7923e6 100644 --- a/markdown/bitburner.ns.tformat.md +++ b/markdown/bitburner.format.time.md @@ -1,15 +1,15 @@ -[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [tFormat](./bitburner.ns.tformat.md) +[Home](./index.md) > [bitburner](./bitburner.md) > [Format](./bitburner.format.md) > [time](./bitburner.format.time.md) -## NS.tFormat() method +## Format.time() method Format time to a readable string. **Signature:** ```typescript -tFormat(milliseconds: number, milliPrecision?: boolean): string; +time(milliseconds: number, milliPrecision?: boolean): string; ``` ## Parameters diff --git a/markdown/bitburner.md b/markdown/bitburner.md index 6de6b5d647..e671d508a2 100644 --- a/markdown/bitburner.md +++ b/markdown/bitburner.md @@ -58,6 +58,7 @@ | [Export](./bitburner.export.md) | Export order for a material | | [FactionWorkTask](./bitburner.factionworktask.md) | Faction Work | | [FileRequirement](./bitburner.filerequirement.md) | Player must have a specific Literature or Message file on their home computer. | +| [Format](./bitburner.format.md) | Format API | | [Formulas](./bitburner.formulas.md) | Formulas API | | [Fragment](./bitburner.fragment.md) | | | [GameInfo](./bitburner.gameinfo.md) | Game Information | diff --git a/markdown/bitburner.ns.format.md b/markdown/bitburner.ns.format.md new file mode 100644 index 0000000000..43e87a5f0d --- /dev/null +++ b/markdown/bitburner.ns.format.md @@ -0,0 +1,18 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [format](./bitburner.ns.format.md) + +## NS.format property + +Namespace for formatting functions. + +**Signature:** + +```typescript +readonly format: Format; +``` + +## Remarks + +RAM cost: 0 GB + diff --git a/markdown/bitburner.ns.md b/markdown/bitburner.ns.md index c08ac5b999..a2d2250864 100644 --- a/markdown/bitburner.ns.md +++ b/markdown/bitburner.ns.md @@ -36,6 +36,7 @@ export async function main(ns) { | [codingcontract](./bitburner.ns.codingcontract.md) | readonly | [CodingContract](./bitburner.codingcontract.md) | Namespace for codingcontract functions. | | [corporation](./bitburner.ns.corporation.md) | readonly | [Corporation](./bitburner.corporation.md) | Namespace for corporation functions. Contains spoilers. | | [enums](./bitburner.ns.enums.md) | | [NSEnums](./bitburner.nsenums.md) | | +| [format](./bitburner.ns.format.md) | readonly | [Format](./bitburner.format.md) | Namespace for formatting functions. | | [formulas](./bitburner.ns.formulas.md) | readonly | [Formulas](./bitburner.formulas.md) | Namespace for formulas functions. | | [gang](./bitburner.ns.gang.md) | readonly | [Gang](./bitburner.gang.md) | Namespace for gang functions. Contains spoilers. | | [go](./bitburner.ns.go.md) | readonly | [Go](./bitburner.go.md) | Namespace for Go functions. | @@ -69,9 +70,6 @@ export async function main(ns) { | [exit()](./bitburner.ns.exit.md) | Terminates the current script immediately. | | [fileExists(filename, host)](./bitburner.ns.fileexists.md) | Check if a file exists. | | [flags(schema)](./bitburner.ns.flags.md) | Parse command line flags. | -| [formatNumber(n, fractionalDigits, suffixStart, isInteger)](./bitburner.ns.formatnumber.md) | Format a number. | -| [formatPercent(n, fractionalDigits, suffixStart)](./bitburner.ns.formatpercent.md) | Format a number as a percentage. | -| [formatRam(n, fractionalDigits)](./bitburner.ns.formatram.md) | Format a number as an amount of ram. | | [ftpcrack(host)](./bitburner.ns.ftpcrack.md) | Runs FTPCrack.exe on a server. | | [getBitNodeMultipliers(n, lvl)](./bitburner.ns.getbitnodemultipliers.md) | Get the current BitNode multipliers. | | [getFavorToDonate()](./bitburner.ns.getfavortodonate.md) | Returns the amount of Faction favor required to be able to donate to a faction. | @@ -134,7 +132,6 @@ export async function main(ns) { | [moveTail(x, y, pid)](./bitburner.ns.movetail.md) | Move a tail window. | | [mv(host, source, destination)](./bitburner.ns.mv.md) | Move a file on the target server. | | [nextPortWrite(port)](./bitburner.ns.nextportwrite.md) | Listen for a port write. | -| [nFormat(n, format)](./bitburner.ns.nformat.md) | Format a number using the numeral library. This function is deprecated and will be removed in 2.4. | | [nuke(host)](./bitburner.ns.nuke.md) | Runs NUKE.exe on a server. | | [peek(portNumber)](./bitburner.ns.peek.md) | Get a copy of the data from a port without popping it. | | [print(args)](./bitburner.ns.print.md) | Prints one or more values or variables to the script’s logs. | @@ -163,7 +160,6 @@ export async function main(ns) { | [sprintf(format, args)](./bitburner.ns.sprintf.md) | Format a string. | | [sqlinject(host)](./bitburner.ns.sqlinject.md) | Runs SQLInject.exe on a server. | | [tail(fn, host, args)](./bitburner.ns.tail.md) | Open the tail window of a script. | -| [tFormat(milliseconds, milliPrecision)](./bitburner.ns.tformat.md) | Format time to a readable string. | | [toast(msg, variant, duration)](./bitburner.ns.toast.md) | Queue a toast (bottom-right notification). | | [tprint(args)](./bitburner.ns.tprint.md) | Prints one or more values or variables to the Terminal. | | [tprintf(format, values)](./bitburner.ns.tprintf.md) | Prints a raw value or a variable to the Terminal. | diff --git a/markdown/bitburner.ns.nformat.md b/markdown/bitburner.ns.nformat.md deleted file mode 100644 index ff39390eb1..0000000000 --- a/markdown/bitburner.ns.nformat.md +++ /dev/null @@ -1,40 +0,0 @@ - - -[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [nFormat](./bitburner.ns.nformat.md) - -## NS.nFormat() method - -> Warning: This API is now obsolete. -> -> Use ns.formatNumber, formatRam, or formatPercent instead. Will be removed in 2.4. -> - -Format a number using the numeral library. This function is deprecated and will be removed in 2.4. - -**Signature:** - -```typescript -nFormat(n: number, format: string): string; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| n | number | Number to format. | -| format | string | Formatting options. See http://numeraljs.com/\#format for valid formats. | - -**Returns:** - -string - -Formatted number. - -## Remarks - -RAM cost: 0 GB - -Converts a number into a string with the specified format options. See http://numeraljs.com/\#format for documentation on format strings supported. - -This function is deprecated and will be removed in 2.3. - diff --git a/src/Constants.ts b/src/Constants.ts index 5686e5b58c..7dd70a06b8 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -6,7 +6,7 @@ export const CONSTANTS = { VersionString: "2.6.3dev", isDevBranch: true, - VersionNumber: 40, + VersionNumber: 41, /** Max level for any skill, assuming no multipliers. Determined by max numerical value in javascript for experience * and the skill level formula in Player.js. Note that all this means it that when experience hits MAX_INT, then diff --git a/src/SaveObject.ts b/src/SaveObject.ts index 99883506e6..385e928caf 100644 --- a/src/SaveObject.ts +++ b/src/SaveObject.ts @@ -45,6 +45,7 @@ import { downloadContentAsFile } from "./utils/FileUtils"; import { showAPIBreaks } from "./utils/APIBreaks/APIBreak"; import { breakInfos261 } from "./utils/APIBreaks/2.6.1"; import { handleGetSaveDataError } from "./Netscript/ErrorMessages"; +import { breakInfos300 } from "./utils/APIBreaks/3.0.0"; /* SaveObject.js * Defines the object used to save/load games @@ -740,6 +741,22 @@ Error: ${e}`); if (ver < 39) { showAPIBreaks("2.6.1", ...breakInfos261); } + if (ver < 41) { + const changes: [RegExp, string][] = [ + [/formatNumber/g, "format.number"], + [/formatRam/g, "format.ram"], + [/formatPercent/g, "format.percent"], + [/tFormat/g, "format.time"], + ]; + + for (const server of GetAllServers()) { + for (const script of server.scripts.values()) { + script.content = convert(script.code, changes); + } + } + + showAPIBreaks("3.0.0", ...breakInfos300); + } } async function loadGame(saveData: SaveData): Promise { diff --git a/src/utils/APIBreaks/3.0.0.ts b/src/utils/APIBreaks/3.0.0.ts new file mode 100644 index 0000000000..da46ce9da9 --- /dev/null +++ b/src/utils/APIBreaks/3.0.0.ts @@ -0,0 +1,14 @@ +import { APIBreakInfo } from "./APIBreak"; + +export const breakInfos300: APIBreakInfo[] = [ + { + brokenFunctions: ["ns.formatNumber", "ns.formatRam", "ns.formatPercent", "ns.tFormat"], + info: + "The formatting functions have been moved to their own interface, ns.format.\n" + + "Additionally, the naming of ns.tFormat has been changed to ns.format.time.", + }, + { + brokenFunctions: ["ns.nFormat"], + info: "The ns.nFormat function has been removed. Use ns.format.number instead.", + }, +];