import { __require as requireGetIntrinsic } from "../../get-intrinsic/index.js";
import { __require as requireType } from "../../es-errors/type.js";
import { __require as requireCallBound } from "../../call-bound/index.js";
import { __require as requireSafeRegexTest } from "../../safe-regex-test/index.js";
import { __require as requireString_prototype_trim } from "../../string.prototype.trim/index.js";
var StringToNumber;
var hasRequiredStringToNumber;
function requireStringToNumber() {
  if (hasRequiredStringToNumber) return StringToNumber;
  hasRequiredStringToNumber = 1;
  var GetIntrinsic = requireGetIntrinsic();
  var $RegExp = GetIntrinsic("%RegExp%");
  var $TypeError = requireType();
  var $parseInteger = GetIntrinsic("%parseInt%");
  var callBound = requireCallBound();
  var regexTester = requireSafeRegexTest();
  var $strSlice = callBound("String.prototype.slice");
  var isBinary = regexTester(/^0b[01]+$/i);
  var isOctal = regexTester(/^0o[0-7]+$/i);
  var isInvalidHexLiteral = regexTester(/^[-+]0x[0-9a-f]+$/i);
  var nonWS = ["", "​", ""].join("");
  var nonWSregex = new $RegExp("[" + nonWS + "]", "g");
  var hasNonWS = regexTester(nonWSregex);
  var $trim = requireString_prototype_trim();
  StringToNumber = function StringToNumber2(argument) {
    if (typeof argument !== "string") {
      throw new $TypeError("Assertion failed: `argument` is not a String");
    }
    if (isBinary(argument)) {
      return +$parseInteger($strSlice(argument, 2), 2);
    }
    if (isOctal(argument)) {
      return +$parseInteger($strSlice(argument, 2), 8);
    }
    if (hasNonWS(argument) || isInvalidHexLiteral(argument)) {
      return NaN;
    }
    var trimmed = $trim(argument);
    if (trimmed !== argument) {
      return StringToNumber2(trimmed);
    }
    return +argument;
  };
  return StringToNumber;
}
export {
  requireStringToNumber as __require
};
