UNPKG

locutus

Version:

Locutus other languages' standard libraries to JavaScript for fun and educational purposes

22 lines (21 loc) 826 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FormatInt = FormatInt; function FormatInt(i, base) { // discuss at: https://locutus.io/golang/strconv/FormatInt // parity verified: Go 1.23 // original by: Kevin van Zonneveld (https://kvz.io) // note 1: Returns the string representation of i in the given base (2 to 36). // example 1: FormatInt(42, 10) // returns 1: '42' // example 2: FormatInt(255, 16) // returns 2: 'ff' // example 3: FormatInt(10, 2) // returns 3: '1010' i = Number.parseInt(String(i), 10); base = Number.parseInt(String(base), 10) || 10; if (base < 2 || base > 36) { throw new Error('strconv: illegal base ' + base); } return i.toString(base); }