<commit_before>'use strict';

/**
 * Module dependencies.
 */

var path = require('path');
var matter = require('gray-matter');
var parsePath = require('parse-filepath');
var normalize = require('normalize-path');
var File = require('gulp-util').File;


/**
 * ## .parseFile
 *
 * Parses a file and its filepath, creates a new vinyl-fs `file` object
 * and extends it with extra properties:
 *
 *   - `cwd`: {String} The current working directory.
 *   - `base`: {String} Typically where a glob starts, used to generate relative paths.
 *   - `path`: {String} The full path to the file.
 *   - `dirname`: {String} The dirname from `path.dirname()`.
 *   - `basename`: {String} The basename from `path.basename()`.
 *   - `name`: {String} The basename of the file without extension.
 *   - `extname`: {String} The file extension from `path.extname()`.
 *   - `extSegments`: {Array} File extensions. e.g. `.min.js` => `['.min', '.js']`
 *   - `orig`: {Buffer} The original, unparsed content of the file.
 *   - `contents`: {Buffer} The parsed content of the file, excluding front-matter.
 *   - `locals`: {Object} Parsed data from front-matter
 *   - `stat`: {Object}
 *
 * @param {String} `filepath` path to file to parse
 * @param {String} `str` optional string content to parse
 * @param {Object} `options`
 * @return {Object} The `file` object.
 */

exports.parseFile = function parseFile(name, str, options) {
  if (arguments.length === 2) {
    if (typeof str !== 'string') {
      options = str;
      str = null;
    }
  }
  options = options || {};

  // `name` is usually a filepath.
  name = path.resolve(name);
  var parsed = parsePath(name);
  var page = str ? matter(str, options) : matter.read(name, options);

  var file = new File({
    path: normalize(name),
    contents: new Buffer(page.content)
  });

  // Buffer the original content, in case it's needed
  file.orig = new Buffer(page.original);
  file.data = page.data;

  // Normalize paths
  file.base = normalize(file.base);
  file.cwd = normalize(options.cwd || file.cwd);

  // Add path properties to the `file` object
  for (var key in parsed) {
    if (parsed.hasOwnProperty(key)) {
      file[key] = parsed[key];
    }
  }
  return file;
};



exports.parseString = function parseFile(str, options) {
  options = options || {};

  var page = matter(str, options);
  var file = new File({
    path: options.path || process.cwd(),
    contents: new Buffer(page.content)
  });

  file.orig = new Buffer(page.original);
  file.data = page.data;
  file.base = normalize(file.base);
  file.cwd = normalize(options.cwd || file.cwd);
  return file;
};
<commit_msg>fix `parseString` function name<commit_after>'use strict';

/**
 * Module dependencies.
 */

var path = require('path');
var matter = require('gray-matter');
var parsePath = require('parse-filepath');
var normalize = require('normalize-path');
var File = require('gulp-util').File;


/**
 * ## .parseFile
 *
 * Parses a file and its filepath, creates a new vinyl-fs `file` object
 * and extends it with extra properties:
 *
 *   - `cwd`: {String} The current working directory.
 *   - `base`: {String} Typically where a glob starts, used to generate relative paths.
 *   - `path`: {String} The full path to the file.
 *   - `dirname`: {String} The dirname from `path.dirname()`.
 *   - `basename`: {String} The basename from `path.basename()`.
 *   - `name`: {String} The basename of the file without extension.
 *   - `extname`: {String} The file extension from `path.extname()`.
 *   - `extSegments`: {Array} File extensions. e.g. `.min.js` => `['.min', '.js']`
 *   - `orig`: {Buffer} The original, unparsed content of the file.
 *   - `contents`: {Buffer} The parsed content of the file, excluding front-matter.
 *   - `locals`: {Object} Parsed data from front-matter
 *   - `stat`: {Object}
 *
 * @param {String} `filepath` path to file to parse
 * @param {String} `str` optional string content to parse
 * @param {Object} `options`
 * @return {Object} The `file` object.
 */

exports.parseFile = function parseFile(name, str, options) {
  if (arguments.length === 2) {
    if (typeof str !== 'string') {
      options = str;
      str = null;
    }
  }
  options = options || {};

  // `name` is usually a filepath.
  name = path.resolve(name);
  var parsed = parsePath(name);
  var page = str ? matter(str, options) : matter.read(name, options);

  var file = new File({
    path: normalize(name),
    contents: new Buffer(page.content)
  });

  // Buffer the original content, in case it's needed
  file.orig = new Buffer(page.original);
  file.data = page.data;

  // Normalize paths
  file.base = normalize(file.base);
  file.cwd = normalize(options.cwd || file.cwd);

  // Add path properties to the `file` object
  for (var key in parsed) {
    if (parsed.hasOwnProperty(key)) {
      file[key] = parsed[key];
    }
  }
  return file;
};



exports.parseString = function parseString(str, options) {
  options = options || {};

  var page = matter(str, options);
  var file = new File({
    path: options.path || process.cwd(),
    contents: new Buffer(page.content)
  });

  file.orig = new Buffer(page.original);
  file.data = page.data;
  file.base = normalize(file.base);
  file.cwd = normalize(options.cwd || file.cwd);
  return file;
};

{'fraction_non_alphanumeric': 0.15765595463137996, 'fraction_numerical': 0.0003780718336483932, 'mean_word_length': 3.294642857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2437577', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1674, 'n_words': 533}