english-a-an
Advanced tools
Comparing version 0.8.9 to 0.8.10
export interface AnList { | ||
[key: string]: number; | ||
} | ||
export declare function getAAn(anList: AnList, text: string): 'a' | 'an'; | ||
interface ContractData { | ||
aan: 'a' | 'an'; | ||
} | ||
interface ContractsData { | ||
[key: string]: ContractData; | ||
} | ||
export declare function getAAn(contractsData: ContractsData, anList: AnList, text: string): 'a' | 'an'; | ||
export {}; |
@@ -6,3 +6,3 @@ "use strict"; | ||
const moreExceptions = { Irishman: 1, SSO: 1, HEPA: 1, AI: 1, honour: 1 }; | ||
function getAAn(anList, text) { | ||
function getAAn(contractsData, anList, text) { | ||
if (!text) { | ||
@@ -14,3 +14,6 @@ const err = new Error(); | ||
} | ||
if ((anList && anList[text] == 1) || (moreExceptions && moreExceptions[text] == 1)) { | ||
if (contractsData && contractsData[text] && contractsData[text].aan) { | ||
return contractsData[text].aan; | ||
} | ||
else if ((anList && anList[text] == 1) || (moreExceptions && moreExceptions[text] == 1)) { | ||
return 'an'; | ||
@@ -17,0 +20,0 @@ } |
{ | ||
"name": "english-a-an", | ||
"version": "0.8.9", | ||
"version": "0.8.10", | ||
"description": "English a/an indefinite articles, based on WordNet", | ||
@@ -47,3 +47,3 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"english-a-an-list": "0.8.9" | ||
"english-a-an-list": "0.8.10" | ||
}, | ||
@@ -59,3 +59,3 @@ "keywords": [ | ||
"license": "MIT", | ||
"gitHead": "cad6ab45154f6680478ace7af2b4eb3b233f9392" | ||
"gitHead": "c4be3bba693b9c5e1564b6da828850c26c7e030f" | ||
} |
# English a/an | ||
Determines whether a sequence (word or adjective) should start with `a` or `an`: _an elephant_, _a European_, _an Irishman_, _an heir_, etc. | ||
Determines whether a sequence (noun or adjective) should start with `a` or `an`: _an elephant_, _a European_, _an Irishman_, _an heir_, etc. | ||
It is based on a list of words or adjectives that must be preceded by `an`: use `english-a-an-list` as that list. | ||
It is based on a list of words that must be preceded by `an`: use `english-a-an-list` as that list. | ||
@@ -11,4 +11,5 @@ | ||
`getAAn` will return either `a` or `an` based on: | ||
- a list of words or adjectives that must be preceded by `an`: use `english-a-an-list` | ||
- the word or adjective as a string | ||
- a list custom of exceptions: map where the word is the key, and value has a `aan` key with either `a` or `an` as a value; in general put just null here | ||
- a list of words that must be preceded by `an`: use `english-a-an-list` | ||
- the word as a string | ||
@@ -31,7 +32,7 @@ Case matters: | ||
// an | ||
console.log(englishAAn.getAAn(englishAAnList, 'English')); | ||
console.log(englishAAn.getAAn(null, englishAAnList, 'English')); | ||
// a | ||
console.log(englishAAn.getAAn(englishAAnList, 'European')); | ||
console.log(englishAAn.getAAn(null, englishAAnList, 'European')); | ||
``` | ||
@@ -43,22 +43,29 @@ const assert = require('assert'); | ||
describe('english-a-an', function() { | ||
describe('nominal', function() { | ||
for (let i = 0; i < testCases.length; i++) { | ||
const testCase = testCases[i]; | ||
const splitted = testCase.split(' '); | ||
const expected = splitted[0]; | ||
const word = splitted[1]; | ||
it(`${testCase}`, function() { | ||
assert.equal(EnglishAAn.getAAn(EnglishAAnList, word), expected); | ||
describe('english-a-an', function () { | ||
describe('nominal', function () { | ||
describe('using standard list', function () { | ||
for (let i = 0; i < testCases.length; i++) { | ||
const testCase = testCases[i]; | ||
const splitted = testCase.split(' '); | ||
const expected = splitted[0]; | ||
const word = splitted[1]; | ||
it(`${testCase}`, function () { | ||
assert.equal(EnglishAAn.getAAn(null, EnglishAAnList, word), expected); | ||
}); | ||
} | ||
}); | ||
describe('using specific list', function () { | ||
it(`a intelligent`, function () { | ||
assert.equal(EnglishAAn.getAAn({ intelligent: { aan: 'a' } }, EnglishAAnList, 'intelligent'), 'a'); | ||
}); | ||
} | ||
}); | ||
}); | ||
describe('edge cases', function() { | ||
it('empty list is ok', function() { | ||
assert.equal(EnglishAAn.getAAn(null, 'boy'), 'a'); | ||
describe('edge cases', function () { | ||
it('empty list is ok', function () { | ||
assert.equal(EnglishAAn.getAAn(null, null, 'boy'), 'a'); | ||
}); | ||
it('empty word not ok', function() { | ||
assert.throws(() => EnglishAAn.getAAn(EnglishAAnList, null), /text/); | ||
it('empty word not ok', function () { | ||
assert.throws(() => EnglishAAn.getAAn(null, EnglishAAnList, null), /text/); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49681
608
37