<commit_before>/** @module Node Pom Parser */
"use strict";
import fs from "fs";
import xml2js, { Options } from "xml2js";
import traverse from "traverse";

// xmljs options https://github.com/Leonidas-from-XIV/node-xml2js#options
var XML2JS_OPTS = {
  trim: true,
  normalizeTags: true,
  normalize: true,
  mergeAttrs: true,
};

/**
 * Parses xml into javascript object by using a file path or an xml content.
 * @param {object} opt Is the option with the filePath or xmlContent and the optional format.
 * @return {object} The pom object along with the timers.
 */
function parse(
  opt: (Options & { filePath?: string; xmlContent?: string }) | null,
  callback: (
    e: Error | null,
    r?: {
      pomXml: string;
      pomObject: object;
    } | null
  ) => void
) {
  if (!opt) {
    throw new Error(
      "You must provide options: opt.filePath and any other option of " +
        "https://github.com/Leonidas-from-XIV/node-xml2js#options"
    );
  }
  if (!opt.xmlContent && !opt.filePath) {
    throw new Error("You must provide the opt.filePath or the opt.xmlContent");
  }<commit_msg>fix: formatting<commit_after>/** @module Node Pom Parser */

"use strict";

import fs from "fs";
import xml2js, { Options } from "xml2js";
import traverse from "traverse";

// xmljs options https://github.com/Leonidas-from-XIV/node-xml2js#options
var XML2JS_OPTS = {
  trim: true,
  normalizeTags: true,
  normalize: true,
  mergeAttrs: true
};

/**
 * Parses xml into javascript object by using a file path or an xml content.
 * @param {object} opt Is the option with the filePath or xmlContent and the optional format.
 * @return {object} The pom object along with the timers.
 */
function parse(
  opt: (Options & { filePath?: string; xmlContent?: string }) | null,
  callback: (
    e: Error | null,
    r?: {
      pomXml: string;
      pomObject: object;
    } | null
  ) => void
) {
  if (!opt) {
    throw new Error(
      "You must provide options: opt.filePath and any other option of " +
        "https://github.com/Leonidas-from-XIV/node-xml2js#options"
    );
  }
  if (!opt.xmlContent && !opt.filePath) {
    throw new Error("You must provide the opt.filePath or the opt.xmlContent");
  }
{'fraction_non_alphanumeric': 0.12721490231712856, 'fraction_numerical': 0.004543389368468878, 'mean_word_length': 3.2022900763358777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, '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': '6044852', 'n_tokens_mistral': 723, 'n_tokens_neox': 714, 'n_words': 241}