Initial public release of Numbers™ from cohost.
There are minor differences between the code as released and what we were running in production. These differences are:
- remove some logic to pick a correct publish date and post ID when given a
specific post; finding the correct publish date is the responsibility of
whatever includes
<Numbers />
now.- this change is because we would have to release typedefs for the actual Post object, which is irrelevant for anyone other than us.
- change the Numbers™ display to use a style attribute instead of a
tailwind class
- adding a tailwind dependency would be silly. we are sparing y'all of that.
for those who don't want to read the code
The Numbers™ algorithm is very simple:
- seed a random number generator off a post ID.
- roll the dice four times
- Numbers™ score
- Negative score
- Fractional score
- Exponent score
- Multiply the Numbers™ score by the number of seconds since/until the
selected date.
- For posts created before April 1 at midnight UTC, this date is April 1 at midnight UTC.
- For posts created after April 1 at midnight UTC, this date is the post publish date.
- Check the Fractional score against a threshold
- There is a 2% chance for a given post to have a decimal
- If this check passes, normalize the roll from 0-0.02 to 0-1, lerp with this against our fraction digit range, floor the result. (1-5)
- Use this when calling
toLocaleString
later.
- Check the Exponent score against a threshold
- There is a 50% chance for a given post to see exponential growth
- If this check passes, normalize the roll from 0-0.5 to 0-1, lerp with this against our exponent range (1 - 1.42).
- 1.42 was chosen solely because jae liked the aesthetics of the range that got us.
- Check the Negative score against a threshold.
- The Negative threshold shifts throughout the weekend, starting at 5% and capping at 60%.
- Posts have a chance of becoming Negative at any time, although some rolls (>=0.6) will never go negative.
- If this check passes, multiply the Number by -1.
- Turn that shit into a locale string
- This is where we actually use the fraction result.
- Render it
- When the user clicks the Number, we run all this again. Clicking DOES NOT increase the number, the number increases on its own by virtue of time having passed since you last clicked it.
You shouldn't use this. Reference dates are all hardcoded to April 1 because that's when we released it. This release provided mostly for reference, but if you really want to use it:
import {Numbers} from "@antisoftwareclub/numbers";
// your actual code goes here
<>
<Numbers postId={69420} publishedAt="2022-02-03T08:30:00.000Z" />
</>
- This does not include tests. If you want to write tests for it, knock yourself out.
- jae wrote this over the course of about two hours. set your code quality expectations accordingly.
This release is licensed under an MIT license.
PLEASE NOTE: this license ONLY covers this release of Numbers.tsx
. It DOES NOT
apply to any other part of the cohost code base.
jae was too tired to get github actions to publish the package to npm so we've gotta publish manually. this does not actually matter.