<commit_before>'use strict';

const _   = require('lodash');
const fs  = require('fs-extra');
const rcs = require('../rcs');
const StringDecoder = require('string_decoder').StringDecoder;

// matches from . or # every character until : or . or ) (for pseudo elements or dots or even in :not(.class))
const regex = {
    selectors: /(#|\.)[^\s:\.\{)[>+,\s]+/g, // matches all selectors beginning with . or # - e.g. .matching#alsomatch .matchmetoo
    multiLineComments: /\/\*([\s\S]*?)\*\//g, // match /* */ from files
    doubleQuotes: /"[^"]*"/g, // match everything within " " (double quotes)
    singleQuotes: /'[^']*'/g, // match everything within " " (double quotes)
    sizesWithDots: /\.([0-9]+?)(em|rem|%|vh|vw|s|cm|ex|in|mm|pc|pt|px|vmin)[^a-zA-Z]/g, // match everything which starts with . and has numbers in it and ends with em, rem,... plus no letter comes after - necessary for .9em or .10s
    onlyNumbers: /\.([0-9]*?)[0-9](\s|;|}|\))/g, // match if there are just numbers between . and \s or ; or } or ) - otherwise it will be regogniced as class
    urlAttributes: /url\(([\s\S]*?)\)/g, // matches url() attributes from css - it can contain .woff or .html or similiar
    hexCodes: /#([a-zA-Z0-9]{3,6})(\s|;|}|!|,)/g, // matches hex colors with 3 or 6 values - unfortunately also matches also ids with 3 or 6 digits - e.g. matches #fff #header #0d0d0d
    strings: /('|")\s*[\s\S]*?\s*('|")/g, // matches strings such as: 'hello' or "hello"
    attributeContent: /:.+(;|})/g // matches everything between : and ; - in case everything is in one line, and `;` is missing it will go until `}` - good for: `filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);`
};

/**
 * parses through every single document and renames the names
 * (require(rcs-core)).replace
 *
 * @module replace
 */
const replace = module.exports = {};

/**
 * Parse a file and returns new selectors if the option 'isSelectors' is set to true
 * runs internally replace.buffer
 *
 * @param  {String} filepath    the file's path to change
 * @param  {Object} [options]   same as replace.buffer
 * @param  {Object} cb          the callback
 *
 * @return {Object}
 */
replace.file = (filepath, options, cb) => {
    const decoder = new StringDecoder('utf8');

    // set cb if options are not set
    if (typeof cb !== 'function') {
        cb      = options;<commit_msg>fix matching string which are no strings (fix #5)<commit_after>'use strict';

const _   = require('lodash');
const fs  = require('fs-extra');
const rcs = require('../rcs');
const StringDecoder = require('string_decoder').StringDecoder;

// matches from . or # every character until : or . or ) (for pseudo elements or dots or even in :not(.class))
const regex = {
    selectors: /(#|\.)[^\s:\.\{)[>+,\s]+/g, // matches all selectors beginning with . or # - e.g. .matching#alsomatch .matchmetoo
    multiLineComments: /\/\*([\s\S]*?)\*\//g, // match /* */ from files
    doubleQuotes: /"[^"]*"/g, // match everything within " " (double quotes)
    singleQuotes: /'[^']*'/g, // match everything within " " (double quotes)
    sizesWithDots: /\.([0-9]+?)(em|rem|%|vh|vw|s|cm|ex|in|mm|pc|pt|px|vmin)[^a-zA-Z]/g, // match everything which starts with . and has numbers in it and ends with em, rem,... plus no letter comes after - necessary for .9em or .10s
    onlyNumbers: /\.([0-9]*?)[0-9](\s|;|}|\))/g, // match if there are just numbers between . and \s or ; or } or ) - otherwise it will be regogniced as class
    urlAttributes: /url\(([\s\S]*?)\)/g, // matches url() attributes from css - it can contain .woff or .html or similiar
    hexCodes: /#([a-zA-Z0-9]{3,6})(\s|;|}|!|,)/g, // matches hex colors with 3 or 6 values - unfortunately also matches also ids with 3 or 6 digits - e.g. matches #fff #header #0d0d0d
    strings: /"\s*[\S\w\d ]*?\s*"|'\s*[\S\w\d ]*?\s*'/g, // matches strings such as: 'hello' or "hello"
    attributeContent: /:.+(;|})/g // matches everything between : and ; - in case everything is in one line, and `;` is missing it will go until `}` - good for: `filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);`
};

/**
 * parses through every single document and renames the names
 * (require(rcs-core)).replace
 *
 * @module replace
 */
const replace = module.exports = {};

/**
 * Parse a file and returns new selectors if the option 'isSelectors' is set to true
 * runs internally replace.buffer
 *
 * @param  {String} filepath    the file's path to change
 * @param  {Object} [options]   same as replace.buffer
 * @param  {Object} cb          the callback
 *
 * @return {Object}
 */
replace.file = (filepath, options, cb) => {
    const decoder = new StringDecoder('utf8');

    // set cb if options are not set
    if (typeof cb !== 'function') {
        cb      = options;
{'fraction_non_alphanumeric': 0.18250156608895385, 'fraction_numerical': 0.00897891000208812, 'mean_word_length': 3.1471861471861473, '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': '6306906', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1552, 'n_words': 527}