UNPKG

graphql-language-service-server

Version:
23 lines (21 loc) 540 B
/** * Copyright (c) 2021 GraphQL Contributors * All rights reserved. * * This source code is licensed under the license found in the * LICENSE file in the root directory of this source tree. * */ /* eslint-disable no-bitwise */ export default function stringToHash(str: string): number { let hash = 0; if (str.length === 0) { return hash; } for (let i = 0; i < str.length; i++) { const chr = str.charCodeAt(i); hash = (hash << 5) - hash + chr; hash |= 0; // Convert to 32bit integer } return hash; }