Skip to content

Commit 7d23982

Browse files
authored
fix: Fix bugs to ignore Capital letter at the beginning of the Sentence (#6)
* fix bugs * add comment and get rid of some redundant code * fix change required by author and passed all the testcase
1 parent 1775e0f commit 7d23982

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"textlint-scripts": "^2.1.0"
3636
},
3737
"dependencies": {
38-
"array-includes": "^3.0.1",
38+
"array-includes": "^3.0.3",
3939
"is-capitalized": "^1.0.0"
4040
}
4141
}

src/textlint-rule-unexpanded-acronym.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Step
2727
3. expandedAcronymList.includes(acronymList)
2828
- Not found Acronym and throw error
2929
*/
30-
export default function (context, options = {}) {
30+
module.exports = function (context, options = {}) {
3131
const minAcronymLength = options.min_acronym_len || defaultOptions.min_acronym_len;
3232
const maxAcronymLength = options.max_acronym_len || defaultOptions.max_acronym_len;
3333
const ignoreAcronymList = options.ignore_acronyms || defaultOptions.ignore_acronyms;
@@ -67,18 +67,22 @@ export default function (context, options = {}) {
6767
} else if (!includes(acronymJoiningWords, word) // ignore of and...
6868
&& acronymCreator.canExtractAcronym()) {
6969
// Create Acronym
70-
var acronym = acronymCreator.extractAcronym();
71-
if (isWordSatisfy(acronym)) {
72-
expandedAcronymList.push(acronym);
73-
}
70+
var acronyms = acronymCreator.extractAcronym();
71+
acronyms.forEach(acronym => {
72+
if (isWordSatisfy(acronym)) {
73+
expandedAcronymList.push(acronym);
74+
}
75+
});
7476
}
7577
});
7678
if (acronymCreator.canExtractAcronym()) {
7779
// Create Acronym
78-
var acronym = acronymCreator.extractAcronym();
79-
if (isWordSatisfy(acronym)) {
80-
expandedAcronymList.push(acronym);
81-
}
80+
var acronyms = acronymCreator.extractAcronym();
81+
acronyms.forEach(acronym => {
82+
if (isWordSatisfy(acronym)) {
83+
expandedAcronymList.push(acronym);
84+
}
85+
});
8286
}
8387
},
8488
[Syntax.Document + ":exit"](node){

src/word-utils.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,29 @@ export function expandOneWordToAcronym(CapitalWord) {
2525
}
2626
/*
2727
* create Acronym from words.
28-
* @param words
29-
* @returns {string}
30-
* @example XMLHttpRequest -> XHR
31-
* @example World Health Organization -> WHO
28+
* @param {string[]} words
29+
* @returns (1)string if only one word (2) array if multiple words
3230
*/
3331
export function expandWordsToAcronym(words) {
32+
//XMLHttpRequest -> XHR
3433
if (words.length === 1) {
35-
return expandOneWordToAcronym(words[0]);
34+
return [expandOneWordToAcronym(words[0])];
35+
}
36+
else{
37+
const result = [];
38+
//In American Broadcast Company -> ["C", "BC", "ABC", "IABC"]
39+
words.reverse().reduce((acronym, word, i) => {
40+
acronym.unshift(word.charAt(0))
41+
result.push(acronym.join(""))
42+
return acronym;
43+
}, []);
44+
45+
//In American Broadcast Company -> ["I", "IA", "IAB", "IABC"]
46+
words.reverse().reduce((acronym, word, i) => {
47+
acronym.push(word.charAt(0));
48+
result.push(acronym.join(""))
49+
return acronym;
50+
}, []);
51+
return result;
3652
}
37-
// World Health Organization -> WHO
38-
return words.reduce((acronym, word) => {
39-
acronym += word.charAt(0);
40-
return acronym;
41-
}, "");
4253
}

test/textlint-rule-unexpanded-acronym-test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ always remember (or at least consider).this foodstuff's effect on one's ever-exp
1313
Now we know what SOC stands for`,
1414
// capitalized word
1515
"ABC can stand form the Australian Broadcasting Commission",
16-
"XHR is XMLHttpRequest",
16+
"XHR is known as XMLHttpRequest.",
1717
{
1818
text: `
1919
VHSIC stands for "Very High Speed Integrated Circuit".
@@ -23,6 +23,8 @@ SQL: ([siːkwəl] or ess-cue-el) Structured Query Language.
2323
IEEE: (I triple E) Institute of Electrical and Electronics Engineers
2424
NAACP: (N double A C P) National Association for the Advancement of Colored People
2525
NCAA: (N C double A or N C two A or N C A A) National Collegiate Athletic Association
26+
In the Amazon Web Service, it can be short as AWS.
27+
Enter the Amazon Resource Names(ARN) for the Lambda you created in the setting
2628
`
2729
},
2830
// options

0 commit comments

Comments
 (0)