Prototype methods discussion
Here is a tentative list of methods I'd like to implement:
String
-
.capitalize(): capitalizes the first letter of the given string. ReplacescapFirstChar(). Not to be confused withString.toUpperCase(), which changes the case of the entire string.
"test".capitalize() // "Test"
-
.uncapitalize(): changes the first letter of the given string to lowercase. ReplaceuncapFirstChar(). Not to be confused withString.toLowerCase(), which changes the case of the entire string.
"Test".uncapitalize() // "test"
"TEST".upcapitalize() // "tEST"
-
.isEmpty(): returns whether the string is empty.
"".isEmpty() // true
"test".isEmpty() // false
Number
-
.between(): returns whether the number is between two given numbers (currently in progress in !9355 (merged)). Replacesbetween().
(10).between(1, 20) // true
(1).between(1, 20) // false
- `.gaussian(): returns a normal distribution between two given numbers, with an optional skew.
Number().gaussian(1, 10) // number with normal distribution
-
.round(): returns a number rounded to a given step. Not to be confused withMath.round(), which rounds to the nearest integer.
(8).round(5) // 10
-
.toCash(): returns the number formatted as currency. ReplacescashFormat()andcashFormatColor().
(10).toCash() // ¤10
(-10).toCash() // -¤10
-
.toRep(): returns the number formatted as reputation. ReplacesrepFormat().
(10).toRep() // "10 rep"
-
.toMass(): returns the number formatted as mass. ReplacesmassFormat().
(10000).toMass() // "10 tons"
(100).toMass() // "100 kg" or "220.4 pounds"
-
.toCentimeters(): returns the number converted to centimeters.
(10).toCentimeters() // 25.4
-
.toInches(): returns the number converted to inches.
(25.4).toInches() // 10
-
.toFeet(): returns a number given in inches converted to feet and inches.
(60).toFeet() // 5'
(66).toFeet() // 5' 6"
-
.toPounds(): returns the number converted to pounds.
(10).toPounds() // 22.05
-
.toKilograms(): returns a number converted to kilograms
(22.05).toKilograms() // 10
-
.format(): returns a number as either a word ("two") or integer ("2"), depending on the user's settings. Replacesnum()and*toEitherUnit().
(10).format() // "ten" or "10"
(10).format('cm') // "ten centimeters" or "10 centimeters"
(10).format('in') // "ten inches" or "10 inches"
(10).format('either') // "ten inches (25.4cm)"
-
.isFloat(): returns whether the number is a float.
(10.01).isFloat() // true
(10).isFloat() // false
-
.withCommas(): returns the number as a string with added comma separators. ReplacescommaNum().
(10000).withCommas() // "10,000"
Array
-
.random(): returns a random item from an array.
[1, 10, "test"].random() // one of 1, 10, or "test"
-
.toSentence(): returns an array of strings as one string joined with "," and " and ". ReplacestoSentence().
["foo", "bar", "baz"].toSentence() // "foo, bar and baz"
This is a WIP list, and will be updated as discussion continues.
Edited by brickode