As this question is for TensorFlow.js though not Python, it seems its just a function that transforms a number into some bucketized version right? So that is not too hard to replicate in JS as a pre-processing step before you use the values if needed to be done client side.
Curious to see the results you get @sphere for the different approaches including your one with the 5x 1 hot encodings representing each digit, vs someting like this bucketed version to reduce the number of unique encodings needed to represent the data