Skip to content

djb2

Calculates the hash of a string using the djb2 algorithm.

Syntax

typescript
djb2(str: string): number

Parameters

NameTypeDescription
strstringThe string to be processed

Returns

TypeDescription
numberThe calculated hash value (unsigned 32 bits)

Example

typescript
djb2("hello"); // 210714636441

Notes

  • Throws a TypeError if the value is not a string.
  • The djb2 algorithm is simple and fast, but not secure for cryptographic use.

References

Released under the MIT License.