@nsis/dent 0.3.1 → 0.4.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.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > An opinionated code formatter for NSIS scripts
4
4
 
5
5
  [![License](https://img.shields.io/github/license/idleberg/node-dent?color=blue&style=for-the-badge)](https://github.com/idleberg/node-dent/blob/main/LICENSE)
6
- [![npm](https://img.shields.io/npm/v/@nsis/dent?style=for-the-badge)](https://www.npmjs.org/package/@nsis/dent)
6
+ [![Version](https://img.shields.io/npm/v/@nsis/dent?style=for-the-badge)](https://www.npmjs.org/package/@nsis/dent)
7
7
  [![Build](https://img.shields.io/github/actions/workflow/status/idleberg/node-dent/default.yml?style=for-the-badge)](https://github.com/idleberg/node-dent/actions)
8
8
 
9
9
  ## Installation
@@ -52,7 +52,7 @@ Default: `true`
52
52
 
53
53
  ## Related
54
54
 
55
- - [CLI for `dent`](https://www.npmjs.com/package/@nsis/dent-cli)
55
+ - [CLI](https://www.npmjs.com/package/@nsis/dent-cli)
56
56
 
57
57
  ## License
58
58
 
package/dist/dent.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Formats the given file contents using the Dent formatting style.
3
+ *
4
+ * @param {NsisDent.Options} options - The options for the Dent formatter.
5
+ * @returns {function(string): string} The formatting function.
6
+ * @throws {Error} Throws an error if the options are invalid.
7
+ */
8
+ declare function createFormatter(options?: NsisDent.Options): (fileContents: string) => string;
9
+
10
+ export { createFormatter };
package/dist/dent.js ADDED
@@ -0,0 +1,10 @@
1
+ import { detectNewline } from 'detect-newline';
2
+ import { platform } from 'node:os';
3
+
4
+ var d={indenters:["!if","!ifdef","!ifmacrodef","!ifmacrondef","!ifndef","!macro","${Case}","${Case2}","${Case3}","${Case4}","${Case5}","${CaseElse}","${Default}","${Do}","${DoUntil}","${DoWhile}","${For}","${ForEach}","${If}","${IfNot}","${MementoSection}","${MementoUnselectedSection}","${Select}","${Switch}","${Unless}","Function","PageEx","Section","SectionGroup"].map(s=>s.toLowerCase()),dedenters:["!endif","!macroend","${EndIf}","${EndSelect}","${EndSwitch}","${EndWhile}","${Loop}","${LoopUntil}","${LoopWhile}","${MementoSectionEnd}","${Next}","${While}","FunctionEnd","PageExEnd","SectionEnd","SectionGroupEnd"].map(s=>s.toLowerCase()),specialIndenters:["!else","!elseif","${Else}","${ElseIf}","${ElseIfNot}","${ElseUnless}","${AndIf}","${AndIfNot}","${AndUnless}","${OrIf}","${OrIfNot}","${OrUnless}"].map(s=>s.toLowerCase()),specialDedenters:["${Break}"].map(s=>s.toLowerCase())};var f=2;function C(s={}){let n={endOfLines:platform()==="win32"?"crlf":"lf",indentSize:f,trimEmptyLines:!0,useTabs:!0,...s};if(n.useTabs===!1&&n.indentSize&&(isNaN(n.indentSize)||n.indentSize<=0))throw Error("The indentSize option expects a positive integer");function p(t){let e=0,l=0,c=u(t),i=[];return (n.trimEmptyLines===!0?t.trim().replaceAll(/^(\s*\r?\n){2,}/gm,c).split(c):t.split(c)).forEach(r=>{let a=r.trim().split(" ").at(0)??"";switch(a.toLowerCase()==="${Switch}"&&(l=e),!0){case a.toLowerCase()==="${EndSwitch}":e=l,i.push(o(r,e)),e=e===0?0:e-1;break;case d.specialIndenters.includes(a.toLowerCase()):i.push(o(r,e-1));break;case d.specialDedenters.includes(a.toLowerCase()):i.push(o(r,e)),e--;break;case d.indenters.includes(a.toLowerCase()):i.push(o(r,e)),e++;break;case d.dedenters.includes(a.toLowerCase()):e=e===0?0:e-1,i.push(o(r,e));break;default:i.push(o(r,e));break}}),i.join(c)}function o(t,e){return t.length?`${m(e)}${t.trim()}`:""}function u(t){if(n.endOfLines)return n.endOfLines==="crlf"?`\r
5
+ `:`
6
+ `;let e=detectNewline(t);return e!==void 0?e:platform()==="win32"?`\r
7
+ `:`
8
+ `}function m(t){return (n.useTabs?" ".repeat(n.indentSize||f):" ".repeat(n.indentSize||f)).repeat(t)}return p}
9
+
10
+ export { C as createFormatter };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@nsis/dent",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "An opinionated code formatter for NSIS scripts",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
- "build": "esbuild src/main.ts --bundle --platform=node --outfile=dist/index.mjs --format=esm --external:detect-newline --external:globby",
7
+ "build": "tsup",
8
8
  "dev": "npm run start",
9
9
  "fix": "eslint --fix ./src",
10
10
  "lint:json": "eslint ./*.json --ignore-path .gitignore",
@@ -23,10 +23,10 @@
23
23
  "README.md"
24
24
  ],
25
25
  "type": "module",
26
- "typings": "types/",
27
- "exports": "./dist/index.mjs",
26
+ "typings": "dist/dent.d.ts",
27
+ "exports": "./dist/dent.js",
28
28
  "engines": {
29
- "node": "^14.13.1 || >=16.0.0"
29
+ "node": ">=18.0.0"
30
30
  },
31
31
  "repository": {
32
32
  "type": "git",
@@ -37,21 +37,21 @@
37
37
  "formatter"
38
38
  ],
39
39
  "dependencies": {
40
- "detect-newline": "^4.0.0"
40
+ "detect-newline": "^4.0.1"
41
41
  },
42
42
  "devDependencies": {
43
- "@types/node": "^20.2.1",
44
- "@typescript-eslint/eslint-plugin": "^6.0.0",
45
- "@typescript-eslint/parser": "^6.0.0",
46
- "esbuild": "^0.18.13",
47
- "eslint": "^8.45.0",
43
+ "@types/node": "^18.19.3",
44
+ "@typescript-eslint/eslint-plugin": "^6.16.0",
45
+ "@typescript-eslint/parser": "^6.16.0",
46
+ "eslint": "^8.56.0",
48
47
  "eslint-plugin-json": "^3.1.0",
49
48
  "husky": "^8.0.3",
50
- "lint-staged": "^13.2.3",
51
- "npm-run-all2": "^6.0.6",
52
- "tslib": "^2.6.0",
49
+ "lint-staged": "^15.2.0",
50
+ "npm-run-all2": "^6.1.1",
51
+ "tslib": "^2.6.2",
53
52
  "tsm": "^2.3.0",
54
- "typescript": "^5.1.6",
53
+ "tsup": "^8.0.1",
54
+ "typescript": "^5.3.3",
55
55
  "uvu": "^0.5.6"
56
56
  },
57
57
  "lint-staged": {
package/types/index.d.ts CHANGED
@@ -11,4 +11,3 @@ declare namespace NsisDent {
11
11
 
12
12
  export = NsisDent;
13
13
  export as namespace NsisDent;
14
-
package/dist/index.mjs DELETED
@@ -1,151 +0,0 @@
1
- // src/main.ts
2
- import { detectNewline } from "detect-newline";
3
- import { platform } from "node:os";
4
-
5
- // src/rules.ts
6
- var rules = {
7
- indenters: [
8
- "!if",
9
- "!ifdef",
10
- "!ifmacrodef",
11
- "!ifmacrondef",
12
- "!ifndef",
13
- "!macro",
14
- "${Case}",
15
- "${Case2}",
16
- "${Case3}",
17
- "${Case4}",
18
- "${Case5}",
19
- "${CaseElse}",
20
- "${Default}",
21
- "${Do}",
22
- "${DoUntil}",
23
- "${DoWhile}",
24
- "${For}",
25
- "${ForEach}",
26
- "${If}",
27
- "${IfNot}",
28
- "${MementoSection}",
29
- "${MementoUnselectedSection}",
30
- "${Select}",
31
- "${Switch}",
32
- "${Unless}",
33
- "Function",
34
- "PageEx",
35
- "Section",
36
- "SectionGroup"
37
- ].map((i) => i.toLowerCase()),
38
- dedenters: [
39
- "!endif",
40
- "!macroend",
41
- "${EndIf}",
42
- "${EndSelect}",
43
- "${EndSwitch}",
44
- "${EndWhile}",
45
- "${Loop}",
46
- "${LoopUntil}",
47
- "${LoopWhile}",
48
- "${MementoSectionEnd}",
49
- "${Next}",
50
- "${While}",
51
- "FunctionEnd",
52
- "PageExEnd",
53
- "SectionEnd",
54
- "SectionGroupEnd"
55
- ].map((i) => i.toLowerCase()),
56
- // These follow indenters, but aren't indented themselves
57
- specialIndenters: [
58
- "!else",
59
- "!elseif",
60
- "${Else}",
61
- "${ElseIf}",
62
- "${ElseIfNot}",
63
- "${ElseUnless}",
64
- "${AndIf}",
65
- "${AndIfNot}",
66
- "${AndUnless}",
67
- "${OrIf}",
68
- "${OrIfNot}",
69
- "${OrUnless}"
70
- ].map((i) => i.toLowerCase()),
71
- specialDedenters: [
72
- "${Break}"
73
- ].map((i) => i.toLowerCase())
74
- };
75
-
76
- // src/main.ts
77
- var defaultIndentation = 2;
78
- function createFormatter(options = {}) {
79
- const mergedOptions = {
80
- endOfLines: platform() === "win32" ? "crlf" : "lf",
81
- indentSize: defaultIndentation,
82
- trimEmptyLines: true,
83
- useTabs: true,
84
- ...options
85
- };
86
- if (mergedOptions.useTabs === false && mergedOptions.indentSize) {
87
- if (isNaN(mergedOptions.indentSize) || mergedOptions.indentSize <= 0) {
88
- throw Error("The indentSize option expects a positive integer");
89
- }
90
- }
91
- function format(fileContents) {
92
- let indentationLevel = 0;
93
- let switchIndentationLevel = 0;
94
- const lineEndings = detectEOL(fileContents);
95
- const formattedLines = [];
96
- const lines = mergedOptions.trimEmptyLines === true ? fileContents.trim().replaceAll(/^(\s*\r?\n){2,}/gm, lineEndings).split(lineEndings) : fileContents.split(lineEndings);
97
- lines.forEach((line) => {
98
- const keyword = line.trim().split(" ").at(0) ?? "";
99
- if (keyword.toLowerCase() === "${Switch}") {
100
- switchIndentationLevel = indentationLevel;
101
- }
102
- switch (true) {
103
- case keyword.toLowerCase() === "${EndSwitch}":
104
- indentationLevel = switchIndentationLevel;
105
- formattedLines.push(appendLine(line, indentationLevel));
106
- indentationLevel = indentationLevel === 0 ? 0 : indentationLevel - 1;
107
- break;
108
- case rules.specialIndenters.includes(keyword.toLowerCase()):
109
- formattedLines.push(appendLine(line, indentationLevel - 1));
110
- break;
111
- case rules.specialDedenters.includes(keyword.toLowerCase()):
112
- formattedLines.push(appendLine(line, indentationLevel));
113
- indentationLevel--;
114
- break;
115
- case rules.indenters.includes(keyword.toLowerCase()):
116
- formattedLines.push(appendLine(line, indentationLevel));
117
- indentationLevel++;
118
- break;
119
- case rules.dedenters.includes(keyword.toLowerCase()):
120
- indentationLevel = indentationLevel === 0 ? 0 : indentationLevel - 1;
121
- formattedLines.push(appendLine(line, indentationLevel));
122
- break;
123
- default:
124
- formattedLines.push(appendLine(line, indentationLevel));
125
- break;
126
- }
127
- });
128
- return formattedLines.join(lineEndings);
129
- }
130
- function appendLine(line, level) {
131
- return line.length ? `${getIndentChar(level)}${line.trim()}` : "";
132
- }
133
- function detectEOL(input) {
134
- if (mergedOptions.endOfLines) {
135
- return mergedOptions.endOfLines === "crlf" ? "\r\n" : "\n";
136
- }
137
- const newLine = detectNewline(input);
138
- if (newLine !== void 0) {
139
- return newLine;
140
- } else {
141
- return platform() === "win32" ? "\r\n" : "\n";
142
- }
143
- }
144
- function getIndentChar(level) {
145
- return (mergedOptions.useTabs ? " ".repeat(mergedOptions.indentSize || defaultIndentation) : " ".repeat(mergedOptions.indentSize || defaultIndentation)).repeat(level);
146
- }
147
- return format;
148
- }
149
- export {
150
- createFormatter
151
- };