heading-case 0.1.0 → 0.1.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.
package/README.md CHANGED
@@ -38,12 +38,18 @@ Install:
38
38
  npm add heading-case -D
39
39
  ```
40
40
 
41
- Format all markdown and MDX files in the current directory:
41
+ Check all markdown and MDX files in the current directory:
42
42
 
43
43
  ```bash
44
44
  npx heading-case
45
45
  ```
46
46
 
47
+ Check and write the formatted content to the file:
48
+
49
+ ```bash
50
+ npx heading-case --write
51
+ ```
52
+
47
53
  ## License
48
54
 
49
55
  [MIT](./LICENSE).
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export declare function globMarkdownFiles(cwd: string): Promise<string[]>;
2
+ export declare const formatLine: (originalLine: string) => string;
2
3
  export declare function headingCase({ root, }?: {
3
4
  root?: string;
4
5
  }): Promise<void>;
package/dist/index.js CHANGED
@@ -2912,14 +2912,19 @@ const dict = [
2912
2912
  ...Object.values(general_namespaceObject),
2913
2913
  ...Object.values(products_namespaceObject),
2914
2914
  ...Object.values(softwares_namespaceObject),
2915
+ 'Angular',
2915
2916
  'Create React App',
2917
+ 'Cloudflare Pages',
2916
2918
  'CSS Modules',
2917
2919
  'Docusaurus Faster',
2918
2920
  'EJS',
2921
+ 'Emotion',
2919
2922
  'Fast Refresh',
2923
+ 'GitHub Pages',
2920
2924
  'I',
2921
2925
  'Lightning CSS',
2922
2926
  'Module Federation',
2927
+ 'Relay',
2923
2928
  'Parcel',
2924
2929
  'Preact',
2925
2930
  'Preact Refresh',
@@ -2937,8 +2942,12 @@ const dict = [
2937
2942
  'Rspress',
2938
2943
  'Rstest',
2939
2944
  'Solid',
2945
+ 'Svelte',
2940
2946
  'Server Action',
2947
+ 'Service Worker',
2948
+ 'TanStack Router',
2941
2949
  'Vite',
2950
+ 'Vue',
2942
2951
  'Web Workers',
2943
2952
  'Xcode'
2944
2953
  ];
@@ -2965,6 +2974,7 @@ const isTerm = (word, line)=>dict.some((term)=>{
2965
2974
  if (term.includes(` ${word}`) || term.includes(`${word} `)) return line.includes(term);
2966
2975
  return term === word;
2967
2976
  });
2977
+ const shouldWrite = process.argv.includes('--write');
2968
2978
  const formatLine = (originalLine)=>{
2969
2979
  let line = originalLine;
2970
2980
  const words = line.trim().split(/\s+/);
@@ -2980,20 +2990,28 @@ const formatLine = (originalLine)=>{
2980
2990
  }
2981
2991
  return line;
2982
2992
  };
2983
- function formatContent(content) {
2993
+ function formatContent(content, filePath) {
2984
2994
  const lines = content.split('\n');
2985
2995
  return lines.map((originalLine)=>{
2986
- if (isTitleLine(originalLine)) return formatLine(originalLine);
2996
+ if (isTitleLine(originalLine)) {
2997
+ const formattedLine = formatLine(originalLine);
2998
+ if (!shouldWrite && formattedLine !== originalLine) {
2999
+ logger.error(`Unexpected heading case in ${picocolors_default().dim(filePath)}`);
3000
+ logger.log(` Current: ${picocolors_default().cyan(originalLine)}`);
3001
+ logger.log(` Expected: ${picocolors_default().cyan(formattedLine)}\n`);
3002
+ }
3003
+ return formattedLine;
3004
+ }
2987
3005
  return originalLine;
2988
3006
  }).join('\n');
2989
3007
  }
2990
3008
  async function formatFile(filePath) {
2991
3009
  const content = await __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].promises.readFile(filePath, 'utf-8');
2992
- const formatted = formatContent(content);
3010
+ const formatted = formatContent(content, filePath);
2993
3011
  const isChanged = formatted !== content;
2994
- if (isChanged) {
3012
+ if (isChanged && shouldWrite) {
2995
3013
  await __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].promises.writeFile(filePath, formatted);
2996
- logger.success(`formatted: ${picocolors_default().dim(filePath)}`);
3014
+ logger.success(`[heading-case] formatted: ${picocolors_default().dim(filePath)}`);
2997
3015
  }
2998
3016
  return isChanged;
2999
3017
  }
@@ -3004,6 +3022,12 @@ async function headingCase({ root = process.cwd() } = {}) {
3004
3022
  const isFormatted = await formatFile(file);
3005
3023
  if (isFormatted) count++;
3006
3024
  }
3007
- if (count) logger.success(`[heading-case] formatted ${picocolors_default().yellow(count.toString())} files.`);
3025
+ if (count) {
3026
+ if (shouldWrite) logger.success(`[heading-case] formatted ${picocolors_default().yellow(count.toString())} files.`);
3027
+ else {
3028
+ logger.info(`[heading-case] found issues in ${picocolors_default().yellow(count.toString())} files.`);
3029
+ process.exit(1);
3030
+ }
3031
+ }
3008
3032
  }
3009
- export { globMarkdownFiles, headingCase };
3033
+ export { formatLine, globMarkdownFiles, headingCase };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heading-case",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "repository": "https://github.com/rspack-contrib/heading-case",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,9 +15,16 @@
15
15
  },
16
16
  "module": "./dist/index.mjs",
17
17
  "types": "./dist/index.d.ts",
18
- "files": [
19
- "dist"
20
- ],
18
+ "files": ["dist"],
19
+ "scripts": {
20
+ "build": "rslib build",
21
+ "dev": "rslib build --watch",
22
+ "lint": "biome check .",
23
+ "lint:write": "biome check . --write",
24
+ "prepare": "simple-git-hooks && npm run build",
25
+ "test": "node test/index.js",
26
+ "bump": "npx bumpp"
27
+ },
21
28
  "simple-git-hooks": {
22
29
  "pre-commit": "npm run lint:write"
23
30
  },
@@ -32,16 +39,9 @@
32
39
  "tinyglobby": "^0.2.10",
33
40
  "typescript": "^5.7.2"
34
41
  },
42
+ "packageManager": "pnpm@9.14.4",
35
43
  "publishConfig": {
36
44
  "access": "public",
37
45
  "registry": "https://registry.npmjs.org/"
38
- },
39
- "scripts": {
40
- "build": "rslib build",
41
- "dev": "rslib build --watch",
42
- "lint": "biome check .",
43
- "lint:write": "biome check . --write",
44
- "test": "playwright test",
45
- "bump": "npx bumpp"
46
46
  }
47
- }
47
+ }