grammarland v1.1.9
Grammarland
Ever done this?
return "A" + item.name
But then turns out the name was Apple, and now you've said A Apple
? Now theres a handy package to take some of the struggle out of every-day grammar formatting, including the "a/an" situation, converting an array of words to a nice proper sentence, and more!
Think we need a feature, or found a bug? Submit an issue!
Usage
MeteorJS
Install with meteor npm meteor npm install --save grammarland
import grammarland from 'grammarland';
console.log(grammarland.startsWithVowel("apple"));
NPM
Install with npm npm i grammarland
let grammarland = require('grammarland');
console.log(grammarland.startsWithVowel("apple"));
Table of Contents
This package contains:
- Accessor methods - Return a representation of the data passed in
- Mutator methods - Return a modified version of the data passed in
- sentenceify() - Make a string a proper sentence
- indefiniteArticle() - Add "a" or "an" to start of a string
- stringifyArray() - Convert array of strings to a comma seperated list string with correct grammar
- ordinalSuffix() - Adds a suffix for ranking (like 'st', 'nd', etc) to a number
- pluralForm() - Returns plural form of provided word if provided number is not one
Grammarland also exposes a string prototype
Accessor Methods
startsWithVowel() - Check if a string starts with a vowel
startsWithVowel(str)
Checks if first letter of str is a vowel. Returns true or false. Case-insensitive.
validateSentence() - Check if a string is a valid sentence
validateSentence(str)
Similar to sentenceify(), except instead of fixing the sentence throws a human-friendly error if there is an issue with the sentence, or true if there are no issues. Unlike sentenceify(), validateSentence() does not accept options.
Mutator Methods
sentenceify() - Make a string a proper sentence
stringifyArray(str, options)
Does the following fixes to a string (if not already done):
- Makes the first letter uppercase
- Adds a period or options.endMark (see below) to the end (if the last character is not a period, question mark, or exclamation point)
Accepts optional options object with following properties:
{
endMark:String (default: ".") // Defines the end mark to be used if there is not already one present.
}
indefiniteArticle() - Add "a" or "an" to start of a string
indefiniteArticle(str, capitalize)
Returns str with "a" or "an" added to start depending on if the first character in str is a vowel. Capitalize is optional, and defaults to true. Pass true to capitalze (e.g. A, An) and false to keep lowercase (e.g. a, an).
Consider using sentenceify() to ensure that you have a complete sentence.
stringifyArray() - Convert array to a string with correct grammar
stringifyArray(array)
Returns a string with correct comma-list grammar. Consider using sentenceify() to ensure that you have a complete sentence.
Example:
- stringifyArray('a'); // "a"
- stringifyArray('a', 'b'); // "a and b"
- stringifyArray('a', 'b', 'c'); // "a, b, and c"
ordinalSuffix() - Adds a suffix for ranking to a number
ordinalSuffix(num)
Given a number for num, returns a string with an added suffix for ordinal ranking. For example, 1 returns '1st', 2 returns '2nd', and so-on.
pluralForm() - Returns plural form of provided word if provided number is not one
pluralForm(num, str, options)
Given a number for num, returns str un-changed if number is 1, otherwise returns str + "s".
Accepts optional options object with following properties:
{
addition:String (default: "s") // Overrides the string added for plural form. This is needed for words like "actress" whose plural form is "actresses" not "actresss"
}
String Prototype
These functions are also added to the string prototype with the first str argument omitted:
- validateSentence
- sentenceify
- startsWithVowel
- indefiniteArticle
Usage
<string>.<function>(<args>);
Example
// Note that if you were using the grammarland function you'd be passing a str argument, but since this is a prototype it's ommitted
let sentence = "hello world".sentenceify({"endMark":"!"});
let swv = "hello world".startsWithVowel();
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago