diff --git a/src/core/api/modules/checker.ts b/src/core/api/modules/checker.ts index 26af713..6588475 100644 --- a/src/core/api/modules/checker.ts +++ b/src/core/api/modules/checker.ts @@ -332,6 +332,17 @@ export class ODChecker extends ODManagerData { this.options = options ?? {} } + /**Get a human-readable number string. */ + #ordinalNumber(num:number){ + const i = Math.abs(Math.round(num)) + const cent = i % 100 + if (cent >= 10 && cent <= 20) return i+'th' + const dec = i % 10 + if (dec === 1) return i+'st' + if (dec === 2) return i+'nd' + if (dec === 3) return i+'rd' + return i+'th' + } /**Run this checker. Returns all errors*/ check(): ODCheckerResult { this.messages = [] @@ -343,12 +354,12 @@ export class ODChecker extends ODManagerData { messages:this.messages } } - /**Create a string from the location trace (path)*/ + /**Create a string from the location trace/path in a human readable format. */ locationTraceToString(trace:ODCheckerLocationTrace){ const final: ODCheckerLocationTrace = [] trace.forEach((t) => { if (typeof t == "number"){ - final.push(`:${t}`) + final.push(`:(${this.#ordinalNumber(t+1)})`) }else{ final.push(`."${t}"`) } diff --git a/src/core/startup/init.ts b/src/core/startup/init.ts index 66279de..a243ebe 100644 --- a/src/core/startup/init.ts +++ b/src/core/startup/init.ts @@ -117,7 +117,11 @@ export interface ODUtilities { * * It shouldn't be used by plugins because this is an internal API feature! */ - ODVersionMigration:new (version:api.ODVersion,func:() => void|Promise,afterInitFunc:() => void|Promise) => ODVersionMigration + ODVersionMigration:new (version:api.ODVersion,func:() => void|Promise,afterInitFunc:() => void|Promise) => ODVersionMigration, + /**## ordinalNumber `utility function` + * Get a human readable ordinal number (e.g. 1st, 2nd, 3rd, 4th, ...) from a Javascript number. + */ + ordinalNumber(num:number): string, } /**## ODVersionMigration `utility class` @@ -252,5 +256,15 @@ export const utilities: ODUtilities = { "LOREMIPSUM", //TODO ] }, - ODVersionMigration + ODVersionMigration, + ordinalNumber(num:number){ + const i = Math.abs(Math.round(num)) + const cent = i % 100 + if (cent >= 10 && cent <= 20) return i+'th' + const dec = i % 10 + if (dec === 1) return i+'st' + if (dec === 2) return i+'nd' + if (dec === 3) return i+'rd' + return i+'th' + } } \ No newline at end of file