@nsis/dent 0.2.0 → 0.2.2

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 (3) hide show
  1. package/README.md +45 -1
  2. package/dist/index.mjs +10 -11
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -10,7 +10,51 @@
10
10
 
11
11
  `npm install @nsis/dent`
12
12
 
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { Dent } from '@nsis/dent';
17
+
18
+ const dent = new Dent(/* user options */);
19
+
20
+ dent.format(`
21
+ # Look ma, no indentation
22
+ Name "Demo"
23
+ Section
24
+ Nop
25
+ Section
26
+ `);
27
+ ```
28
+
29
+ ### Options
30
+
31
+ #### `options.endOfLines`
32
+
33
+ Type: `"crlf" | "lf"`
34
+ Default: `"crlf"` (Windows), `"lf"` (Linux, macOS)
35
+
36
+ #### `options.indentSize`
37
+
38
+ Type: `number`
39
+ Default: `2`
40
+
41
+ #### `options.trimEmptyLines`
42
+
43
+ Type: `boolean`
44
+ Default: `true`
45
+
46
+ #### `options.useTabs`
47
+
48
+ Type: `boolean`
49
+ Default: `true`
50
+
51
+ :white_check_mark: [Why defaulting to tabs is good for accessibility](https://github.com/prettier/prettier/issues/7475#issuecomment-668544890)
52
+
53
+ ## Related
54
+
55
+ - [CLI for `dent`](https://www.npmjs.com/package/@nsis/dent-cli)
56
+
13
57
  ## License
14
58
 
15
59
  This work is licensed under [The MIT License](LICENSE)
16
-
60
+
package/dist/index.mjs CHANGED
@@ -74,14 +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
- endOfLines: void 0,
80
- indentSize: 2,
81
- trimEmptyLines: true,
82
- useTabs: true
83
- };
79
+ options;
84
80
  constructor(options = {}) {
81
+ this.options = {
82
+ endOfLines: platform() === "win32" ? "crlf" : "lf",
83
+ indentSize: defaultIndentation,
84
+ trimEmptyLines: true,
85
+ useTabs: true,
86
+ ...options
87
+ };
85
88
  if (options.useTabs === true && options.indentSize) {
86
89
  throw Error("The indentSize option can only be mixed with useTabs");
87
90
  }
@@ -90,10 +93,6 @@ var Dent = class {
90
93
  throw Error("The indentSize option expects a positive integer");
91
94
  }
92
95
  }
93
- this.options = {
94
- ...this.options,
95
- ...options
96
- };
97
96
  }
98
97
  format(fileContents) {
99
98
  let indentationLevel = 0;
@@ -149,7 +148,7 @@ var Dent = class {
149
148
  }
150
149
  }
151
150
  getIndentChar() {
152
- return this.options.useTabs ? " ".repeat(this.options.indentSize) : " ".repeat(this.options.indentSize);
151
+ return this.options.useTabs ? " ".repeat(this.options.indentSize || defaultIndentation) : " ".repeat(this.options.indentSize || defaultIndentation);
153
152
  }
154
153
  };
155
154
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nsis/dent",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
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"