base62.js 520 B

1234567891011121314151617181920212223242526
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. *
  8. */
  9. 'use strict';
  10. var BASE62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  11. function base62(number) {
  12. if (!number) {
  13. return '0';
  14. }
  15. var string = '';
  16. while (number > 0) {
  17. string = BASE62[number % 62] + string;
  18. number = Math.floor(number / 62);
  19. }
  20. return string;
  21. }
  22. module.exports = base62;