chromium-formatters 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ // Copyright 2026 Cyril Li
2
+ // Copyright 2015 The Chromium Authors
3
+ //
4
+ // Redistribution and use in source and binary forms, with or without
5
+ // modification, are permitted provided that the following conditions are
6
+ // met:
7
+ //
8
+ // * Redistributions of source code must retain the above copyright
9
+ // notice, this list of conditions and the following disclaimer.
10
+ // * Redistributions in binary form must reproduce the above
11
+ // copyright notice, this list of conditions and the following disclaimer
12
+ // in the documentation and/or other materials provided with the
13
+ // distribution.
14
+ // * Neither the name of Google LLC nor the names of its
15
+ // contributors may be used to endorse or promote products derived from
16
+ // this software without specific prior written permission.
17
+ //
18
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # chromium-format-javascript
2
+
3
+ The same formatters used by Chrom(ium) DevTools' "Pretty Print" feature, extracted into a standalone module for use outside of it. The supported languages are CSS, HTML, JavaScript, and JSON.
4
+
5
+ ## Installation
6
+
7
+ This library has no external dependencies and has both ESM and UMD builds.
8
+
9
+ ## Usage
10
+
11
+ ### ESM (e.g. Node.js with "type": "module" or browser with `<script type="module">`):
12
+
13
+ ```js
14
+ import chromiumFormatter from 'dist/main.esm.js';
15
+
16
+ // Use the MIME type corresponding with the language of the input string (e.g. for JavaScript):
17
+ const { content } = chromiumFormatter('text/javascript', input);
18
+
19
+ // Use a different indent amount (default is 4 spaces):
20
+ const { content } = chromiumFormatter('text/javascript', input, ' ');
21
+ ```
22
+
23
+ ### UMD (e.g. AMD, CJS, or browser `<script>` tag without `type="module"`):
24
+
25
+ ```html
26
+ <script src="dist/main.cjs"></script>
27
+ <script>
28
+ const { content } = chromiumFormatter("text/javascript", input);
29
+ </script>
30
+ ```
31
+
32
+ ```js
33
+ // CommonJS
34
+ const chromiumFormatter = require('../dist/main.cjs');
35
+ const { content } = chromiumFormatter("text/javascript", input);
36
+ ```
37
+
38
+ ## Build
39
+
40
+ ```bash
41
+ npm run build
42
+ ```
43
+
44
+ ## Tests
45
+
46
+ See [tests/README.md](./tests/README.md).
47
+
48
+ ## Chromium Source Files
49
+
50
+ All files had their `import` paths modified to reference this project's flat `src` directory, and filetypes adjusted between JS and TS as needed.
51
+
52
+ - acorn.mjs: Acorn version 8.10.0, as per [README.chromium](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/third_party/acorn/README.chromium).
53
+ - [AcornTokenizer.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/entrypoints/formatter_worker/AcornTokenizer.ts)
54
+ - [ArrayUtilities.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/platform/ArrayUtilities.ts)
55
+ - [CSSFormatter.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/entrypoints/formatter_worker/CSSFormatter.ts)
56
+ - [ESTreeWalker.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/entrypoints/formatter_worker/ESTreeWalker.ts)
57
+ - [FormattedContentBuilder.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/entrypoints/formatter_worker/FormattedContentBuilder.ts)
58
+ - [FormatterActions.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/entrypoints/formatter_worker/FormatterActions.ts)
59
+ - [FormatterWorker.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/entrypoints/formatter_worker/FormatterWorker.ts)
60
+ - The debug function `disableLoggingForTest` and its required import [root.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/root/root.ts) were removed.
61
+ - codemirror.trimmed.mjs: Codemirror version 5.61.0, as per [README.chromium](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/third_party/codemirror/README.chromium).
62
+ - codemirror.trimmed.mjs was created from concatenating `lib/codemirror.js`, `mode/css/css.js`, and `mode/xml/xml.js`, only keeping the parts of the code used by the formatters.
63
+ - [HTMLFormatter.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/entrypoints/formatter_worker/HTMLFormatter.ts)
64
+ - [IdentityFormatter.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/entrypoints/formatter_worker/IdentityFormatter.ts)
65
+ - [JavaScriptFormatter.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/entrypoints/formatter_worker/JavaScriptFormatter.ts)
66
+ - [JSONFormatter.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/entrypoints/formatter_worker/JSONFormatter.ts)
67
+ - [platform.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/platform/platform.ts): A thinned-down version only importing and re-exporting `ArrayUtilities` and `StringUtilities`.
68
+ - [ScopeParser.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/entrypoints/formatter_worker/ScopeParser.ts)
69
+ - [StringUtilities.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/platform/StringUtilities.ts)
70
+ - The type file [Brand.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/platform/Brand.ts) was removed.
71
+ - [Substitute.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/entrypoints/formatter_worker/Substitute.ts)
72
+ - [text_utils.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/models/text_utils/text_utils.ts): A thinned-down version only importing and re-exporting `TextCursor`.
73
+ - [TextCursor.ts](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/models/text_utils/TextCursor.ts)