the browser-facing portion of osu!
at master 546 B view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 2// See the LICENCE file in the repository root for full licence text. 3 4export function getInt(input: unknown) { 5 if (Number.isInteger(input)) { 6 // Number.isInteger doesn't guard input as number. 7 // Reference: https://github.com/microsoft/TypeScript/issues/15048 8 return input as number; 9 } 10 11 if (typeof input === 'string') { 12 const num = parseInt(input, 10); 13 14 if (Number.isInteger(num)) { 15 return num; 16 } 17 } 18}