-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(inflector): fix and improve support for inflector
Added test to inflector, fixs issues while inflecting, added more options to inflections
- Loading branch information
1 parent
38d31f5
commit 78be90c
Showing
2 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
import * as i from 'i'; | ||
|
||
const inflector = i(); | ||
const inflections = requireSafe(ProyPath('config', 'inflections'), { | ||
const inflections = Object.assign({}, { | ||
plural: [], | ||
irregular: [], | ||
singular: [], | ||
uncontable: [] | ||
uncountable: [] | ||
}, requireSafe(ProyPath('config', 'inflections'), {})); | ||
|
||
let uncountable = inflections.uncountable.map((inflection) => { | ||
return [inflection, `/${inflection}/`] | ||
}); | ||
|
||
inflections.singular.forEach((inflect) => { | ||
inflector.inflections.singular(inflect[1], inflect[0]); | ||
}); | ||
|
||
let irregular = (inflections.plural || []) | ||
.concat(inflections.singular || []) | ||
.concat(inflections.irregular || []), | ||
uncontable = (inflections.uncountable || []).map((inflection) => { | ||
return `/${inflection}/` | ||
}); | ||
irregular.forEach((inflect) => { | ||
inflections.plural.forEach((inflect) => { | ||
inflector.inflections.irregular(inflect[0], inflect[1]); | ||
}); | ||
uncontable.forEach((inflect) => { | ||
|
||
inflections.irregular.forEach((inflect) => { | ||
inflector.inflections.irregular(inflect[0], inflect[1]); | ||
}); | ||
|
||
uncountable.forEach((inflect) => { | ||
console.log(inflect) | ||
inflector.inflections.uncountable(inflect[0]); | ||
}); | ||
|
||
export default inflector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/*global describe, it*/ | ||
import * as assert from 'assert'; | ||
import * as fs from 'fs-extra'; | ||
|
||
let inflectorFile = ` | ||
module.exports={ | ||
plural:[['person','people']], | ||
singular:[['mice','mouse']], | ||
irregular:[['chilaquil','chilaquiles']], | ||
uncountable:['oil'] | ||
} | ||
`; | ||
|
||
fs.outputFileSync(ProyPath('config', 'inflections.js'), inflectorFile); | ||
const inflector = require('../../../src/support/inflector').default; | ||
|
||
fs.removeSync(ProyPath('config')); | ||
|
||
describe('Inflector', function() { | ||
it('person <-> people', function() { | ||
assert.equal("person", inflector.singularize('people'), 'singular'); | ||
assert.equal("people", inflector.pluralize('person'), 'plural'); | ||
}); | ||
|
||
it('mice <-> mouse', function() { | ||
assert.equal("mouse", inflector.singularize('mice'), 'singular'); | ||
assert.equal("mice", inflector.pluralize('mouse'), 'plural'); | ||
}); | ||
it('chilaquil <-> chilaquiles', function() { | ||
assert.equal("chilaquil", inflector.singularize('chilaquiles'), 'singular'); | ||
assert.equal("chilaquiles", inflector.pluralize('chilaquil'), 'plural'); | ||
}); | ||
it('oil <-> oil', function() { | ||
assert.equal("oil", inflector.singularize('oil'), 'singular'); | ||
assert.equal("oil", inflector.pluralize('oil'), 'plural'); | ||
}); | ||
|
||
}); |