uint.js 707 B

12345678910111213141516171819202122
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. export function toUint8(v) {
  6. if (v < 0) {
  7. return 0;
  8. }
  9. if (v > 255 /* MAX_UINT_8 */) {
  10. return 255 /* MAX_UINT_8 */;
  11. }
  12. return v | 0;
  13. }
  14. export function toUint32(v) {
  15. if (v < 0) {
  16. return 0;
  17. }
  18. if (v > 4294967295 /* MAX_UINT_32 */) {
  19. return 4294967295 /* MAX_UINT_32 */;
  20. }
  21. return v | 0;
  22. }