<commit_before>import './Object';

declare global {
  interface StringConstructor {
    isNullOrEmpty(value: string): boolean;
    stringify(value: any, replacer?: any, space?: string | number): string;
  }
}

function isNullOrEmpty(value: string) {
  return value == null || value === '';
}

function stringify(value: any, replacer?: any, space: string | number = 2) {
  let result: string = null;

  if (value != null) {
    result = value.toString();

    if (result === '[object Object]') {
      result = Object.getName(value);

      if (result === 'Object') {
        try {
          result = JSON.stringify(value, replacer, space);
        }
        catch (e) {
          // console.warn('Attempt to stringify failed');
          // console.log(e);
        }
      }
    }
  }

  return result;
}

String.isNullOrEmpty = Object.fallback(String.isNullOrEmpty, isNullOrEmpty);
String.stringify = Object.fallback(String.stringify, stringify);<commit_msg>adding String.isString extension type guard<commit_after>import './Object';

declare global {
  interface StringConstructor {
    isString(value: any): value is string;
    isNullOrEmpty(value: string): boolean;
    stringify(value: any, replacer?: any, space?: string | number): string;
  }
}

function isString(value: any): value is string {
  return typeof(value) === 'string' || value instanceof String;
}

function isNullOrEmpty(value: string) {
  return value == null || value === '';
}

function stringify(value: any, replacer?: any, space: string | number = 2) {
  let result: string = null;

  if (value != null) {
    result = value.toString();

    if (result === '[object Object]') {
      result = Object.getName(value);

      if (result === 'Object') {
        try {
          result = JSON.stringify(value, replacer, space);
        }
        catch (e) {
          // console.warn('Attempt to stringify failed');
          // console.log(e);
        }
      }
    }
  }

  return result;
}

String.isString = Object.fallback(String.isString, isString);
String.isNullOrEmpty = Object.fallback(String.isNullOrEmpty, isNullOrEmpty);
String.stringify = Object.fallback(String.stringify, stringify);
{'fraction_non_alphanumeric': 0.14200092208390963, 'fraction_numerical': 0.0009220839096357768, 'mean_word_length': 3.086629001883239, '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': '3677822', 'n_tokens_mistral': 652, 'n_tokens_neox': 635, 'n_words': 165}