heading-case 0.1.2 → 0.1.3

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
@@ -2975,20 +2975,47 @@ const isTerm = (word, line)=>dict.some((term)=>{
2975
2975
  return term === word;
2976
2976
  });
2977
2977
  const shouldWrite = process.argv.includes('--write');
2978
- const formatLine = (originalLine)=>{
2979
- let line = originalLine;
2980
- const words = line.trim().split(/\s+/);
2978
+ const lineToWords = (line)=>{
2979
+ const words = [];
2980
+ let lastWord = {
2981
+ type: 'word',
2982
+ value: ''
2983
+ };
2984
+ for (const char of line.split(''))if (/\s/.test(char)) {
2985
+ if ('space' === lastWord.type) lastWord.value += char;
2986
+ else {
2987
+ words.push(lastWord);
2988
+ lastWord = {
2989
+ type: 'space',
2990
+ value: char
2991
+ };
2992
+ }
2993
+ } else if ('word' === lastWord.type) lastWord.value += char;
2994
+ else {
2995
+ words.push(lastWord);
2996
+ lastWord = {
2997
+ type: 'word',
2998
+ value: char
2999
+ };
3000
+ }
3001
+ words.push(lastWord);
3002
+ return words;
3003
+ };
3004
+ const formatLine = (line)=>{
3005
+ const words = lineToWords(line);
2981
3006
  const englishWords = [];
2982
3007
  for(let index = 0; index < words.length; index++){
2983
3008
  const word = words[index];
2984
- if (isEnglishWord(word)) englishWords.push(word);
3009
+ const { type, value } = word;
3010
+ if ('space' === type) continue;
3011
+ if (isEnglishWord(value)) englishWords.push(value);
2985
3012
  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);
3013
+ isTerm(value, line) || // only format the first-char-uppercase English words
3014
+ !isFirstCharUppercase(value)) continue;
3015
+ const lowerCase = value.toLowerCase();
3016
+ if (lowerCase !== value) word.value = lowerCase;
2990
3017
  }
2991
- return line;
3018
+ return words.map((word)=>word.value).join('');
2992
3019
  };
2993
3020
  function formatContent(content, filePath) {
2994
3021
  const lines = content.split('\n');
@@ -3028,6 +3055,6 @@ async function headingCase({ root = process.cwd() } = {}) {
3028
3055
  logger.info(`[heading-case] found issues in ${picocolors_default().yellow(count.toString())} files.`);
3029
3056
  process.exit(1);
3030
3057
  }
3031
- }
3058
+ } else logger.success(`[heading-case] ${picocolors_default().yellow(files.length)} files scanned, no issues found.`);
3032
3059
  }
3033
3060
  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.3",
4
4
  "repository": "https://github.com/rspack-contrib/heading-case",
5
5
  "license": "MIT",
6
6
  "type": "module",