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. Replaces capFirstChar(). Not to be confused with String.toUpperCase(), which changes the case of the entire string.
"test".capitalize() // "Test"
  • .uncapitalize(): changes the first letter of the given string to lowercase. Replace uncapFirstChar(). Not to be confused with String.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)). Replaces between().
(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 with Math.round(), which rounds to the nearest integer.
(8).round(5) // 10
  • .toCash(): returns the number formatted as currency. Replaces cashFormat() and cashFormatColor().
(10).toCash() // ¤10
(-10).toCash() // -¤10
  • .toRep(): returns the number formatted as reputation. Replaces repFormat().
(10).toRep() // "10 rep"
  • .toMass(): returns the number formatted as mass. Replaces massFormat().
(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. Replaces num() 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. Replaces commaNum().
(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 ". Replaces toSentence().
["foo", "bar", "baz"].toSentence() // "foo, bar and baz"

This is a WIP list, and will be updated as discussion continues.

Edited by brickode