1.1.9 • Published 6 years ago

grammarland v1.1.9

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

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:

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:

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(); 
1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago