@purestack/ts-format 0.0.0-stage → 1.1.24
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 +21 -0
- package/README.md +44 -2
- package/dist/files.d.mts +39 -0
- package/dist/files.d.mts.map +1 -0
- package/dist/files.mjs +19070 -0
- package/dist/files.mjs.map +1 -0
- package/dist/ts-format.d.mts +178 -0
- package/dist/ts-format.d.mts.map +1 -0
- package/dist/ts-format.mjs +18981 -0
- package/dist/ts-format.mjs.map +1 -0
- package/package.json +46 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ahmed Yasin Koculu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @purestack/ts-format
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The shared PureStack formatter used by PureStack CLI and the VS Code extension.
|
|
4
|
+
Formats component markup in MDX/RMDX and `html`/`svg` tagged templates in TypeScript.
|
|
5
|
+
Markdown prose, frontmatter, code samples, expressions, and surrounding TypeScript
|
|
6
|
+
are preserved. Biome handles the rest of the project's formatting.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { formatSource } from '@purestack/ts-format'
|
|
10
|
+
|
|
11
|
+
const result = await formatSource(source, { filePath: 'content/page.mdx' })
|
|
12
|
+
// result.code, result.changed, result.edits, result.diagnostics
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Options include `printWidth` (80), `tabSize` (2), `useTabs` (false), and an optional
|
|
16
|
+
`onlyWithinRange` with UTF-16 source offsets. Edits refer to the original source.
|
|
17
|
+
Line endings are preserved. Diagnostics identify markup that could not be formatted.
|
|
18
|
+
|
|
19
|
+
For files and directories:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { formatFiles } from '@purestack/ts-format/files'
|
|
23
|
+
|
|
24
|
+
const result = await formatFiles(['content'], {
|
|
25
|
+
cwd: process.cwd(),
|
|
26
|
+
write: true,
|
|
27
|
+
})
|
|
28
|
+
// result.checked, result.changed, result.errors
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
File operations default to checking without writing, honor Git ignores for directory
|
|
32
|
+
scans, skip symlinks and generated directories, and collect failures across files.
|
|
33
|
+
A file with formatting errors is never written. `exclude` accepts additional file
|
|
34
|
+
or directory paths relative to `cwd`. Without Git, directory scans still work and
|
|
35
|
+
skip known output, dependency, and cache directories.
|
|
36
|
+
|
|
37
|
+
From a PureStack project:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
purestack format content --write
|
|
41
|
+
purestack format content --check
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
In this repository, `yarn format:markup --write` formats PureStack markup only.
|
|
45
|
+
`yarn format` runs Biome followed by this formatter; `yarn format:check` checks both.
|
package/dist/files.d.mts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*! @purestack/ts-format v1.1.24 | (c) 2026 Ahmed Yasin Koculu | MIT License */
|
|
2
|
+
|
|
3
|
+
//#region packages/ts-format/src/html.d.ts
|
|
4
|
+
interface HtmlFormattingOptions {
|
|
5
|
+
printWidth: number;
|
|
6
|
+
tabSize: number;
|
|
7
|
+
useTabs: boolean;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region packages/ts-format/src/source.d.ts
|
|
11
|
+
interface SourceRange {
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
}
|
|
15
|
+
interface FormatOptions extends Partial<HtmlFormattingOptions> {
|
|
16
|
+
filePath?: string;
|
|
17
|
+
language?: 'mdx' | 'typescript';
|
|
18
|
+
onlyWithinRange?: SourceRange;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region packages/ts-format/src/files.d.ts
|
|
22
|
+
export interface FormatFilesOptions extends Omit<FormatOptions, 'filePath' | 'language' | 'onlyWithinRange'> {
|
|
23
|
+
cwd?: string;
|
|
24
|
+
write?: boolean;
|
|
25
|
+
/** Files or directories to omit, relative to cwd. */
|
|
26
|
+
exclude?: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
export interface FormatFileError {
|
|
29
|
+
filePath: string;
|
|
30
|
+
message: string;
|
|
31
|
+
}
|
|
32
|
+
/** Discover source files, honor Git ignores in repositories, and collect all failures. */
|
|
33
|
+
export declare function formatFiles(inputs?: readonly string[], options?: FormatFilesOptions): Promise<{
|
|
34
|
+
checked: number;
|
|
35
|
+
changed: string[];
|
|
36
|
+
errors: FormatFileError[];
|
|
37
|
+
}>;
|
|
38
|
+
//#endregion
|
|
39
|
+
//# sourceMappingURL=files.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.mts","names":[],"sources":["../src/html.ts","../src/source.ts","../src/files.ts"],"mappings":";UAsBiB;EACf;EACA;EACA;;;;UCvBe;EACf;EACA;;UAWe,sBAAsB,QAAQ;EAC7C;EACA;EACA,kBAAkB;;;;iBCSH,2BACP,KAAK;EACb;EACA;;EAEA;;iBAGe;EACf;EACA;;;wBAIoB,YACpB,4BACA,UAAS,qBAAuB"}
|