pokerogue/scripts/helpers/strings.js
github-actions[bot] b0f126430b
Release v1.10.0 to beta (#6321)
* Stage release v1.10.0

* [GitHub] Workflows will now run on `release` branch (#6329)

* [Beta] [Balance] Add Wild Evo Delay to Gallade / Froslass (#6324)

* Update pokemon-evolutions.ts
---------
Co-authored-by: damocleas <damocleas25@gmail.com>
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* [Beta] [Balance] Fix Wrong Teras in Trainer Config (#6326)

* Update trainer-config.ts
---------
Co-authored-by: damocleas <damocleas25@gmail.com>

* Revert #6307 "Remove duplicate animation json for ... variants" (#6332)

Revert "[Refactor][Sprite] Remove duplicate animation json for shinies, sprite-based variants (#6307)"

This reverts commit 7bdb62ed1d.

* [Beta] Fresh Start no longer overrides IV unlocks (#6333)

Unpack ivs when copying dexData

* [UI/UX] Always show starter's natures and ivs in evolution's dex entry (#6335)

Natures and ivs use starter's dexEntry

* [Bug] Sheer Force no longer boosts Fickle Beam; Focus Energy gives +2 crit instead of +1 (#6331)

[Bug] Sheer Force no longer boosts Fickle Beam; Focus Energy correctly gives +2 crit stages instead of +1

* Restricted party options for fainted mons in hardcore (#6336)

* [Challenge] No hardcore breeder (#6334)

Disallow expert breeder encounter in space

Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com>

* [Bug] [Beta] Fix trick room message (#6327)

Fix trick room's arena tag message

* [Beta][Bug][UI/UX] Fix broken candy upgrades (#6322)

* Candy upgrades change permanent starter data again

* Updating cost icon and passive bg in starter select after buying pokédex upgrades

* [Beta] [Balance] Even More 1.10 Balance Changes (Egg Moves + Passive Changes) (#6339)

1.10 Egg Moves and Passives pt 3

* [Bug][Sprite] Remove fake Deerling variants (#6330)

* Remove fake Deerling variants

* Remove unused json

* [Bug] Ensure MEs disabled in a challenge mode only do so while challenge is active (#6337)

* Ensure MEs disabled in a challenge mode only do so while challenge is active

* Optimize checking disallowed challenges

* [Misc] Moved `scrapeTrainerNames` to a script; removed `selfStatLowerMoves` (#6258)

* Removed scrape trainer names

* Removed `selfStatLowerMoves`

* Update move.ts

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* Started work on the script again

* Made script actually work

* Made finishing touches on script

* Fixed main repo code to not expect snake cased locale strings

* Update trainer.ts

Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com>

* Remove biome ignore range

* Fix typedoc.json

* rename `getRandomLocaleKey` to `getRandomLocaleEntry`

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com>

* Update locales

* [Balance] [ME] Trash to Treasure Option 1 Adjustment (#6341)

* Update trash-to-treasure-encounter.ts

* Update trash-to-treasure-encounter.test.ts tests

* [Misc] [UX] Add Daily Run Achievement, Re-Arrange Achievements, Replace some Icon Sprites (#6292)

* wip achievement changes

* Adjust egg image sizes, re-export item atlas

* painful eggs

* Add egg to legacy UI, re-export item atlas

* run biome

* Update achievement.test.ts

* Fix achievement test file

* Fix tera stellar missing icon path

* Fix achievement test file

* egg s

* Optimize new images, re-export item atlas

* update pngs and locale

* add daily achv and other sorting

* Optimize ribbons, re-export item atlas

* Bump to version 1.11.0

* more changes, waiting on pngs

* Update package.json

* ribbon fixes

* images!

* Optimize images, re-export item atlas

* final fix

---------

Co-authored-by: Madmadness65 <blaze.the.fireman@gmail.com>
Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com>

* [Bug] [UI/UX] [Beta] Fix visibility of egg moves in ssui (#6343)

Fix visibility of egg moves when backing out of fresh start and back into ssui

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
Co-authored-by: Blitzy <118096277+Blitz425@users.noreply.github.com>
Co-authored-by: damocleas <damocleas25@gmail.com>
Co-authored-by: Wlowscha <54003515+Wlowscha@users.noreply.github.com>
Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com>
Co-authored-by: AJ Fontaine <36677462+Fontbane@users.noreply.github.com>
Co-authored-by: Madmadness65 <blaze.the.fireman@gmail.com>
2025-08-22 19:13:37 -05:00

180 lines
5.6 KiB
JavaScript

// #region Split string code
// Regexps involved with splitting words in various case formats.
// Sourced from https://www.npmjs.com/package/change-case (with slight tweaking here and there)
/**
* Regex to split at word boundaries.
* @type {RegExp}
*/
const SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
/**
* Regex to split around single-letter uppercase words.
* @type {RegExp}
*/
const SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
/**
* Regexp involved with stripping non-word delimiters from the result.
* @type {RegExp}
*/
const DELIM_STRIP_REGEXP = /[-_ ]+/giu;
// The replacement value for splits.
const SPLIT_REPLACE_VALUE = "$1\0$2";
/**
* Split any cased string into an array of its constituent words.
* @param {string} value
* @returns {string[]} The new string, delimited at each instance of one or more spaces, underscores, hyphens
* or lower-to-upper boundaries.
*/
function splitWords(value) {
let result = value.trim();
result = result.replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE).replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);
result = result.replace(DELIM_STRIP_REGEXP, "\0");
// Trim the delimiter from around the output string
return trimFromStartAndEnd(result, "\0").split(/\0/g);
}
/**
* Helper function to remove one or more sequences of characters from either end of a string.
* @param {string} str - The string to replace
* @param {string} charToTrim - The string to remove
* @returns {string} The string having been trimmed
*/
function trimFromStartAndEnd(str, charToTrim) {
let start = 0;
let end = str.length;
const blockLength = charToTrim.length;
while (str.startsWith(charToTrim, start)) {
start += blockLength;
}
if (start - end === blockLength) {
// Occurs if the ENTIRE string is made up of charToTrim (at which point we return nothing)
return "";
}
while (str.endsWith(charToTrim, end)) {
end -= blockLength;
}
return str.slice(start, end);
}
// #endregion Split String code
/**
* Capitalize the first letter of a string.
* @example
* ```ts
* console.log(capitalizeFirstLetter("consectetur adipiscing elit")); // returns "Consectetur adipiscing elit"
* ```
* @param {string} str - The string whose first letter is to be capitalized
* @return {string} The original string with its first letter capitalized.
*/
export function capitalizeFirstLetter(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
/**
* Helper method to convert a string into `Title Case` (such as one used for console logs).
* @example
* ```ts
* console.log(toTitleCase("lorem ipsum dolor sit amet")); // returns "Lorem Ipsum Dolor Sit Amet"
* ```
* @param {string} str - The string being converted
* @returns {string} The result of converting `str` into title case.
*/
export function toTitleCase(str) {
return splitWords(str)
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join(" ");
}
/**
* Helper method to convert a string into `camelCase` (such as one used for i18n keys).
* @example
* ```ts
* console.log(toCamelCase("BIG_ANGRY_TRAINER")); // returns "bigAngryTrainer"
* ```
* @param {string} str - The string being converted
* @returns {string} The result of converting `str` into camel case.
*/
export function toCamelCase(str) {
return splitWords(str)
.map((word, index) =>
index === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(),
)
.join("");
}
/**
* Helper method to convert a string into `PascalCase`.
* @example
* ```ts
* console.log(toPascalCase("hi how was your day")); // returns "HiHowWasYourDay"
* ```
* @param {string} str - The string being converted
* @returns {string} The result of converting `str` into pascal case.
*/
export function toPascalCase(str) {
return splitWords(str)
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join("");
}
/**
* Helper method to convert a string into `kebab-case` (such as one used for filenames).
* @example
* ```ts
* console.log(toKebabCase("not_kebab-caSe String")); // returns "not-kebab-case-string"
* ```
* @param {string} str - The string being converted
* @returns {string} The result of converting `str` into kebab case.
*/
export function toKebabCase(str) {
return splitWords(str)
.map(word => word.toLowerCase())
.join("-");
}
/**
* Helper method to convert a string into `snake_case` (such as one used for filenames).
* @example
* ```ts
* console.log(toSnakeCase("not-in snake_CaSe")); // returns "not_in_snake_case"
* ```
* @param {string} str - The string being converted
* @returns {string} The result of converting `str` into snake case.
*/
export function toSnakeCase(str) {
return splitWords(str)
.map(word => word.toLowerCase())
.join("_");
}
/**
* Helper method to convert a string into `UPPER_SNAKE_CASE`.
* @example
* ```ts
* console.log(toUpperSnakeCase("apples bananas_oranGes-PearS")); // returns "APPLES_BANANAS_ORANGES_PEARS"
* ```
* @param {string} str - The string being converted
* @returns {string} The result of converting `str` into upper snake case.
*/
export function toUpperSnakeCase(str) {
return splitWords(str)
.map(word => word.toUpperCase())
.join("_");
}
/**
* Helper method to convert a string into `Pascal_Snake_Case`.
* @example
* ```ts
* console.log(toPascalSnakeCase("apples-bananas_oranGes Pears")); // returns "Apples_Bananas_Oranges_Pears"
* ```
* @param {string} str - The string being converted
* @returns {string} The result of converting `str` into pascal snake case.
*/
export function toPascalSnakeCase(str) {
return splitWords(str)
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join("_");
}