Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs to ignore Capital letter at the beginning of the Sentence #6

Merged
merged 3 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"textlint-scripts": "^2.1.0"
},
"dependencies": {
"array-includes": "^3.0.1",
"array-includes": "^3.0.3",
"is-capitalized": "^1.0.0"
}
}
32 changes: 25 additions & 7 deletions src/textlint-rule-unexpanded-acronym.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Step
3. expandedAcronymList.includes(acronymList)
- Not found Acronym and throw error
*/
export default function (context, options = {}) {
module.exports = function (context, options = {}) {
const minAcronymLength = options.min_acronym_len || defaultOptions.min_acronym_len;
const maxAcronymLength = options.max_acronym_len || defaultOptions.max_acronym_len;
const ignoreAcronymList = options.ignore_acronyms || defaultOptions.ignore_acronyms;
Expand Down Expand Up @@ -67,17 +67,35 @@ export default function (context, options = {}) {
} else if (!includes(acronymJoiningWords, word) // ignore of and...
&& acronymCreator.canExtractAcronym()) {
// Create Acronym
var acronym = acronymCreator.extractAcronym();
if (isWordSatisfy(acronym)) {
expandedAcronymList.push(acronym);
var acronyms = acronymCreator.extractAcronym();
//if the acronyms is a string i.e. only one acronym
if(!Array.isArray(acronyms)){
if (isWordSatisfy(acronyms)) {
expandedAcronymList.push(acronyms);
}
//if the acronyms is an array of acronym, we need to extract the satisfied ones
}else{
acronyms.forEach(acronym => {
if (isWordSatisfy(acronym)) {
expandedAcronymList.push(acronym);
}
});
}
}
});
if (acronymCreator.canExtractAcronym()) {
// Create Acronym
var acronym = acronymCreator.extractAcronym();
if (isWordSatisfy(acronym)) {
expandedAcronymList.push(acronym);
var acronyms = acronymCreator.extractAcronym();
if(!Array.isArray(acronyms)){
if (isWordSatisfy(acronyms)) {
expandedAcronymList.push(acronyms);
}
}else{
acronyms.forEach(acronym => {
if (isWordSatisfy(acronym)) {
expandedAcronymList.push(acronym);
}
});
}
}
},
Expand Down
29 changes: 20 additions & 9 deletions src/word-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,29 @@ export function expandOneWordToAcronym(CapitalWord) {
}
/*
* create Acronym from words.
* @param words
* @returns {string}
* @example XMLHttpRequest -> XHR
* @example World Health Organization -> WHO
* @param words (array)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not JSDoc.

Suggested change
* @param words (array)
* @param {string[]} words

* @returns (1)string if only one word (2) array if multiple words
*/
export function expandWordsToAcronym(words) {
//XMLHttpRequest -> XHR
if (words.length === 1) {
return expandOneWordToAcronym(words[0]);
Copy link
Member

@azu azu Aug 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good interface that always return an array.

return [expandOneWordToAcronym(words[0]))

This change will remove unnessary Array.isArray code from https://github.com/textlint-rule/textlint-rule-unexpanded-acronym/pull/6/files#diff-8c133963a70d07eee0bd3b0a4e71f38eR72

                    var acronyms = acronymCreator.extractAcronym();
-                    //if the acronyms is a string i.e. only one acronym
-                    if(!Array.isArray(acronyms)){
-                        if (isWordSatisfy(acronyms)) {
-                            expandedAcronymList.push(acronyms);
-                        }
-                    //if the acronyms is an array of acronym, we need - to extract the satisfied ones
-                    }else{
                        acronyms.forEach(acronym => {
                            if (isWordSatisfy(acronym)) {
                                expandedAcronymList.push(acronym);
                            }
                        });
-                    }

}
// World Health Organization -> WHO
return words.reduce((acronym, word) => {
acronym += word.charAt(0);
return acronym;
}, "");
else{
const result = [];
//In American Broadcast Company -> ["C", "BC", "ABC", "IABC"]
words.reverse().reduce((acronym, word, i) => {
acronym.unshift(word.charAt(0))
result.push(acronym.join(""))
return acronym;
}, []);

//In American Broadcast Company -> ["I", "IA", "IAB", "IABC"]
words.reverse().reduce((acronym, word, i) => {
acronym += word.charAt(0);
result.push(acronym)
return acronym;
}, []);
donganzh-zz marked this conversation as resolved.
Show resolved Hide resolved
return result;
}
}
4 changes: 3 additions & 1 deletion test/textlint-rule-unexpanded-acronym-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ always remember (or at least consider).this foodstuff's effect on one's ever-exp
Now we know what SOC stands for`,
// capitalized word
"ABC can stand form the Australian Broadcasting Commission",
"XHR is XMLHttpRequest",
"XHR is known as XMLHttpRequest.",
{
text: `
VHSIC stands for "Very High Speed Integrated Circuit".
Expand All @@ -23,6 +23,8 @@ SQL: ([siːkwəl] or ess-cue-el) Structured Query Language.
IEEE: (I triple E) Institute of Electrical and Electronics Engineers
NAACP: (N double A C P) National Association for the Advancement of Colored People
NCAA: (N C double A or N C two A or N C A A) National Collegiate Athletic Association
In the Amazon Web Service, it can be short as AWS.
Enter the Amazon Resource Names(ARN) for the Lambda you created in the setting
`
},
// options
Expand Down