heading-case 0.0.1 → 0.1.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 +33 -1
- package/dist/index.js +35 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# heading-case
|
|
2
2
|
|
|
3
|
-
Format page titles and section headings in markdown files to use sentence-style capitalization.
|
|
3
|
+
Format page titles and section headings in markdown files to use [sentence-style capitalization](https://learn.microsoft.com/en-us/style-guide/text-formatting/using-type/use-sentence-style-capitalization).
|
|
4
4
|
|
|
5
5
|
<p>
|
|
6
6
|
<a href="https://npmjs.com/package/heading-case">
|
|
@@ -10,6 +10,26 @@ Format page titles and section headings in markdown files to use sentence-style
|
|
|
10
10
|
<a href="https://npmcharts.com/compare/heading-case?minimal=true"><img src="https://img.shields.io/npm/dm/heading-case.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
|
+
## Example
|
|
14
|
+
|
|
15
|
+
- Input:
|
|
16
|
+
|
|
17
|
+
```md
|
|
18
|
+
# A New Method for Creating JavaScript Rollovers
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- Output:
|
|
22
|
+
|
|
23
|
+
```md
|
|
24
|
+
# A new method for creating JavaScript rollovers
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Limitations
|
|
28
|
+
|
|
29
|
+
This package is designed for Rspack's documentation. It follows the writing style of Rspack documentation and may not work well for other projects.
|
|
30
|
+
|
|
31
|
+
There are some edge cases that can not be correctly handled, so the execution result is not completely reliable.
|
|
32
|
+
|
|
13
33
|
## Usage
|
|
14
34
|
|
|
15
35
|
Install:
|
|
@@ -18,6 +38,18 @@ Install:
|
|
|
18
38
|
npm add heading-case -D
|
|
19
39
|
```
|
|
20
40
|
|
|
41
|
+
Check all markdown and MDX files in the current directory:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx heading-case
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Check and write the formatted content to the file:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npx heading-case --write
|
|
51
|
+
```
|
|
52
|
+
|
|
21
53
|
## License
|
|
22
54
|
|
|
23
55
|
[MIT](./LICENSE).
|
package/dist/index.js
CHANGED
|
@@ -2912,21 +2912,35 @@ const dict = [
|
|
|
2912
2912
|
...Object.values(general_namespaceObject),
|
|
2913
2913
|
...Object.values(products_namespaceObject),
|
|
2914
2914
|
...Object.values(softwares_namespaceObject),
|
|
2915
|
+
'Create React App',
|
|
2916
|
+
'CSS Modules',
|
|
2917
|
+
'Docusaurus Faster',
|
|
2915
2918
|
'EJS',
|
|
2916
|
-
'
|
|
2919
|
+
'Fast Refresh',
|
|
2920
|
+
'I',
|
|
2921
|
+
'Lightning CSS',
|
|
2922
|
+
'Module Federation',
|
|
2923
|
+
'Parcel',
|
|
2924
|
+
'Preact',
|
|
2925
|
+
'Preact Refresh',
|
|
2926
|
+
'React',
|
|
2927
|
+
'React Compiler',
|
|
2928
|
+
'React Router',
|
|
2929
|
+
'React Server Components',
|
|
2930
|
+
'Rollup',
|
|
2917
2931
|
'Rsbuild',
|
|
2918
2932
|
'Rsdoctor',
|
|
2919
2933
|
'Rslib',
|
|
2934
|
+
'Rspack',
|
|
2935
|
+
'Rstack',
|
|
2936
|
+
'Rspack Stack',
|
|
2920
2937
|
'Rspress',
|
|
2921
2938
|
'Rstest',
|
|
2922
|
-
'
|
|
2923
|
-
'
|
|
2939
|
+
'Solid',
|
|
2940
|
+
'Server Action',
|
|
2924
2941
|
'Vite',
|
|
2925
|
-
'Module Federation',
|
|
2926
|
-
'CSS Modules',
|
|
2927
2942
|
'Web Workers',
|
|
2928
|
-
'
|
|
2929
|
-
'React Router'
|
|
2943
|
+
'Xcode'
|
|
2930
2944
|
];
|
|
2931
2945
|
async function globMarkdownFiles(cwd) {
|
|
2932
2946
|
return glob([
|
|
@@ -2951,6 +2965,7 @@ const isTerm = (word, line)=>dict.some((term)=>{
|
|
|
2951
2965
|
if (term.includes(` ${word}`) || term.includes(`${word} `)) return line.includes(term);
|
|
2952
2966
|
return term === word;
|
|
2953
2967
|
});
|
|
2968
|
+
const shouldWrite = process.argv.includes('--write');
|
|
2954
2969
|
const formatLine = (originalLine)=>{
|
|
2955
2970
|
let line = originalLine;
|
|
2956
2971
|
const words = line.trim().split(/\s+/);
|
|
@@ -2966,20 +2981,28 @@ const formatLine = (originalLine)=>{
|
|
|
2966
2981
|
}
|
|
2967
2982
|
return line;
|
|
2968
2983
|
};
|
|
2969
|
-
function formatContent(content) {
|
|
2984
|
+
function formatContent(content, filePath) {
|
|
2970
2985
|
const lines = content.split('\n');
|
|
2971
2986
|
return lines.map((originalLine)=>{
|
|
2972
|
-
if (isTitleLine(originalLine))
|
|
2987
|
+
if (isTitleLine(originalLine)) {
|
|
2988
|
+
const formattedLine = formatLine(originalLine);
|
|
2989
|
+
if (!shouldWrite && formattedLine !== originalLine) {
|
|
2990
|
+
logger.error(`Unexpected heading case in ${picocolors_default().dim(filePath)}`);
|
|
2991
|
+
logger.log(` Current: ${picocolors_default().cyan(originalLine)}`);
|
|
2992
|
+
logger.log(` Expected: ${picocolors_default().cyan(formattedLine)}\n`);
|
|
2993
|
+
}
|
|
2994
|
+
return formattedLine;
|
|
2995
|
+
}
|
|
2973
2996
|
return originalLine;
|
|
2974
2997
|
}).join('\n');
|
|
2975
2998
|
}
|
|
2976
2999
|
async function formatFile(filePath) {
|
|
2977
3000
|
const content = await __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].promises.readFile(filePath, 'utf-8');
|
|
2978
|
-
const formatted = formatContent(content);
|
|
3001
|
+
const formatted = formatContent(content, filePath);
|
|
2979
3002
|
const isChanged = formatted !== content;
|
|
2980
|
-
if (isChanged) {
|
|
3003
|
+
if (isChanged && shouldWrite) {
|
|
2981
3004
|
await __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].promises.writeFile(filePath, formatted);
|
|
2982
|
-
logger.success(
|
|
3005
|
+
logger.success(`[heading-case] formatted: ${picocolors_default().dim(filePath)}`);
|
|
2983
3006
|
}
|
|
2984
3007
|
return isChanged;
|
|
2985
3008
|
}
|