nextcloud/apps/files/src/utils/hashUtils.ts
Ferdinand Thiessen 3782142f59
refactor(files): Fix nullish operator usage and add missing code comment
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2024-06-24 12:53:53 +02:00

17 lines
479 B
TypeScript

/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
/**
* Simple non-secure hashing function similar to Java's `hashCode`
* @param str The string to hash
* @return {number} a non secure hash of the string
*/
export const hashCode = function(str: string): number {
let hash = 0
for (let i = 0; i < str.length; i++) {
hash = ((hash << 5) - hash + str.charCodeAt(i)) | 0
}
return (hash >>> 0)
}