Skip to content

Digitizer

Converts an abitrary value into individual digits.

Instantiate

TS
function useDigitizer(): UseDigitizer;

Returns

TS
type UseDigitizer = {
    digitize: (value: any) => DigitizedValues;
    isDigitized: (value: any) => boolean;
};
TS
type DigitizedValue = string;
TS
type DigitizedValues = (DigitizedValue | DigitizedValues)[];

Usage

ts
const { digitize, isDigitized } = useDigitizer();

console.log(digitize('hello')); // ['h', 'e', 'l', 'l', 'o']
console.log(digitize(['hello', 'world'])); // [['h', 'e', 'l', 'l', 'o'], ['w', 'o', 'r', 'l', 'd']]

console.log(isDigitized(['hello'])); // false
console.log(isDigitized(['h', 'e', 'l', 'l', 'o'])); // true

TIP

These are just a few examples and far from complete. If you want to see a feature-complete example, check tests/helpers/digitizer.test.ts in the repo.

Released under the MIT License.