@mitre/inspec-objects 0.0.2 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,4 @@
1
1
  import Profile from '../objects/profile';
2
2
  import { ProfileDiff } from '../types/diff';
3
- import Control from '../objects/control';
4
- export declare function updateControl(originalControlString: string, originalControl: Control, updatedControl: Control): void;
3
+ export declare function removeNewlines(control?: Record<string, unknown>): Record<string, unknown>;
5
4
  export declare function diffProfile(fromProfile: Profile, toProfile: Profile): ProfileDiff;
@@ -1,13 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.diffProfile = exports.updateControl = void 0;
3
+ exports.diffProfile = exports.removeNewlines = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const json_diff_1 = require("json-diff");
6
6
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
- function updateControl(originalControlString, originalControl, updatedControl) {
8
- console.log('Here is the original control:');
7
+ function removeNewlines(control) {
8
+ if (!control) {
9
+ return {};
10
+ }
11
+ return lodash_1.default.mapValues(control, (value) => {
12
+ if (typeof value === 'string') {
13
+ return value.replace(/\n/g, '{{{{newlineHERE}}}}').trim();
14
+ }
15
+ else if (typeof value === 'object' && value !== null) {
16
+ return removeNewlines(value);
17
+ }
18
+ return value;
19
+ });
9
20
  }
10
- exports.updateControl = updateControl;
21
+ exports.removeNewlines = removeNewlines;
11
22
  function diffProfile(fromProfile, toProfile) {
12
23
  const profileDiff = {
13
24
  addedControlIDs: [],
@@ -4,5 +4,6 @@ declare const escapeQuotes: (s: string) => string;
4
4
  declare const escapeDoubleQuotes: (s: string) => string;
5
5
  declare const wrapAndEscapeQuotes: (s: string, lineLength?: number) => string;
6
6
  export { escapeQuotes, escapeDoubleQuotes, wrapAndEscapeQuotes };
7
+ export declare function removeNewlinePlaceholders(s: string): string;
7
8
  export declare function getFirstPath(object: Record<string, unknown>, paths: string[]): string;
8
9
  export declare function hasPath(file: Record<string, unknown>, path: string | string[]): boolean;
@@ -1,11 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasPath = exports.getFirstPath = exports.wrapAndEscapeQuotes = exports.escapeDoubleQuotes = exports.escapeQuotes = exports.unformatText = exports.wrap = void 0;
3
+ exports.hasPath = exports.getFirstPath = exports.removeNewlinePlaceholders = exports.wrapAndEscapeQuotes = exports.escapeDoubleQuotes = exports.escapeQuotes = exports.unformatText = exports.wrap = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
6
  // Breaks lines down to lineLength number of characters
7
7
  function wrap(s, lineLength = 80) {
8
- return s.replace(new RegExp(`(?![^\n]{1,${lineLength}}$)([^\n]{1,${lineLength}})`, "g"), "$1\n");
8
+ let newString = "";
9
+ let currentLine = "";
10
+ let currentLength = 0;
11
+ let shouldBreakLine = false;
12
+ for (var i = 0; i < s.length; i++) {
13
+ if (shouldBreakLine) {
14
+ newString += `\n`;
15
+ currentLength = 0;
16
+ shouldBreakLine = false;
17
+ }
18
+ let currentChar = s.charAt(i);
19
+ let nextChar = s.charAt(i + 1);
20
+ if (nextChar === " ") {
21
+ if (currentLength >= lineLength) {
22
+ shouldBreakLine = true;
23
+ newString += currentChar;
24
+ currentLength++;
25
+ }
26
+ else {
27
+ newString += currentChar;
28
+ currentLength++;
29
+ }
30
+ }
31
+ else {
32
+ newString += currentChar;
33
+ currentLength++;
34
+ }
35
+ }
36
+ return newString;
9
37
  }
10
38
  exports.wrap = wrap;
11
39
  function unformatText(s) {
@@ -18,6 +46,10 @@ const escapeDoubleQuotes = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
18
46
  exports.escapeDoubleQuotes = escapeDoubleQuotes;
19
47
  const wrapAndEscapeQuotes = (s, lineLength) => escapeDoubleQuotes(wrap(s, lineLength)); // Escape backslashes and quotes, and wrap long lines
20
48
  exports.wrapAndEscapeQuotes = wrapAndEscapeQuotes;
49
+ function removeNewlinePlaceholders(s) {
50
+ return s.replace(/\{\{\{\{newlineHERE\}\}\}\}/g, '\n');
51
+ }
52
+ exports.removeNewlinePlaceholders = removeNewlinePlaceholders;
21
53
  function getFirstPath(object, paths) {
22
54
  const index = lodash_1.default.findIndex(paths, (p) => hasPath(object, p));
23
55
  if (index === -1) {
@@ -1,5 +1,6 @@
1
1
  import { DecodedDescription } from '../types/xccdf';
2
2
  export declare function convertEncodedXmlIntoJson(encodedXml: string): any;
3
+ export declare function removeXMLSpecialCharacters(input: string): string;
3
4
  export declare function severityStringToImpact(string: string, id: string): number;
4
5
  export declare function impactNumberToSeverityString(impact: number): string;
5
6
  export declare function convertEncodedHTMLIntoJson(encodedHTML?: string): DecodedDescription;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertEncodedHTMLIntoJson = exports.impactNumberToSeverityString = exports.severityStringToImpact = exports.convertEncodedXmlIntoJson = void 0;
3
+ exports.convertEncodedHTMLIntoJson = exports.impactNumberToSeverityString = exports.severityStringToImpact = exports.removeXMLSpecialCharacters = exports.convertEncodedXmlIntoJson = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fast_xml_parser_1 = tslib_1.__importDefault(require("fast-xml-parser"));
6
6
  const htmlparser = tslib_1.__importStar(require("htmlparser2"));
@@ -14,6 +14,10 @@ function convertEncodedXmlIntoJson(encodedXml) {
14
14
  });
15
15
  }
16
16
  exports.convertEncodedXmlIntoJson = convertEncodedXmlIntoJson;
17
+ function removeXMLSpecialCharacters(input) {
18
+ return input.replace(/&amp;/gm, '&').replace(/&lt;/gm, '<').replace(/&gt;/gm, '>');
19
+ }
20
+ exports.removeXMLSpecialCharacters = removeXMLSpecialCharacters;
17
21
  function severityStringToImpact(string, id) {
18
22
  var _a, _b, _c, _d, _e;
19
23
  if ((_a = string.match(/none|na|n\/a|not[\s()*_|]?applicable/i)) === null || _a === void 0 ? void 0 : _a.length) {
Binary file
Binary file