<commit_before>/**
 * Escape string from any regex format.
 * Source: http://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript
 * @param string 
 */
export function escapeRegExp(string: string) {
    return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}

/**
 * Replace all occurences in a string
 * Source: http://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript
 * @param string
 * @param find
 * @param replace
 */
export function replaceAll(string: string, find: string, replace: string) {
    return string.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}

/**
 * Object to Array
 */
export function objToArray(obj: any) {
        let returney: any[] = [];

        Object
            .keys(obj)
            .map((objectKey, Index) => {
                returney[Index] = obj[objectKey];
                returney[Index]._objectKey = objectKey;
            });

        return returney;
}
/**
 * Detect if a string RTL
 */
export function detectRTL(text: string) {
      var rtlChar = /[\u0590-\u083F]|[\u08A0-\u08FF]|[\uFB1D-\uFDFF]|[\uFE70-\uFEFF]/mg;
      
      var totalRTL = text.match(rtlChar) ? text.match(rtlChar).length : 0;
      var totalLTR = text.length - totalRTL;
      
      var ratio = totalRTL / totalLTR;
      
      return ratio >= 1 ? true : false;
}<commit_msg>Fixed bug detextRTL for new line and spaces<commit_after>/**
 * Escape string from any regex format.
 * Source: http://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript
 * @param string 
 */
export function escapeRegExp(string: string) {
    return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}

/**
 * Replace all occurences in a string
 * Source: http://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript
 * @param string
 * @param find
 * @param replace
 */
export function replaceAll(string: string, find: string, replace: string) {
    return string.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}

/**
 * Object to Array
 */
export function objToArray(obj: any) {
        let returney: any[] = [];

        Object
            .keys(obj)
            .map((objectKey, Index) => {
                returney[Index] = obj[objectKey];
                returney[Index]._objectKey = objectKey;
            });

        return returney;
}
/**
 * Detect if a string RTL
 */
export function detectRTL(text: string) {
    
    // don't count spaces and new line
    text = text.replace(/[\n ]/g, "");

    var rtlChar = /[\u0590-\u083F]|[\u08A0-\u08FF]|[\uFB1D-\uFDFF]|[\uFE70-\uFEFF]/mg;
    
    var totalRTL = text.match(rtlChar) ? text.match(rtlChar).length : 0;
    var totalLTR = text.length - totalRTL;
    
    var ratio = totalRTL / totalLTR;
    
    return ratio >= 1 ? true : false;
}
{'fraction_non_alphanumeric': 0.16412742382271467, 'fraction_numerical': 0.0221606648199446, 'mean_word_length': 2.666243654822335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5169592', 'n_tokens_mistral': 1020, 'n_tokens_neox': 963, 'n_words': 206}