Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
indefinite
Advanced tools
Prefix a noun with an indefinite article - a or an - based on whether it begins with a vowel
The 'indefinite' npm package is used to determine the correct indefinite article ('a' or 'an') for a given word or phrase. This can be particularly useful in natural language processing, text generation, and other applications where proper grammar is important.
Basic Usage
This feature allows you to get the correct indefinite article for a single word. The function takes a word as input and returns the word prefixed with the correct indefinite article.
const indefinite = require('indefinite');
console.log(indefinite('apple')); // Output: 'an apple'
console.log(indefinite('banana')); // Output: 'a banana'
Handling Phrases
This feature allows you to get the correct indefinite article for a phrase. The function takes a phrase as input and returns the phrase prefixed with the correct indefinite article.
const indefinite = require('indefinite');
console.log(indefinite('hour of work')); // Output: 'an hour of work'
console.log(indefinite('unicorn in the garden')); // Output: 'a unicorn in the garden'
Custom Options
This feature allows you to customize the output, such as capitalizing the first letter of the article. The function takes a word or phrase and an options object as input and returns the word or phrase prefixed with the correct indefinite article, formatted according to the options.
const indefinite = require('indefinite');
console.log(indefinite('apple', { capitalize: true })); // Output: 'An apple'
console.log(indefinite('banana', { capitalize: true })); // Output: 'A banana'
The 'an' package provides similar functionality by determining whether to use 'a' or 'an' before a word. It is simpler and more lightweight compared to 'indefinite', but it may not handle complex phrases as effectively.
The 'article' package also determines the correct indefinite article for a given word. It is comparable to 'indefinite' in terms of functionality but may have different handling for edge cases and custom options.
Prefix a noun with an indefinite article - a or an - based on whether it begins with a vowel.
npm install --save indefinite
It's not hard to check whether a noun begins with a vowel and decide whether to prefix with "a" or "an," but I got tired of doing it manually every time. So now there's this. Just pass in the word, and indefinite
will return the word prefixed with either "a " or "an " depending on the first letter of the word.
As of version 2.0.0, indefinite
will attempt to detect when an acronym is passed in and treat the response differently. E.g. it should be "a UFO" not "an UFO" because of how we pronounce a long U. This isn't a perfect science, so you might have false positives.
As of version 2.0.2, indefinite
will also consult a list of irregular words to determine the appropriate article. For example, it should be "an hour" not "a hour." It also attempts to do this with various forms of the words (checking for singular, plural, and even past tense, since past tense verbs can be used as adjectives, as in "an honored man"). This is not an exact science, and the list of irregulars is not exhaustive (and probably won't ever be), but if you find a word that's not in the list that's returning the wrong thing, please open an issue so it can be corrected.
var a = require('indefinite');
console.log(a('apple')); // "an apple"
console.log(a('banana')); // "a banana"
console.log(a('UFO')); // 'a UFO'
console.log(a('hour')); // 'an hour'
console.log(a('ukelele')); // 'a ukelele'
Indefinite also accepts an options object as the second parameter. Currently, two options are supported: capitalize
, for capitalizing the article, and caseInsensitive
for ignoring the casing of the word passed in (i.e. bypassing the acronym checking). This is useful if, for some reason, you're yelling on the internet and want to make sure "UGLY GARDEN GNOME" doesn't become "a UGLY GARDEN GNOME."
console.log(a('apple', { capitalize: true })); // 'An apple'
console.log(a('banana', { capitalize: true })); // 'A banana'
console.log(a('UGLY SWEATER', { caseInsensitve: true })); // 'an UGLY SWEATER'
Just serve dist/indefinite.min.js
however you serve javascript, then call indefinite("noun")
. The indefinite
function is added to window.
Please see the contribution guidelines.
FAQs
Prefix a noun with an indefinite article - a or an - based on whether it begins with a vowel
The npm package indefinite receives a total of 148,375 weekly downloads. As such, indefinite popularity was classified as popular.
We found that indefinite demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.