<commit_before>export var Type = Function;
export var Math = window.Math;

export class FIELD {
  constructor(definition) {
    this.definition = definition;
  }
}

export class CONST {}
export class ABSTRACT {}
export class IMPLEMENTS {}


export function isPresent(obj):boolean {
  return obj !== undefined && obj !== null;
}

export function isBlank(obj):boolean {
  return obj === undefined || obj === null;
}

export function toBool(obj) {
  return !!obj;
}

export function autoConvertAdd(a, b) {
  return a + b;
}

export function stringify(token):string {
  if (typeof token === 'string') {
    return token;
  }

  if (token === undefined || token === null) {
    return '' + token;
  }

  if (token.name) {
    return token.name;
  }

  return token.toString();
}

export class StringWrapper {
  static fromCharCode(code:int) {
    return String.fromCharCode(code);
  }

  static charCodeAt(s:string, index:int) {
    return s.charCodeAt(index);
  }
}

export class StringJoiner {
  constructor() {
    this.parts = [];
  }

  add(part:string) {
    this.parts.push(part);
  }

  toString():string {
    return this.parts.join("");
  }
}

export class NumerParseError extends Error {
  constructor(message) {
    this.message = message;
  }

  toString() {
    return this.message;
  }
}


export class NumberWrapper {
  static parseIntAutoRadix(text:string):int {
    var result:int = parseInt(text);
    if (isNaN(result)) {
      throw new NumerParseError("Invalid integer literal when parsing " + text);
    }
    return result;
  }

  static parseInt(text:string, radix:int):int {
    if (radix == 10) {
      if (/^(\-|\+)?[0-9]+$/.test(text)) {
        return parseInt(text, radix);
      }
    } else if (radix == 16) {
      if (/^(\-|\+)?[0-9ABCDEFabcdef]+$/.test(text)) {
        return parseInt(text, radix);
      }
    } else {
      var result:int = parseInt(text, radix);
      if (!isNaN(result)) {
        return result;
      }
    }
    throw new NumerParseError("Invalid integer literal when parsing " + text + " in base " + radix);
  }

  // TODO: NaN is a valid literal but is returned by parseFloat to indicate an error.
  static parseFloat(text:string):number {
    return parseFloat(text);
  }

  static isNaN(value) {
    return isNaN(value);
  }

  static get NaN():number {
    return NaN;
  }
}

export function int() {};
int.assert = function(value) {
  return value == null || typeof value == 'number' && value === Math.floor(value);
}

export var RegExp = window.RegExp;

export class RegExpWrapper {
  static create(regExpStr):RegExp {
    return new RegExp(regExpStr, 'g');
  }
  static matcher(regExp, input) {
    return {
      re: regExp,<commit_msg>fix(lang): fix small typo.<commit_after>export var Type = Function;
export var Math = window.Math;

export class FIELD {
  constructor(definition) {
    this.definition = definition;
  }
}

export class CONST {}
export class ABSTRACT {}
export class IMPLEMENTS {}


export function isPresent(obj):boolean {
  return obj !== undefined && obj !== null;
}

export function isBlank(obj):boolean {
  return obj === undefined || obj === null;
}

export function toBool(obj) {
  return !!obj;
}

export function autoConvertAdd(a, b) {
  return a + b;
}

export function stringify(token):string {
  if (typeof token === 'string') {
    return token;
  }

  if (token === undefined || token === null) {
    return '' + token;
  }

  if (token.name) {
    return token.name;
  }

  return token.toString();
}

export class StringWrapper {
  static fromCharCode(code:int) {
    return String.fromCharCode(code);
  }

  static charCodeAt(s:string, index:int) {
    return s.charCodeAt(index);
  }
}

export class StringJoiner {
  constructor() {
    this.parts = [];
  }

  add(part:string) {
    this.parts.push(part);
  }

  toString():string {
    return this.parts.join("");
  }
}

export class NumberParseError extends Error {
  constructor(message) {
    this.message = message;
  }

  toString() {
    return this.message;
  }
}


export class NumberWrapper {
  static parseIntAutoRadix(text:string):int {
    var result:int = parseInt(text);
    if (isNaN(result)) {
      throw new NumberParseError("Invalid integer literal when parsing " + text);
    }
    return result;
  }

  static parseInt(text:string, radix:int):int {
    if (radix == 10) {
      if (/^(\-|\+)?[0-9]+$/.test(text)) {
        return parseInt(text, radix);
      }
    } else if (radix == 16) {
      if (/^(\-|\+)?[0-9ABCDEFabcdef]+$/.test(text)) {
        return parseInt(text, radix);
      }
    } else {
      var result:int = parseInt(text, radix);
      if (!isNaN(result)) {
        return result;
      }
    }
    throw new NumberParseError("Invalid integer literal when parsing " + text + " in base " + radix);
  }

  // TODO: NaN is a valid literal but is returned by parseFloat to indicate an error.
  static parseFloat(text:string):number {
    return parseFloat(text);
  }

  static isNaN(value) {
    return isNaN(value);
  }

  static get NaN():number {
    return NaN;
  }
}

export function int() {};
int.assert = function(value) {
  return value == null || typeof value == 'number' && value === Math.floor(value);
}

export var RegExp = window.RegExp;

export class RegExpWrapper {
  static create(regExpStr):RegExp {
    return new RegExp(regExpStr, 'g');
  }
  static matcher(regExp, input) {
    return {
      re: regExp,
{'fraction_non_alphanumeric': 0.1407462135205024, 'fraction_numerical': 0.0029553010712966383, 'mean_word_length': 3.062265566391598, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6510616', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1743, 'n_words': 454}