heading-case 0.1.2 → 0.1.4

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare function globMarkdownFiles(cwd: string): Promise<string[]>;
2
- export declare const formatLine: (originalLine: string) => string;
2
+ export declare const formatLine: (line: string) => string;
3
3
  export declare function headingCase({ root, }?: {
4
4
  root?: string;
5
5
  }): Promise<void>;
package/dist/index.js CHANGED
@@ -2916,14 +2916,19 @@ const dict = [
2916
2916
  'Create React App',
2917
2917
  'Cloudflare Pages',
2918
2918
  'CSS Modules',
2919
+ 'Docusaurus',
2919
2920
  'Docusaurus Faster',
2920
2921
  'EJS',
2921
2922
  'Emotion',
2922
2923
  'Fast Refresh',
2924
+ 'GitHub Actions',
2923
2925
  'GitHub Pages',
2924
2926
  'I',
2925
2927
  'Lightning CSS',
2926
2928
  'Module Federation',
2929
+ 'Nextra',
2930
+ 'Netlify',
2931
+ 'Kinsta',
2927
2932
  'Relay',
2928
2933
  'Parcel',
2929
2934
  'Preact',
@@ -2949,7 +2954,8 @@ const dict = [
2949
2954
  'Vite',
2950
2955
  'Vue',
2951
2956
  'Web Workers',
2952
- 'Xcode'
2957
+ 'Xcode',
2958
+ 'Zeabur'
2953
2959
  ];
2954
2960
  async function globMarkdownFiles(cwd) {
2955
2961
  return glob([
@@ -2975,20 +2981,47 @@ const isTerm = (word, line)=>dict.some((term)=>{
2975
2981
  return term === word;
2976
2982
  });
2977
2983
  const shouldWrite = process.argv.includes('--write');
2978
- const formatLine = (originalLine)=>{
2979
- let line = originalLine;
2980
- const words = line.trim().split(/\s+/);
2984
+ const lineToWords = (line)=>{
2985
+ const words = [];
2986
+ let lastWord = {
2987
+ type: 'word',
2988
+ value: ''
2989
+ };
2990
+ for (const char of line.split(''))if (/\s/.test(char)) {
2991
+ if ('space' === lastWord.type) lastWord.value += char;
2992
+ else {
2993
+ words.push(lastWord);
2994
+ lastWord = {
2995
+ type: 'space',
2996
+ value: char
2997
+ };
2998
+ }
2999
+ } else if ('word' === lastWord.type) lastWord.value += char;
3000
+ else {
3001
+ words.push(lastWord);
3002
+ lastWord = {
3003
+ type: 'word',
3004
+ value: char
3005
+ };
3006
+ }
3007
+ words.push(lastWord);
3008
+ return words;
3009
+ };
3010
+ const formatLine = (line)=>{
3011
+ const words = lineToWords(line);
2981
3012
  const englishWords = [];
2982
3013
  for(let index = 0; index < words.length; index++){
2983
3014
  const word = words[index];
2984
- if (isEnglishWord(word)) englishWords.push(word);
3015
+ const { type, value } = word;
3016
+ if ('space' === type) continue;
3017
+ if (isEnglishWord(value)) englishWords.push(value);
2985
3018
  if (englishWords.length <= 1 || // ignore terms
2986
- isTerm(word, originalLine) || // only format the first-char-uppercase English words
2987
- !isFirstCharUppercase(word)) continue;
2988
- const lowerCaseWord = word.toLowerCase();
2989
- if (lowerCaseWord !== word) line = line.replace(new RegExp(`\\b${word}\\b`, 'g'), lowerCaseWord);
3019
+ isTerm(value, line) || // only format the first-char-uppercase English words
3020
+ !isFirstCharUppercase(value)) continue;
3021
+ const lowerCase = value.toLowerCase();
3022
+ if (lowerCase !== value) word.value = lowerCase;
2990
3023
  }
2991
- return line;
3024
+ return words.map((word)=>word.value).join('');
2992
3025
  };
2993
3026
  function formatContent(content, filePath) {
2994
3027
  const lines = content.split('\n');
@@ -3028,6 +3061,6 @@ async function headingCase({ root = process.cwd() } = {}) {
3028
3061
  logger.info(`[heading-case] found issues in ${picocolors_default().yellow(count.toString())} files.`);
3029
3062
  process.exit(1);
3030
3063
  }
3031
- }
3064
+ } else logger.success(`[heading-case] ${picocolors_default().yellow(files.length)} files scanned, no issues found.`);
3032
3065
  }
3033
3066
  export { formatLine, globMarkdownFiles, headingCase };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heading-case",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "repository": "https://github.com/rspack-contrib/heading-case",
5
5
  "license": "MIT",
6
6
  "type": "module",