@mitre/inspec-objects 0.0.4 → 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.
@@ -49,10 +49,8 @@ function diffProfile(fromProfile, toProfile) {
49
49
  const toControl = toProfile.controls.find((control) => control.id === fromControl.id);
50
50
  if (toControl) {
51
51
  const controlDiff = (0, json_diff_1.diff)(fromControl, toControl);
52
- console.log(controlDiff);
53
52
  if (controlDiff) {
54
53
  Object.entries(controlDiff).forEach(([key, value]) => {
55
- console.log(value);
56
54
  if (lodash_1.default.has(value, '__new')) {
57
55
  lodash_1.default.set(profileDiff, 'changedControls.' + fromControl.id + '.' + key.replace('.', '\\.'), lodash_1.default.get(controlDiff, key + '.__new'));
58
56
  }
@@ -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) {
Binary file
Binary file
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@mitre/inspec-objects",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@mitre/inspec-objects",
9
- "version": "0.0.1",
9
+ "version": "0.0.3",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@types/flat": "^5.0.2",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mitre/inspec-objects",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Typescript objects for normalizing between InSpec profiles and XCCDF benchmarks",
5
5
  "main": "lib/index.js",
6
6
  "publishConfig": {
Binary file