The input to hash. Can be string, number, object, or null/undefined.
The MD5 hash of the input as a string, or the input itself if null/undefined
Error if input type is not supported (e.g., Symbol)
md5sum("hello") // Returns "5d41402abc4b2a76b9719d911017c592"
md5sum(123) // Returns "202cb962ac59075b964b07152d234b70"
md5sum({ foo: "bar" }) // Returns hash of stringified object
md5sum(null) // Returns null
export function md5sum<T>(input: NonNullable<T>): string | T {
if (input === null || input === undefined) {
return input;
}
if (typeof input === 'object' && input !== null) {
return md5(JSON.stringify(input));
}
if (typeof input === 'number') {
return md5(String(input));
}
if (typeof input !== 'string') {
throw new Error('Unexpected input type: ' + typeof input);
}
return md5(input);
}
MD5 hash function that handles various input types. Converts input to string representation before hashing.