@nsis/dent 0.1.2 → 0.2.1

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.
Files changed (2) hide show
  1. package/dist/index.mjs +15 -12
  2. package/package.json +2 -1
package/dist/index.mjs CHANGED
@@ -74,13 +74,17 @@ var rules = {
74
74
  };
75
75
 
76
76
  // src/main.ts
77
+ var defaultIndentation = 2;
77
78
  var Dent = class {
78
- options = {
79
- indentSize: 2,
80
- trimEmptyLines: true,
81
- useTabs: true
82
- };
79
+ options;
83
80
  constructor(options = {}) {
81
+ this.options = {
82
+ endOfLines: platform() === "win32" ? "crlf" : "lf",
83
+ indentSize: defaultIndentation,
84
+ trimEmptyLines: true,
85
+ useTabs: true,
86
+ ...options
87
+ };
84
88
  if (options.useTabs === true && options.indentSize) {
85
89
  throw Error("The indentSize option can only be mixed with useTabs");
86
90
  }
@@ -89,10 +93,6 @@ var Dent = class {
89
93
  throw Error("The indentSize option expects a positive integer");
90
94
  }
91
95
  }
92
- this.options = {
93
- ...this.options,
94
- ...options
95
- };
96
96
  }
97
97
  format(fileContents) {
98
98
  let indentationLevel = 0;
@@ -134,9 +134,12 @@ var Dent = class {
134
134
  return formattedLines.join(lineEndings);
135
135
  }
136
136
  appendLine(line, level) {
137
- return line.length ? `${this.getIndentChar(this.options).repeat(level)}${line.trim()}` : "";
137
+ return line.length ? `${this.getIndentChar().repeat(level)}${line.trim()}` : "";
138
138
  }
139
139
  detectEOL(input) {
140
+ if (this.options.endOfLines) {
141
+ return this.options.endOfLines === "crlf" ? "\r\n" : "\n";
142
+ }
140
143
  const newLine = detectNewline(input);
141
144
  if (newLine !== void 0) {
142
145
  return newLine;
@@ -144,8 +147,8 @@ var Dent = class {
144
147
  return platform() === "win32" ? "\r\n" : "\n";
145
148
  }
146
149
  }
147
- getIndentChar(options) {
148
- return options.useTabs ? " " : " ".repeat(options.indentSize);
150
+ getIndentChar() {
151
+ return this.options.useTabs ? " ".repeat(this.options.indentSize || defaultIndentation) : " ".repeat(this.options.indentSize || defaultIndentation);
149
152
  }
150
153
  };
151
154
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nsis/dent",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "description": "An opinionated code formatter for NSIS scripts",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -21,6 +21,7 @@
21
21
  "README.md"
22
22
  ],
23
23
  "type": "module",
24
+ "types": "./src/main.ts",
24
25
  "exports": {
25
26
  ".": {
26
27
  "import": "./dist/index.mjs"